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.
 
 
 
 
 
 

839 rivejä
34 KiB

  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 张帅
  12. * PhpStorm SubmitData.php
  13. * Create By 2017/4/20 10:48 $
  14. */
  15. namespace backend\modules\api\logic;
  16. use backend\modules\api\models\OperaProductRun;
  17. use backend\modules\api\models\OrderComment;
  18. use backend\modules\api\models\OrderGroupConnect;
  19. use backend\modules\api\models\OrderHtConsumeStock;
  20. use backend\modules\api\models\OrderOperaLog;
  21. use backend\modules\api\models\OrderPayDetail;
  22. use backend\modules\api\models\OrderPayMain;
  23. use backend\modules\api\models\OrderStatusLog;
  24. use backend\modules\api\models\OrderTitle;
  25. use backend\modules\api\models\RunBus;
  26. use backend\modules\api\models\RunHotel;
  27. use backend\modules\api\models\RunHotelDistrib;
  28. use backend\modules\api\models\RunProd;
  29. use backend\modules\api\models\RunStock;
  30. use backend\modules\api\models\OrderHtStatusLog;
  31. use backend\modules\api\models\OperaHotelLog;
  32. use yii\db\Exception;
  33. use backend\modules\api\models\OrderMain;
  34. use yii\db\Expression;
  35. use yii\db\Query;
  36. use Yii;
  37. class SubmitGroupData extends Query
  38. {
  39. public $order_title_base;//组合订单数据配置
  40. public $order_group_connect_base;//组合订单关联配置
  41. public $order_main_base = [];//订单基础配置
  42. public $pay_main_base = [];//主支付记录基础配置
  43. public $pay_detail_base = [];//支付明细基础配置
  44. public $order_id_arr = [];//订单id数组
  45. public $order_main_arr = [];//订单数组
  46. public $pay_main_arr = [];//主支付记录数组
  47. public $pay_detail_arr = [];//支付明细记录
  48. public $stock_order_arr = [];//库存相关修改数组
  49. public $order_title_id = 0;//组合订单号
  50. public $product_result;//预定产品信息
  51. /**
  52. * Function Description:获取基础信息
  53. * Function Name: getBaseData
  54. * @param array $order_title_base 组合订单数据配置
  55. * @param array $order_group_connect_base 组合订单关联配置
  56. * @param array $order_main_base 订单基础配置
  57. * @param array $order_main_arr 订单数组
  58. * @param array $pay_main_base 主支付记录基础配置
  59. * @param array $pay_main_arr 主支付记录数组
  60. * @param array $pay_detail_base 支付明细基础配置
  61. * @param array $pay_detail_arr 支付明细记录
  62. * @param array $order_id_arr 订单id数组
  63. * @param array $stock_order_arr 库存相关修改数组
  64. * @param array $product_result 预定产品信息
  65. *
  66. * @author 张帅
  67. */
  68. public function getBaseData($order_title_base, $order_group_connect_base, $order_main_base, $order_main_arr, $pay_main_base, $pay_main_arr, $pay_detail_base, $pay_detail_arr, $order_id_arr, $stock_order_arr, $product_result)
  69. {
  70. $this->order_title_base = $order_title_base;//组合订单数据配置
  71. $this->order_group_connect_base = $order_group_connect_base;//组合订单关联配置
  72. $this->order_main_base = $order_main_base;//订单基础配置
  73. $order_arr = [];//订单数组
  74. foreach ($order_main_arr as $key => $vel) {
  75. $order_arr[$vel['ID']] = $vel;
  76. }
  77. $this->order_main_arr = $order_arr;//订单数组
  78. $this->pay_main_base = $pay_main_base;//主支付记录基础配置
  79. $this->pay_main_arr = $pay_main_arr;//主支付记录数组
  80. $this->pay_detail_base = $pay_detail_base;//支付明细基础配置
  81. $this->pay_detail_arr = $pay_detail_arr;//支付明细记录
  82. $this->order_id_arr = $order_id_arr;//订单id数组
  83. $this->stock_order_arr = $stock_order_arr;//库存相关修改数组
  84. $this->product_result = $product_result;//预定产品信息
  85. }
  86. /**
  87. * Function Description:提交order_main数据
  88. * Function Name: submitOrderMain
  89. *
  90. *
  91. * @author 张帅
  92. */
  93. public function submitOrderMain()
  94. {
  95. try {
  96. #region 获取提交的表头和值
  97. $order_main_base = $this->order_main_base;
  98. $order_main_key = array_keys($order_main_base);
  99. $order_main_vel = $this->order_main_arr;
  100. #endregion
  101. #region 组合订单下单更新ORDER_TITLE_ID
  102. if ($this->order_title_id != 0) {
  103. foreach ($order_main_vel as $key => $vel) {
  104. if ($vel['AGENT_LEVEL'] == 1) { //只有终端订单才加上order_title_id
  105. $order_main_vel[$key]['ORDER_TITLE_ID'] = $this->order_title_id;
  106. }
  107. }
  108. }
  109. #endregion
  110. $this->order_main_arr = $order_main_vel;
  111. #region 提交数据
  112. $order_main = new OrderMain();
  113. $res = $order_main::find()->createCommand()->batchInsert(OrderMain::tableName(), $order_main_key, $order_main_vel)->execute();
  114. if (!$res) {
  115. $error = $order_main->getErrors();
  116. throw new Exception(json_encode($error));
  117. }
  118. #endregion
  119. $json['code'] = '0';
  120. $json['info'] = '成功';
  121. } catch (Exception $e) {
  122. $json['code'] = '1';
  123. $json['info'] = '失败';
  124. $json['error'] = '提交order_main数据:' . $e->getMessage();
  125. }
  126. return $json;
  127. }
  128. /**
  129. * Function Description:提交order_pay_main数据
  130. * Function Name: submitOrderPayMain
  131. *
  132. * @return mixed
  133. *
  134. * @author 张帅
  135. */
  136. public function submitOrderPayMain()
  137. {
  138. try {
  139. #region 获取提交的表头和值
  140. $pay_main_base = $this->pay_main_base;
  141. $pay_main_key = array_keys($pay_main_base);
  142. $pay_main_vel = $this->pay_main_arr;
  143. #endregion
  144. #region 提交数据
  145. $order_pay_main = new OrderPayMain();
  146. $res = $order_pay_main::find()->createCommand()->batchInsert(OrderPayMain::tableName(), $pay_main_key, $pay_main_vel)->execute();
  147. if (!$res) {
  148. $error = $order_pay_main->getErrors();
  149. throw new Exception(json_encode($error));
  150. }
  151. #endregion
  152. $json['code'] = '0';
  153. $json['info'] = '成功';
  154. } catch (Exception $e) {
  155. $json['code'] = '1';
  156. $json['info'] = '失败';
  157. $json['error'] = '提交order_pay_main数据:' . $e->getMessage();
  158. }
  159. return $json;
  160. }
  161. /**
  162. * Function Description:提交order_pay_detail数据
  163. * Function Name: submitOrderPayDetail
  164. *
  165. * @return mixed
  166. *
  167. * @author 张帅
  168. */
  169. public function submitOrderPayDetail()
  170. {
  171. try {
  172. #region 获取提交的表头和值
  173. $pay_detail_base = $this->pay_detail_base;
  174. $pay_detail_key = array_keys($pay_detail_base);
  175. $pay_detail_vel = $this->pay_detail_arr;
  176. #endregion
  177. #region 提交数据
  178. $order_pay_detail = new OrderPayDetail();
  179. $res = $order_pay_detail::find()->createCommand()->batchInsert(OrderPayDetail::tableName(), $pay_detail_key, $pay_detail_vel)->execute();
  180. if (!$res) {
  181. $error = $order_pay_detail->getErrors();
  182. throw new Exception(json_encode($error));
  183. }
  184. #endregion
  185. $json['code'] = '0';
  186. $json['info'] = '成功';
  187. } catch (Exception $e) {
  188. $json['code'] = '1';
  189. $json['info'] = '失败';
  190. $json['error'] = '提交order_pay_detail数据:' . $e->getMessage();
  191. }
  192. return $json;
  193. }
  194. /**
  195. * Function Description:修改巴士库存
  196. * Function Name: updateBusStockInfo
  197. *
  198. * @return mixed
  199. *
  200. * @author 张帅
  201. */
  202. public function updateBusStockInfo()
  203. {
  204. try {
  205. #region 1.更新run_x
  206. $run_x_arr = $this->stock_order_arr['run_x_arr'];
  207. foreach ($run_x_arr as $key => $vel) {
  208. $run_month = date('Ym', strtotime($vel['run_date']));//run_x表名
  209. $update_sql = 'update run_' . $run_month . '
  210. set order_main_id = ' . $vel['order_main_id'] . ',
  211. order_main_prod_id = ' . $vel['order_main_prod_id'] . ',
  212. order_prod_id = ' . $vel['order_prod_id'] . ',
  213. seat_status = ' . $vel['seat_status'] . ',
  214. order_lock_user_id = ' . $vel['order_lock_user_id'] . ',
  215. order_lock_time = \'' . $vel['order_lock_time'] . '\'
  216. where id in (' . implode(',', $vel['run_x_id']) . ')';
  217. $res = Yii::$app->db->createCommand($update_sql)->execute();
  218. if (!$res) {
  219. throw new Exception('占位失败');
  220. }
  221. }
  222. #endregion
  223. #region 2.更新run_bus
  224. $run_bus = new RunBus();
  225. $run_bus_arr = $this->stock_order_arr['run_bus_arr'];
  226. foreach ($run_bus_arr as $key => $vel) {
  227. $update_value = [
  228. 'UPDATE_USER_ID' => $vel['update_user_id'],
  229. 'UPDATE_TIME' => $vel['update_time'],
  230. 'SALED_COUNT' => new Expression('SALED_COUNT+' . $vel['num']),
  231. ];
  232. $update_where = [
  233. 'and',
  234. ['=', 'run_id', $vel['run_id']],
  235. ['=', 'bus_order_id', $vel['bus_order_id']],
  236. ['=', 'cancel_flag', 0],
  237. ];
  238. $res = $run_bus::updateAll($update_value, $update_where);
  239. if (!$res) {
  240. $error = $run_bus->getErrors();
  241. throw new Exception(json_encode($error));
  242. }
  243. }
  244. #endregion
  245. #region 2.1 更新bus_cost
  246. foreach ($run_bus_arr as $k => $v) {
  247. $res = SubmitBusAgentOrder::updateBusCost($v['run_id'], $v['bus_order_id']);
  248. if (!file_exists(__DIR__ . '/../log/bus_cost')) {
  249. mkdir(__DIR__ . '/../log/bus_cost');
  250. }
  251. file_put_contents(__DIR__ . '/../log/bus_cost/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . json_encode($res) . PHP_EOL, FILE_APPEND);
  252. }
  253. #endregion
  254. #region 3.更新run_prod
  255. $run_prod = new RunProd();
  256. $run_prod_arr = $this->stock_order_arr['run_prod_arr'];
  257. foreach ($run_prod_arr as $key => $vel) {
  258. $update_value = [
  259. 'UPDATE_USER_ID' => $vel['update_user_id'],
  260. 'UPDATE_TIME' => $vel['update_time'],
  261. 'SALED_COUNT' => new Expression('SALED_COUNT+' . $vel['num']),
  262. ];
  263. $update_where = [
  264. 'and',
  265. ['=', 'run_id', $vel['run_id']],
  266. ['=', 'prod_id', $vel['ticket_id']],
  267. ['=', 'cancel_flag', 0],
  268. ];
  269. $res = $run_prod::updateAll($update_value, $update_where);
  270. if (!$res) {
  271. $error = $run_prod->getErrors();
  272. throw new Exception(json_encode($error));
  273. }
  274. }
  275. #endregion
  276. #region 4.更新run_stock
  277. $run_stock = new RunStock();
  278. $run_stock_arr = $this->stock_order_arr['run_stock_arr'];
  279. foreach ($run_stock_arr as $key => $vel) {
  280. $update_value = [
  281. 'UPDATE_USER_ID' => $vel['update_user_id'],
  282. 'UPDATE_TIME' => $vel['update_time'],
  283. 'SALED_COUNT' => new Expression('SALED_COUNT+' . $vel['num']),
  284. ];
  285. $update_where = [
  286. 'and',
  287. ['=', 'run_id', $vel['run_id']],
  288. ['=', 'seq_id', $vel['seq_id']],
  289. ['=', 'seat_type', $vel['seat_type']],
  290. ['=', 'cancel_flag', 0],
  291. ];
  292. $res = $run_stock::updateAll($update_value, $update_where);
  293. if (!$res) {
  294. $error = $run_stock->getErrors();
  295. throw new Exception(json_encode($error));
  296. }
  297. }
  298. #endregion
  299. $json['code'] = '0';
  300. $json['info'] = '成功';
  301. } catch (Exception $e) {
  302. $json['code'] = '1';
  303. $json['info'] = '失败';
  304. $json['error'] = '修改巴士库存失败:' . $e->getMessage();
  305. }
  306. return $json;
  307. }
  308. /**
  309. * Function Description:修改酒店库存
  310. * Function Name: updateHotelStockInfo
  311. *
  312. * @return mixed
  313. *
  314. * @author 张帅
  315. */
  316. public function updateHotelStockInfo()
  317. {
  318. try {
  319. #region 1.更新run_hotel
  320. $run_hotel = new RunHotel();
  321. $run_hotel_arr = $this->stock_order_arr['run_hotel_arr'];
  322. foreach ($run_hotel_arr as $key => $vel) {
  323. $update_value = [
  324. 'UPDATE_USER_ID' => $vel['update_user_id'],
  325. 'UPDATE_TIME' => $vel['update_time'],
  326. 'REMAINING_COUNT' => new Expression('REMAINING_COUNT-' . $vel['num']),
  327. 'SALED_COUNT' => new Expression('SALED_COUNT+' . $vel['num']),
  328. ];
  329. $update_where = [
  330. 'and',
  331. ['=', 'hotel_id', $vel['hotel_id']],
  332. ['=', 'base_room_type', $vel['base_room_type']],
  333. ['=', 'run_date', $vel['run_date']],
  334. ['=', 'stock_type', $vel['stock_type']],
  335. ];
  336. $res = $run_hotel::updateAll($update_value, $update_where);
  337. if (!$res) {
  338. $error = $run_hotel->getErrors();
  339. throw new Exception(json_encode($error));
  340. }
  341. }
  342. #endregion
  343. #region 2.更新run_hotel_distrib
  344. $run_hotel_distrib = new RunHotelDistrib();
  345. $run_hotel_distrib_arr = $this->stock_order_arr['run_hotel_distrib_arr'];
  346. foreach ($run_hotel_distrib_arr as $key => $vel) {
  347. $update_value = [
  348. 'UPDATE_USER_ID' => $vel['update_user_id'],
  349. 'UPDATE_TIME' => $vel['update_time'],
  350. 'REMAINING_COUNT' => new Expression('REMAINING_COUNT-' . $vel['num']),
  351. 'SALED_COUNT' => new Expression('SALED_COUNT+' . $vel['saled_count']),
  352. ];
  353. $update_where = [
  354. 'and',
  355. ['=', 'distrib_id', $vel['channel_id']],
  356. ['=', 'hotel_id', $vel['hotel_id']],
  357. ['=', 'base_room_type', $vel['base_room_type']],
  358. ['=', 'room_type', $vel['room_type']],
  359. ['=', 'run_date', $vel['run_date']],
  360. ];
  361. $res = $run_hotel_distrib::updateAll($update_value, $update_where);
  362. if (!$res) {
  363. $error = $run_hotel_distrib->getErrors();
  364. throw new Exception(json_encode($error));
  365. }
  366. }
  367. #endregion
  368. #region 3.修改渠道库存
  369. $run_hotel_disperse_result = $this->stock_order_arr['run_hotel_disperse_result'];
  370. #region 3.1 渠道借房
  371. if (count($run_hotel_disperse_result['run_hotel_distrib_disperse_arr']) > 0) {
  372. foreach ($run_hotel_disperse_result['run_hotel_distrib_disperse_arr'] as $key => $vel) {
  373. $update_value = [
  374. 'UPDATE_USER_ID' => $vel['update_user_id'],
  375. 'UPDATE_TIME' => $vel['update_time'],
  376. 'REMAINING_COUNT' => new Expression('REMAINING_COUNT-' . $vel['num']),
  377. ];
  378. $update_where = [
  379. 'and',
  380. ['=', 'distrib_id', $vel['distrib_id']],
  381. ['=', 'hotel_id', $vel['hotel_id']],
  382. ['=', 'base_room_type', $vel['base_room_type']],
  383. ['=', 'room_type', $vel['room_type']],
  384. ['=', 'run_date', $vel['run_date']],
  385. ];
  386. $res = $run_hotel_distrib::updateAll($update_value, $update_where);
  387. if (!$res) {
  388. $error = $run_hotel_distrib->getErrors();
  389. throw new Exception(json_encode($error));
  390. }
  391. }
  392. }
  393. #endregion
  394. #region 3.2 订单借房记录
  395. if (count($run_hotel_disperse_result['order_ht_consume_stock']) > 0) {
  396. $order_ht_consume_stock = new OrderHtConsumeStock();
  397. $order_ht_consume_stock_vel = [];
  398. $order_ht_consume_stock_key = ['order_id', 'distrib_id', 'run_date', 'consume_stock_count'];
  399. foreach ($run_hotel_disperse_result['order_ht_consume_stock'] as $key => $vel) {
  400. $order_ht_consume_stock_vel[] = [
  401. 'order_id' => $vel['order_id'],
  402. 'distrib_id' => $vel['distrib_id'],
  403. 'run_date' => $vel['run_date'],
  404. 'consume_stock_count' => $vel['num'],
  405. ];
  406. }
  407. $res = $order_ht_consume_stock::find()->createCommand()->batchInsert(OrderHtConsumeStock::tableName(), $order_ht_consume_stock_key, $order_ht_consume_stock_vel)->execute();
  408. if (!$res) {
  409. $error = $order_ht_consume_stock->getErrors();
  410. throw new Exception(json_encode($error));
  411. }
  412. }
  413. #endregion
  414. #region 4.更新order_comment
  415. if (count($this->stock_order_arr['order_comment_arr']) > 0) {
  416. $order_comment_vel = $this->stock_order_arr['order_comment_arr'];
  417. $order_comment_key = array_keys($order_comment_vel[0]);
  418. #region 提交数据
  419. $order_comment = new OrderComment();
  420. $res = $order_comment::find()->createCommand()->batchInsert(OrderComment::tableName(), $order_comment_key, $order_comment_vel)->execute();
  421. if (!$res) {
  422. $error = $order_comment->getErrors();
  423. throw new Exception(json_encode($error));
  424. }
  425. #endregion
  426. }
  427. #endregion
  428. #endregion
  429. $json['code'] = '0';
  430. $json['info'] = '成功';
  431. } catch (Exception $e) {
  432. $json['code'] = '1';
  433. $json['info'] = '失败';
  434. $json['error'] = '修改酒店库存:' . $e->getMessage();
  435. }
  436. return $json;
  437. }
  438. /**
  439. * Function Description:修改门票库存
  440. * Function Name: updateTicketStockInfo
  441. *
  442. * @return mixed
  443. *
  444. * @author 张帅
  445. */
  446. public function updateTicketStockInfo()
  447. {
  448. try {
  449. #region 更新opera_product_run
  450. $opera_product_run = new OperaProductRun();
  451. $opera_product_run_arr = $this->stock_order_arr['opera_product_run_arr'];
  452. foreach ($opera_product_run_arr as $key => $vel) {
  453. $update_value = [
  454. 'UPDATE_USER_ID' => $vel['update_user_id'],
  455. 'UPDATE_TIME' => $vel['update_time'],
  456. 'SALED_COUNT' => new Expression('SALED_COUNT+' . $vel['num']),
  457. ];
  458. $update_where = [
  459. 'and',
  460. ['=', 'prod_id', $vel['ticket_id']],
  461. ['=', 'run_date', $vel['run_date']],
  462. ['=', 'cancel_flag', 0],
  463. ];
  464. $res = $opera_product_run::updateAll($update_value, $update_where);
  465. if (!$res) {
  466. $error = $opera_product_run->getErrors();
  467. throw new Exception(json_encode($error));
  468. }
  469. }
  470. #endregion
  471. $json['code'] = '0';
  472. $json['info'] = '成功';
  473. } catch (Exception $e) {
  474. $json['code'] = '1';
  475. $json['info'] = '失败';
  476. $json['error'] = '修改门票库存:' . $e->getMessage();
  477. }
  478. return $json;
  479. }
  480. /**
  481. * Function Description:提交组合订单信息
  482. * Function Name: submitOrderTitle
  483. *
  484. * @return mixed
  485. *
  486. * @author 张帅
  487. */
  488. public function submitOrderTitle()
  489. {
  490. try {
  491. $order_title = new OrderTitle();
  492. $order_group_connect = new OrderGroupConnect();
  493. $order_group_connect_vel = [];//组合订单关联数组
  494. $order_group_connect_key = array_keys($this->order_group_connect_base);//组合订单关联表头
  495. $order_title_base = $this->order_title_base;//组合订单数据配置
  496. $order_id_arr = $this->order_id_arr;//订单id数组
  497. #region 提交order_title数据
  498. #region 巴士产品订单号
  499. if (isset($order_id_arr['bus_product'])) {
  500. $order_title_base['bus_order'] = implode(',', $order_id_arr['bus_product']);//对应子巴士产品订单号,多个用逗号隔开
  501. #region 获取组合订单关联数组
  502. foreach ($order_id_arr['bus_product'] as $key => $vel) {
  503. $order_group_connect_one = $this->order_group_connect_base;
  504. $order_group_connect_one['order_main_id'] = $vel;
  505. $order_group_connect_one['order_type'] = 1;
  506. $order_group_connect_vel[] = $order_group_connect_one;
  507. }
  508. #endregion
  509. }
  510. #endregion
  511. #region 酒店产品订单号
  512. if (isset($order_id_arr['hotel_product'])) {
  513. $order_title_base['hotel_order'] = implode(',', $order_id_arr['hotel_product']);//对应酒店子产品订单号,多个用逗号隔开
  514. #region 获取组合订单关联数组
  515. foreach ($order_id_arr['hotel_product'] as $key => $vel) {
  516. $order_group_connect_one = $this->order_group_connect_base;
  517. $order_group_connect_one['order_main_id'] = $vel;
  518. $order_group_connect_one['order_type'] = 2;
  519. $order_group_connect_vel[] = $order_group_connect_one;
  520. }
  521. #endregion
  522. }
  523. #endregion
  524. #region 门票产品订单号
  525. if (isset($order_id_arr['ticket_product'])) {
  526. $order_title_base['ticket_order'] = implode(',', $order_id_arr['ticket_product']);//对应门票子产品订单号,多个用逗号隔开
  527. #region 获取组合订单关联数组
  528. foreach ($order_id_arr['ticket_product'] as $key => $vel) {
  529. $order_group_connect_one = $this->order_group_connect_base;
  530. $order_group_connect_one['order_main_id'] = $vel;
  531. $order_group_connect_one['order_type'] = 3;
  532. $order_group_connect_vel[] = $order_group_connect_one;
  533. }
  534. #endregion
  535. }
  536. #endregion
  537. $order_title->attributes = $order_title_base;
  538. $res = $order_title->insert();
  539. if (!$res) {
  540. $error = $order_title->getErrors();
  541. throw new Exception(json_encode($error));
  542. }
  543. $order_title_id = $order_title->order_title_id;
  544. $this->order_title_id = $order_title_id;
  545. #endregion
  546. #region 提交order_group_connect数据
  547. foreach ($order_group_connect_vel as $key => $vel) {
  548. $order_group_connect_vel[$key]['order_title_id'] = $order_title_id;
  549. }
  550. $res = $order_group_connect::find()->createCommand()->batchInsert(OrderGroupConnect::tableName(), $order_group_connect_key, $order_group_connect_vel)->execute();
  551. if (!$res) {
  552. $error = $order_group_connect->getErrors();
  553. throw new Exception(json_encode($error));
  554. }
  555. #endregion
  556. $json['code'] = '0';
  557. $json['info'] = '成功';
  558. $json['order_title_id'] = $order_title_id;
  559. } catch (Exception $e) {
  560. $json['code'] = '1';
  561. $json['info'] = '失败';
  562. $json['error'] = '提交组合订单信息:' . $e->getMessage();
  563. }
  564. return $json;
  565. }
  566. /**
  567. * Function Description:提交巴士日志
  568. * Function Name: submitBusLog
  569. *
  570. * @return mixed
  571. *
  572. * @author 温依莅
  573. */
  574. public function submitBusLog()
  575. {
  576. $order_id_arr = $this->order_id_arr;//订单id数组
  577. $bus_order_arr = $order_id_arr['bus_product'];//巴士订单数组
  578. $order_main_arr = $this->order_main_arr;//订单数据
  579. $order_base_info = $this->product_result['order_info'];//订单基础配置
  580. $bus_product_list = array();//巴士产品信息(包含代售信息)
  581. //这里对巴士产品信息按主订单号重排,方便下面订单日志对代售信息插入对应数据
  582. foreach ($this->product_result['bus_product'] as $bk => $bv) {
  583. $bus_product_list[$bv['order_id']] = $bv;
  584. }
  585. $order_opera_log_vel = [];//巴士操作日志
  586. $order_opera_log_key = [];//巴士操作日志表头
  587. $order_status_log_vel = [];//巴士状态日志
  588. $order_status_log_key = [];//巴士状态日志表头
  589. try {
  590. foreach ($bus_order_arr as $key => $vel) {
  591. $order_info = $order_main_arr[$vel];//订单详情
  592. /*$order_num = explode('|', $order_info['ORDER_DESCRIPTION']);
  593. $order_num = end($order_num);//订单人数*/
  594. #region 添加巴士日志
  595. foreach ($bus_product_list[$key]['agent_list'] as $ik => $iv) {
  596. $title_info = ($iv['agent_level'] == 1 ? '【组合订单号:' . $order_info['ORDER_TITLE_ID'] . '】' : '');
  597. $order_opera_log_one = [
  598. 'order_id' => $iv['order_id'],
  599. 'opera_user_id' => $iv['agent_level'] == 1 ? $order_info['CREATE_USER_ID'] : 2,
  600. 'opera_type' => 1,
  601. 'opera_time' => date('Y-m-d H:i:s'),
  602. 'opera_detail' => '创建订单,出发日期' . $order_info['RUN_DATE'] . ',订单渠道:' . $iv['outside_sale_org_name'] . ',单价' . $iv['price'] . ',总额' . $iv['total_order_price'] . ',联系人信息:' . $order_info['CUSTOMER_NAME'] . ',' . $order_info['CUSTOMER_MOBILE'] . ',' . $order_info['CUSTOMER_ID_NO'] . ',备注信息:' . $order_info['CUSTOMER_MEMO'] . $title_info,
  603. 'member_id' => $order_info['MEMBER_ID'],
  604. 'opera_platform' => '统一下单',
  605. ];
  606. if (count($order_opera_log_key) == 0) {
  607. $order_opera_log_key = array_keys($order_opera_log_one);//巴士操作日志表头
  608. }
  609. $order_opera_log_vel[] = $order_opera_log_one;//巴士操作日志
  610. }
  611. #endregion
  612. #region 添加巴士订单状态
  613. $order_status = $order_info['ORDER_PAY_STATUS'] == 1 ? [451, 452, 453] : [451];
  614. foreach ($order_status as $status_key => $status_vel) {
  615. foreach ($bus_product_list[$key]['agent_list'] as $ik => $iv) {
  616. $order_status_log_one = [
  617. 'order_id' => $iv['order_id'],
  618. 'new_status' => $status_vel,
  619. 'change_time' => date('Y-m-d H:i:s'),
  620. ];
  621. if (count($order_status_log_key) == 0) {
  622. $order_status_log_key = array_keys($order_status_log_one);//巴士状态日志表头
  623. }
  624. $order_status_log_vel[] = $order_status_log_one;//巴士状态日志
  625. }
  626. }
  627. #endregion
  628. }
  629. #region 提交巴士日志
  630. $order_opera_log = new OrderOperaLog();
  631. $res = $order_opera_log::find()->createCommand()->batchInsert(OrderOperaLog::tableName(), $order_opera_log_key, $order_opera_log_vel)->execute();
  632. if (!$res) {
  633. $error = $order_opera_log->getErrors();
  634. throw new Exception(json_encode($error));
  635. }
  636. #endregion
  637. #region 提交巴士订单状态
  638. $order_status_log = new OrderStatusLog();
  639. $res = $order_status_log::find()->createCommand()->batchInsert(OrderStatusLog::tableName(), $order_status_log_key, $order_status_log_vel)->execute();
  640. if (!$res) {
  641. $error = $order_status_log->getErrors();
  642. throw new Exception(json_encode($error));
  643. }
  644. $json['code'] = '0';
  645. $json['info'] = '成功';
  646. #endregion
  647. } catch (Exception $e) {
  648. $json['code'] = '1';
  649. $json['info'] = '失败';
  650. $json['error'] = '提交巴士日志:' . $e->getMessage();
  651. }
  652. return $json;
  653. }
  654. /**
  655. * Function Description:提交酒店日志
  656. * Function Name: submitHotelLog
  657. *
  658. * @return mixed
  659. *
  660. * @author 温依莅
  661. */
  662. public function submitHotelLog()
  663. {
  664. $order_id_arr = $this->order_id_arr;//订单id数组
  665. $hotel_order_arr = $order_id_arr['hotel_product'];//酒店订单数组
  666. $order_main_arr = $this->order_main_arr;//订单数据
  667. $opera_hotel_log_vel = [];//酒店操作日志
  668. $opera_hotel_log_key = [];//酒店操作日志表头
  669. $order_ht_status_log_vel = [];//酒店状态日志
  670. $order_ht_status_log_key = [];//酒店状态日志表头
  671. try {
  672. foreach ($hotel_order_arr as $key => $vel) {
  673. $order_info = $order_main_arr[$vel];//订单详情
  674. #region 添加酒店日志
  675. $opera_hotel_log_one = [
  676. 'CREATE_USER_ID' => $order_info['CREATE_USER_ID'],
  677. 'CREATE_TIME' => $order_info['CREATE_TIME'],
  678. 'LOG_TYPE' => 3,
  679. 'HOTEL_ID' => $order_info['PARENT_PROD_ID'],
  680. 'PARENT_ROOM_TYPE' => 0,
  681. 'ROOM_TYPE' => $order_info['PROD_ID'],
  682. 'LOG_DESC' => '组合订单:创建订单号为' . $order_info['ORDER_ID'] . '的订单,组合订单号:' . $order_info['ORDER_TITLE_ID'],
  683. 'ORDER_ID' => $order_info['ORDER_ID'],
  684. ];
  685. if (count($opera_hotel_log_key) == 0) {
  686. $opera_hotel_log_key = array_keys($opera_hotel_log_one);//酒店操作日志表头
  687. }
  688. $opera_hotel_log_vel[] = $opera_hotel_log_one;//酒店操作日志
  689. #endregion
  690. #region 添加酒店订单状态
  691. $order_ht_status_log_one = [
  692. 'ORDER_ID' => $order_info['ORDER_ID'],
  693. 'ORDER_STATUS' => 313,
  694. 'BEFORE_STATUS' => 0,
  695. 'CREATE_USER_ID' => $order_info['CREATE_USER_ID'],
  696. 'CREATE_TIME' => $order_info['CREATE_TIME'],
  697. 'UPDATE_USER_ID' => $order_info['CREATE_USER_ID'],
  698. 'UPDATE_TIME' => $order_info['CREATE_TIME'],
  699. 'CANCEL_FLAG' => 1,
  700. ];
  701. $order_ht_status_log_two = [
  702. 'ORDER_ID' => $order_info['ORDER_ID'],
  703. 'ORDER_STATUS' => 198,
  704. 'BEFORE_STATUS' => 313,
  705. 'CREATE_USER_ID' => $order_info['CREATE_USER_ID'],
  706. 'CREATE_TIME' => $order_info['CREATE_TIME'],
  707. 'UPDATE_USER_ID' => $order_info['CREATE_USER_ID'],
  708. 'UPDATE_TIME' => $order_info['CREATE_TIME'],
  709. 'CANCEL_FLAG' => 0,
  710. ];
  711. if (count($order_ht_status_log_key) == 0) {
  712. $order_ht_status_log_key = array_keys($order_ht_status_log_one);//酒店状态日志表头
  713. }
  714. $order_ht_status_log_vel[] = $order_ht_status_log_one;//酒店状态日志
  715. $order_ht_status_log_vel[] = $order_ht_status_log_two;//酒店状态日志
  716. #endregion
  717. }
  718. #region 提交酒店日志
  719. $opera_hotel_log = new OperaHotelLog();
  720. $res = $opera_hotel_log::find()->createCommand()->batchInsert(OperaHotelLog::tableName(), $opera_hotel_log_key, $opera_hotel_log_vel)->execute();
  721. if (!$res) {
  722. $error = $opera_hotel_log->getErrors();
  723. throw new Exception(json_encode($error));
  724. }
  725. #endregion
  726. #region 提交酒店订单状态
  727. $order_ht_status_log = new OrderHtStatusLog();
  728. $res = $order_ht_status_log::find()->createCommand()->batchInsert(OrderHtStatusLog::tableName(), $order_ht_status_log_key, $order_ht_status_log_vel)->execute();
  729. if (!$res) {
  730. $error = $order_ht_status_log->getErrors();
  731. throw new Exception(json_encode($error));
  732. }
  733. $json['code'] = '0';
  734. $json['info'] = '成功';
  735. #endregion
  736. } catch (Exception $e) {
  737. $json['code'] = '1';
  738. $json['info'] = '失败';
  739. $json['error'] = '提交酒店日志:' . $e->getMessage();
  740. }
  741. return $json;
  742. }
  743. }