You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

541 lines
18 KiB

  1. <?php
  2. /**
  3. * 鏁版嵁搴撹〃绫? cms_category_prod
  4. * ============================================================================
  5. * * 鐗堟潈鎵?鏈? 铚樿洓鍑鸿 * *
  6. * 缃戠珯鍦板潃: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 杩欎笉鏄竴涓嚜鐢辫蒋浠讹紒鎮ㄥ彧鑳藉湪涓嶇敤浜庡晢涓氱洰鐨勭殑鍓嶆彁涓嬪绋嬪簭浠g爜杩涜淇敼鍜?
  9. * 浣跨敤锛涗笉鍏佽瀵圭▼搴忎唬鐮佷互浠讳綍褰㈠紡浠讳綍鐩殑鐨勫啀鍙戝竷銆?
  10. * ============================================================================
  11. * Author By: 鍊畻閿?
  12. * PhpStorm LoginController.php
  13. * Create By 2017/06/13 14:27 $
  14. */
  15. namespace common\models;
  16. use common\util\Util;
  17. use yii\db\ActiveRecord;
  18. use yii\db\Expression;
  19. /**
  20. * 鏁版嵁搴撹〃绫? cms_category_prod.
  21. * @property integer $id
  22. * @property integer $prod_cate_id
  23. * @property integer $cms_cate_id
  24. * @property integer $show_sort
  25. * @property integer $delete_flag
  26. * @property string $create_time
  27. * @property string $update_time
  28. * @property string $update_user
  29. */
  30. class CmsCategoryProd extends ActiveRecord
  31. {
  32. /**
  33. * @inheritdoc
  34. */
  35. public static function tableName()
  36. {
  37. return 'cms_category_prod';
  38. }
  39. /**
  40. * @inheritdoc
  41. */
  42. public function rules()
  43. {
  44. return [
  45. [['prod_cate_id', 'cms_cate_id', 'show_sort', 'delete_flag', 'system'], 'integer'],
  46. [['cms_cate_id'], 'required'],
  47. [['create_time', 'update_time'], 'safe'],
  48. [['update_user'], 'string', 'max' => 50],
  49. ];
  50. }
  51. /**
  52. * @inheritdoc
  53. */
  54. public function attributeLabels()
  55. {
  56. return [
  57. 'id' => 'ID',
  58. 'prod_cate_id' => 'Prod Cate ID',
  59. 'cms_cate_id' => 'Cms Cate ID',
  60. 'show_sort' => 'Show Sort',
  61. 'delete_flag' => 'Delete Flag',
  62. 'create_time' => 'Create Time',
  63. 'update_time' => 'Update Time',
  64. 'update_user' => 'Update User',
  65. 'system' => 'System',
  66. ];
  67. }
  68. /*
  69. * 获取子产品列表
  70. */
  71. public function getChildProdList($param)
  72. {
  73. $page_size = $param['page_size'];
  74. $current_page = $param['current_page'];
  75. $system_id = $param['system_id'];
  76. $cms_category_id = $param['cms_category_id'];
  77. $where = [
  78. 'and',
  79. ['=', 'a.delete_flag', 0],
  80. ['=', 'a.system', $system_id],
  81. ['=', 'a.cms_cate_id', $cms_category_id],
  82. ['=', 'b.delete_flag', 0],
  83. ['!=', 'b.show_img', '']
  84. ];
  85. $offset = ($current_page - 1) * $page_size;
  86. $select = [
  87. 'a.prod_cate_id',
  88. 'a.show_sort',
  89. 'b.pro_cate_name'
  90. ];
  91. $result = self::find()->select($select)
  92. ->from(self::tableName() . ' a')
  93. ->innerJoin(ProdCategory::tableName() . ' b', 'b.pro_cate_id = a.prod_cate_id')
  94. ->where($where)
  95. ->groupBy('a.prod_cate_id')
  96. ->orderBy('a.show_sort DESC')
  97. ->offset($offset)
  98. ->limit((int)$page_size)
  99. ->asArray()
  100. ->all();
  101. $result1 = self::find()->select('count(1) as count')
  102. ->from(self::tableName() . ' a')
  103. ->leftJoin(ProdCategory::tableName() . ' b', 'b.pro_cate_id = a.prod_cate_id')
  104. ->asArray()
  105. ->where($where)
  106. ->one();
  107. $result1 = $result1['count'];
  108. return ['list' => $result, 'count' => $result1];
  109. }
  110. /*
  111. * 选择产品
  112. */
  113. public function selectProd($param)
  114. {
  115. $pro_cate_id = $param['pro_cate_id'];
  116. $system_id = $param['system_id'];
  117. $cms_cate_id = $param['cms_cate_id'];
  118. $values = [
  119. 'cms_cate_id' => $cms_cate_id,
  120. 'system' => $system_id,
  121. 'create_time' => date('Y-m-d H:i:s'),
  122. 'show_sort' => 1000,
  123. 'delete_flag' => 0,
  124. 'prod_cate_id' => $pro_cate_id
  125. ];
  126. $this->attributes = $values;
  127. $flag = $this->insert();
  128. return $flag;
  129. }
  130. /*
  131. * 取消或删除产品
  132. */
  133. public function cancelSelectProd($param)
  134. {
  135. $pro_cate_id = $param['pro_cate_id'];
  136. $system_id = $param['system_id'];
  137. $cms_cate_id = $param['cms_cate_id'];
  138. $tab = clone $this;
  139. $flag = $tab::deleteAll(['and', ['=', 'system', $system_id], ['=', 'cms_cate_id', $cms_cate_id], ['=', 'prod_cate_id', $pro_cate_id]]);
  140. return $flag;
  141. }
  142. /*
  143. * 修改子产品排序
  144. */
  145. public function changeProdSort($param)
  146. {
  147. $system_id = $param['system_id'];
  148. $cms_cate_id = $param['cms_cate_id'];
  149. $show_sort = $param['show_sort'];
  150. $prod_cate_id = $param['prod_cate_id'];
  151. $flag = self::updateAll(['show_sort' => $show_sort, 'update_time' => date('Y-m-d H:i:s')], ['and', ['=', 'system', $system_id], ['=', 'cms_cate_id', $cms_cate_id], ['=', 'prod_cate_id', $prod_cate_id], ['=', 'delete_flag', 0]]);
  152. return $flag;
  153. }
  154. /*
  155. * ************************C端接口
  156. *
  157. * */
  158. /**
  159. * Des:获取首页产品数据
  160. * Name: getHomePro
  161. * @param $cmsArr
  162. * @return array|ActiveRecord[]
  163. * @author 倪宗锋
  164. */
  165. public function getHomePro($cmsArr)
  166. {
  167. $where = [
  168. 'and',
  169. ['=', 'a.delete_flag', 0],
  170. ['=', 'a.system', 2],
  171. ['=', 'a.cms_cate_id', $cmsArr['cms_id']],
  172. ['!=', 'b.show_img', ''],
  173. ['=', 'b.delete_flag', 0]
  174. ];
  175. $select = [
  176. 'b.pro_cate_id',
  177. 'b.pro_cate_name',
  178. 'b.show_price',
  179. 'b.star',
  180. 'b.show_img',
  181. 'b.sales_count',
  182. 'b.original_price',
  183. 'b.category_id',
  184. '(select category_name from base_category as c where c.category_id = b.category_id) as category_name'
  185. ];
  186. $result = self::find()->select($select)
  187. ->from(self::tableName() . ' a')
  188. ->innerJoin(ProdCategory::tableName() . ' b', 'b.pro_cate_id = a.prod_cate_id')
  189. ->where($where)
  190. ->groupBy('a.prod_cate_id')
  191. ->orderBy('a.show_sort DESC')
  192. ->limit($cmsArr['cnt'])
  193. ->asArray()
  194. ->all();
  195. return $result;
  196. }
  197. //猜你喜欢
  198. public function getLikeList()
  199. {
  200. $where = ['and', ['=', 'a.delete_flag', 0], ['=', 'a.system', 2], ['=', 'a.cms_cate_id', 106]];
  201. $select = [
  202. 'b.pro_cate_id',
  203. 'b.pro_cate_name',
  204. 'b.show_price',
  205. 'b.star',
  206. 'b.show_img',
  207. 'b.sales_count',
  208. 'b.original_price',
  209. 'b.category_id',
  210. '(select category_name from base_category as c where c.category_id = b.category_id) as category_name'
  211. ];
  212. $result = self::find()->select($select)
  213. ->from(self::tableName() . ' a')
  214. ->innerJoin(ProdCategory::tableName() . ' b', 'b.pro_cate_id = a.prod_cate_id')
  215. ->where($where)
  216. ->groupBy('a.prod_cate_id')
  217. ->orderBy('a.show_sort DESC')
  218. ->limit(3)
  219. ->asArray()
  220. ->all();
  221. foreach ($result as &$v) {
  222. $v['show_price'] = $this->dealFloat($v['show_price']);
  223. }
  224. return $result;
  225. }
  226. //精品推荐
  227. public function getRecommendList($config)
  228. {
  229. $where = ['and', ['=', 'a.delete_flag', 0], ['=', 'b.delete_flag', 0], ['=', 'c.delete_flag', 0], ['=', 'a.system', 2], ['=', 'a.cms_cate_id', $config['cms_id']], ['!=', 'b.category_id', 1]];
  230. $select = [
  231. 'b.pro_cate_id',
  232. 'b.pro_cate_name',
  233. 'b.show_price',
  234. 'show_img' => new Expression("CONCAT(b.show_img,'.min',RIGHT(b.show_img,LOCATE('.', REVERSE(b.show_img))))"),
  235. 'b.original_price',
  236. 'b.category_id',
  237. 'c.category_name',
  238. 'comment_count' => new Expression('(select count(id) from prod_comment where prod_id=b.pro_cate_id)'),
  239. 'b.sales_count',
  240. 'b.star'
  241. ];
  242. $result = self::find()->select($select)
  243. ->from(self::tableName() . ' a')
  244. ->innerJoin(ProdCategory::tableName() . ' b', 'b.pro_cate_id = a.prod_cate_id')
  245. ->leftJoin(BaseCategory::tableName() . ' c', 'c.category_id = b.category_id')
  246. ->where($where)
  247. ->groupBy('a.prod_cate_id')
  248. ->orderBy('a.show_sort DESC,a.prod_cate_id')
  249. ->limit($config['cnt'])
  250. ->asArray()
  251. ->all();
  252. foreach ($result as &$v) {
  253. $v['show_price'] = $this->dealFloat($v['show_price']);
  254. }
  255. return $result;
  256. }
  257. public function getShowProdList($prodIds)
  258. {
  259. $where = [
  260. 'and',
  261. ['=', 'b.delete_flag', 0],
  262. ['=', 'c.delete_flag', 0],
  263. ['!=', 'b.category_id', 1],
  264. ['in', 'b.pro_cate_id', explode(",", $prodIds)]
  265. ];
  266. $select = [
  267. 'b.pro_cate_id',
  268. 'b.pro_cate_name',
  269. 'b.show_price',
  270. 'show_img' => new Expression("CONCAT(b.show_img,'.min',RIGHT(b.show_img,LOCATE('.', REVERSE(b.show_img))))"),
  271. 'b.original_price',
  272. 'b.category_id',
  273. 'c.category_name',
  274. 'comment_count' => new Expression('(select count(id) from prod_comment where prod_id=b.pro_cate_id)'),
  275. 'b.sales_count',
  276. 'b.star'
  277. ];
  278. $result = self::find()->select($select)
  279. ->from(ProdCategory::tableName() . ' b')
  280. ->leftJoin(BaseCategory::tableName() . ' c', 'c.category_id = b.category_id')
  281. ->where($where)
  282. ->groupBy('b.pro_cate_id')
  283. ->orderBy('b.pro_cate_id DESC')
  284. ->asArray()
  285. ->all();
  286. foreach ($result as &$v) {
  287. $v['show_price'] = $this->dealFloat($v['show_price']);
  288. }
  289. return $result;
  290. }
  291. /**
  292. * Des:获取门票数据列表
  293. * Name: getCatCold
  294. * @param $param
  295. * @return array
  296. * @author 孙彤
  297. */
  298. public function getProdForDestination($param)
  299. {
  300. $select = [
  301. 'b.prod_cate_id',
  302. 'd.category_name',
  303. 'c.pro_cate_name',
  304. 'c.star',
  305. 'c.prod_des',
  306. 'c.category_id',
  307. 'c.show_price',
  308. 'c.original_price',
  309. 'c.show_img',
  310. 'c.sales_count',
  311. ];
  312. $where = [
  313. 'and',
  314. ['=', 'b.cms_cate_id', $param['cms_category_id']],
  315. ['=', 'c.delete_flag', 0]
  316. ];
  317. if (empty($param['prod_name']) == false) {
  318. $where[] = ['like', 'c.pro_cate_name', $param['prod_name']];
  319. }
  320. $list = self::find()->select($select)
  321. ->from(self::tableName() . ' b')
  322. ->innerJoin(CmsCategory::tableName() . ' a', 'b.cms_cate_id=a.cms_category_id')
  323. ->innerJoin(ProdCategory::tableName() . ' c', 'c.pro_cate_id = b.prod_cate_id')
  324. ->innerJoin(BaseCategory::tableName() . ' d', 'c.category_id=d.category_id')
  325. ->where($where)
  326. ->orderBy('b.show_sort DESC')
  327. ->asArray()
  328. ->all();
  329. if (empty($list['0'])) {
  330. return [];
  331. } else {
  332. foreach ($list as &$v) {
  333. $v['show_price'] = $this->dealFloat($v['show_price']);
  334. $v['original_price'] = $this->dealFloat($v['original_price']);
  335. }
  336. }
  337. return $list;
  338. }
  339. /**
  340. * Function Description:根据cms_category_id获取当地玩乐一日游信息
  341. * Function Name: getOneDayTrip
  342. * @param $categoryId
  343. * @return array|ActiveRecord[]
  344. * @author 田玲菲
  345. */
  346. public function getOneDayTrip($categoryId)
  347. {
  348. $select = [
  349. 'b.prod_cate_id',
  350. 'd.category_name',
  351. 'c.pro_cate_name',
  352. 'c.star',
  353. 'c.prod_des',
  354. 'c.category_id',
  355. 'c.show_price',
  356. 'c.original_price',
  357. 'show_img' => new Expression('concat(c.show_img,".min.jpg")'),
  358. 'c.sales_count',
  359. 'comment_count' => new Expression('(select count(id) from prod_comment where prod_id=c.pro_cate_id)'),
  360. ];
  361. $where = [
  362. 'and',
  363. ['=', 'b.cms_cate_id', $categoryId],
  364. ['=', 'c.delete_flag', 0],
  365. ['=', 'd.category_id', 4]
  366. ];
  367. $list = self::find()->select($select)
  368. ->from(self::tableName() . ' b')
  369. ->innerJoin(CmsCategory::tableName() . ' a', 'b.cms_cate_id=a.cms_category_id and a.system = 2')
  370. ->innerJoin(ProdCategory::tableName() . ' c', 'c.pro_cate_id = b.prod_cate_id')
  371. ->innerJoin(BaseCategory::tableName() . ' d', 'c.category_id=d.category_id')
  372. ->where($where)
  373. ->orderBy('b.show_sort DESC')
  374. ->asArray()
  375. ->all();
  376. if (empty($list['0'])) {
  377. return [];
  378. } else {
  379. foreach ($list as &$v) {
  380. $v['show_price'] = $this->dealFloat($v['show_price']);
  381. $v['original_price'] = $this->dealFloat($v['original_price']);
  382. }
  383. }
  384. return $list;
  385. }
  386. /**
  387. * Function Description:根据cms_category_id获取当地玩乐门票信息
  388. * Function Name: getTicket
  389. * @param $categoryId
  390. * @return array|ActiveRecord[]
  391. * @author 田玲菲
  392. */
  393. public function getTicket($categoryId)
  394. {
  395. $food_list = self::find()->select('prod_cate_id')->from(self::tableName())
  396. ->where(['and', ['=', 'delete_flag', 0], ['=', 'system', 2], ['=', 'cms_cate_id', 127]])->indexBy('prod_cate_id')->asArray()->all();
  397. $food_list = array_keys($food_list);
  398. $select = [
  399. 'b.prod_cate_id',
  400. 'd.category_name',
  401. 'c.pro_cate_name',
  402. 'c.star',
  403. 'c.prod_des',
  404. 'c.category_id',
  405. 'c.show_price',
  406. 'c.original_price',
  407. 'show_img' => new Expression('concat(c.show_img,".min.jpg")'),
  408. 'c.sales_count',
  409. 'comment_count' => new Expression('(select count(id) from prod_comment where prod_id=c.pro_cate_id)'),
  410. ];
  411. $where = [
  412. 'and',
  413. ['=', 'b.cms_cate_id', $categoryId],
  414. ['=', 'c.delete_flag', 0],
  415. ['=', 'd.category_id', 2],
  416. ['!=', 'a.cms_category_id', 127],
  417. ['not in', 'b.prod_cate_id', $food_list]
  418. ];
  419. $list = self::find()->select($select)
  420. ->from(self::tableName() . ' b')
  421. ->innerJoin(CmsCategory::tableName() . ' a', 'b.cms_cate_id=a.cms_category_id and a.system = 2')
  422. ->innerJoin(ProdCategory::tableName() . ' c', 'c.pro_cate_id = b.prod_cate_id')
  423. ->innerJoin(BaseCategory::tableName() . ' d', 'c.category_id=d.category_id')
  424. ->where($where)
  425. ->orderBy('b.show_sort DESC')
  426. ->asArray()
  427. ->all();
  428. if (empty($list['0'])) {
  429. return [];
  430. } else {
  431. foreach ($list as &$v) {
  432. $v['show_price'] = $this->dealFloat($v['show_price']);
  433. $v['original_price'] = $this->dealFloat($v['original_price']);
  434. }
  435. }
  436. return $list;
  437. }
  438. /**
  439. * Function Description:根据cms_category_id获取当地玩乐美食娱乐的列表
  440. * Function Name: getFoodList
  441. * @param $categoryId
  442. * @return array|ActiveRecord[]
  443. * @author 田玲菲
  444. */
  445. public function getFoodList($categoryId)
  446. {
  447. $cmcCategory = new CmsCategory();
  448. $foodId = $cmcCategory->getFoodId();
  449. if (!isset($foodId['cms_category_id'])) {
  450. $foodId['cms_category_id'] = 0;
  451. }
  452. $select = [
  453. 'b.prod_cate_id',
  454. 'd.category_name',
  455. 'c.pro_cate_name',
  456. 'c.star',
  457. 'c.prod_des',
  458. 'c.category_id',
  459. 'c.show_price',
  460. 'c.original_price',
  461. 'show_img' => new Expression('concat(c.show_img,".min.jpg")'),
  462. 'c.sales_count',
  463. 'comment_count' => new Expression('(select count(id) from prod_comment where prod_id=c.pro_cate_id)'),
  464. ];
  465. $where = [
  466. 'and',
  467. ['=', 'b.cms_cate_id', $categoryId],
  468. ['=', 'c.delete_flag', 0],
  469. ];
  470. $list = self::find()->select($select)
  471. ->from(self::tableName() . ' b')
  472. ->innerJoin(self::tableName() . ' e', 'e.prod_cate_id = b.prod_cate_id and e.cms_cate_id = ' . $foodId['cms_category_id'])
  473. // ->innerJoin(self::tableName() . ' e')
  474. ->innerJoin(CmsCategory::tableName() . ' a', 'b.cms_cate_id=a.cms_category_id and a.system = 2')
  475. ->innerJoin(ProdCategory::tableName() . ' c', 'c.pro_cate_id = b.prod_cate_id')
  476. ->innerJoin(BaseCategory::tableName() . ' d', 'c.category_id=d.category_id')
  477. ->where($where)
  478. ->orderBy('b.show_sort DESC')
  479. ->asArray()
  480. ->all();
  481. if (empty($list['0'])) {
  482. return [];
  483. } else {
  484. foreach ($list as &$v) {
  485. $v['show_price'] = $this->dealFloat($v['show_price']);
  486. $v['original_price'] = $this->dealFloat($v['original_price']);
  487. }
  488. }
  489. return $list;
  490. }
  491. /**
  492. * Function Description:处理价格
  493. * Function Name: dealFloat
  494. * @param $float
  495. *
  496. * @return float
  497. *
  498. * @author LUOCJ
  499. */
  500. public function dealFloat($float)
  501. {
  502. $int = floor($float);
  503. if ($float - $int == 0) {
  504. $float = $int;
  505. }
  506. return $float;
  507. }
  508. }