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.
 
 
 
 
 
 

1125 lines
49 KiB

  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 张帅
  12. * PhpStorm SubmitGroupOrder.php
  13. * Create By 2017/4/14 15:31 $
  14. */
  15. namespace backend\modules\api\logic;
  16. use backend\modules\api\logic\SubmitBusAgentOrder;
  17. use backend\modules\api\models\BaseUniqueId2;
  18. use backend\modules\api\models\BaseUser;
  19. use yii\db\Exception;
  20. use yii\db\Query;
  21. use Yii;
  22. use backend\modules\api\models\OrderMain;
  23. use common\models\Msg;
  24. use backend\modules\api\models\BaseUniqueLog;
  25. class SubmitGroupOrder extends Query
  26. {
  27. public $order_title_base = [
  28. 'main_corp_id' => 0,//运营主体
  29. 'create_date' => '',
  30. 'create_user_id' => 0,
  31. 'create_time' => '',//下单时刻
  32. 'update_user_id' => 0,//最后更新人
  33. 'update_time' => '',//最后更新时刻
  34. 'confirm_time' => '',
  35. 'outside_sale_org_id' => 0,//渠道
  36. 'outside_order_no' => '',//渠道订单号
  37. 'order_title_prod_name' => '',//产品名(自动生成)
  38. 'order_title_prod_description' => '',//产品明细
  39. 'start_date' => '',//出发日期
  40. 'start_time' => '',//出发时刻
  41. 'cus_name' => '',//联系人
  42. 'cus_phone' => '',//联系手机
  43. 'cus_id_no' => '',//联系人身份证
  44. 'cus_remark' => '',//备注
  45. 'cus_id_type' => '',//联系人证件类型150身份证 153护照
  46. 'cus_num' => 0,//总人数
  47. 'order_title_all_price' => 0,//总收入
  48. 'order_title_per_price' => 0,//单人收入
  49. 'order_prod_type' => 0,//组合订单种类:[100]单车票[010]单酒店[001]单门票[110]车+酒[101]车+门[011]酒+门[111]车+酒+门
  50. 'order_pay_type' => '',//组合订单支付方式
  51. 'order_title_status' => 2,//组合订单整体状态, 1:待确认 2: 已确认 3:已完成 4: 已取消。
  52. 'cancel_flag' => 0,
  53. 'bus_order' => '',//对应子巴士产品订单号,多个用逗号隔开
  54. 'ticket_order' => '',//对应门票子产品订单号,多个用逗号隔开
  55. 'hotel_order' => '',//对应酒店子产品订单号,多个用逗号隔开
  56. 'order_title_type' => 1,//组合订单种类:1自由选择(CS) 2跟团游(微信商城)。。。
  57. 'tourist_id' => 0,//组合产品id,为0是自由组合的组合订单
  58. 'is_buy_insurance' => 0,//是否购买保险
  59. ];//组合订单数据配置
  60. public $order_group_connect_base = [
  61. 'order_title_id' => 0,
  62. 'order_main_id' => 0,
  63. 'order_type' => 0,
  64. 'cancel_flag' => 0,
  65. 'create_time' => '',
  66. 'update_time' => '',
  67. 'create_user_id' => 0,
  68. 'create_date' => '',
  69. ];//组合订单关联配置
  70. public $product_result = [];//产品数据
  71. public $order_main_base = [
  72. 'ID' => 1,
  73. 'CANCEL_FLAG' => 0,
  74. 'MAIN_CREATE_USER_ID' => 1,
  75. 'CREATE_USER_ID' => 1,
  76. 'CREATE_TIME' => '',
  77. 'UPDATE_USER_ID' => 1,
  78. 'UPDATE_TIME' => '',
  79. 'SALE_ORG_ID' => 0,
  80. 'SALE_TOP_ORG_ID' => 0,
  81. 'PROD_TOP_ORG_ID' => 0,
  82. 'ORDER_ID' => 0,
  83. 'ORDER_DESCRIPTION' => '',
  84. 'OUTSIDE_ORDER_NO' => '',
  85. 'ORDER_VALID_STATUS' => 1,
  86. 'ORDER_BOOK_STATUS' => 0,
  87. 'ORDER_PAY_STATUS' => 0,
  88. 'ORDER_PAY_MAIN_ID' => 0,
  89. 'ORDER_PAY_USER_ID' => 1,
  90. 'ORDER_PAY_TIME' => '',
  91. 'ORDER_PRINT_TIMES' => 0,
  92. 'PARENT_ORDER_ID' => 0,
  93. 'PROD_ID' => 0,
  94. 'PARENT_PROD_ID' => 0,
  95. 'PROD_NAME' => '',
  96. 'PARENT_PROD_NAME' => '',
  97. 'ORDER_PRICE' => 0,
  98. 'ORDER_PROD_TYPE' => 0,
  99. 'PROD_SUPPLY_ORG_NAME' => '',
  100. 'BASE_PRICE' => 0,
  101. 'MID_PRICE' => 0,
  102. 'RUN_ID' => 0,
  103. 'RUN_DATE' => '',
  104. 'RUN_DATE_NUM' => 0,
  105. 'RUN_TIME' => '',
  106. 'RUN_TIME_MINUTES' => 0,
  107. 'RUN_BUS_ORDER_ID' => 0,
  108. 'RUN_BUS_SEAT_TYPE' => 0,
  109. 'RUN_BUS_SEAT_SEQ_ID' => 0,
  110. 'RUN_BUS_SEAT_ID' => 0,
  111. 'RUN_BUS_SEAT_NAME' => '',
  112. 'PROD_START_STATION_RES_ID' => 0,
  113. 'PROD_START_STATION_RES_NAME' => '',
  114. 'PROD_START_STATION_CHECKPORT_RES_ID' => 0,
  115. 'PROD_START_STATION_CHECKPORT_RES_NAME' => '',
  116. 'PROD_START_STATION_SEQ_ID' => 0,
  117. 'PROD_START_STATION_DATE' => '',
  118. 'PROD_START_STATION_DATE_NUM' => 0,
  119. 'PROD_START_STATION_TIME' => '',
  120. 'PROD_START_STATION_TIME_MINUTES' => 0,
  121. 'PROD_START_STATION_AREA_ID' => 0,
  122. 'PROD_START_STATION_AREA_NAME' => '',
  123. 'PROD_END_STATION_RES_ID' => 0,
  124. 'PROD_END_STATION_RES_NAME' => '',
  125. 'PROD_END_STATION_SEQ_ID' => 0,
  126. 'PROD_END_STATION_DATE' => '',
  127. 'PROD_END_STATION_DATE_NUM' => 0,
  128. 'PROD_END_STATION_TIME' => '',
  129. 'PROD_END_STATION_TIME_MINUTES' => 0,
  130. 'PROD_END_STATION_AREA_ID' => 0,
  131. 'PROD_END_STATION_AREA_NAME' => '',
  132. 'CUSTOMER_NAME' => '',
  133. 'CUSTOMER_SEX' => 1,
  134. 'CUSTOMER_MOBILE' => '',
  135. 'CUSTOMER_ID_TYPE' => 0,
  136. 'CUSTOMER_ID_NO' => '',
  137. 'CUSTOMER_ADDRESS' => '',
  138. 'CUSTOMER_ADDRESS_AREA_ID' => 0,
  139. 'CUSTOMER_POSTCODE' => '',
  140. 'CUSTOMER_MEMO' => '',
  141. 'MEMBER_ID' => 0,
  142. 'MEMBER_SCORE_PAY' => 0,
  143. 'MEMBER_SCORE_GET' => 0,
  144. 'ORDER_STATUS' => 0,
  145. 'ORDER_DISABLE_TYPE' => 0,
  146. 'ORDER_DISABLE_USER_ID' => 0,
  147. 'ORDER_DISABLE_TIME' => '',
  148. 'ORDER_DISABLE_PERCENT' => 0,
  149. 'ORDER_DISABLE_FEE' => 0,
  150. 'ORDER_DISABLE_APPLY_USER_ID' => 0,
  151. 'ORDER_DISABLE_APPLY_TIME' => '',
  152. 'KEEP_END_TIME' => '',
  153. 'KEEP_END_MINUTES' => 0,
  154. 'if_gift' => 0,
  155. 'reorder_times' => 0,
  156. 'IF_LAST_PROD' => 1,
  157. 'ORDER_LEVEL' => 0,
  158. 'ORDER_CONFIRM_CODE' => '',
  159. 'OUTSIDE_SALE_ORG_ID' => 0,
  160. 'IS_UP' => 1,
  161. 'APPLY_ID' => 0,
  162. 'SALES_MAN' => '',
  163. 'PRINCIPAL_ID' => 0,
  164. 'RECEIVE_VALUE' => 0,
  165. 'REAL_PASSENGER_NUM' => -1,
  166. 'STOCK_TYPE' => 0,
  167. 'REFUSE_FLAG' => 0,
  168. 'PROFIT_VALUE' => 0,
  169. 'TOTAL_COMMISSION' => 0,
  170. 'ORDER_TITLE_ID' => 0,
  171. 'SUB_CHANNEL_ID' => 0,// int(11) NOT NULL DEFAULT '0' COMMENT '下级渠道id(用于代售)',
  172. 'SUB_CHANNEL_NO' => '',// varchar(100) NOT NULL DEFAULT '' COMMENT '下级渠道订单号',
  173. 'MAIN_CORP_ID' => 1,// int(11) NOT NULL DEFAULT '0' COMMENT '订单所属运营主体',
  174. 'SALE_PATH' => '',// varchar(50) NOT NULL DEFAULT '' COMMENT '销售路径(代售)eg:1001,1002,1003',
  175. 'AGENT_LEVEL' => 1,// int(3) NOT NULL DEFAULT '1' COMMENT '销售层级:终端1,上一级2,再上一级3',
  176. 'SOURCE_MAIN_CORP_ID' => 1,// int(11) NOT NULL DEFAULT '0' COMMENT '线路所属运营主体',
  177. ];//订单基础配置
  178. public $pay_main_base = [
  179. 'ID' => 0,
  180. 'CREATE_USER_ID' => 1,
  181. 'CREATE_TIME' => '',
  182. 'UPDATE_USER_ID' => 1,
  183. 'UPDATE_TIME' => '',
  184. 'PAY_TOTAL' => 0,
  185. 'ORDER_ID' => 0,
  186. ];//主支付记录基础配置
  187. public $pay_detail_base = [
  188. 'ID' => 0,
  189. 'CREATE_USER_ID' => 1,
  190. 'CREATE_TIME' => '',
  191. 'UPDATE_USER_ID' => 1,
  192. 'UPDATE_TIME' => '',
  193. 'PAY_MAIN_ID' => 0,
  194. 'PAY_TYPE_ID_1' => 0,
  195. 'PAY_MONEY' => 0,
  196. ];//支付明细
  197. public $user_id;//用户id
  198. public $create_time;//创建时间
  199. public $unique_id = 1000000;//唯一键值
  200. public $channel_id;//渠道号
  201. public $order_id_arr = [];//订单id数组
  202. public $order_main_arr = [];//订单数组
  203. public $pay_main_arr = [];//主支付记录数组
  204. public $pay_detail_arr = [];//支付明细记录
  205. public $stock_order_arr = [];//库存相关修改数组
  206. public $check_submit_date;
  207. public $get_bus_order_data;
  208. public $get_hotel_order_data;
  209. public $get_ticket_order_data;
  210. public $submit_group_data;
  211. public $final_unique_id;//最终id
  212. /**
  213. * Function Description:获取服务
  214. * Function Name: getService
  215. * @param $type
  216. *
  217. * @return CheckSubmitData|GetBusOrderData|GetHotelOrderData|GetTicketOrderData|SubmitGroupData|bool
  218. *
  219. * @author 张帅
  220. */
  221. public function getService($type)
  222. {
  223. switch ($type) {
  224. case 'check':
  225. if ($this->check_submit_date == '') {
  226. $this->check_submit_date = new CheckSubmitData();
  227. }
  228. return $this->check_submit_date;
  229. case 'bus':
  230. if ($this->get_bus_order_data == '') {
  231. $this->get_bus_order_data = new GetBusOrderData();
  232. }
  233. return $this->get_bus_order_data;
  234. case 'hotel':
  235. if ($this->get_hotel_order_data == '') {
  236. $this->get_hotel_order_data = new GetHotelOrderData();
  237. }
  238. return $this->get_hotel_order_data;
  239. case 'ticket':
  240. if ($this->get_ticket_order_data == '') {
  241. $this->get_ticket_order_data = new GetTicketOrderData();
  242. }
  243. return $this->get_ticket_order_data;
  244. case 'submit':
  245. if ($this->submit_group_data == '') {
  246. $this->submit_group_data = new SubmitGroupData();
  247. $this->submit_group_data->getBaseData($this->order_title_base, $this->order_group_connect_base, $this->order_main_base, $this->order_main_arr, $this->pay_main_base, $this->pay_main_arr, $this->pay_detail_base, $this->pay_detail_arr, $this->order_id_arr, $this->stock_order_arr, $this->product_result);
  248. }
  249. return $this->submit_group_data;
  250. default:
  251. return false;
  252. }
  253. }
  254. /**
  255. * Function Description:检验提交数据格式
  256. * Function Name: checkSubmitData
  257. * @param string $product_name 产品名称
  258. * @param string $bus_product 巴士产品
  259. * @param string $hotel_product 酒店产品
  260. * @param string $ticket_product 门票产品
  261. * @param string $customer_info 顾客信息
  262. * @param string $order_info 订单基础信息
  263. * @param float $group_order_price 组合产品总价格
  264. * @param string $tourist_mark 订单基础信息 标志该组合下单是否是自由行产品下单:0表示否,如是则传组合产品的ID值 tourist_id
  265. * @param float $tourist_org_id 组合产品总价格 自由行产品销售渠道id,区别于order_info里的outside_sale_org_id[运营主体所对应]内部采购渠道id
  266. * @param string $tourist_extra_info 自由行产品下单其他参数(成人,儿童数)
  267. * @param array $passenger_info 乘车人详细 [{姓名,身份证},{姓名,身份证},{姓名,身份证}] array数组json_encode
  268. * @return mixed
  269. *
  270. * @author 张帅
  271. */
  272. public function checkSubmitData($product_name, $bus_product, $hotel_product, $ticket_product, $customer_info, $order_info, $group_order_price, $tourist_mark, $tourist_org_id, $tourist_extra_info, $passenger_info=[])
  273. {
  274. $check_submit_date = $this->getService('check');
  275. $result['passenger_info'] = $passenger_info;//出行人信息列表
  276. $result['tourist_mark'] = $tourist_mark;
  277. $result['tourist_org_id'] = $tourist_org_id;
  278. $result['tourist_extra_info'] = json_decode($tourist_extra_info, true);
  279. #region 检验产品名称
  280. if (empty($product_name)) {
  281. $json['code'] = '1';
  282. $json['info'] = '产品名称有误';
  283. return $json;
  284. }
  285. $result['product_name'] = $product_name;//产品名称有误
  286. #endregion
  287. #region 检验巴士数据
  288. $result['bus_product'] = $check_submit_date->checkBusProductData($bus_product);
  289. if ($result['bus_product'] === false) {
  290. $json['code'] = '1';
  291. $json['info'] = '巴士产品有误';
  292. return $json;
  293. }
  294. #endregion
  295. #region 检验酒店数据
  296. $result['hotel_product'] = $check_submit_date->checkHotelProductData($hotel_product);
  297. if ($result['hotel_product'] === false) {
  298. $json['code'] = '1';
  299. $json['info'] = '酒店产品有误';
  300. return $json;
  301. }
  302. #endregion
  303. #region 检验门票数据
  304. $result['ticket_product'] = $check_submit_date->checkTicketProductData($ticket_product);
  305. if ($result['ticket_product'] === false) {
  306. $json['code'] = '1';
  307. $json['info'] = '门票产品有误';
  308. return $json;
  309. }
  310. #endregion
  311. #region 检验顾客数据
  312. $result['customer_info'] = $check_submit_date->checkCustomerInfoData($customer_info);
  313. if ($result['customer_info'] === false) {
  314. $json['code'] = '1';
  315. $json['info'] = '顾客数据有误';
  316. return $json;
  317. }
  318. #endregion
  319. #region 检验订单基本信息 和 组合产品总价
  320. $result['order_info'] = $check_submit_date->checkOrderInfoData($order_info, $group_order_price);
  321. if ($result['order_info'] === false) {
  322. $json['code'] = '1';
  323. $json['info'] = '必须数据有误';
  324. return $json;
  325. }
  326. #endregion
  327. //组合产品总价
  328. $result['group_order_price'] = $group_order_price;
  329. $this->product_result = $result;
  330. $json['code'] = '0';
  331. $json['info'] = '成功';
  332. return $json;
  333. }
  334. /**
  335. * Function Description:获取巴士订单数据
  336. * Function Name: getBusOrderData
  337. *
  338. * @return array|bool|mixed|\yii\db\ActiveRecord[]
  339. *
  340. * @author 张帅
  341. */
  342. public function getBusOrderData()
  343. {
  344. #region 获取巴士选购产品
  345. $bus_product = $this->product_result['bus_product'];
  346. #endregion
  347. #region 判断是否有巴士产品
  348. if (count($bus_product) == 0) {
  349. $json['code'] = '0';
  350. $json['info'] = '成功';
  351. return $json;
  352. }
  353. #endregion
  354. $get_bus_order_data = $this->getService('bus');
  355. #region 获取要选购的巴士产品详情
  356. $bus_product_info = $get_bus_order_data->getBusProductListData($bus_product);
  357. if (isset($bus_product_info['code']) && $bus_product_info['code'] == '1') {
  358. return $bus_product_info;
  359. }
  360. #endregion
  361. #region 检验班次是否存在并粗略检查库存
  362. $check_result = $get_bus_order_data->checkRunX();
  363. if (isset($check_result['code']) && $check_result['code'] == '1') {
  364. return $check_result;
  365. }
  366. #endregion
  367. #region 获取巴士产品座位并检查库存
  368. $bus_product_info = $get_bus_order_data->getRunBusSeat();
  369. if (isset($bus_product_info['code']) && $bus_product_info['code'] == '1') {
  370. return $bus_product_info;
  371. }
  372. #endregion
  373. $this->product_result['bus_product'] = $bus_product_info;
  374. $json['code'] = '0';
  375. $json['info'] = '成功';
  376. return $json;
  377. }
  378. /**
  379. * Function Description:获取酒店佣金相关参数
  380. * Function Name: getHotelCommission
  381. * @param string $hotel_product 酒店产品信息(json格式)eg:{"hotel_id":"81","base_room_type":"100074","room_type":"5","hotel_memo":"舟山酒店备注","run_room":[{"run_date":"2017-06-14","prod_num":"2","prod_price":766.5},{"run_date":"2017-06-15","prod_num":"2","prod_price":766.5}]}
  382. * @param int $channel_id 酒店渠道id
  383. * @return string
  384. *
  385. * @author 温依莅
  386. */
  387. public function getHotelCommission($hotel_product, $channel_id)
  388. {
  389. $hotel_arr = json_decode($hotel_product, true);
  390. if (!$hotel_arr) {
  391. return $hotel_product;
  392. }
  393. $res = (new Query())->select('commision_flag,commision_type,back_commision_type,back_commision_method,back_percent,back_value')
  394. ->from('base_supplier_sale')
  395. ->where([
  396. 'parent_type' => 25,
  397. 'supplier_id' => $channel_id,
  398. 'cancel_flag' => 0
  399. ])->one();
  400. //循环处理酒店产品信息
  401. foreach ($hotel_arr as $k => $v) {
  402. foreach ($v['run_room'] as $ik => $iv) {
  403. $hotel_arr[$k]['run_room'][$ik]['back_value'] = $res['back_value'];
  404. $hotel_arr[$k]['run_room'][$ik]['back_percent'] = $res['back_percent'];
  405. $hotel_arr[$k]['run_room'][$ik]['back_commision_method'] = $res['back_commision_method'];
  406. }
  407. }
  408. //重新赋值类属性中的hotel_product属性
  409. $this->product_result['hotel_product'] = $hotel_arr;
  410. return json_encode($hotel_arr);
  411. }
  412. /**
  413. * Function Description:获取酒店订单数据
  414. * Function Name: getTicketOrderData
  415. *
  416. * @return mixed
  417. *
  418. * @author 张帅
  419. */
  420. public function getHotelOrderData()
  421. {
  422. #region 获取酒店选购产品
  423. $hotel_product = $this->product_result['hotel_product'];
  424. #endregion
  425. #region 判断是否有酒店产品
  426. if (count($hotel_product) == 0) {
  427. $json['code'] = '0';
  428. $json['info'] = '成功';
  429. return $json;
  430. }
  431. #endregion
  432. $get_hotel_order_data = $this->getService('hotel');
  433. #region 获取酒店产品的基础房型
  434. $hotel_product_info = $get_hotel_order_data->getBaseRoomInfo($hotel_product);
  435. if (isset($hotel_product_info['code']) && $hotel_product_info['code'] == '1') {
  436. return $hotel_product_info;
  437. }
  438. #endregion
  439. #region 获取渠道的基础库存
  440. $hotel_base_stock = $get_hotel_order_data->getRoomBaseStock($this->channel_id);
  441. if (isset($hotel_base_stock['code']) && $hotel_base_stock['code'] == '1') {
  442. return $hotel_base_stock;
  443. }
  444. #endregion
  445. #region 获取渠道的详情库存
  446. $hotel_info_stock = $get_hotel_order_data->getRoomInfoStock();
  447. if (isset($hotel_info_stock['code']) && $hotel_info_stock['code'] == '1') {
  448. return $hotel_info_stock;
  449. }
  450. #endregion
  451. #region 判断库存是否充足
  452. $hotel_product_info = $get_hotel_order_data->checkHotelProductStock();
  453. if (isset($hotel_product_info['code']) && $hotel_product_info['code'] == '1') {
  454. return $hotel_product_info;
  455. }
  456. #endregion
  457. $this->product_result['hotel_product'] = $hotel_product_info;
  458. $json['code'] = '0';
  459. $json['info'] = '成功';
  460. return $json;
  461. }
  462. /**
  463. * Function Description:获取门票订单数据
  464. * Function Name: getTicketOrderData
  465. *
  466. * @return mixed
  467. *
  468. * @author 张帅
  469. */
  470. public function getTicketOrderData()
  471. {
  472. #region 获取门票选购产品
  473. $ticket_product = $this->product_result['ticket_product'];
  474. #endregion
  475. #region 判断是否有门票产品
  476. if (count($ticket_product) == 0) {
  477. $json['code'] = '0';
  478. $json['info'] = '成功';
  479. return $json;
  480. }
  481. #endregion
  482. $get_bus_order_data = $this->getService('ticket');
  483. #region 获取主订单数据详情
  484. $ticket_product_info = $get_bus_order_data->getTicketMainProductList($ticket_product);
  485. if (isset($ticket_product_info['code']) && $ticket_product_info['code'] == '1') {
  486. return $ticket_product_info;
  487. }
  488. #endregion
  489. #region 获取子订单产品详情
  490. $ticket_product_info = $get_bus_order_data->getTicketSonProductList();
  491. if (isset($ticket_product_info['code']) && $ticket_product_info['code'] == '1') {
  492. return $ticket_product_info;
  493. }
  494. #endregion
  495. $this->product_result['ticket_product'] = $ticket_product_info;
  496. $json['code'] = '0';
  497. $json['info'] = '成功';
  498. return $json;
  499. }
  500. /**
  501. * Function Description:生成订单各配置数据
  502. * Function Name: getOrderMainBase
  503. *
  504. *
  505. * @author 张帅
  506. */
  507. public function getOrderMainBase()
  508. {
  509. $customer_info = $this->product_result['customer_info'];//顾客信息
  510. $order_info = $this->product_result['order_info'];//订单信息
  511. $product_name = $this->product_result['product_name'];//产品名称
  512. $tourist_mark = $this->product_result['tourist_mark'];//自由行产品id,如果没有,为0
  513. $tourist_org_id = $this->product_result['tourist_org_id'];//自由行产品对应的渠道id
  514. $tourist_extra_info = $this->product_result['tourist_extra_info'];//自由行其他信息(成人儿童数)
  515. #region 补充订单基础配置
  516. $this->order_main_base['MAIN_CREATE_USER_ID'] = $order_info['user_id'];
  517. $this->order_main_base['CREATE_USER_ID'] = $order_info['user_id'];
  518. $this->order_main_base['UPDATE_USER_ID'] = $order_info['user_id'];
  519. $this->order_main_base['CREATE_TIME'] = date('Y-m-d H:i:s');
  520. $this->order_main_base['UPDATE_TIME'] = date('Y-m-d H:i:s');
  521. $this->order_main_base['OUTSIDE_ORDER_NO'] = $order_info['outside_sale_order_no'];
  522. $this->order_main_base['ORDER_BOOK_STATUS'] = $order_info['order_book_status'];
  523. $this->order_main_base['ORDER_PAY_STATUS'] = $order_info['order_pay_status'];
  524. $this->order_main_base['ORDER_PAY_USER_ID'] = $order_info['user_id'];
  525. $this->order_main_base['ORDER_PAY_TIME'] = date('Y-m-d H:i:s');
  526. $this->order_main_base['CUSTOMER_NAME'] = $customer_info['customer_name'];
  527. $this->order_main_base['CUSTOMER_MOBILE'] = $customer_info['customer_mobile'];
  528. $this->order_main_base['CUSTOMER_ID_TYPE'] = $customer_info['customer_id_type'];
  529. $this->order_main_base['CUSTOMER_ID_NO'] = $customer_info['customer_id_no'];
  530. $this->order_main_base['CUSTOMER_MEMO'] = $customer_info['customer_memo'];
  531. $this->order_main_base['MEMBER_ID'] = $order_info['member_id'];
  532. $this->order_main_base['ORDER_STATUS'] = $order_info['order_status'];
  533. $this->order_main_base['OUTSIDE_SALE_ORG_ID'] = $order_info['outside_sale_org_id'];
  534. $this->order_main_base['SALES_MAN'] = $order_info['sales_man'];
  535. #endregion
  536. $this->user_id = $order_info['user_id'];//用户id
  537. $this->create_time = date('Y-m-d H:i:s');
  538. $this->channel_id = $order_info['outside_sale_org_id'];//渠道id
  539. #region 补充主支付方式基础配置
  540. $this->pay_main_base['CREATE_USER_ID'] = $order_info['user_id'];
  541. $this->pay_main_base['UPDATE_USER_ID'] = $order_info['user_id'];
  542. $this->pay_main_base['CREATE_TIME'] = date('Y-m-d H:i:s');
  543. $this->pay_main_base['UPDATE_TIME'] = date('Y-m-d H:i:s');
  544. #endregion
  545. #region 补充支付明细基础配置
  546. $this->pay_detail_base['CREATE_USER_ID'] = $order_info['user_id'];
  547. $this->pay_detail_base['UPDATE_USER_ID'] = $order_info['user_id'];
  548. $this->pay_detail_base['CREATE_TIME'] = date('Y-m-d H:i:s');
  549. $this->pay_detail_base['UPDATE_TIME'] = date('Y-m-d H:i:s');
  550. $this->pay_detail_base['PAY_TYPE_ID_1'] = $order_info['pay_type'];
  551. #endregion
  552. #region 补充order_title基础配置
  553. $main_corp_id = BaseUser::find()->select('main_corp_id')->where('id = ' . $order_info['user_id'])->asArray()->one();
  554. $this->order_title_base['main_corp_id'] = $main_corp_id['main_corp_id'];//运营主体
  555. $this->order_title_base['create_date'] = date('Y-m-d');
  556. $this->order_title_base['create_user_id'] = $order_info['user_id'];
  557. $this->order_title_base['create_time'] = date('Y-m-d H:i:s');
  558. $this->order_title_base['update_user_id'] = $order_info['user_id'];
  559. $this->order_title_base['update_time'] = date('Y-m-d H:i:s');//最后更新人
  560. $this->order_title_base['outside_sale_org_id'] = $tourist_mark ? $tourist_org_id : $order_info['outside_sale_org_id'];//渠道【如果是组合产品下单,则取tourist_org_id,否则取order_info的outside_sale_org_id】
  561. $this->order_title_base['outside_order_no'] = (string)$order_info['outside_sale_order_no'];//渠道订单号
  562. $this->order_title_base['order_title_prod_name'] = $product_name;//产品名称
  563. $this->order_title_base['order_title_prod_description'] = $product_name;//产品明细
  564. $this->order_title_base['cus_name'] = $customer_info['customer_name'];//联系人
  565. $this->order_title_base['cus_phone'] = $customer_info['customer_mobile'];//联系手机
  566. $this->order_title_base['cus_id_no'] = $customer_info['customer_id_no'];//联系人身份证
  567. $this->order_title_base['cus_remark'] = $customer_info['customer_memo'];
  568. $this->order_title_base['cus_id_type'] = $customer_info['customer_id_type'];
  569. $this->order_title_base['order_pay_type'] = $order_info['pay_type'];//组合订单支付方式
  570. $this->order_title_base['order_title_type'] = $tourist_mark ? 2 : 1;//组合订单种类:1自由选择(CS) 2自由行产品(微信商城)
  571. $this->order_title_base['tourist_id'] = $tourist_mark;//自由行产品id
  572. $this->order_title_base['adult_num'] = $tourist_extra_info['adult_num'];//自由行产品 成人人数
  573. $this->order_title_base['child_num'] = $tourist_extra_info['child_num'];//自由行产品 儿童人数
  574. #endregion
  575. #region 补充order_group_connect基础配置
  576. $this->order_group_connect_base['create_time'] = date('Y-m-d H:i:s');
  577. $this->order_group_connect_base['update_time'] = date('Y-m-d H:i:s');
  578. $this->order_group_connect_base['create_user_id'] = $order_info['user_id'];
  579. $this->order_group_connect_base['create_date'] = date('Y-m-d');
  580. #endregion
  581. }
  582. /**
  583. * Function Description:获取唯一键值并补充主订单配置
  584. * Function Name: getUniqueId
  585. *
  586. *
  587. * @author 张帅
  588. */
  589. public function getUniqueId()
  590. {
  591. $agent_obj = new SubmitBusAgentOrder();
  592. #region 获取产品详情
  593. $product_result = $this->product_result;
  594. $order_info = $product_result['order_info'];
  595. #endregion
  596. //1,----------------------- 对巴士产品做进一步处理,添加代售相关信息,为进一步计算order_id做准备 -----------------------------
  597. $bus_prod_list = $product_result['bus_product'];
  598. if ($bus_prod_list) {
  599. foreach ($product_result['bus_product'] as $k => $v) {
  600. $res = $agent_obj->getTicketAgentInfo($v['ticket_id'], $order_info['outside_sale_org_id'], $order_info['user_id']);
  601. if ($res['code'] != '0') {
  602. $result['code'] = 1;
  603. $result['info'] = $res['info'];
  604. return $result;
  605. }
  606. $list = $res['list'];
  607. #prod_list_final里ticket对应的值存 销售层级1的数据
  608. $bus_prod_list[$k]['is_agent'] = $list['is_agent'];//是否是代理票种
  609. $bus_prod_list[$k]['agent_depth'] = $list['agent_depth'];//销售层数
  610. $bus_prod_list[$k]['prod_top_org_id'] = $list['ticket_agent_list'][1]['prod_top_org_id'];//供应商id
  611. $bus_prod_list[$k]['prod_supply_org_name'] = $list['ticket_agent_list'][1]['prod_supply_org_name'];//供应商姓名
  612. $bus_prod_list[$k]['outside_sale_org_id'] = $order_info['outside_sale_org_id'];//渠道商id
  613. $bus_prod_list[$k]['outside_order_no'] = $order_info['outside_sale_order_no'];//渠道订单号
  614. $bus_prod_list[$k]['sub_channel_id'] = $order_info['outside_sale_org_id'];//下级渠道id
  615. $bus_prod_list[$k]['sub_channel_no'] = $order_info['outside_sale_order_no'];//下级渠道订单号
  616. $bus_prod_list[$k]['main_corp_id'] = $list['ticket_agent_list'][1]['main_corp_id'];//订单所属运营主体
  617. $bus_prod_list[$k]['source_main_corp_id'] = $list['ticket_agent_list'][1]['source_main_corp_id'];//线路所属运营主体
  618. $bus_prod_list[$k]['sale_path'] = $list['ticket_agent_list'][1]['sale_path'];//销售路径(代售才有,自营为空)
  619. $bus_prod_list[$k]['agent_level'] = $list['ticket_agent_list'][1]['agent_level'];//售卖层级:终端1,上一级2,再上一级3
  620. $bus_prod_list[$k]['base_price'] = $list['ticket_agent_list'][1]['base_price'];//子订单成本
  621. $bus_prod_list[$k]['total_base_price'] = $bus_prod_list[$k]['base_price'] * $bus_prod_list[$k]['prod_num'];//主订单成本
  622. #根据销售层级得到代收数组
  623. $bus_prod_list[$k]['agent_list'] = $list['ticket_agent_list'];
  624. }
  625. }
  626. //2,---------------- 生成订单号:其中主订单id直接嵌入数组相关字段,子订单给出起始id,完成base_unique_id2表的更新 --------------------
  627. #2.1,计算BaseUniqueId 需要增加的值(主订单和子订单的id个数),更新唯一键值
  628. #region order_title基础配置所需数据
  629. $addCnt = 0;
  630. $unique_id_add = 0;
  631. $total_price = 0;//总价
  632. $total_num = 0;//总人数
  633. $order_prod_type = '';//组合订单种类
  634. $start_date = [];//出发日期
  635. $start_time = [];//出发时刻
  636. $order_title_status = 2;//组合订单状态
  637. $confirm_time = '';//确认时间
  638. #endregion
  639. #region 遍历巴士订单
  640. /*if (count($product_result['bus_product']) > 0) {
  641. $order_prod_type .= '1';//组合订单种类
  642. foreach ($product_result['bus_product'] as $key => $vel) {
  643. $final_unique_id = $final_unique_id + 2 + $vel['prod_num'];//最终唯一id
  644. $total_price += $vel['price'] * $vel['prod_num'];//总价
  645. $total_num += $vel['prod_num'];//总人数
  646. $start_date[] = $vel['run_date'];//出发日期
  647. $start_time[] = $vel['start_time'];//出发时刻
  648. }
  649. } else {
  650. $order_prod_type .= '0';//组合订单种类
  651. }*/
  652. if (count($bus_prod_list) > 0) {
  653. $order_prod_type .= '1';//组合订单种类
  654. foreach ($bus_prod_list as $key => $vel) {
  655. $addCnt += ($vel['prod_num'] + 1) * $vel['agent_depth'];
  656. $unique_id_add += $vel['agent_depth'];//此处修改接下来的订单分配id起始值,刨除了巴士代售的主订单号
  657. $total_price += $vel['price'] * $vel['prod_num'];//总价
  658. $total_num += $vel['prod_num'];//总人数
  659. $start_date[] = $vel['run_date'];//出发日期
  660. $start_time[] = $vel['start_time'];//出发时刻
  661. }
  662. } else {
  663. $order_prod_type .= '0';//组合订单种类
  664. }
  665. #endregion
  666. #region 遍历酒店订单
  667. if (count($product_result['hotel_product']) > 0) {
  668. $order_prod_type .= '1';//组合订单种类
  669. foreach ($product_result['hotel_product'] as $hotel_key => $hotel_vel) {
  670. $addCnt += 2;
  671. foreach ($hotel_vel['run_room'] as $room_key => $room_vel) {
  672. $total_price += $room_vel['total_price'];//总价
  673. $total_num += $room_vel['prod_num'];//总人数
  674. $addCnt += $room_vel['prod_num'];
  675. $start_date[] = $room_vel['run_date'];//出发日期
  676. }
  677. }
  678. $order_title_status = 1;
  679. } else {
  680. $confirm_time = date('Y-m-d H:i:s');
  681. $order_prod_type .= '0';//组合订单种类
  682. }
  683. #endregion
  684. #region 遍历门票订单
  685. if (count($product_result['ticket_product']) > 0) {
  686. $order_prod_type .= '1';//组合订单种类
  687. foreach ($product_result['ticket_product'] as $main_key => $main_vel) {
  688. $addCnt += 2;
  689. foreach ($main_vel['son_ticket'] as $son_key => $son_vel) {
  690. $total_price += $son_vel['price'] * $son_vel['prod_num'];//总价
  691. $total_num += $son_vel['prod_num'];//总人数
  692. $addCnt += $son_vel['prod_num'];
  693. $start_date[] = $main_vel['run_date'];//出发日期
  694. }
  695. }
  696. } else {
  697. $order_prod_type .= '0';//组合订单种类
  698. }
  699. #endregion
  700. // $do = false;
  701. // do{
  702. #region 获取唯一主键
  703. // $unique_id = BaseUniqueId2::find()->select('unique_id')->where('id = 1')->asArray()->one();
  704. // $base_main_id = $unique_id['unique_id'] + 0;
  705. // $this->unique_id = $unique_id['unique_id'] + 1 + $unique_id_add;
  706. // $final_unique_id = $unique_id['unique_id'] + 1 + $addCnt;//最终唯一id
  707. #endregion
  708. #region 更新唯一键值
  709. // $unique_id = BaseUniqueId2::findOne(['id' => 1]);
  710. // $unique_id->UNIQUE_ID = $final_unique_id;
  711. // $json = array();
  712. $time=time().rand(0,999999);
  713. $sql="update base_unique_id2 set unique_id=(unique_id + 1 + $addCnt),update_time='$time' where id =1";
  714. if (!Yii::$app->getDb()->createCommand($sql)->execute()) {
  715. $json['code'] = '1';
  716. $json['info'] = 'unique_id更新错误' . serialize($sql);
  717. return $json;
  718. } else {
  719. $unique_id = BaseUniqueLog::find()->select('unique_id1,unique_id2')->where(['update_time'=>$time])->asArray()->one();
  720. $base_main_id = $unique_id['unique_id1'] + 0;
  721. $this->unique_id = $unique_id['unique_id1'] + 1 + $unique_id_add;
  722. $final_unique_id = $unique_id['unique_id1'] + 1 + $addCnt;//最终唯一id
  723. // if ($unique_id['unique_id'] != $final_unique_id) {//更新成功
  724. // $do = true;
  725. // }else{
  726. // $do=false;
  727. // }
  728. }
  729. // sleep(rand(1,5));
  730. // }while($do == true);
  731. // while ($do == true) {//再来一次
  732. // $base_main_id = $unique_id['unique_id'] + 0;
  733. // $this->unique_id = $unique_id['unique_id'] + 1 + $unique_id_add;
  734. // $final_unique_id = $unique_id['unique_id'] + 1 + $addCnt;//最终唯一id
  735. // $unique_id = BaseUniqueId2::findOne(['id' => 1]);
  736. // $unique_id->UNIQUE_ID = $final_unique_id;
  737. // $json = array();
  738. // if (!$unique_id->update()) {
  739. // $json['code'] = '1';
  740. // $json['info'] = 'unique_id更新错误do' . serialize($unique_id->getErrors());
  741. // return $json;
  742. // }
  743. // }
  744. #endregion
  745. #2.2,生成巴士主订单号,按需求重组进bus_prod_list数组里
  746. $main_bus_order_id_arr = array();//主订单号数组
  747. foreach ($bus_prod_list as $k => $v) {
  748. $agent_depth = $v['agent_depth'];
  749. $id_arr = $agent_obj->getPointNum($base_main_id, $agent_depth);//array(1001,1002,1003)
  750. $base_main_id += $agent_depth;//增加初始值
  751. $id_str = implode(',', $id_arr);//1001,1002,1003
  752. $main_bus_order_id_arr[$k] = $id_arr;
  753. $bus_prod_list[$k]['order_id'] = $id_arr[1];
  754. $bus_prod_list[$k]['sale_path'] = $v['is_agent'] ? $id_str : '';//如果是代售票种,写入销售路径,否则为空字符串
  755. foreach ($v['agent_list'] as $ak => $av) {
  756. $bus_prod_list[$k]['agent_list'][$ak]['order_id'] = $id_arr[$ak];//主订单号
  757. $bus_prod_list[$k]['agent_list'][$ak]['sale_path'] = $bus_prod_list[$k]['sale_path'];//销售路径
  758. $av['price'] = $av['order_price'];
  759. $bus_prod_list[$k]['agent_list'][$ak]['price'] = $av['order_price'];
  760. if ($ak == 1) { //agent_level_1
  761. $bus_prod_list[$k]['agent_list'][$ak]['outside_order_no'] = $bus_prod_list[$k]['outside_order_no'];//agent_level_1 渠道订单号
  762. $bus_prod_list[$k]['agent_list'][$ak]['sub_channel_no'] = $bus_prod_list[$k]['sub_channel_no'];//agent_level_1 下级订单号
  763. $bus_prod_list[$k]['agent_list'][$ak]['price'] = $bus_prod_list[$k]['price'];//agent_level_1 子订单售价
  764. $bus_prod_list[$k]['agent_list'][$ak]['total_order_price'] = $bus_prod_list[$k]['price'] * $bus_prod_list[$k]['prod_num'];//agent_level_1 主订单售价
  765. $bus_prod_list[$k]['agent_list'][$ak]['total_base_price'] = $bus_prod_list[$k]['total_base_price'];//agent_level_1 主订单成本
  766. } else if ($ak == 2) { //agent_level_2
  767. $bus_prod_list[$k]['agent_list'][$ak]['outside_order_no'] = 'SPIDER-' . $id_arr[1];//agent_level_2 渠道订单号
  768. $bus_prod_list[$k]['agent_list'][$ak]['sub_channel_no'] = $bus_prod_list[$k]['outside_order_no'];//agent_level_2 下级订单号
  769. $bus_prod_list[$k]['agent_list'][$ak]['total_order_price'] = $av['price'] * $bus_prod_list[$k]['prod_num'];//agent_level_2 主订单售价
  770. $bus_prod_list[$k]['agent_list'][$ak]['total_base_price'] = $av['base_price'] * $bus_prod_list[$k]['prod_num'];//agent_level_2 主订单成本
  771. } else if ($ak == 3) { //agent_level_3
  772. $bus_prod_list[$k]['agent_list'][$ak]['outside_order_no'] = 'SPIDER-' . $id_arr[2];//agent_level_3 渠道订单号
  773. $bus_prod_list[$k]['agent_list'][$ak]['sub_channel_no'] = 'SPIDER-' . $id_arr[1];//agent_level_3 下级订单号
  774. $bus_prod_list[$k]['agent_list'][$ak]['total_order_price'] = $av['price'] * $bus_prod_list[$k]['prod_num'];//agent_level_3 主订单售价
  775. $bus_prod_list[$k]['agent_list'][$ak]['total_base_price'] = $av['base_price'] * $bus_prod_list[$k]['prod_num'];//agent_level_3 主订单成本
  776. }
  777. }
  778. }
  779. $this->product_result['bus_product'] = $bus_prod_list;
  780. #region 获取出发日期和出发时刻
  781. sort($start_date);
  782. $start_date = $start_date[0];
  783. if (count($start_time) > 0) {
  784. sort($start_time);
  785. $start_time = $start_time[0];
  786. } else {
  787. $start_time = '00:00';
  788. }
  789. #endregion
  790. #region 补充order_title基础配置
  791. $this->order_title_base['start_date'] = $start_date;//出发日期
  792. $this->order_title_base['start_time'] = $start_time;//出发时刻
  793. $this->order_title_base['cus_num'] = $total_num;//总人数
  794. $this->order_title_base['order_title_all_price'] = round($this->product_result['group_order_price'], 2);//round($total_price, 2);//总收入
  795. $this->order_title_base['order_title_per_price'] = round($this->order_title_base['order_title_all_price'] / $total_num, 2);//单人收入
  796. $this->order_title_base['order_prod_type'] = $order_prod_type;//组合订单种类:[100]单车票[010]单酒店[001]单门票[110]车+酒[101]车+门[011]酒+门[111]车+酒+门
  797. $this->order_title_base['order_title_status'] = $order_title_status;//组合订单状态
  798. $this->order_title_base['confirm_time'] = $confirm_time;//确认时间
  799. #endregion
  800. $this->final_unique_id = $final_unique_id;
  801. $json['code'] = '0';
  802. $json['info'] = '唯一键值配置成功';
  803. return $json;
  804. }
  805. function addCnt($addCnt)
  806. {
  807. }
  808. /**
  809. * Function Description:获取订单提交数据配置
  810. * Function Name: getSubmitGroupOrderData
  811. *
  812. *
  813. * @author 张帅
  814. */
  815. public function getSubmitGroupOrderData()
  816. {
  817. #region 获取巴士订单提交所需数据
  818. if (count($this->product_result['bus_product']) > 0) {
  819. $result = $this->getService('bus')->getSubmitBusData($this->unique_id, $this->order_main_base, $this->pay_main_base, $this->pay_detail_base, $this->user_id, $this->create_time, $this->product_result['bus_product']);
  820. #region 补充设置数据
  821. $this->unique_id = $result['unique_id'];//唯一键值
  822. $this->order_main_arr = array_merge($this->order_main_arr, $result['order_main_arr']);//订单数据
  823. $this->pay_main_arr = array_merge($this->pay_main_arr, $result['pay_main_arr']);//主支付记录
  824. $this->pay_detail_arr = array_merge($this->pay_detail_arr, $result['pay_detail_arr']);//支付明细
  825. $this->order_id_arr['bus_product'] = $result['main_order_id_arr'];//唯一键值
  826. $this->stock_order_arr = array_merge($this->stock_order_arr,
  827. [
  828. 'run_x_arr' => $result['run_x_arr'],//run_x需要修改数据
  829. 'run_bus_arr' => $result['run_bus_arr'],//run_bus需要修改数据
  830. 'run_prod_arr' => $result['run_prod_arr'],//run_prod需要修改数据
  831. 'run_stock_arr' => $result['run_stock_arr'],//run_stock需要更新数据
  832. ]
  833. );
  834. #endregion
  835. }
  836. #endregion
  837. #region 获取酒店订单提交所需数据
  838. if (count($this->product_result['hotel_product']) > 0) {
  839. $result = $this->getService('hotel')->getSubmitHotelData($this->unique_id, $this->order_main_base, $this->pay_main_base, $this->pay_detail_base, $this->user_id, $this->create_time);
  840. #region 补充设置数据
  841. $this->unique_id = $result['unique_id'];//唯一键值
  842. $this->order_main_arr = array_merge($this->order_main_arr, $result['order_main_arr']);//订单数据
  843. $this->pay_main_arr = array_merge($this->pay_main_arr, $result['pay_main_arr']);//主支付记录
  844. $this->pay_detail_arr = array_merge($this->pay_detail_arr, $result['pay_detail_arr']);//支付明细
  845. $this->order_id_arr['hotel_product'] = $result['main_order_id_arr'];//唯一键值
  846. $this->stock_order_arr = array_merge($this->stock_order_arr,
  847. [
  848. 'run_hotel_arr' => $result['run_hotel_arr'],//run_hotel需要修改的库存
  849. 'run_hotel_distrib_arr' => $result['run_hotel_distrib_arr'],//run_hotel_distrib需要修改的库存
  850. 'run_hotel_disperse_result' => $result['run_hotel_disperse_result'],//run_hotel_distrib需要分摊数据
  851. 'order_comment_arr' => $result['order_comment_arr'],
  852. ]
  853. );
  854. #endregion
  855. }
  856. #endregion
  857. #region 获取门票订单提交所需数据
  858. if (count($this->product_result['ticket_product']) > 0) {
  859. $result = $this->getService('ticket')->getSubmitTicketData($this->unique_id, $this->order_main_base, $this->pay_main_base, $this->pay_detail_base, $this->user_id, $this->create_time);
  860. #region 补充设置数据
  861. $this->unique_id = $result['unique_id'];//唯一键值
  862. $this->order_main_arr = array_merge($this->order_main_arr, $result['order_main_arr']);//订单数据
  863. $this->pay_main_arr = array_merge($this->pay_main_arr, $result['pay_main_arr']);//主支付记录
  864. $this->pay_detail_arr = array_merge($this->pay_detail_arr, $result['pay_detail_arr']);//支付明细
  865. $this->order_id_arr['ticket_product'] = $result['main_order_id_arr'];//唯一键值
  866. $this->stock_order_arr = array_merge($this->stock_order_arr,
  867. [
  868. 'opera_product_run_arr' => $result['opera_product_run_arr'],//opera_product_run需要修改数据
  869. ]
  870. );
  871. #endregion
  872. }
  873. #endregion
  874. }
  875. /**
  876. * Function Description:提交订单数据
  877. * Function Name: submitGroupOrder
  878. *
  879. * @return mixed
  880. *
  881. * @author 张帅
  882. */
  883. public function submitGroupOrder()
  884. {
  885. if ($this->unique_id != $this->final_unique_id) {
  886. $json['code'] = '1';
  887. $json['info'] = '计数异常,下单失败';
  888. return $json;
  889. }
  890. $submit_data = $this->getService('submit');
  891. $transaction = Yii::$app->db->beginTransaction();
  892. try {
  893. #region 1.order_pay_main插入数据
  894. $result = $submit_data->submitOrderPayMain();
  895. if (!isset($result['code']) || $result['code'] == '1') {
  896. throw new Exception($result['error']);
  897. }
  898. #endregion
  899. #region 2.order_pay_detail插入数据
  900. $result = $submit_data->submitOrderPayDetail();
  901. if (!isset($result['code']) || $result['code'] == '1') {
  902. throw new Exception($result['error']);
  903. }
  904. #endregion
  905. #region 3.修改巴士库存
  906. if (count($this->product_result['bus_product']) > 0) {
  907. $result = $submit_data->updateBusStockInfo();
  908. if (!isset($result['code']) || $result['code'] == '1') {
  909. throw new Exception($result['error']);
  910. }
  911. }
  912. #endregion
  913. #region 4.修改酒店库存
  914. if (count($this->product_result['hotel_product']) > 0) {
  915. $result = $submit_data->updateHotelStockInfo();
  916. if (!isset($result['code']) || $result['code'] == '1') {
  917. throw new Exception($result['error']);
  918. }
  919. }
  920. #endregion
  921. #region 5.修改门票库存
  922. if (count($this->product_result['ticket_product']) > 0) {
  923. $result = $submit_data->updateTicketStockInfo();
  924. if (!isset($result['code']) || $result['code'] == '1') {
  925. throw new Exception($result['error']);
  926. }
  927. }
  928. #endregion
  929. #region 6.新增组合订单数据
  930. $result = $submit_data->submitOrderTitle();
  931. if (!isset($result['code']) || $result['code'] == '1') {
  932. throw new Exception($result['error']);
  933. }
  934. $order_title_id = $result['order_title_id'];
  935. #endregion
  936. #region 7.order_main插入数据
  937. $result = $submit_data->submitOrderMain();
  938. if (!isset($result['code']) || $result['code'] == '1') {
  939. throw new Exception($result['error']);
  940. }
  941. #endregion
  942. #region 8.插入巴士日志
  943. if (isset($this->order_id_arr['bus_product'])) {
  944. $result = $submit_data->submitBusLog();
  945. if (!isset($result['code']) || $result['code'] == '1') {
  946. throw new Exception($result['error']);
  947. }
  948. }
  949. #endregion
  950. #region 9.插入酒店日志
  951. if (isset($this->order_id_arr['hotel_product'])) {
  952. $result = $submit_data->submitHotelLog();
  953. if (!isset($result['code']) || $result['code'] == '1') {
  954. throw new Exception($result['error']);
  955. }
  956. }
  957. #endregion
  958. #region 10.插入巴士订单出行人
  959. if (isset($this->product_result['passenger_info']) && count($this->product_result['bus_product']) > 0) {
  960. $passenger_info = $this->product_result['passenger_info'];
  961. $agent_obj = $agent_obj = new SubmitBusAgentOrder();
  962. if (count($passenger_info) != 0) {
  963. $order_id_str = implode(',', $this->order_id_arr['bus_product']);
  964. $agent_obj->IstPassengerInfo($order_id_str, $passenger_info);
  965. }
  966. }
  967. #endregion
  968. $transaction->commit();
  969. $json['code'] = '0';
  970. $json['info'] = '下单成功';
  971. $json['order_title_id'] = $order_title_id;
  972. $json['order_id'] = $this->order_id_arr;
  973. //add by qius on 2017.08.21 发送预定短信
  974. // $bus_id_array = implode(',', $this->order_id_arr['bus_product']);
  975. if (count($this->product_result['bus_product']) > 0) {
  976. foreach ($this->order_id_arr['bus_product'] as $key => $vel) {
  977. $url = 'http://' . CS1_DOMAIN . '/api/msg/order-send-msg';
  978. $sendInfo = array();
  979. $sendInfo['order_id'] = $vel;
  980. $sendInfo['msg_type'] = 'cs';
  981. Msg::httpRequest($url, $sendInfo);
  982. }
  983. }
  984. } catch (Exception $e) {
  985. $json['code'] = '1';
  986. $json['info'] = '下单失败';
  987. $json['error'] = $e->getMessage();
  988. }
  989. return $json;
  990. }
  991. /**
  992. * Function Description:供应商扣款
  993. * Function Name: insertBalance
  994. * @param $order_title_id
  995. *
  996. * @return array
  997. *
  998. * @author LUOCJ
  999. */
  1000. public function insertBalance($order_title_id)
  1001. {
  1002. $res_data = ['code' => '0', 'info' => '供应商扣款成功'];
  1003. $order_hotel_models = OrderMain::find()->from(OrderMain::tableName())
  1004. ->where(['and', ['=', 'order_title_id', $order_title_id], ['=', 'cancel_flag', 0], ['in', 'order_prod_type', [25, 81]]])->all();
  1005. if (!$order_hotel_models) {
  1006. $res_data['code'] = '1';
  1007. $res_data['info'] = '无该酒店订单数据,不需要进行扣款';
  1008. return $res_data;
  1009. }
  1010. $submit_order = new SubmitOrder();
  1011. foreach ($order_hotel_models as $k => $v) {
  1012. $submit_order->SupplierBalance($v->ORDER_ID, 1, '组合订单:下单扣款');
  1013. }
  1014. return $res_data;
  1015. }
  1016. }