25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

766 lines
26 KiB

  1. <?php
  2. /**
  3. * 数据库表类 order_main
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm LoginController.php
  13. * Create By 2017/06/15 10:33 $
  14. */
  15. namespace common\models;
  16. use yii\db\ActiveRecord;
  17. use yii\db\Expression;
  18. /**
  19. * 数据库表类 order_main.
  20. * @property integer $order_id
  21. * @property string $order_name
  22. * @property string $spider_order_id
  23. * @property string $total_money
  24. * @property integer $category_id
  25. * @property integer $prod_cate_id
  26. * @property integer $prod_source
  27. * @property integer $prod_cnt
  28. * @property integer $sh_uid
  29. * @property integer $fx_uid
  30. * @property string $start_time
  31. * @property string $end_time
  32. * @property string $start_date
  33. * @property string $end_date
  34. * @property integer $order_status
  35. * @property string $update_time
  36. * @property string $create_time
  37. * @property integer $delete_flag
  38. * @property integer $system
  39. * @property string $start_area
  40. * @property string $end_area
  41. * @property integer $main_user_id
  42. */
  43. class OrderMain extends ActiveRecord
  44. {
  45. /**
  46. * @inheritdoc
  47. */
  48. public static function tableName()
  49. {
  50. return 'order_main';
  51. }
  52. /**
  53. * @inheritdoc
  54. */
  55. public function rules()
  56. {
  57. return [
  58. [['original_price', 'total_money'], 'number'],
  59. [['category_id', 'prod_cate_id', 'prod_source', 'prod_cnt', 'sh_uid', 'fx_uid', 'order_status', 'delete_flag', 'system', 'main_user_id'], 'integer'],
  60. [['start_time', 'end_time', 'start_date', 'end_date', 'update_time', 'create_time'], 'safe'],
  61. [['order_name', 'spider_order_id', 'start_area', 'end_area','remark'], 'string', 'max' => 255],
  62. ];
  63. }
  64. /**
  65. * @inheritdoc
  66. */
  67. public function attributeLabels()
  68. {
  69. return [
  70. 'order_id' => 'Order ID',
  71. 'order_name' => 'Order Name',
  72. 'spider_order_id' => 'Spider Order ID',
  73. 'total_money' => 'Total Money',
  74. 'original_price' => 'original_price',
  75. 'category_id' => 'Category ID',
  76. 'prod_cate_id' => 'Prod Cate ID',
  77. 'prod_source' => 'Prod Source',
  78. 'prod_cnt' => 'Prod Cnt',
  79. 'sh_uid' => 'Sh Uid',
  80. 'fx_uid' => 'Fx Uid',
  81. 'start_time' => 'Start Time',
  82. 'end_time' => 'End Time',
  83. 'start_date' => 'Start Date',
  84. 'end_date' => 'End Date',
  85. 'order_status' => 'Order Status',
  86. 'update_time' => 'Update Time',
  87. 'create_time' => 'Create Time',
  88. 'delete_flag' => 'Delete Flag',
  89. 'system' => 'System',
  90. 'start_area' => 'Start Area',
  91. 'end_area' => 'End Area',
  92. 'main_user_id' => 'Main User ID'
  93. ];
  94. }
  95. /**
  96. * Des:根据订单ID 获取订单详情
  97. * Name: getOrderInfoById
  98. * @param $order_id
  99. * @return array
  100. * @author 倪宗锋
  101. */
  102. public function getOrderInfoById($order_id)
  103. {
  104. $where = ['=', 'a.order_id', $order_id];
  105. $select = [
  106. 'order_id' => 'a.order_id',//订单ID
  107. 'a.order_name',//订单名称
  108. 'spider_order_id' => 'a.spider_order_id',//cs订单号
  109. 'total_money' => 'a.total_money',//总金额
  110. 'category_id' => 'a.category_id',//订单类型ID
  111. 'prod_cate_id' => 'a.prod_cate_id',//产品品类ID
  112. 'prod_cnt' => 'a.prod_cnt',//产品数量
  113. 'fx_uid' => 'a.fx_uid',//分销商ID
  114. 'sh_uid' => 'a.sh_uid',//用户ID
  115. 'start_time' => 'a.start_time',//出发时间
  116. 'start_date' => 'a.start_date',//出发日期
  117. 'end_date' => 'a.end_date',//接收日期
  118. 'order_status' => 'a.order_status',//订单状态
  119. 'update_time' => 'a.update_time',//更新时间
  120. 'create_time' => 'a.create_time',//下单时间
  121. 'delete_flag' => 'a.delete_flag',//是否删除 无用
  122. 'contacts_name' => 'b.contacts_name',//联系人
  123. 'contacts_phone' => 'b.contacts_phone',//手机号
  124. 'contacts_ID' => 'b.contacts_ID',//证件
  125. 'pro_cate_name' => 'a.order_name',//产品名称
  126. 'prod_source' => 'a.prod_source',//产品来源
  127. 'start_area' => new Expression("ifnull(a.start_area,'')"),
  128. 'end_area' => new Expression("ifnull(a.end_area,'')"),
  129. 'system' => 'a.system',
  130. 'pay_order_id' => new Expression("ifnull((SELECT pay_order_id from pay_main WHERE order_id = a.order_id),'')"),
  131. 'category_name' => new Expression("(SELECT category_name from base_category WHERE category_id = a.category_id)"),//产品类型
  132. //产品详细 ' ¥',format(x.total_price,2)
  133. 'prod_info' => new Expression("(
  134. SELECT GROUP_CONCAT(x.prod_name,' ',x.count separator '</br>')
  135. from order_info x
  136. WHERE x.order_id = a.order_id and x.count > 0
  137. GROUP BY x.order_id
  138. )
  139. "),
  140. 'order_status_des' => new Expression("CASE a.order_status
  141. WHEN 1 THEN '待支付'
  142. WHEN 2 THEN '已支付'
  143. WHEN 3 THEN '已完成'
  144. WHEN 4 THEN '已退款'
  145. WHEN 5 THEN '已取消'
  146. ELSE '异常'
  147. END
  148. "),
  149. 'sign' => new Expression("(SELECT x.sign from prod_category x where pro_cate_id = a.prod_cate_id)"),
  150. 'original_price',
  151. 'hotel_id' => new Expression("ifnull(c.hotel_id,'')"),
  152. 'room_id' => new Expression("ifnull(c.room_id,'')"),
  153. 'hotel_name' => new Expression("ifnull(c.hotel_name,'')"),
  154. 'room_name' => new Expression("ifnull(c.room_name,'')"),
  155. 'is_gift' => new Expression("ifnull(c.is_gift,0)"),
  156. 'gift_describe' => new Expression("ifnull(c.gift_describe,'')"),
  157. 'breakfast' => new Expression("ifnull(c.breakfast,'')"),
  158. 'is_confirm' => new Expression("ifnull(c.is_confirm,'')"),
  159. 'total_details' => new Expression("ifnull(c.total_details,'[]')"),
  160. 'remarks' => new Expression("ifnull(c.remarks,'')")
  161. ];
  162. $getInfo = self::find()->select($select)
  163. ->from(self::tableName() . ' as a')
  164. ->innerJoin(OrderContacts::tableName() . ' as b', 'a.order_id = b.order_id and b.contacts_type=1')
  165. ->leftJoin(OrderHotelExtra::tableName() . ' c', 'c.main_order_id = a.order_id')
  166. ->where($where)
  167. ->asArray()
  168. ->one();
  169. if (empty($getInfo['order_id'])) {
  170. return [];
  171. } else {
  172. $getInfo['total_money'] = $this->dealFloat($getInfo['total_money']);
  173. }
  174. return $getInfo;
  175. }
  176. /**
  177. * Function Description:处理价格
  178. * Function Name: dealFloat
  179. * @param $float
  180. *
  181. * @return float
  182. *
  183. * @author LUOCJ
  184. */
  185. public function dealFloat($float)
  186. {
  187. $int = floor($float);
  188. if ($float - $int == 0) {
  189. $float = $int;
  190. }
  191. return $float;
  192. }
  193. /**
  194. * Des:修改订单信息
  195. * Name: upOrder
  196. * @param $value
  197. * @param $orderIds
  198. * @return int
  199. * @author 倪宗锋
  200. */
  201. public function upOrder($value, $orderIds)
  202. {
  203. $count = self::updateAll($value, ['in', 'order_id', $orderIds]);
  204. return $count;
  205. }
  206. /**
  207. * Function Description:去cs下巴士订单获取基础数据
  208. * Function Name: GetCsProdInfo
  209. * @param $orderId
  210. *
  211. * @return array|null|\yii\db\ActiveRecord
  212. *
  213. * @author 娄梦宁
  214. */
  215. public function GetCsBusProdInfo($orderId)
  216. {
  217. $result = self::find()->select(["(select bus_ticket_id from prod_category where pro_cate_id =a.prod_cate_id limit 1) as ticket_id", "bus_run_id as run_id",
  218. "(select unit_price from order_info where order_id=a.order_id limit 1) as price", 'a.total_money', 'a.prod_cnt', 'b.contacts_name', 'b.contacts_phone', 'b.contacts_ID', 'a.system'])
  219. ->from(self::tableName() . ' as a')
  220. ->leftJoin('order_contacts as b', 'a.order_id=b.order_id and b.contacts_type = 1')
  221. ->where(['a.order_id' => $orderId])
  222. ->asArray()
  223. ->one();
  224. return $result;
  225. }
  226. /**
  227. * Des:获取非巴士产品的下单产品信息
  228. * Name: getCsUnBusProdInfo
  229. * @param $orderId
  230. * @return array
  231. * @author 倪宗锋
  232. */
  233. public function getCsUnBusProdInfo($orderId)
  234. {
  235. $where = [
  236. 'and',
  237. ['!=', 'a.count', 0],
  238. ['=', 'a.order_id', $orderId]
  239. ];
  240. $select = [
  241. 'prod_str' => new Expression("GROUP_CONCAT(CONCAT('{',b.bus_id,',',a.unit_price,',',a.count,'}') separator '')"),
  242. 'c.contacts_name',
  243. 'c.contacts_phone',
  244. 'c.contacts_ID',
  245. 'main_prod_id' => 'd.sign',
  246. 'run_date' => new Expression("(SELECT start_date FROM order_main WHERE order_id = a.order_id)"),
  247. 'e.system'
  248. ];
  249. $getProdStr = self::find()->select($select)
  250. ->from(OrderInfo::tableName() . ' a')
  251. ->innerJoin(OrderMain::tableName() . ' e', 'a.order_id = e.order_id')
  252. ->innerJoin(ProdCategory::tableName() . ' d', 'e.prod_cate_id=d.pro_cate_id')
  253. ->innerJoin(ProdMain::tableName() . ' b', 'a.prod_id = b.prod_id')
  254. ->innerJoin(OrderContacts::tableName() . ' c', 'a.order_id = c.order_id and c.contacts_type=1')
  255. ->where($where)
  256. ->asArray()
  257. ->one();
  258. if (empty($getProdStr)) {
  259. $getProdStr = [];
  260. }
  261. return $getProdStr;
  262. }
  263. /**
  264. * Des:添加cs订单ID记录
  265. * Name: addSpiderOrder
  266. * @param $spider_id
  267. * @param $order_id
  268. * @return int
  269. * @author 倪宗锋
  270. */
  271. public function addSpiderOrder($spider_id, $order_id)
  272. {
  273. $count = self::updateAll(['spider_order_id' => $spider_id], ['=', 'order_id', $order_id]);
  274. return $count;
  275. }
  276. /**
  277. * Function Description:插入主订单
  278. * Function Name: insertOrder
  279. * @param $param_arr
  280. *
  281. * @return bool
  282. *
  283. * @author 娄梦宁
  284. */
  285. public function insertOrder($param_arr)
  286. {
  287. $values = [
  288. 'remark'=>$param_arr['remark'],
  289. 'total_money' => $param_arr['total_money'],
  290. 'original_price' => $param_arr['total_money'],//原价
  291. 'prod_cate_id' => (int)$param_arr['pro_cate_id'],
  292. 'prod_cnt' => $param_arr['prod_cnt'],
  293. 'fx_uid' => $param_arr['fx_uid'],
  294. 'start_date' => $param_arr['start_date'],
  295. 'start_time' => $param_arr['start_time'],
  296. 'end_time' => empty($param_arr['end_time']) ? '00:00:00' : $param_arr['end_time'],
  297. 'sh_uid' => $param_arr['sh_uid'],
  298. 'order_status' => 1,
  299. 'create_time' => date('Y-m-d H:i:s'),
  300. 'end_date' => $param_arr['end_date'],
  301. 'category_id' => $param_arr['category_id'],
  302. 'system' => $param_arr['system'],
  303. 'order_name' => $param_arr['order_name'],
  304. 'prod_source' => $param_arr['prod_source'],
  305. 'start_area' => $param_arr['start_area'],
  306. 'end_area' => $param_arr['end_area'],
  307. 'main_user_id' => empty($param_arr['main_user_id']) ? 0 : $param_arr['main_user_id']
  308. ];
  309. $this->attributes = $values;
  310. $res = $this->insert();
  311. if (!$res) {
  312. return false;
  313. } else {
  314. return true;
  315. }
  316. }
  317. /**
  318. * Des:判断某个产品是否存在订单
  319. * Name: existOrder
  320. * @param $param array
  321. * @return bool
  322. * @author 付泓程
  323. */
  324. public function existOrder($param)
  325. {
  326. $prod_cate_id = $param['prod_cate_id'];
  327. $start_date = $param['start_date'];
  328. $run_time = $param['start_time'];
  329. $small24 = $param['small24']; //是否小于0 -即提前X天。
  330. $select = ['count(order_id) as count'];
  331. $where = [
  332. 'and',
  333. ['=', 'a.prod_cate_id', $prod_cate_id],
  334. ['=', 'a.start_date', $start_date],
  335. ['=', 'a.order_status', 2],
  336. ['=', 'a.delete_flag', 0]
  337. ];
  338. if (!$small24) {
  339. $where[] = ['>=', 'a.start_time', $run_time];
  340. }
  341. $result = self::find()
  342. ->select($select)
  343. ->from(OrderMain::tableName() . ' a')
  344. ->where($where)
  345. ->asArray()
  346. ->one();
  347. $count = $result['count'];
  348. if ($count > 0) {
  349. return true;
  350. }
  351. return false;
  352. }
  353. /**
  354. * Des:获取订单列表
  355. * Name: getListForZzcx
  356. * @param $param
  357. * @return array|ActiveRecord[]
  358. * @author 倪宗锋
  359. */
  360. public function getListForZzcx($param)
  361. {
  362. //where条件
  363. $where = [
  364. 'and',
  365. ['=', 'a.sh_uid', $param['sh_uid']],
  366. ['=', 'a.delete_flag', 0],
  367. [
  368. 'or',
  369. ['=', 'a.system', 2],//蜘蛛出行的订单全部展示
  370. ['not in', 'a.order_status', [1, 5]]//其他渠道的订单 如分销,未支付的订单是废单,不进行展示
  371. ]
  372. ];
  373. if (empty($param['order_status']) == false) {
  374. $where[] = ['in', 'a.order_status', explode(',', $param['order_status'])];
  375. }
  376. //查询字段
  377. $select = [
  378. 'a.order_id',//订单ID
  379. "a.create_time as create_order_time",//下单时间
  380. "c.category_name as order_type_des",//订单类型
  381. "a.order_name as book_product",//产品品类名称
  382. "(
  383. SELECT GROUP_CONCAT(CONCAT(x.prod_name,'',x.count,' ') SEPARATOR ' ')
  384. from order_info x
  385. WHERE x.order_id = a.order_id
  386. GROUP BY x.order_id
  387. ) as prod_des
  388. ",//具体产品及数量
  389. 'a.start_date',
  390. 'a.start_time',
  391. new Expression("CASE a.order_status
  392. WHEN 1 THEN '待支付'
  393. WHEN 2 THEN '已支付'
  394. WHEN 3 THEN '已完成'
  395. WHEN 4 THEN '已退款'
  396. WHEN 5 THEN '已取消'
  397. ELSE ''
  398. END
  399. as order_status_des
  400. ")
  401. ,//订单状态名称
  402. "a.order_status as order_status_id",//订单状态标识ID
  403. "if(d.pay_type=1,'微信',if(d.pay_type=2,'支付宝','预付款')) as pay_type_des",//支付类型名称
  404. "if(a.order_status in (1,2),
  405. if(a.start_date >= '" . date('Y-m-d') . "',0,1), 1)
  406. as if_can_cancel",//是否可以取消订单
  407. 'a.total_money',
  408. 'a.start_area',
  409. 'a.end_area',
  410. 'a.prod_cnt',
  411. 'a.category_id',
  412. ];
  413. //拼接sql语句
  414. $offset = ($param['current_page'] - 1) * $param['page_size'];
  415. $result = self::find()->select($select)
  416. ->from(self::tableName() . ' a')
  417. ->innerJoin(BaseCategory::tableName() . ' c', ' a.category_id = c.category_id')
  418. ->leftJoin(PayMain::tableName() . ' d', ' a.order_id = d.order_id')
  419. ->leftJoin(OrderContacts::tableName() . ' e', 'a.order_id = e.order_id and e.contacts_type=1')
  420. ->where($where)
  421. ->orderBy('a.start_date DESC,a.start_time desc')
  422. ->offset($offset)
  423. ->limit($param['page_size'])
  424. ->asArray()
  425. ->all();
  426. if (empty($result[0])) {
  427. $result = [];
  428. } else {
  429. foreach ($result as &$v) {
  430. $v['total_money'] = $this->dealfloat($v['total_money']);
  431. }
  432. }
  433. return $result;
  434. }
  435. /**
  436. * Des:获取订单产品ID
  437. * Name: getProdIdByCsOrderId
  438. * @param $cs_order_id
  439. * @return int|mixed
  440. * @author 倪宗锋
  441. */
  442. public function getProdIdByCsOrderId($cs_order_id)
  443. {
  444. $select = [
  445. 'prod_id' => new Expression("CONCAT(IFNULL(b.pro_cate_id,0),',',IFNULL(d.pro_cate_id,0))")
  446. ];
  447. $where = ['=', 'a.spider_order_id', $cs_order_id];
  448. $getProd = self::find()->select($select)
  449. ->from(OrderMain::tableName() . ' a')
  450. ->leftJoin(ProdCategory::tableName() . ' b', 'a.prod_cate_id = b.pro_cate_id')
  451. ->leftJoin(BusTicket::tableName() . ' c', 'b.bus_ticket_id = c.ticket_id')
  452. ->leftJoin(ProdCategory::tableName() . ' d', 'c.line_id = d.sign')
  453. ->where($where)
  454. ->asArray()
  455. ->one();
  456. if (empty($getProd['prod_id'])) {
  457. return 0;
  458. }
  459. return $getProd['prod_id'];
  460. }
  461. /**
  462. * Des:根据供应商订单ID获取订单ID
  463. * Name: getOrderIdBySpiderOrderId
  464. * @param $order_id
  465. * @param $type
  466. * @return mixed|string
  467. * @author 倪宗锋
  468. */
  469. public function getOrderIdBySpiderOrderId($order_id, $type)
  470. {
  471. $where = [
  472. 'and',
  473. ['=', 'spider_order_id', $order_id],
  474. ];
  475. if (empty($type)) {
  476. $where[] = ['=', 'category_id', $type];
  477. }
  478. $select = ['order_id'];
  479. $getInfo = self::find()->select($select)
  480. ->where($where)
  481. ->asArray()
  482. ->one();
  483. if (empty($getInfo['order_id'])) {
  484. return '';
  485. }
  486. return $getInfo['order_id'];
  487. }
  488. /**
  489. * Des:获取巴士自由行下单所用产品参数
  490. * Name: getCsFreeWalkProdForMakeOrder
  491. * @param $order_id
  492. * @return array
  493. * @author 倪宗锋
  494. */
  495. public function getCsFreeWalkProdForMakeOrder($order_id)
  496. {
  497. $select = [
  498. 'prod_id' => 'b.bus_id',
  499. 'b.prod_name',
  500. 'prod_num' => 'a.count'
  501. ];
  502. $where = [
  503. 'and',
  504. ['=', 'a.order_id', $order_id],
  505. ['>', 'a.count', 0]
  506. ];
  507. $getProdArr = self::find()->select($select)
  508. ->from(OrderInfo::tableName() . ' a')
  509. ->innerJoin(ProdMain::tableName() . ' b', 'a.prod_id = b.prod_id')
  510. ->where($where)
  511. ->asArray()
  512. ->all();
  513. if (empty($getProdArr[0])) {
  514. return [];
  515. }
  516. return $getProdArr;
  517. }
  518. /**
  519. * Des:获取巴士产品下单推荐的产品的ID
  520. * Name: prodCategoryByBusOrder
  521. * @param $order_id
  522. * @return array
  523. * @author 倪宗锋
  524. */
  525. public function prodCategoryByBusOrder($order_id)
  526. {
  527. $where = [
  528. 'and',
  529. ['=', 'a.order_id', $order_id],
  530. ['!=', 'f.category_id', '1'],
  531. ['=', 'f.delete_flag', '0']
  532. ];
  533. $getList = self::find()->select(['e.prod_cate_id'])
  534. ->from(static::tableName() . ' a')
  535. ->innerJoin(ProdCategory::tableName() . ' b', 'a.prod_cate_id = b.pro_cate_id')
  536. ->innerJoin(BusTicket::tableName() . ' c', 'b.bus_ticket_id = c.ticket_id')
  537. ->innerJoin(CmsCategoryExtra::tableName() . ' d', 'd.area_id = c.end_area_id')
  538. ->innerJoin(CmsCategoryProd::tableName() . ' e', 'd.category_id = e.cms_cate_id')
  539. ->innerJoin(ProdCategory::tableName() . ' f', 'e.prod_cate_id = f.pro_cate_id')
  540. ->where($where)
  541. ->indexBy('prod_cate_id')
  542. ->asArray()
  543. ->all();
  544. if (empty($getList)) {
  545. return [];
  546. }
  547. return $getList;
  548. }
  549. /**
  550. * Des:获取非巴士产品下单推荐的产品的ID
  551. * Name: prodCategoryByUnBusOrder
  552. * @param $order_id
  553. * @return array|ActiveRecord[]
  554. * @author 倪宗锋
  555. */
  556. public function prodCategoryByUnBusOrder($order_id)
  557. {
  558. $getList = self::find()->select(['y.pro_cate_id'])
  559. ->distinct()
  560. ->from(BusTicket::tableName() . ' x')
  561. ->innerJoin(ProdCategory::tableName() . ' y', 'x.line_id=y.sign and category_id=1 and delete_flag =0')
  562. ->innerJoin(OrderMain::tableName() . ' z', '(INSTR(x.start_area_name,SUBSTR(z.order_name FROM 1 FOR 1)) or INSTR(x.end_area_name,SUBSTR(z.order_name FROM 1 FOR 1))) and z.order_id = ' . $order_id)
  563. ->asArray()
  564. ->indexBy('pro_cate_id')
  565. ->limit(8)
  566. ->all();
  567. if (count($getList) == 0) {
  568. return [];
  569. }
  570. return $getList;
  571. }
  572. /**
  573. * Des:获取下单微信通模板数据
  574. * Name: getSendCreateWxMsg
  575. * @param $order_id
  576. * @return array
  577. * @author 倪宗锋
  578. */
  579. public function getSendCreateWxMsg($order_id)
  580. {
  581. $where = ['=', 'a.order_id', $order_id];
  582. $select = [
  583. 'a.category_id',
  584. 'a.start_date',
  585. 'a.start_time',
  586. 'a.order_id',
  587. 'a.order_name',
  588. 'a.prod_cnt',
  589. 'a.total_money',
  590. 'a.start_area',
  591. 'a.end_area',
  592. 'users' => new Expression("(select GROUP_CONCAT(b.contacts_name) from order_contacts b WHERE a.order_id = b.order_id and b.contacts_type = 3)"),
  593. 'open_id' => new Expression("IFNULL((SELECT open_id from pay_main c where a.order_id = c.order_id and c.pay_type = 1),'')")
  594. ];
  595. $getWxMsg = self::find()->select($select)
  596. ->from(static::tableName() . ' a')
  597. ->where($where)
  598. ->asArray()
  599. ->one();
  600. return $getWxMsg;
  601. }
  602. /**
  603. * Des:获取班次发车一小时前的数据
  604. * Name: getSendWxMsgOrderForRunBus
  605. * @return array
  606. * @author 倪宗锋
  607. */
  608. public function getSendWxMsgOrderForRunBus()
  609. {
  610. $where = [
  611. 'and',
  612. ['=', 'category_id', 1],
  613. ['in', 'order_status', [2, 3]],
  614. // ['=','order_id','11410'],
  615. ['=', new Expression("DATE_FORMAT(CONCAT(start_date,' ',start_time),'%Y-%m-%d %H:%i')"), new Expression("DATE_FORMAT(DATE_ADD(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %H:%i')")]
  616. ];
  617. $select = [
  618. 'start_area',
  619. 'spider_order_id',
  620. 'run_date' => new Expression("CONCAT(start_date,' ',start_time)"),
  621. 'order_id',
  622. 'open_id' => new Expression("IFNULL((SELECT open_id from pay_main c where " . static::tableName() . ".order_id = c.order_id and c.pay_type = 1),'')")
  623. ];
  624. $getInfo = self::find()->select($select)
  625. ->where($where)
  626. ->asArray()
  627. ->all();
  628. return $getInfo;
  629. }
  630. /**
  631. * Des:获取酒店订车信息
  632. * Name: getHotelOrderInfo
  633. * @param $order_id
  634. * @return array
  635. * @author 倪宗锋
  636. */
  637. public function getHotelOrderInfo($order_id)
  638. {
  639. $select = [
  640. 'a.order_id',
  641. 'c.hotel_name',
  642. 'c.hotel_id',
  643. 'c.room_name',
  644. 'c.room_id',
  645. 'a.prod_cnt',
  646. 'a.start_date',
  647. 'a.end_date',
  648. 'all_days' => new Expression("DATEDIFF(a.end_date,a.start_date)"),
  649. 'a.total_money',
  650. 'a.original_price',
  651. 'b.contacts_name',
  652. 'b.contacts_phone',
  653. 'c.total_details',
  654. 'c.remarks',
  655. 'a.system',
  656. 'c.address',
  657. 'users' => new Expression("(SELECT GROUP_CONCAT(contacts_name SEPARATOR ' ') from order_contacts where contacts_type = 3 and order_id = a.order_id)"),
  658. 'commission' => new Expression("ifnull((SELECT total_money from fx_commission_info where order_id = a.order_id and delete_flag = 0 limit 1),0)")
  659. ];
  660. $where = ['=', 'a.order_id', $order_id];
  661. $getInfo = self::find()->select($select)
  662. ->from(self::tableName() . ' a')
  663. ->innerJoin(OrderContacts::tableName() . ' b', 'a.order_id = b.order_id and b.contacts_type=1')
  664. ->innerJoin(OrderHotelExtra::tableName() . ' c', 'a.order_id = c.main_order_id')
  665. ->where($where)
  666. ->asArray()
  667. ->one();
  668. return $getInfo;
  669. }
  670. /**
  671. * Des:获取为支付订单列表
  672. * Name: getUnPayOrder
  673. * @param $start_time
  674. * @param $end_time
  675. * @return array|ActiveRecord[]
  676. * @author 倪宗锋
  677. */
  678. public function getUnPayOrder($start_time, $end_time)
  679. {
  680. $select = [
  681. 'a.order_id',
  682. 'b.contacts_phone'
  683. ];
  684. $where = [
  685. 'and',
  686. ['>=', 'a.create_time', $start_time],
  687. ['<', 'a.create_time', $end_time],
  688. ['=', 'a.order_status', 1]
  689. ];
  690. $getList = self::find()->select($select)
  691. ->from(self::tableName() . ' a')
  692. ->innerJoin(OrderContacts::tableName() . ' b', 'a.order_id = b.order_id')
  693. ->where($where)
  694. ->asArray()
  695. ->all();
  696. return $getList;
  697. }
  698. /**
  699. * Des:获取发送出行通知的 酒店订单
  700. * Name: getSendTravelTipsHotels
  701. * @return array
  702. * @author 倪宗锋
  703. */
  704. public function getSendTravelTipsHotels()
  705. {
  706. $date = date("Y-m-d", strtotime("+1 day"));
  707. $where = [
  708. 'and',
  709. ['in', 'a.order_status', [2, 3]],
  710. ['=', 'a.start_date', $date],
  711. ['=', 'a.category_id', 3],
  712. ['=', 'b.pay_type', 1]
  713. ];
  714. $select = [
  715. 'a.order_id',
  716. 'b.open_id',
  717. 'a.start_date',
  718. 'a.end_date',
  719. 'c.hotel_name',
  720. 'c.room_name'
  721. ];
  722. $getList = self::find()->select($select)
  723. ->from(static::tableName() . ' a')
  724. ->innerJoin(PayMain::tableName() . ' b', 'a.order_id = b.order_id')
  725. ->innerJoin(OrderHotelExtra::tableName() . ' c', 'a.order_id = c.main_order_id')
  726. ->where($where)
  727. ->asArray()
  728. ->all();
  729. if (empty($getList[0])) {
  730. return [];
  731. }
  732. return $getList;
  733. }
  734. }