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.
 
 
 
 
 

803 rivejä
28 KiB

  1. <?php
  2. namespace common\models;
  3. use common\util\Util;
  4. use Yii;
  5. use yii\base\Exception;
  6. use yii\db\Expression;
  7. /**
  8. * This is the model class for table "prod_category".
  9. *
  10. * @property integer $pro_cate_id
  11. * @property string $pro_cate_name
  12. * @property integer $category_id
  13. * @property string $show_price
  14. * @property string $show_img
  15. * @property integer $sales_count
  16. * @property string $memo
  17. * @property string $commission
  18. * @property integer $create_user_id
  19. * @property integer $is_recom
  20. * @property string $create_time
  21. * @property string $update_time
  22. * @property integer $delete_flag
  23. * @property string $update_user
  24. * @property string $address
  25. * @property integer $bus_ticket_id
  26. * @property integer $bus_line_type
  27. */
  28. class ProdCategory extends \yii\db\ActiveRecord
  29. {
  30. /**
  31. * @inheritdoc
  32. */
  33. public static function tableName()
  34. {
  35. return 'prod_category';
  36. }
  37. /**
  38. * @inheritdoc
  39. */
  40. public function rules()
  41. {
  42. return [
  43. [['pro_cate_name', 'category_id'], 'required'],
  44. [['category_id', 'sales_count', 'create_user_id', 'is_recom', 'delete_flag', 'bus_ticket_id', 'bus_line_type'], 'integer'],
  45. [['show_price', 'commission', 'original_price'], 'number'],
  46. [['create_time', 'update_time', 'sign'], 'safe'],
  47. [['pro_cate_name', 'address'], 'string', 'max' => 100],
  48. [['show_img', 'sign', 'prod_des'], 'string', 'max' => 255],
  49. [['memo',], 'string', 'max' => 65536],
  50. [['update_user', 'close_sale_time'], 'string', 'max' => 50],
  51. ];
  52. }
  53. /**
  54. * @inheritdoc
  55. */
  56. public function attributeLabels()
  57. {
  58. return [
  59. 'pro_cate_id' => 'Pro Cate ID',
  60. 'pro_cate_name' => 'Pro Cate Name',
  61. 'category_id' => 'Category ID',
  62. 'show_price' => 'Show Price',
  63. 'show_img' => 'Show Img',
  64. 'sign' => 'sign',
  65. 'prod_des' => 'prod_des',
  66. 'sales_count' => 'Sales Count',
  67. 'memo' => 'Memo',
  68. 'commission' => 'Commission',
  69. 'create_user_id' => 'Create User ID',
  70. 'is_recom' => 'Is Recom',
  71. 'create_time' => 'Create Time',
  72. 'update_time' => 'Update Time',
  73. 'delete_flag' => 'Delete Flag',
  74. 'update_user' => 'Update User',
  75. 'address' => 'Address',
  76. 'bus_ticket_id' => 'Bus Ticket ID',
  77. 'bus_line_type' => 'Bus Line Type',
  78. ];
  79. }
  80. /**
  81. * Function Description:热销商品推荐10个
  82. * Function Name: GetHotProd
  83. * @param string $searchStr
  84. *
  85. * @return array|\yii\db\ActiveRecord[]
  86. *
  87. * @author 娄梦宁
  88. */
  89. public function GetHotProd($searchStr = '')
  90. {
  91. $where = [
  92. 'and',
  93. ['<>', 'show_img', ''],
  94. ['=', 'a.delete_flag', 0],
  95. ['=', 'b.delete_flag', 0],
  96. ['=', 'b.system', 1]
  97. ];
  98. if ($searchStr != '') {
  99. $where[] = ['like', 'pro_cate_name', $searchStr];
  100. }
  101. $result = self::find()->select(['pro_cate_id', 'sales_count', "IFNULL(prod_des, '') prod_des", 'pro_cate_name', 'if(category_id=1,(if(sign is null,category_id,1000)),category_id) as category_id', 'show_price', "concat(show_img,'.','min.jpg') as show_img"])
  102. ->from(self::tableName() . ' a')
  103. ->innerJoin('cms_category_prod b', 'a.pro_cate_id=b.prod_cate_id')
  104. ->where($where)
  105. ->orderBy(['sales_count' => SORT_DESC, 'pro_cate_id' => SORT_DESC])
  106. ->limit(10)
  107. ->asArray()
  108. ->all();
  109. foreach($result as &$v){
  110. $v['show_price'] = $this->dealFloat($v['show_price']);
  111. }
  112. return $result;
  113. }
  114. /**
  115. * Function Description:推荐产品列表
  116. * Function Name: GetRecommendProd
  117. * @param string $where
  118. *
  119. * @return array|\yii\db\ActiveRecord[]
  120. *
  121. * @author 娄梦宁
  122. */
  123. public function GetRecommendProd($where = '')
  124. {
  125. if ($where == '') {
  126. $result = self::find()->select(['pro_cate_id', 'sales_count', 'pro_cate_name', "IFNULL(prod_des, '') prod_des", 'if(category_id=1,(if(sign is null,category_id,1000)),category_id) as category_id', 'show_price', "concat(show_img,'.','min.jpg') as show_img"])
  127. ->from(self::tableName() . ' a')
  128. ->leftJoin('cms_category_prod b', 'a.pro_cate_id=b.prod_cate_id and b.delete_flag=0')
  129. ->where(['and', ['=', 'is_recom', 1], ['!=', 'show_img', ''], ['=', 'a.delete_flag', 0], ['=', 'b.system', 1]])
  130. ->orderBy(['pro_cate_id' => SORT_DESC])
  131. ->asArray()
  132. ->all();
  133. } else {
  134. $result = self::find()->select(['pro_cate_id', 'sales_count', 'pro_cate_name', "IFNULL(prod_des, '') prod_des", 'if(category_id=1,(if(sign is null,category_id,1000)),category_id) as category_id', 'show_price', "concat(show_img,'.','min.jpg') as show_img"])
  135. ->from(self::tableName() . ' a')
  136. ->leftJoin('cms_category_prod b', 'a.pro_cate_id=b.prod_cate_id and b.delete_flag=0')
  137. ->where(['and', ['=', 'is_recom', 1], ['!=', 'show_img', ''], ['=', 'a.delete_flag', 0], ['=', 'b.system', 1]])
  138. ->andWhere(['like', 'pro_cate_name', $where])
  139. ->orderBy(['pro_cate_id' => SORT_DESC])
  140. ->asArray()
  141. ->all();
  142. }
  143. foreach($result as &$v){
  144. $v['show_price'] = $this->dealFloat($v['show_price']);
  145. }
  146. return $result;
  147. }
  148. /**
  149. * Function Description:首页列表查询产品
  150. * Function Name: GetListProd
  151. * @param $prod_id
  152. * @param string $where
  153. *
  154. * @return array|\yii\db\ActiveRecord[]
  155. *
  156. * @author 娄梦宁
  157. */
  158. public function GetListProd($prod_id, $where = '')
  159. {
  160. if ($where == '') {
  161. $result = self::find()->select(['pro_cate_id', 'sales_count', 'pro_cate_name', "IFNULL(prod_des, '') prod_des", 'if(category_id=1,(if(sign is null,category_id,1000)),category_id) as category_id', 'show_price', "concat(show_img,'.','min.jpg') as show_img"])
  162. ->from(self::tableName() . ' a')
  163. ->leftJoin('cms_category_prod b', 'a.pro_cate_id=b.prod_cate_id and b.delete_flag=0')
  164. ->where(['and', ['=', 'b.cms_cate_id', $prod_id], ['<>', 'a.show_img', ''], ['=', 'a.delete_flag', 0]])
  165. ->orderBy(['show_sort' => SORT_ASC, 'a.pro_cate_id' => SORT_DESC])
  166. ->asArray()
  167. ->all();
  168. } else {
  169. $result = self::find()->select(['pro_cate_id', 'sales_count', 'pro_cate_name', "IFNULL(prod_des, '') prod_des", 'if(category_id=1,(if(sign is null,category_id,1000)),category_id) as category_id', 'show_price', "concat(show_img,'.','min.jpg') as show_img"])
  170. ->from(self::tableName() . ' a')
  171. ->leftJoin('cms_category_prod b', 'a.pro_cate_id=b.prod_cate_id and b.delete_flag=0')
  172. ->where(['and', ['=', 'b.cms_cate_id', $prod_id], ['<>', 'a.show_img', ''], ['=', 'a.delete_flag', 0]])
  173. ->andWhere(['like', 'pro_cate_name', $where])
  174. ->orderBy(['show_sort' => SORT_ASC, 'a.pro_cate_id' => SORT_DESC])
  175. ->asArray()
  176. ->all();
  177. }
  178. foreach($result as &$v){
  179. $v['show_price'] = $this->dealFloat($v['show_price']);
  180. }
  181. return $result;
  182. }
  183. /**
  184. * Function Description:非巴士产品获取详情
  185. * Function Name: getProdDetail
  186. * @param $pro_cate_id
  187. *
  188. * @return array|null|\yii\db\ActiveRecord
  189. *
  190. * @author 娄梦宁
  191. */
  192. public function getProdDetail($pro_cate_id)
  193. {
  194. $result = self::find()->select(['pro_cate_id', 'pro_cate_name', "IFNULL(prod_des, '') prod_des", 'category_id', 'show_img', 'memo booking_notice', 'sign', 'show_price', 'close_sale_time',
  195. "(select category_name from cms_category where cms_category_id =(select cms_cate_id from cms_category_prod where prod_cate_id=$pro_cate_id limit 1)) as category_name"])
  196. ->from(self::tableName())
  197. ->where(['and', ['=', 'pro_cate_id', $pro_cate_id], ['=', 'delete_flag', 0]])
  198. ->asArray()
  199. ->one();
  200. $result['show_price'] = $this->dealFloat($result['show_price']);
  201. return $result;
  202. }
  203. /**
  204. * Des:获取产品详细信息
  205. * Name: getProdInfo
  206. * @param $pro_cate_id
  207. * @return array|null|\yii\db\ActiveRecord
  208. * @author 倪宗锋
  209. */
  210. public function getProdCateInfo($pro_cate_id)
  211. {
  212. $result = self::find()
  213. ->from(self::tableName())
  214. ->where(['=', 'pro_cate_id', $pro_cate_id])
  215. ->asArray()
  216. ->one();
  217. return $result;
  218. }
  219. /**
  220. * Function Description:巴士产品获取详情
  221. * Function Name: getBusProdDetail
  222. * @param $pro_cate_id
  223. *
  224. * @return array|null|\yii\db\ActiveRecord
  225. *
  226. * @author 娄梦宁
  227. */
  228. public function getBusProdDetail($pro_cate_id)
  229. {
  230. $result = self::find()->select(['pro_cate_id', 'pro_cate_name', "IFNULL(prod_des, '') prod_des", 'category_id', 'sign', 'show_img', 'IFNULL(close_sale_time,24) as close_sale_time', "(select category_name from cms_category where cms_category_id =(select cms_cate_id from cms_category_prod where prod_cate_id=$pro_cate_id limit 1)) as category_name"
  231. , 'b.start_area_name', 'b.start_area_id', 'b.start_res_name', 'b.end_res_name', 'b.end_area_name', 'b.end_area_id', 'memo booking_notice'])
  232. ->from(self::tableName() . ' as a')
  233. ->leftJoin('bus_ticket b', 'a.bus_ticket_id=b.ticket_id')
  234. ->where(['and', ['=', 'pro_cate_id', $pro_cate_id]])
  235. ->asArray()
  236. ->one();
  237. return $result;
  238. }
  239. /*
  240. * 后台产品列表
  241. */
  242. public function AdminGetList($param)
  243. {
  244. $where = ['and', ['=', 'a.delete_flag', 0]];
  245. if ($param['category_id'] != '') {
  246. $where[] = ['=', 'b.cms_cate_id', $param['category_id']];
  247. }
  248. if ($param['pro_cate_name'] != '') {
  249. $where[] = ['like', 'pro_cate_name', $param['pro_cate_name']];
  250. }
  251. if ($param['is_recom'] != '') {
  252. $where[] = ['=', 'is_recom', $param['is_recom']];
  253. }
  254. $offset = ($param['current_page'] - 1) * $param['page_size'];
  255. $select = [
  256. 'pro_cate_id',
  257. 'a.category_id',
  258. "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",
  259. 'pro_cate_name', 'close_sale_time',
  260. 'memo', "IFNULL(prod_des, '') prod_des",
  261. 'commission', 'show_img',
  262. 'is_recom as is_recom_id',
  263. 'if(is_recom=1,"已推荐","未推荐") as is_recom'
  264. , "(select 1) as commission_way_id", "(select '按金额') as commission_way",
  265. "ifnull((select category_name from cms_category where cms_category_id =(select cms_cate_id from cms_category_prod where prod_cate_id=a.pro_cate_id limit 1)),'') as category_name"
  266. , "ifnull(b.cms_cate_id,-1) as cms_category_id"
  267. ];
  268. $result = self::find()->select($select)
  269. ->from(self::tableName() . ' a')
  270. ->leftJoin('cms_category_prod as b', 'b.prod_cate_id = a.pro_cate_id')
  271. ->innerJoin(BaseCategory::tableName() . ' c', 'c.category_id = a.category_id')
  272. ->where($where)
  273. ->groupBy('a.pro_cate_id')
  274. ->orderBy('a.pro_cate_id DESC')
  275. ->offset($offset)
  276. ->limit((int)$param['page_size'])
  277. ->asArray()
  278. ->all();
  279. $result1 = self::find()->select('count(1) as count')
  280. ->from(self::tableName() . ' a')
  281. ->leftJoin('cms_category_prod as b', 'b.prod_cate_id=a.pro_cate_id')
  282. ->asArray()
  283. ->where($where)
  284. ->one();
  285. $result1 = $result1['count'];
  286. return ['list' => $result, 'count' => $result1];
  287. }
  288. /*
  289. * 产品推荐
  290. */
  291. public function Recommend($pro_cate_id)
  292. {
  293. $is_recom = self::find()->select(["is_recom"])->from(self::tableName())->where(['=', 'pro_cate_id', $pro_cate_id])->asArray()->one();
  294. if ($is_recom['is_recom'] == 1) {
  295. $count = self::updateAll(['is_recom' => 0], ['=', 'pro_cate_id', $pro_cate_id]);
  296. } else {
  297. $count = self::updateAll(['is_recom' => 1], ['=', 'pro_cate_id', $pro_cate_id]);
  298. }
  299. return $count;
  300. }
  301. /*
  302. * 添加产品
  303. */
  304. public function addProd($param)
  305. {
  306. $values = [
  307. 'category_id' => $param['category_id'],
  308. 'pro_cate_name' => $param['pro_cate_name'],
  309. 'memo' => $param['memo'],
  310. 'sales_count' => rand(1, 10),
  311. 'show_img' => $param['show_img'],
  312. 'create_time' => date('Y-m-d H:i:s'),
  313. 'prod_des' => $param['prod_des'],
  314. 'close_sale_time' => $param['close_sale_time'] //截止售卖时间 2017-05-18 fuhc
  315. ];
  316. $transaction = Yii::$app->db->beginTransaction();
  317. try {
  318. $this->attributes = $values;
  319. $res = $this->insert();
  320. if (!$res) {
  321. throw new Exception('添加出错');
  322. }
  323. $transaction->commit();
  324. return true;
  325. } catch (Exception $e) {
  326. $transaction->rollBack();
  327. return false;
  328. }
  329. }
  330. /*
  331. * 修改show price
  332. */
  333. public function changeShowPrice($pro_cate_id)
  334. {
  335. //查当前产品的子产品最低价
  336. $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();
  337. $show_price = $show_price['price'];
  338. $count = self::updateAll(['show_price' => $show_price], ['and', ['=', 'pro_cate_id', $pro_cate_id]]);
  339. return $count;
  340. }
  341. /*
  342. * 自定义佣金
  343. */
  344. public function DefineCommission($pro_cate_id, $commission)
  345. {
  346. $count = self::updateAll(['commission' => $commission], ['and', ['=', 'pro_cate_id', $pro_cate_id]]);
  347. return $count;
  348. }
  349. /*
  350. * 后台修改产品信息
  351. */
  352. public function uptAdminProd($param)
  353. {
  354. $values = [
  355. 'category_id' => $param['category_id'],
  356. 'pro_cate_name' => $param['pro_cate_name'],
  357. 'memo' => $param['memo'],
  358. 'show_img' => $param['show_img'],
  359. 'prod_des' => $param['prod_des'],
  360. 'update_time' => date('Y-m-d H:i:s'),
  361. 'close_sale_time' => $param['close_sale_time'] //截止售卖时间 2017-05-18 fuhc
  362. ];
  363. $transaction = Yii::$app->db->beginTransaction();
  364. try {
  365. $uptOne = self::findOne(['pro_cate_id' => $param['pro_cate_id']]);
  366. $uptOne->attributes = $values;
  367. $res = $uptOne->update();
  368. if ($res === false) {
  369. throw new Exception('添加出错');
  370. }
  371. $transaction->commit();
  372. return true;
  373. } catch (Exception $e) {
  374. $transaction->rollBack();
  375. return false;
  376. }
  377. }
  378. /*
  379. * 产品增量
  380. */
  381. public function addCount($pro_cate_id, $cnt)
  382. {
  383. $sql = '' . "UPDATE prod_category
  384. set sales_count=sales_count+$cnt
  385. where pro_cate_id = $pro_cate_id
  386. ";
  387. $res = $this->getDb()->createCommand($sql)->execute();
  388. if (!$res) {
  389. return false;
  390. }
  391. return true;
  392. }
  393. /**
  394. * Des:
  395. * Name: getEntranceTicket
  396. * @return array
  397. * @author 倪宗锋
  398. */
  399. public function getEntranceTicket()
  400. {
  401. $result = self::find()
  402. ->from(self::tableName())
  403. ->where(['and', ['<>', 'sign', ''], ['=', 'category_id', 2], ['=', 'delete_flag', 0]])
  404. ->indexBy('sign')
  405. ->asArray()
  406. ->all();
  407. return $result;
  408. }
  409. /**
  410. * Des:同步门票数据
  411. * Name: addEntranceTicketFormCs
  412. * @param $prodArr
  413. * @return int
  414. * @throws \yii\db\Exception
  415. * @author 倪宗锋
  416. */
  417. public function addEntranceTicketFormCs($prodArr)
  418. {
  419. $transaction = Yii::$app->db->beginTransaction();
  420. try {
  421. /**添加产品主表数据***************/
  422. $prodValues = [];
  423. $prodKeys = [
  424. 'pro_cate_name',
  425. 'category_id',
  426. 'create_time',
  427. 'sign',
  428. ];
  429. foreach ($prodArr as $key => $val) {
  430. $prodVal = [];
  431. $prodVal[] = $val['name'];
  432. $prodVal[] = 2;
  433. $prodVal[] = date('Y-m-d H:i:s');
  434. $prodVal[] = $key;
  435. $prodValues[] = $prodVal;
  436. }
  437. $count = Yii::$app->db->createCommand()->batchInsert('prod_category', $prodKeys, $prodValues)->execute();
  438. if ($count == 0) {
  439. $transaction->rollBack();
  440. return false;
  441. }
  442. /**获取新添加的产品主表数据及其ID**/
  443. $signArr = array_keys($prodArr);
  444. $result = self::find()
  445. ->from(self::tableName())
  446. ->where(['and', ['in', 'sign', $signArr], ['=', 'category_id', 2]])
  447. ->indexBy('sign')
  448. ->asArray()
  449. ->all();
  450. /**将数据产褥prod_main表中*/
  451. $prodMainValues = [];
  452. $prodMainKeys = ['prod_cate_id', 'prod_name', 'create_time', 'bus_id'];
  453. foreach ($result as $key => $val) {
  454. if (!empty($prodArr[$val['sign']]['sub_ticket']) && count($prodArr[$val['sign']]['sub_ticket']) > 0) {
  455. $subTicket = $prodArr[$val['sign']]['sub_ticket'];
  456. foreach ($subTicket as $subVal) {
  457. $prodMainVal = [];
  458. $prodMainVal[] = $val['pro_cate_id'];
  459. $prodMainVal[] = $subVal['prod_name'];
  460. $prodMainVal[] = date('Y-m-d H:i:s');
  461. $prodMainVal[] = $subVal['prod_id'];
  462. $prodMainValues[] = $prodMainVal;
  463. }
  464. }
  465. }
  466. $count = Yii::$app->db->createCommand()->batchInsert('prod_main', $prodMainKeys, $prodMainValues)->execute();
  467. if ($count == 0) {
  468. $transaction->rollBack();
  469. return false;
  470. }
  471. $transaction->commit();
  472. return true;
  473. } catch (Exception $e) {
  474. $transaction->rollBack();
  475. return false;
  476. }
  477. }
  478. /**
  479. * Des: 删除门票数据
  480. * Name: delEntranceTicketFormCs
  481. * @author 倪宗锋
  482. */
  483. public function delEntranceTicketFormCs($prodArr)
  484. {
  485. $transaction = Yii::$app->db->beginTransaction();
  486. try {
  487. $values = [
  488. 'delete_flag' => 1
  489. ];
  490. $signArr = array_keys($prodArr);
  491. $res = self::updateAll($values, ['in', 'sign', $signArr]);
  492. if ($res === false) {
  493. throw new Exception('添加出错');
  494. }
  495. $transaction->commit();
  496. return true;
  497. } catch (Exception $e) {
  498. $transaction->rollBack();
  499. return false;
  500. }
  501. }
  502. /**
  503. * Des:修改订单状态为激活
  504. * Name: interEntranceTicketFormCs
  505. * @param $new_bus_arr_inter
  506. * @return bool
  507. * @throws \yii\db\Exception
  508. * @author 倪宗锋
  509. */
  510. public function interEntranceTicketFormCs($new_bus_arr_inter)
  511. {
  512. $transaction = Yii::$app->db->beginTransaction();
  513. try {
  514. $values = [
  515. 'delete_flag' => 0
  516. ];
  517. $signArr = array_keys($new_bus_arr_inter);
  518. $res = self::updateAll($values, ['in', 'sign', $signArr]);
  519. if ($res === false) {
  520. throw new Exception('编辑出错');
  521. }
  522. $transaction->commit();
  523. return true;
  524. } catch (Exception $e) {
  525. $transaction->rollBack();
  526. return false;
  527. }
  528. }
  529. /**
  530. * Des:每日增加产品的销售量 每月1号重置产品的销售量
  531. * Name: setSaleCnt
  532. * @param $day
  533. * @return bool
  534. * @throws \yii\db\Exception
  535. * @author 倪宗锋
  536. */
  537. public function setSaleCnt($day)
  538. {
  539. if ($day == 1) {
  540. $values = [
  541. 'sales_count' => new Expression("1+ROUND(RAND()*10,0)")
  542. ];
  543. } else {
  544. $values = [
  545. 'sales_count' => new Expression("sales_count+sales_count*0.05+1+ROUND(RAND()*5,0)")
  546. ];
  547. }
  548. $transaction = Yii::$app->db->beginTransaction();
  549. try {
  550. $res = self::updateAll($values);
  551. if ($res === false) {
  552. throw new Exception('添加出错');
  553. }
  554. $transaction->commit();
  555. return true;
  556. } catch (Exception $e) {
  557. $transaction->rollBack();
  558. return false;
  559. }
  560. }
  561. /**
  562. * Des:LBS获取产品列表
  563. * Name: getLBSListByCmsCate
  564. * @param $point
  565. * @param $cms_cate_id
  566. * @return array
  567. * @author 倪宗锋
  568. */
  569. public function getLBSListByCmsCate($point, $cms_cate_id)
  570. {
  571. $pointArr = explode(',', $point);//经纬度坐标
  572. if (empty($pointArr['0']) || empty($pointArr['1'])) {
  573. return [];
  574. }
  575. $longitude = $pointArr['0'];
  576. $latitude = $pointArr['1'];
  577. $sql = '' . "SELECT round(if(a.start_lbs>a.end_lbs,a.end_lbs,a.start_lbs),3) 'lbs', b.pro_cate_id,b.sales_count,
  578. b.pro_cate_name,IFNULL(prod_des, '') prod_des,if(category_id=1,(if(sign is null,category_id,1000)),category_id) as category_id
  579. ,show_price,concat(show_img,'.','min.jpg') as show_img
  580. from (
  581. select ticket_id,line_type,sqrt(
  582. ((({$longitude}-start_res_longitude)*PI()*12656*cos((($latitude+start_res_latitude)/2)*PI()/180)/180)
  583. * (({$longitude}-start_res_longitude)*PI()*12656*cos ((($latitude+start_res_latitude)/2)*PI()/180)/180))
  584. + ((($latitude-start_res_latitude)*PI()*12656/180)
  585. * (($latitude-start_res_latitude)*PI()*12656/180))
  586. )/2 as start_lbs,
  587. sqrt(
  588. ((({$longitude}-end_res_longitude)*PI()*12656*cos((($latitude+end_res_latitude)/2)*PI()/180)/180)
  589. *(({$longitude}-end_res_longitude)*PI()*12656*cos ((($latitude+end_res_latitude)/2)*PI()/180)/180)
  590. )+((($latitude-end_res_latitude)*PI()*12656/180)
  591. *(($latitude-end_res_latitude)*PI()*12656/180))
  592. )/2 as end_lbs,
  593. start_res_longitude, start_res_latitude,end_res_longitude,end_res_latitude
  594. from bus_ticket where
  595. start_res_longitude is not null and end_res_longitude is not NULL
  596. and start_res_latitude is not null and end_res_latitude is not NULL
  597. ) a
  598. JOIN prod_category b on a.ticket_id=b.bus_ticket_id
  599. JOIN cms_category_prod c on b.pro_cate_id = c.prod_cate_id
  600. WHERE b.sign is NULL and c.cms_cate_id={$cms_cate_id} and b.show_img <> '' and b.delete_flag=0
  601. ORDER BY lbs
  602. LIMIT 10 ";
  603. $result = Yii::$app->getDb()->createCommand($sql)->queryAll();
  604. foreach($result as &$v){
  605. $v['show_price'] = $this->dealFloat($v['show_price']);
  606. }
  607. return $result;
  608. }
  609. /**
  610. * Des:
  611. * Name: getEntranceHotel
  612. * @return array
  613. * @author 付泓程
  614. */
  615. public function getEntranceHotel()
  616. {
  617. $result = self::find()
  618. ->from(self::tableName())
  619. ->where(['and', ['<>', 'sign', ''], ['=', 'category_id', 3]])
  620. ->indexBy('sign')
  621. ->asArray()
  622. ->all();
  623. return $result;
  624. }
  625. /**
  626. * Des:同步酒店数据
  627. * Name: addEntranceHotelFormCs
  628. * @param $prodArr
  629. * @return bool
  630. * @throws \yii\db\Exception
  631. * @author 付泓程
  632. */
  633. public function addEntranceHotelFormCs($prodArr)
  634. {
  635. $transaction = Yii::$app->db->beginTransaction();
  636. try {
  637. /**添加产品主表数据***************/
  638. $prodValues = [];
  639. $prodKeys = [
  640. 'pro_cate_name',
  641. 'category_id',
  642. 'create_time',
  643. 'sign',
  644. ];
  645. foreach ($prodArr as $key => $val) {
  646. $prodVal = [];
  647. $prodVal[] = $val['name'];
  648. $prodVal[] = 3;
  649. $prodVal[] = date('Y-m-d H:i:s');
  650. $prodVal[] = $key;
  651. $prodValues[] = $prodVal;
  652. }
  653. $count = Yii::$app->db->createCommand()->batchInsert('prod_category', $prodKeys, $prodValues)->execute();
  654. if ($count == 0) {
  655. $transaction->rollBack();
  656. return false;
  657. }
  658. /**获取新添加的产品主表数据及其ID**/
  659. $signArr = array_keys($prodArr);
  660. $result = self::find()
  661. ->from(self::tableName())
  662. ->where(['and', ['in', 'sign', $signArr], ['=', 'category_id', 3]])
  663. ->indexBy('sign')
  664. ->asArray()
  665. ->all();
  666. /**将数据插入prod_main表中*/
  667. $prodMainValues = [];
  668. $prodMainKeys = ['prod_cate_id', 'prod_name', 'create_time', 'bus_id'];
  669. foreach ($result as $key => $val) {
  670. if (!empty($prodArr[$val['sign']]['sub_ticket']) && count($prodArr[$val['sign']]['sub_ticket']) > 0) {
  671. $subTicket = $prodArr[$val['sign']]['sub_ticket'];
  672. foreach ($subTicket as $subVal) {
  673. $prodMainVal = [];
  674. $prodMainVal[] = $val['pro_cate_id'];
  675. $prodMainVal[] = $subVal['prod_name'];
  676. $prodMainVal[] = date('Y-m-d H:i:s');
  677. $prodMainVal[] = $subVal['prod_id'];
  678. $prodMainValues[] = $prodMainVal;
  679. }
  680. }
  681. }
  682. $count = Yii::$app->db->createCommand()->batchInsert('prod_main', $prodMainKeys, $prodMainValues)->execute();
  683. if ($count == 0) {
  684. $transaction->rollBack();
  685. return false;
  686. }
  687. $transaction->commit();
  688. return true;
  689. } catch (Exception $e) {
  690. $transaction->rollBack();
  691. return false;
  692. }
  693. }
  694. /**
  695. * Des: 删除酒店数据
  696. * Name: delEntranceTicketFormCs
  697. * @author 付泓程
  698. */
  699. public function delEntranceHotelFormCs($prodArr)
  700. {
  701. $transaction = Yii::$app->db->beginTransaction();
  702. try {
  703. $values = [
  704. 'delete_flag' => 1
  705. ];
  706. $signArr = array_keys($prodArr);
  707. $res = self::updateAll($values, ['in', 'sign', $signArr]);
  708. if ($res === false) {
  709. throw new Exception('删除出错');
  710. }
  711. $transaction->commit();
  712. return true;
  713. } catch (Exception $e) {
  714. $transaction->rollBack();
  715. return false;
  716. }
  717. }
  718. /**
  719. * Des:修改订单状态为激活
  720. * Name: interEntranceHotelFormCs
  721. * @param $new_bus_arr_inter
  722. * @return bool
  723. * @throws \yii\db\Exception
  724. * @author 付泓程
  725. */
  726. public function interEntranceHotelFormCs($new_bus_arr_inter)
  727. {
  728. $transaction = Yii::$app->db->beginTransaction();
  729. try {
  730. $values = [
  731. 'delete_flag' => 0
  732. ];
  733. $signArr = array_keys($new_bus_arr_inter);
  734. $res = self::updateAll($values, ['in', 'sign', $signArr]);
  735. if ($res === false) {
  736. throw new Exception('编辑出错');
  737. }
  738. $transaction->commit();
  739. return true;
  740. } catch (Exception $e) {
  741. $transaction->rollBack();
  742. return false;
  743. }
  744. }
  745. /**
  746. * Function Description:处理价格
  747. * Function Name: dealFloat
  748. * @param $float
  749. *
  750. * @return float
  751. *
  752. * @author LUOCJ
  753. */
  754. public function dealFloat($float)
  755. {
  756. $int = floor($float);
  757. if ($float - $int == 0) {
  758. $float = $int;
  759. }
  760. return $float;
  761. }
  762. }