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.

ProdCategory.php 30 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. <?php
  2. namespace common\models;
  3. use common\util\OrderUtil;
  4. use common\util\Util;
  5. use Yii;
  6. use yii\base\Exception;
  7. use yii\db\ActiveRecord;
  8. use yii\db\Expression;
  9. /**
  10. * This is the model class for table "prod_category".
  11. *
  12. * @property integer $pro_cate_id
  13. * @property string $pro_cate_name
  14. * @property integer $category_id
  15. * @property string $show_price
  16. * @property string $show_img
  17. * @property integer $sales_count
  18. * @property string $memo
  19. * @property string $commission
  20. * @property integer $create_user_id
  21. * @property integer $is_recom
  22. * @property string $create_time
  23. * @property string $update_time
  24. * @property integer $delete_flag
  25. * @property string $update_user
  26. * @property string $address
  27. * @property integer $bus_ticket_id
  28. * @property integer $bus_line_type
  29. */
  30. class ProdCategory extends ActiveRecord
  31. {
  32. /**
  33. * @inheritdoc
  34. */
  35. public static function tableName()
  36. {
  37. return 'prod_category';
  38. }
  39. /**
  40. * @inheritdoc
  41. */
  42. public function rules()
  43. {
  44. return [
  45. [['pro_cate_name'], 'required'],
  46. [['prod_des', 'memo', 'trip_desc', 'feature'], 'string'],
  47. [['category_id', 'show_price', 'original_price', 'sales_count', 'commission', 'create_user_id', 'is_recom', 'delete_flag', 'bus_ticket_id', 'bus_line_type'], 'integer'],
  48. [['show_price', 'original_price'], 'number'],
  49. [['create_time', 'update_time'], 'safe'],
  50. [['sign', 'show_img', 'start_area', 'address'], 'string', 'max' => 255],
  51. [['pro_cate_name'], 'string', 'max' => 100],
  52. [['close_sale_time', 'update_user'], 'string', 'max' => 50],
  53. [['star'], 'string', 'max' => 4],
  54. ];
  55. }
  56. /**
  57. * @inheritdoc
  58. */
  59. public function attributeLabels()
  60. {
  61. return [
  62. 'pro_cate_id' => 'Pro Cate ID',
  63. 'sign' => 'Sign',
  64. 'pro_cate_name' => 'Pro Cate Name',
  65. 'prod_des' => 'Prod Des',
  66. 'category_id' => 'Category ID',
  67. 'show_price' => 'Show Price',
  68. 'original_price' => 'Original Price',
  69. 'show_img' => 'Show Img',
  70. 'sales_count' => 'Sales Count',
  71. 'memo' => 'Memo',
  72. 'trip_desc' => 'Trip Desc',
  73. 'feature' => 'Feature',
  74. 'commission' => 'Commission',
  75. 'create_user_id' => 'Create User ID',
  76. 'is_recom' => 'Is Recom',
  77. 'start_area' => 'Start Area',
  78. 'address' => 'Address',
  79. 'close_sale_time' => 'Close Sale Time',
  80. 'star' => 'Star',
  81. 'create_time' => 'Create Time',
  82. 'update_time' => 'Update Time',
  83. 'delete_flag' => 'Delete Flag',
  84. 'update_user' => 'Update User',
  85. 'bus_ticket_id' => 'Bus Ticket ID',
  86. 'bus_line_type' => 'Bus Line Type',
  87. ];
  88. }
  89. /*
  90. * 后台产品列表
  91. */
  92. public function AdminGetList($param)
  93. {
  94. $where = ['and', ['=', 'a.delete_flag', 0]];
  95. if ($param['category_id'] != '') {
  96. $where[] = ['=', 'a.category_id', $param['category_id']];
  97. }
  98. $keywords = $param['pro_cate_name_keywords'];
  99. if ($param['pro_cate_name_keywords'] != '') {
  100. $where[] = ['or', ['like', 'pro_cate_name', "$keywords"], ['like', 'pro_cate_id', $keywords]];
  101. }
  102. if ($param['bs_type'] == 1) {
  103. $where[] = ['=', 'a.category_id', '1'];
  104. $where[] = ['is', 'a.sign', null];
  105. } else if ($param['bs_type'] == 2) {
  106. $where[] = ['=', 'a.category_id', '1'];
  107. $where[] = ['is not', 'a.sign', null];
  108. }
  109. $offset = ($param['current_page'] - 1) * $param['page_size'];
  110. $select = [
  111. 'pro_cate_id',
  112. 'a.category_id',
  113. "if(a.category_id=1,if(a.sign is not null,concat(c.category_name,'(主线路)'),concat(c.category_name,'(子线路)')),c.category_name) as base_category",
  114. 'pro_cate_name', 'close_sale_time',
  115. 'memo', "IFNULL(prod_des, '') prod_des",
  116. 'original_price', 'show_price',
  117. 'commission', 'show_img',
  118. 'IFNULL(trip_desc, \'\') trip_desc'
  119. ];
  120. $result = self::find()->select($select)
  121. ->from(self::tableName() . ' a')
  122. ->innerJoin(BaseCategory::tableName() . ' c', 'c.category_id = a.category_id')
  123. ->where($where)
  124. ->groupBy('a.pro_cate_id')
  125. ->orderBy('a.pro_cate_id DESC')
  126. ->offset($offset)
  127. ->limit((int)$param['page_size'])
  128. ->asArray()
  129. ->all();
  130. $result1 = self::find()->select('count(1) as count')
  131. ->from(self::tableName() . ' a')
  132. ->leftJoin('base_category as b', 'b.category_id=a.category_id')
  133. ->asArray()
  134. ->where($where)
  135. ->one();
  136. $result1 = $result1['count'];
  137. return ['list' => $result, 'count' => $result1];
  138. }
  139. //修改原价
  140. public function updateOriginalPrice($param)
  141. {
  142. $where = ['and', ['=', 'delete_flag', 0]];
  143. $pro_cate_id = $param['pro_cate_id'];
  144. $original_price = $param['original_price'];
  145. $where[] = ['=', 'pro_cate_id', $pro_cate_id];
  146. // self::updateAll(['commission' => $commission], ['and', ['=', 'pro_cate_id', $pro_cate_id]]);
  147. $count = self::updateAll(['original_price' => $original_price], $where);
  148. return $count;
  149. }
  150. //修改展示价
  151. public function updateShowPrice($param)
  152. {
  153. $where = ['and', ['=', 'delete_flag', 0]];
  154. $pro_cate_id = $param['pro_cate_id'];
  155. $show_price = $param['show_price'];
  156. $where[] = ['=', 'pro_cate_id', $pro_cate_id];
  157. // self::updateAll(['commission' => $commission], ['and', ['=', 'pro_cate_id', $pro_cate_id]]);
  158. $count = self::updateAll(['show_price' => $show_price], $where);
  159. return $count;
  160. }
  161. /*
  162. * 給銷售終端產品管理的產品庫列表
  163. *
  164. */
  165. public function toClientProdList($param)
  166. {
  167. $where = ['and', ['=', 'a.delete_flag', 0]];
  168. if ($param['category_id'] != '') {
  169. $where[] = ['=', 'a.category_id', $param['category_id']];
  170. }
  171. $keywords = $param['pro_cate_name'];
  172. if ($param['pro_cate_name'] != '') {
  173. $where[] = ['or', ['like', 'pro_cate_name', "$keywords"], ['like', 'pro_cate_id', $keywords]];
  174. }
  175. $offset = ($param['current_page'] - 1) * $param['page_size'];
  176. $select = [
  177. 'pro_cate_id',
  178. 'a.category_id',
  179. "if(a.category_id=1,if(a.sign is not null,concat(c.category_name,'(主线路)'),concat(c.category_name,'(子线路)')),c.category_name) as base_category",
  180. 'pro_cate_name'
  181. ];
  182. $result = self::find()->select($select)
  183. ->from(self::tableName() . ' a')
  184. ->innerJoin(BaseCategory::tableName() . ' c', 'c.category_id = a.category_id')
  185. ->where($where)
  186. ->groupBy('a.pro_cate_id')
  187. ->orderBy('a.pro_cate_id DESC')
  188. ->offset($offset)
  189. ->limit((int)$param['page_size'])
  190. ->asArray()
  191. ->all();
  192. $result1 = self::find()->select('count(1) as count')
  193. ->from(self::tableName() . ' a')
  194. ->leftJoin('base_category as b', 'b.category_id=a.category_id')
  195. ->asArray()
  196. ->where($where)
  197. ->one();
  198. $result1 = $result1['count'];
  199. return ['list' => $result, 'count' => $result1];
  200. }
  201. /*
  202. * 自定义佣金
  203. */
  204. public function DefineCommission($pro_cate_id, $commission)
  205. {
  206. $count = self::updateAll(['commission' => $commission], ['and', ['=', 'pro_cate_id', $pro_cate_id]]);
  207. return $count;
  208. }
  209. /*
  210. * Des:设置产品佣金 (根据prod_cate_id)
  211. * Name: setProdCommissionByCateId
  212. * @param $param
  213. * @return int
  214. * @author 付泓程
  215. */
  216. public function setProdCommissionByCateId($param)
  217. {
  218. $commission = $param['commission'];
  219. $prod_cate_id = $param['prod_cate_id'];
  220. $count = $this->updateAll(['commission' => $commission], ['and', ['=', 'prod_cate_id', $prod_cate_id], ['=', 'delete_flag', '0']]);
  221. return $count;
  222. }
  223. /*
  224. * Des:设置产品佣金 (根据prod_id)
  225. * Name: setProdCommissionByProdId
  226. * @param $param
  227. * @return int
  228. * @author 付泓程
  229. */
  230. public function setProdCommissionByProdId($param)
  231. {
  232. $commission = $param['commission'];
  233. $prod_id = $param['prod_id'];
  234. $count = $this->updateAll(['commission' => $commission], ['and', ['=', 'prod_id', $prod_id], ['=', 'delete_flag', '0']]);
  235. return $count;
  236. }
  237. /*
  238. * 添加产品
  239. */
  240. public function addProd($param)
  241. {
  242. $values = [
  243. 'category_id' => $param['category_id'],
  244. 'pro_cate_name' => $param['pro_cate_name'],
  245. 'memo' => $param['memo'],
  246. 'sales_count' => rand(1, 10),
  247. 'show_img' => $param['show_img'],
  248. 'create_time' => date('Y-m-d H:i:s'),
  249. 'prod_des' => $param['prod_des'],
  250. 'trip_desc' => $param['trip_desc'],
  251. 'close_sale_time' => $param['close_sale_time'], //截止售卖时间 2017-05-18 fuhc
  252. 'star' => '3.5'
  253. ];
  254. $transaction = Yii::$app->db->beginTransaction();
  255. try {
  256. $this->attributes = $values;
  257. $res = $this->insert(false);
  258. if (!$res) {
  259. return false;
  260. }
  261. $transaction->commit();
  262. return true;
  263. } catch (Exception $e) {
  264. $transaction->rollBack();
  265. return false;
  266. }
  267. }
  268. /*
  269. * 后台修改产品信息
  270. */
  271. public function uptAdminProd($param)
  272. {
  273. $values = [
  274. 'category_id' => $param['category_id'],
  275. 'pro_cate_name' => $param['pro_cate_name'],
  276. 'memo' => $param['memo'],
  277. 'show_img' => $param['show_img'],
  278. 'prod_des' => $param['prod_des'],
  279. 'trip_desc' => $param['trip_desc'],
  280. 'update_time' => date('Y-m-d H:i:s'),
  281. 'close_sale_time' => $param['close_sale_time'] //截止售卖时间 2017-05-18 fuhc
  282. ];
  283. $transaction = Yii::$app->db->beginTransaction();
  284. try {
  285. $count = self::updateAll($values, ['=', 'pro_cate_id', $param['pro_cate_id']]);
  286. if (!$count) {
  287. return false;
  288. }
  289. $transaction->commit();
  290. return true;
  291. } catch (Exception $e) {
  292. $transaction->rollBack();
  293. return false;
  294. }
  295. }
  296. /*
  297. * 修改show price
  298. */
  299. public function changeShowPrice($pro_cate_id)
  300. {
  301. //查当前产品的子产品最低价
  302. $show_price = ProdMain::find()->select(['min(prod_price) as price'])->from('prod_main')->where(['and', ['=', 'delete_flag', '0'], ['=', 'prod_cate_id', $pro_cate_id]])->asArray()->one();
  303. $show_price = $show_price['price'];
  304. $count = self::updateAll(['show_price' => $show_price], ['and', ['=', 'pro_cate_id', $pro_cate_id]]);
  305. return $count;
  306. }
  307. /*
  308. * 获取主产品列表
  309. */
  310. public function getMainProdList($param)
  311. {
  312. $page_size = $param['page_size'];
  313. $current_page = $param['current_page'];
  314. $system_id = $param['system_id'];
  315. $prod_name = $param['prod_name'];
  316. $where = [
  317. 'and',
  318. ['=', 'a.delete_flag', 0],
  319. ['like', 'a.pro_cate_name', $prod_name],
  320. ['!=', 'a.show_img', '']
  321. ];
  322. if (empty($param['base_category_id']) == false) {
  323. $where[] = ['=', 'a.category_id', $param['base_category_id']];
  324. }
  325. $offset = ($current_page - 1) * $page_size;
  326. $select = [
  327. 'a.pro_cate_id',
  328. 'pro_cate_name' => new Expression("concat('[',c.category_name,']',' ',if(a.category_id=1,concat('[',if(a.sign is not null,'主线路','子线路'),']'),''),' ',a.pro_cate_name)"),
  329. 'if(b.system=' . $system_id . ',0,1) as if_have',
  330. ];
  331. $result = self::find()->select($select)
  332. ->distinct()
  333. ->from(self::tableName() . ' a')
  334. ->innerJoin(BaseCategory::tableName() . ' c', 'a.category_id=c.category_id')
  335. ->leftJoin(CmsCategoryProd::tableName() . ' b', 'b.prod_cate_id = a.pro_cate_id and b.cms_cate_id=' . $param['cms_category_id'] . ' and b.system = ' . $system_id . ' and b.delete_flag = 0')
  336. ->where($where)
  337. ->orderBy('a.sign desc,a.category_id')
  338. ->offset($offset)
  339. ->limit((int)$page_size)
  340. ->asArray()
  341. ->all();
  342. $result1 = self::find()->select('count(1) as count')
  343. ->from(self::tableName() . ' a')
  344. ->where($where)
  345. ->asArray()
  346. ->one();
  347. $result1 = $result1['count'];
  348. return ['list' => $result, 'count' => $result1];
  349. }
  350. /**
  351. * Function Description:巴士产品获取详情
  352. * Function Name: getBusProdDetail
  353. * @param $pro_cate_id
  354. *
  355. * @return array|null|\yii\db\ActiveRecord
  356. *
  357. * @author 娄梦宁
  358. */
  359. public function getBusProdDetail($pro_cate_id)
  360. {
  361. $select = [
  362. 'a.pro_cate_id',
  363. 'a.pro_cate_name',
  364. "IFNULL(a.prod_des, '') prod_des",
  365. 'a.category_id',
  366. 'sign' => new Expression("ifnull(a.sign,'')"),
  367. 'a.show_img',
  368. 'IFNULL(a.close_sale_time,24) as close_sale_time',
  369. 'category_name' => new Expression("''"),
  370. "IFNULL(a.memo, '') booking_notice",
  371. "IFNULL(a.trip_desc, '') trip_desc",
  372. 'a.star',
  373. 'a.original_price',
  374. 'comment_cnt' => new Expression("ifnull(c.comment_cnt,0)"),
  375. 'a.delete_flag',
  376. 'b.start_area_name',
  377. 'b.start_area_id',
  378. 'b.start_res_name',
  379. 'b.end_res_name',
  380. 'b.end_area_name',
  381. 'b.end_area_id',
  382. ];
  383. $result = self::find()->select($select)
  384. ->from(self::tableName() . ' as a')
  385. ->leftJoin('bus_ticket b', 'a.bus_ticket_id=b.ticket_id')
  386. ->leftJoin(ProdCategoryInfo::tableName() . ' c', 'a.pro_cate_id = c.pro_cate_id')
  387. ->where(['and', ['=', 'a.pro_cate_id', $pro_cate_id]])
  388. ->asArray()
  389. ->one();
  390. return $result;
  391. }
  392. /**
  393. * Des:获取查询列表
  394. * Name: getSearchList
  395. * @param $param
  396. * @param $type
  397. * @return array
  398. * @author 倪宗锋
  399. */
  400. public function getSearchList($param, $type)
  401. {
  402. $siteConfig = Util::getSiteConfig();
  403. $where = [
  404. 'and',
  405. ['=', 'a.delete_flag', '0'],
  406. ['!=', 'a.show_img', ''],
  407. ['=', 'b.system', $siteConfig['system']],
  408. ['=', 'a.category_id', $type],
  409. ['=', 'd.delete_flag', 0]
  410. ];
  411. if (empty($param['prod_name']) == false) {//查询条件
  412. $where[] = ['like', 'a.pro_cate_name', $param['prod_name']];
  413. }
  414. if (empty($param['cms_id']) == false) {
  415. $where[] = ['=', 'b.cms_cate_id', $param['cms_id']];
  416. }
  417. $select = [
  418. 'a.category_id',
  419. 'a.pro_cate_id',
  420. 'a.pro_cate_name',
  421. 'a.show_img',
  422. 'b.system',
  423. 'c.category_name',
  424. 'a.star',
  425. 'a.original_price',
  426. 'a.show_price',
  427. 'a.sales_count',
  428. 'a.prod_des'
  429. ];
  430. $result = self::find()->select($select)
  431. ->from(self::tableName() . ' a')
  432. ->innerJoin(CmsCategoryProd::tableName() . ' b', 'b.prod_cate_id = a.pro_cate_id')
  433. ->innerJoin(BaseCategory::tableName() . ' c', 'a.category_id = c.category_id')
  434. ->innerJoin(CmsCategory::tableName() . ' d', 'b.cms_cate_id = d.cms_category_id')
  435. ->where($where)
  436. ->orderBy('b.show_sort desc')
  437. ->asArray()
  438. ->all();
  439. return $result;
  440. }
  441. /**
  442. * Des:获取bus产品记录 根据开始POI
  443. * Name: getBusProdByPoi_s
  444. * @param $params
  445. * @return array
  446. * @author 倪宗锋
  447. */
  448. public function getBusProdByPoi_s($params)
  449. {
  450. //where条件
  451. $where = ['and'];
  452. $where[] = ['=', 'a.start_area_id', $params['poi']];
  453. if (empty($params['category_id']) == false) {
  454. $where[] = ['=', 'c.cms_cate_id', $params['category_id']];
  455. }
  456. //查询字段
  457. $select = [
  458. 'b.pro_cate_name',//主线路名称
  459. 'b.pro_cate_id',//主线路ID
  460. 'a.start_area_name',//上车POI名称
  461. 'a.end_area_name',//下车POI名称
  462. 'a.start_area_id',//上册
  463. 'a.end_area_id',
  464. 'show_price' => new Expression("min(d.show_price)"),
  465. 'original_price' => new Expression("min(d.original_price)"),
  466. 'sale_count' => new Expression("SUM(d.sales_count)"),
  467. 'is_hot' => new Expression('1'),
  468. 'b.show_img',
  469. 'a.line_id'
  470. ];
  471. $start_list = self::find()->select($select)
  472. ->from(BusTicket::tableName() . ' a')
  473. ->innerJoin(ProdCategory::tableName() . ' b', 'a.line_id = b.sign and b.delete_flag =0')
  474. ->innerJoin(CmsCategoryProd::tableName() . ' c', 'c.prod_cate_id = b.pro_cate_id')
  475. ->innerJoin(ProdCategory::tableName() . ' d', 'a.ticket_id = d.bus_ticket_id and d.sign is NULL and d.delete_flag=0')
  476. ->orderBy('b.pro_cate_id desc')
  477. ->where($where)
  478. ->groupBy('a.line_id')
  479. //->createCommand()->getRawSql();
  480. ->asArray()
  481. ->all();
  482. if (empty($start_list[0])) {
  483. $return = [];
  484. } else {
  485. $return = [];
  486. foreach ($start_list as $val) {
  487. $val['show_price'] = OrderUtil::getBusDiscountPrice($val['pro_cate_id'], $val['show_price']);
  488. $return[$val['end_area_name']][$val['line_id']] = $val;
  489. }
  490. }
  491. return $return;
  492. }
  493. /**
  494. * Function Description:获取bus产品记录 根据结束POI
  495. * Function Name: getBusProdByPoi_e
  496. * @param $params
  497. *
  498. * @return array
  499. *
  500. * @author 冒炎
  501. */
  502. public function getBusProdByPoi_e($params)
  503. {
  504. //where条件
  505. $where = ['and'];
  506. $where[] = ['=', 'a.end_area_id', $params['poi']];
  507. if (empty($params['category_id']) == false) {
  508. $where[] = ['=', 'c.cms_cate_id', $params['category_id']];
  509. }
  510. //查询字段
  511. $select = [
  512. 'b.pro_cate_name',//主线路名称
  513. 'b.pro_cate_id',//主线路ID
  514. 'a.start_area_name',//上车POI名称
  515. 'a.end_area_name',//下车POI名称
  516. 'a.start_area_id',//上册
  517. 'a.end_area_id',
  518. 'show_price' => new Expression("min(d.show_price)"),
  519. 'original_price' => new Expression("min(d.original_price)"),
  520. 'sale_count' => new Expression("SUM(d.sales_count)"),
  521. 'is_hot' => new Expression('1'),
  522. 'b.show_img',
  523. 'a.line_id'
  524. ];
  525. $start_list = self::find()->select($select)
  526. ->from(BusTicket::tableName() . ' a')
  527. ->innerJoin(ProdCategory::tableName() . ' b', 'a.line_id = b.sign and b.delete_flag =0')
  528. ->innerJoin(CmsCategoryProd::tableName() . ' c', 'c.prod_cate_id = b.pro_cate_id')
  529. ->innerJoin(ProdCategory::tableName() . ' d', 'a.ticket_id = d.bus_ticket_id and d.sign is NULL and d.delete_flag=0')
  530. ->orderBy('b.pro_cate_id desc')
  531. ->where($where)
  532. ->groupBy('a.line_id')
  533. //->createCommand()->getRawSql();
  534. ->asArray()
  535. ->all();
  536. if (empty($start_list[0])) {
  537. $return = [];
  538. } else {
  539. $return = [];
  540. foreach ($start_list as $val) {
  541. $val['show_price'] = OrderUtil::getBusDiscountPrice($val['pro_cate_id'], $val['show_price']);
  542. $return[$val['start_area_name']][$val['line_id']] = $val;
  543. }
  544. }
  545. return $return;
  546. }
  547. /**
  548. * Function Description:根据票种id获取对应的子线路产品
  549. * Function Name: getBusProdByTicket
  550. * @param $ticket_id
  551. *
  552. * @return array|null|ActiveRecord
  553. *
  554. * @author 冒炎
  555. */
  556. public function getBusProdByTicket($ticket_id)
  557. {
  558. $where = ['=', 'a.ticket_id', $ticket_id];
  559. $select = [
  560. 'a.start_area_name',//上车POI名称
  561. 'a.end_area_name',//下车POI名称
  562. 'a.start_area_id',
  563. 'a.end_area_id',
  564. 'a.start_res_name',//上车站点名称
  565. 'a.end_res_name',//下车站点名称
  566. 'a.start_res_id',
  567. 'a.end_res_id',
  568. 'show_price' => new Expression('(select min(prod_price) from prod_main where delete_flag=0 and prod_cate_id=b.pro_cate_id)'),
  569. 'b.original_price',
  570. 'b.pro_cate_id',
  571. ];
  572. $result = self::find()->select($select)
  573. ->from(BusTicket::tableName() . ' a')
  574. ->innerJoin(ProdCategory::tableName() . ' b', 'a.ticket_id = b.bus_ticket_id and b.sign is NULL and b.delete_flag=0')
  575. ->where($where)
  576. ->asArray()
  577. ->one();
  578. if (empty($result) == false) {
  579. $result['show_price'] = OrderUtil::getBusDiscountPrice($result['pro_cate_id'], $result['show_price']);
  580. }
  581. return $result;
  582. }
  583. /**
  584. * Des:根据POI获取巴士自由行产品
  585. * Name: getRecommendByPoi
  586. * @param $params
  587. * @return array
  588. * @author 倪宗锋
  589. */
  590. public function getRecommendByPoi($params)
  591. {
  592. //查询字段
  593. $select = [
  594. 'a.pro_cate_name',
  595. 'a.pro_cate_id',
  596. 'a.show_price',
  597. 'a.prod_des',
  598. 'a.sales_count',
  599. 'is_hot' => new Expression('1'),
  600. 'a.show_img',
  601. 'a.category_id',
  602. 'a.original_price'
  603. ];
  604. //where条件
  605. $where = ['and'];
  606. $where[] = ['=', 'a.delete_flag', '0'];
  607. $where[] = ['=', 'a.category_id', '4'];//巴士自由行产品
  608. $where[] = ['in', 'b.ID', [$params['start_poi'], $params['end_poi']]];//巴士自由行产品
  609. $list = self::find()->select($select)
  610. ->from(self::tableName() . ' a')
  611. ->innerJoin(BaseArea::tableName() . ' b', 'locate(b.AREA_NAME,a.pro_cate_name)')
  612. ->where($where)
  613. ->limit(6)
  614. ->asArray()
  615. ->all();
  616. if (empty($list['0'])) {
  617. $list = [];
  618. }
  619. return $list;
  620. }
  621. /**
  622. * Function Description:非巴士产品获取详情
  623. * Function Name: getProdDetail
  624. * @param $pro_cate_id
  625. *
  626. * @return array
  627. *
  628. * @author 娄梦宁
  629. */
  630. public function getProdDetail($pro_cate_id)
  631. {
  632. $select = [
  633. 'a.pro_cate_id',
  634. 'a.pro_cate_name',
  635. 'prod_des' => new Expression("IFNULL(a.prod_des, '')"),
  636. 'feature' => new Expression("IFNULL(a.feature, '')"),
  637. 'a.category_id',
  638. 'a.show_img',
  639. 'booking_notice' => new Expression("IFNULL(a.memo, '')"),
  640. 'sign' => new Expression("ifnull(a.sign,'')"),
  641. 'a.show_price',
  642. 'a.close_sale_time',
  643. 'category_name' => new Expression("''"),
  644. 'trip_desc' => new Expression("IFNULL(a.trip_desc, '')"),
  645. 'a.star',
  646. 'a.original_price',
  647. 'comment_cnt' => new Expression("(select count(id) from prod_comment where prod_id=a.pro_cate_id)"),
  648. 'a.delete_flag',
  649. 'a.sales_count'
  650. ];
  651. $result = self::find()->select($select)
  652. ->from(self::tableName() . ' a')
  653. ->leftJoin(ProdCategoryInfo::tableName() . ' c', 'a.pro_cate_id = c.pro_cate_id')
  654. ->where(['and', ['=', 'a.pro_cate_id', $pro_cate_id], ['=', 'a.delete_flag', 0]])
  655. ->asArray()
  656. ->one();
  657. $result['show_price'] = $this->dealFloat($result['show_price']);
  658. return $result;
  659. }
  660. /**
  661. * Des:获取产品详细信息
  662. * Name: getProdInfo
  663. * @param $pro_cate_id
  664. * @return array
  665. * @author 倪宗锋
  666. */
  667. public function getProdCateInfo($pro_cate_id)
  668. {
  669. $select = [
  670. new Expression('a.*'),
  671. 'start_area' => new Expression("if(b.start_area_name=b.start_res_name,b.start_res_name,CONCAT(b.start_area_name,b.start_res_name))"),
  672. 'end_area' => new Expression("if(b.end_area_name=b.end_res_name,b.end_res_name,CONCAT(b.end_area_name,b.end_res_name))")
  673. ];
  674. $result = self::find()->select($select)
  675. ->from(self::tableName() . ' a')
  676. ->leftJoin(BusTicket::tableName() . ' b', 'a.bus_ticket_id=b.ticket_id')
  677. ->where(['=', 'a.pro_cate_id', $pro_cate_id])
  678. ->asArray()
  679. ->one();
  680. return $result;
  681. }
  682. /**
  683. * Des:产品增加销售量
  684. * Name: addCount
  685. * @param $pro_cate_id
  686. * @param $cnt
  687. * @return bool
  688. * @author 倪宗锋
  689. */
  690. public function addCount($pro_cate_id, $cnt)
  691. {
  692. $sql = "UPDATE prod_category
  693. set sales_count=sales_count+$cnt
  694. where pro_cate_id = $pro_cate_id
  695. ";
  696. $res = $this->getDb()->createCommand($sql)->execute();
  697. if (!$res) {
  698. return false;
  699. }
  700. return true;
  701. }
  702. /**
  703. * Des:获取主线路产品的子线路产品ID
  704. * Name: getBusSubProdIds
  705. * @param $pro_cate_id
  706. * @return string
  707. * @author 倪宗锋
  708. */
  709. public function getBusSubProdIds($pro_cate_id)
  710. {
  711. $select = [
  712. 'ids' => new Expression("GROUP_CONCAT(c.pro_cate_id)")
  713. ];
  714. $getProdCateIds = self::find()->select($select)
  715. ->from(self::tableName() . 'a')
  716. ->innerJoin(BusTicket::tableName() . ' b', 'a.sign=b.line_id')
  717. ->innerJoin(self::tableName() . ' c', 'b.ticket_id = c.bus_ticket_id and c.sign is null')
  718. ->where(['=', 'pro_cate_id', $pro_cate_id])
  719. ->asArray()
  720. ->one();
  721. if (empty($getProdCateIds['ids'])) {
  722. return '';
  723. }
  724. return $getProdCateIds['ids'];
  725. }
  726. /**
  727. * Des:获取把自由行产品的产品ID组合
  728. * Name: getFreeWalkSigns
  729. * @return array
  730. * @author 倪宗锋
  731. */
  732. public function getFreeWalkSigns()
  733. {
  734. $select = ['sign', 'pro_cate_id'];
  735. $where = [
  736. 'and',
  737. ['=', 'category_id', '4'],
  738. ['=', 'delete_flag', 0]
  739. ];
  740. $getSigns = self::find()->select($select)
  741. ->where($where)
  742. ->indexBy('sign')
  743. ->asArray()
  744. ->all();
  745. if (empty($getSigns)) {
  746. return [];
  747. }
  748. return $getSigns;
  749. }
  750. /**
  751. * Des:根据ID获取产品列表
  752. * Name: getProdListByIds
  753. * @param $ids
  754. * @return array|ActiveRecord[]
  755. * @author 倪宗锋
  756. */
  757. public function getProdListByIds($ids)
  758. {
  759. //查询字段
  760. $select = [
  761. 'a.pro_cate_name',
  762. 'a.pro_cate_id',
  763. 'a.show_price',
  764. 'a.prod_des',
  765. 'a.sales_count',
  766. 'is_hot' => new Expression('1'),
  767. 'a.show_img',
  768. 'a.category_id',
  769. 'a.original_price'
  770. ];
  771. //where条件
  772. $where = ['and'];
  773. $where[] = ['=', 'a.delete_flag', '0'];
  774. $where[] = ['!=', 'a.show_img', ''];
  775. $where[] = ['in', 'a.pro_cate_id', $ids];//巴士自由行产品
  776. $list = self::find()->select($select)
  777. ->from(self::tableName() . ' a')
  778. ->where($where)
  779. ->limit(6)
  780. ->asArray()
  781. ->all();
  782. if (empty($list['0'])) {
  783. $list = [];
  784. }
  785. return $list;
  786. }
  787. /**
  788. * Function Description:根据prod_id查询cms_category_id
  789. * Function Name: getCategoryId
  790. * @param $prod_id
  791. *
  792. * @return array|mixed|null|ActiveRecord
  793. *
  794. * @author 李健
  795. */
  796. public function getCategoryId($prod_id)
  797. {
  798. //查询字段
  799. $select = [
  800. 'c.category_id'
  801. ];
  802. //where条件
  803. $where = ['and'];
  804. $where[] = ['=', 'a.pro_cate_id', $prod_id];
  805. $list = self::find()->select($select)
  806. ->from(self::tableName() . ' a')
  807. ->leftJoin(BusTicket::tableName() . ' b', 'b.ticket_id=a.bus_ticket_id')
  808. ->leftJoin(CmsCategoryExtra::tableName() . ' c', 'c.area_id=b.end_area_id')
  809. ->where($where)
  810. ->asArray()
  811. ->one();
  812. if (!empty($list['category_id'])) {
  813. $list = $list['category_id'];
  814. } else {
  815. $list = null;
  816. }
  817. return $list;
  818. }
  819. /**
  820. * Function Description:获取自由行产品的sign
  821. * Function Name: getFreeWalkSign
  822. * @param $pro_cate_id
  823. * @return array|null|ActiveRecord
  824. * @author 田玲菲
  825. */
  826. public function getFreeWalkSign($pro_cate_id)
  827. {
  828. $select = ['sign' => new Expression('ifnull(sign,0)')];
  829. $where = [
  830. 'and',
  831. ['=', 'category_id', '4'],
  832. ['=', 'delete_flag', 0],
  833. ['=', 'pro_cate_id', $pro_cate_id]
  834. ];
  835. $result = self::find()->select($select)
  836. ->where($where)
  837. ->asArray()
  838. ->one();
  839. return $result;
  840. }
  841. /**
  842. * Function Description:处理价格
  843. * Function Name: dealFloat
  844. * @param $float
  845. *
  846. * @return float
  847. *
  848. * @author LUOCJ
  849. */
  850. public function dealFloat($float)
  851. {
  852. $int = floor($float);
  853. if ($float - $int == 0) {
  854. $float = $int;
  855. }
  856. return $float;
  857. }
  858. }