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.
 
 
 
 
 
 

1893 lines
82 KiB

  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm OrderUtil.php
  13. * Create By 2017/3/10 11:52 $
  14. */
  15. namespace common\util;
  16. use common\models\FxCommissionInfo;
  17. use common\models\FxUser;
  18. use common\models\OrderContacts;
  19. use common\models\OrderHotelExtra;
  20. use common\models\OrderInfo;
  21. use common\models\OrderMain;
  22. use common\models\PayMain;
  23. use common\models\PayRefush;
  24. use common\models\ProdCategory;
  25. use common\models\ProdMain;
  26. use common\models\ShUser;
  27. use common\service\login\LoginService;
  28. use common\service\pay\PayService;
  29. use common\service\WeChatService;
  30. use yii\base\Exception;
  31. use zzcx\service\home\FreeWalker;
  32. use zzcx\service\home\MenP;
  33. class OrderUtil
  34. {
  35. /**
  36. * Des:申请取消订单
  37. * Name: applyCancelOrder
  38. * @param $order_id int 订单号
  39. * @param $is_check int 是否校验,订单可否退款
  40. * @param $is_send int 是否通知供应取消订单
  41. * @param $uid int 用户ID
  42. * @param $u_type int 0系统,1管理员,2分销商,3微信用户
  43. * @param $is_confrim int 0 是否发送酒店拒单通知。0:默认通知 ,1:酒店拒单通知
  44. * @return array
  45. * @author 倪宗锋
  46. */
  47. public static function applyCancelOrder($order_id, $is_check = 1, $is_send = 1, $uid = 0, $u_type = 0, $is_confrim = 0)
  48. {
  49. $transaction = \Yii::$app->db->beginTransaction();
  50. try {
  51. //1.判断订单是否可以取消
  52. $oderMain = new OrderMain();
  53. $orderInfo = $oderMain->getOrderInfoById($order_id);
  54. if ($is_check == 1) {//是否校验 是否可以退款
  55. $isCancel = static::checkOrderCanCancel($orderInfo);
  56. if ($isCancel['flag'] == false) {
  57. $transaction->rollBack();
  58. return $isCancel;
  59. }
  60. }
  61. //2.如果订单已支付 则添加退款记录 取消分销商的佣金
  62. if (in_array($orderInfo['order_status'], [2, 3, 4])) {
  63. $order_status = 4;//退款
  64. //2.1添加退款记录 已经存在记录则自动跳出
  65. $refund = static::addPayRefund($orderInfo);
  66. if ($refund['flag'] == false) {
  67. $transaction->rollBack();
  68. return $refund;
  69. }
  70. //2.2修改佣金记录 没有佣金记录则自动自动退出
  71. $setCommission = static::setCommission($order_id);
  72. if ($setCommission['flag'] == false) {
  73. $transaction->rollBack();
  74. return $refund;
  75. }
  76. } else {
  77. $order_status = 5;//取消
  78. }
  79. //3.修改订单状态 退款 或者 取消
  80. $canCel = static::cancelOrder($order_id, $order_status);
  81. if ($canCel['flag'] == false) {
  82. $transaction->rollBack();
  83. return $canCel;
  84. }
  85. //4.通知供应商订单取消
  86. if ($is_send == 1) {//是否发送退款请求通知供应商
  87. //去cs取消订单 不是车票或没有spider_order_id 会自动跳出方法
  88. $csFlag = static::cancelOrderCsBus($orderInfo);
  89. if ($csFlag['flag'] == false) {
  90. $transaction->rollBack();
  91. return $csFlag;
  92. }
  93. }
  94. //5.发送用户通知 目前只有酒店订单发送通知
  95. static::sendCancelOrderMsg($orderInfo, $is_confrim);
  96. Util::sendWxMsg(['order_id' => $order_id, 'type' => 5]);//发送微信取消通知
  97. $transaction->commit();
  98. if (in_array($orderInfo['order_status'], [2, 3])) {//退款
  99. Util::addOrderLog($uid, $u_type, $order_id, '申请退款', 5);
  100. } else {
  101. Util::addOrderLog($uid, $u_type, $order_id, '自动取消', 4);
  102. }
  103. return Util::returnArrSu();
  104. } catch (Exception $e) {
  105. $transaction->rollBack();//回滚
  106. return Util::returnArrEr('订单取消失败![10000]');
  107. }
  108. }
  109. /**
  110. * Des:取消订单发送短信通知
  111. * Name: sendCancelOrderMsg
  112. * @param $orderInfo
  113. * @return array
  114. * @author 倪宗锋
  115. */
  116. public static function sendCancelOrderMsg($orderInfo, $is_confirm = 0)
  117. {
  118. if (in_array($orderInfo['category_id'], [3]) == false) {
  119. return Util::returnArrSu();
  120. }
  121. $siteConfig = Util::getSiteConfig();
  122. try {
  123. $orderMain = new OrderMain();
  124. $hotelOrderInfo = $orderMain->getHotelOrderInfo($orderInfo['order_id']);
  125. $night = count(json_decode($hotelOrderInfo['total_details'], true));
  126. if ($is_confirm == 0) {
  127. $msg = "预订失败:订单号{$orderInfo['order_id']},您预订的{$hotelOrderInfo['start_date']}入住";
  128. $msg .= "{$hotelOrderInfo['hotel_name']}酒店{$hotelOrderInfo['room_name']}{$hotelOrderInfo['prod_cnt']}间{$night}晚,已支付{$hotelOrderInfo['total_money']}元。";
  129. $msg .= "稍后会将您支付的全款原路退回您的账户,请注意查收。客服电话:{$siteConfig['kefu_tel']},遇到任何问题可关注微信公众号“{$siteConfig['web_name']}”,咨询在线客服,服务时间:09:00 - 21:00,祝您旅途愉快!";
  130. } else {
  131. $msg = "您预定的{$hotelOrderInfo['start_date']}入住的{$hotelOrderInfo['room_name']}{$hotelOrderInfo['prod_cnt']}间{$night}晚的订单已被酒店确认无房,请您选择其他的房型入住。您所支付的金额将会全额退回您的支付账号。请注意查收。";
  132. }
  133. return Util::sendMessage($msg, $hotelOrderInfo['contacts_phone']);
  134. } catch (Exception $e) {
  135. return Util::returnArrEr('发送短信通知失败');
  136. }
  137. }
  138. /**
  139. * Des:判断订单是否可以取消
  140. * Name: checkOrderCanCancel
  141. * @param $orderInfo
  142. * @return array
  143. * @author 倪宗锋
  144. */
  145. private static function checkOrderCanCancel($orderInfo)
  146. {
  147. $siteConfig = Util::getSiteConfig();
  148. if (empty($orderInfo)) {//订单不存在
  149. return Util::returnArrEr('网络异常,请您稍后再试');
  150. }
  151. if ($orderInfo['category_id'] == 1) {//车票只能取消开车前的订单
  152. $busStart = strtotime($orderInfo['start_date'] . ' ' . $orderInfo['start_time']) - 1800;
  153. $time = time();
  154. if ($time > $busStart) {
  155. return Util::returnArrEr('订单取消失败,已过取消截止时间');
  156. }
  157. } elseif (in_array($orderInfo['category_id'], [2, 3, 4, 5])) {//门票、酒店、巴士自由行、上门接 订单不允许退款
  158. return Util::returnArrEr("请您联系客服 {$siteConfig['kefu_tel']} 进行取消和退款。");
  159. } else {//其他订单
  160. $start = strtotime($orderInfo['start_date']);
  161. $date = strtotime(date('Y-m-d'));
  162. if ($date >= $start) {//只能取消开始之前的订单
  163. return Util::returnArrEr('订单取消失败,已过取消截止时间');
  164. }
  165. }
  166. if ($orderInfo['category_id'] == 3 && $orderInfo['is_confirm']) {//已确认的 酒店订单不可以退款
  167. return Util::returnArrEr("请您联系客服 {$siteConfig['kefu_tel']} 进行取消和退款。");
  168. }
  169. if (in_array($orderInfo['order_status'], [1, 2]) == false) {//订单状态 1,2取消(支付、未支付) 其他的状态订单不可操作取消
  170. return Util::returnArrEr("请您联系客服 {$siteConfig['kefu_tel']} 进行取消和退款。");
  171. }
  172. return Util::returnArrSu();
  173. }
  174. /**
  175. * Des:取消订单 修改订单状态为5 已取消
  176. * Name: cancelOrder
  177. * @param $order_id
  178. * @param $order_status
  179. * @return array
  180. * @author 倪宗锋
  181. */
  182. private static function cancelOrder($order_id, $order_status = 5)
  183. {
  184. $oderMain = new OrderMain();
  185. $upFlag = $oderMain->upOrder(['order_status' => $order_status], [$order_id]);
  186. if ($upFlag == false) {
  187. return Util::returnArrEr('订单取消失败[10005]');
  188. } else {
  189. return Util::returnArrSu();
  190. }
  191. }
  192. /**
  193. * Des:添加申请退款记录
  194. * Name: addPayRefund
  195. * @param $orderInfo
  196. * @return array
  197. * @author 倪宗锋
  198. */
  199. private static function addPayRefund($orderInfo)
  200. {
  201. //校验申请退款数据是否已存在
  202. $payRefush = new PayRefush();
  203. $pay = $payRefush->getInfoByOrderId($orderInfo['order_id']);
  204. if (empty($pay) == false) {//如果已经存在数据 则只需返回成功
  205. return Util::returnArrSu();
  206. }
  207. //判断订单是否支付过
  208. $payMain = new PayMain();
  209. $payInfo = $payMain->getPayInfo($orderInfo['order_id']);
  210. if (empty($payInfo)) {
  211. return Util::returnArrEr('订单取消失败![10006]');
  212. }
  213. //往退票表提交申请
  214. $resushArr = [
  215. 'order_id' => $orderInfo['order_id'],
  216. 'pay_order_id' => $payInfo['pay_order_id'],
  217. 'pay_type' => $payInfo['pay_type'],
  218. 'amount_money' => $payInfo['amount_money'],
  219. 'refush_money' => $payInfo['order_money'],
  220. 'fx_uid' => $orderInfo['fx_uid'],
  221. 'sh_uid' => $orderInfo['sh_uid'],
  222. 'status' => 1,
  223. 'create_time' => date('Y-m-d H:i:s'),
  224. 'delete_flag' => 0,
  225. 'category_id' => $orderInfo['category_id'],
  226. 'app_id' => $payInfo['app_id'],
  227. 'open_id' => $payInfo['open_id']
  228. ];
  229. $payRefush->attributes = $resushArr;
  230. $insertFlag = $payRefush->insert();
  231. if (!$insertFlag) {
  232. return Util::returnArrEr('add refush fail!');
  233. }
  234. return Util::returnArrSu();
  235. }
  236. /**
  237. * Des:修改佣金状态
  238. * Name: setCommission
  239. * @param $order_id
  240. * @return array
  241. * @author 倪宗锋
  242. */
  243. private static function setCommission($order_id)
  244. {
  245. $commission = new FxCommissionInfo();
  246. $commissionInfo = $commission->getInfoByOrderId($order_id);//获取佣金详细
  247. if (empty($commissionInfo)) {
  248. return Util::returnArrSu();
  249. }
  250. if ($commissionInfo['status'] == '2') {//订单已取消则不可取消
  251. return Util::returnArrSu('订单取消失败![10007]');
  252. }
  253. if ($commissionInfo['status'] == '3') {//已取消则不在操作
  254. return Util::returnArrSu();
  255. }
  256. $up = $commission->editStatus($order_id, 3);//修改订单状态
  257. if ($up) {
  258. return Util::returnArrSu();
  259. }
  260. return Util::returnArrEr('订单取消失败![10008]');
  261. }
  262. /**
  263. * Des:去CS取消订单 - 车
  264. * Name: CancelOrderCs
  265. * @param $order_info array
  266. * @return array
  267. * @author 倪宗锋
  268. */
  269. public static function cancelOrderCsBus($order_info)
  270. {
  271. if (empty($order_info['spider_order_id'])) {//没有关联订单ID
  272. return Util::returnArrSu();
  273. }
  274. $send_data = [
  275. 'action' => '',
  276. 'if_link' => 1,
  277. 'order_id' => $order_info['spider_order_id'],
  278. 'sign' => $order_info['spider_order_id'],
  279. 'cancel_reason' => '取消订单'
  280. ];
  281. if ($order_info['category_id'] == 1) {//如果是车票
  282. $send_data['action'] = 'cancel_bus_order';
  283. $url = '/api/submit-order';
  284. } elseif ($order_info['category_id'] == 2) {//如果是门票
  285. $send_data['action'] = 'cancel_ticket_order';
  286. $url = '/api/submit-order';
  287. } elseif ($order_info['category_id'] == 3) {//如果酒店
  288. $url = '/hotel/api/cancel-hotel-order';
  289. $send_data['HotelID'] = $order_info['hotel_id'];
  290. $send_data['RoomID'] = $order_info['room_id'];
  291. $send_data['OrderID'] = 'fx' . $order_info['order_id'];
  292. $send_data['Reason'] = '订单取消';
  293. $result = Util::sendCs($send_data, $url, 2, 2);
  294. return $result;
  295. #临时模拟成功 ---倪宗锋------++++++++++++++
  296. } elseif ($order_info['category_id'] == 4) {//如果是巴士自由行
  297. $send_data['action'] = 'cancel_tourist';
  298. $url = '/api/submit-order';
  299. } else {//不是车票和门票则 直接跳出该方法
  300. return Util::returnArrSu();
  301. }
  302. $result = Util::sendCs($send_data, $url, 2, $order_info['system']);
  303. return $result;
  304. }
  305. /**
  306. * Des:微信支付
  307. * Name: getWeChatOrderPayParams
  308. * @return array
  309. * @author 倪宗锋
  310. */
  311. public static function weChatOrderPay()
  312. {
  313. $getContent = file_get_contents("php://input");
  314. $content = Util::xmlToArray($getContent);
  315. /**支付结果判定*/
  316. if ($content['result_code'] != 'SUCCESS' || $content['return_code'] != 'SUCCESS') {
  317. return Util::returnArrEr('code error!');
  318. }
  319. $param = [
  320. 'app_id' => $content['appid'],
  321. 'out_trade_no' => $content['out_trade_no'],//订单号
  322. 'total_fee' => $content['total_fee'] / 100,
  323. 'openid' => $content['openid'],//用户标识
  324. 'payType' => 1,
  325. 'trade_no' => $content['transaction_id'],//流水号
  326. ];
  327. return static::payOrder($param);
  328. }
  329. /**
  330. * Des:支付宝支付
  331. * Name: aliOrderPay
  332. * @return array
  333. * @author 倪宗锋
  334. */
  335. public static function aliOrderPay()
  336. {
  337. /***支付结果判定***/
  338. if ($_POST['trade_status'] != 'TRADE_SUCCESS') {
  339. return Util::returnArrEr('code error!');
  340. }
  341. $params = [
  342. 'app_id' => $_POST['app_id'],
  343. 'out_trade_no' => $_POST['out_trade_no'],//订单号
  344. 'total_fee' => intval($_POST['buyer_pay_amount']),
  345. 'openid' => $_POST['buyer_id'],//用户标识
  346. 'payType' => 2,
  347. 'trade_no' => $_POST['trade_no'],//流水号
  348. ];
  349. return static::payOrder($params);
  350. }
  351. /**
  352. * Des:余额支付
  353. * Name: amountPay
  354. * @return array
  355. * @author 倪宗锋
  356. */
  357. public static function amountOrderPay()
  358. {
  359. $time = $_POST['time'];
  360. $code = $_POST['code'];
  361. $code = Util::authCode($code);//将字符串进行解析
  362. parse_str($code, $data);//将get参数转换成数组
  363. if (empty($data['time']) || $time != $data['time']) {
  364. return Util::returnArrEr('code error');
  365. }
  366. $params = [
  367. 'app_id' => '',
  368. 'out_trade_no' => $data['out_trade_no'],//订单号
  369. 'total_fee' => intval($data['buyer_pay_amount']),
  370. 'openid' => '',//用户标识
  371. 'payType' => 3,
  372. 'trade_no' => $data['out_trade_no']
  373. ];
  374. return static::payOrder($params);
  375. }
  376. /**
  377. * Des:订单支付成功 数据处理
  378. * Name: payOrder
  379. * @param $params
  380. * payType int 支付方式 1 微信,2支付宝
  381. * @return array
  382. * @author 倪宗锋
  383. */
  384. public static function payOrder($params)
  385. {
  386. $orderIds = $params['out_trade_no'];//订单ID
  387. $orderStr = explode('_', $orderIds);
  388. $orderArr = explode('-', $orderStr['0']);
  389. /********************数据处理 * 循环设置订单支付信息 *******************************/
  390. $csOrderType = 0;
  391. $transaction = \Yii::$app->db->beginTransaction();
  392. try {
  393. //1.循环设置订单支付信息
  394. foreach ($orderArr as $key => $orderId) {
  395. $setOrderPay = static::setOrderPay($orderId, $params);//修改订单状态及插入订单支付记录
  396. if ($setOrderPay['flag'] == false) {
  397. $transaction->rollBack();
  398. if ($setOrderPay['code'] == '1000') {//如果已经支付 则 返回成功
  399. return Util::returnArrSu();
  400. }
  401. return $setOrderPay;//是否则返回错误信息
  402. }
  403. $csOrderType = $setOrderPay['data']['csOrderType'];//成功则重置订单类型
  404. }
  405. //2.数据提交
  406. $transaction->commit();
  407. } catch (Exception $e) {
  408. $transaction->rollBack();//回滚
  409. return Util::returnArrEr('system error!');
  410. }
  411. //3.添加支付成功记录日志
  412. Util::addOrderLog(0, 0, implode('-', $orderArr), '付款时间', 3);
  413. //4.发送微信通知
  414. foreach ($orderArr as $orderIdVal) {
  415. Util::sendWxMsg(['type' => 1, 'order_id' => $orderIdVal]);
  416. }
  417. if ($csOrderType == 0) {//自有的产品 则到此结束
  418. return Util::returnArrSu();
  419. }
  420. //5.cs下单
  421. /******************如果是其他来源产品的订单 * 去cs下订单**/
  422. $makeOrder = static::makeCsOrder($orderArr, $csOrderType, $params['payType'], $params['trade_no']);
  423. if ($makeOrder['flag'] == false) {
  424. foreach ($orderArr as $key => $orderId) {
  425. $cancel = static::applyCancelOrder($orderId, 0);//微信申请取消订单
  426. if ($cancel['flag'] == false) {
  427. static::sendMsgForCsAddOrderFail($orderId);//发送异常通知
  428. }
  429. }
  430. return Util::returnArrEr('cs error!');
  431. }
  432. //6.发送短信通知
  433. return Util::returnArrSu();
  434. }
  435. /**
  436. * Des:发送酒店确认订单通知
  437. * Name: sendHotelConfirmMsg
  438. * @param $order_id
  439. * @return array
  440. * @author 倪宗锋
  441. */
  442. public static function sendHotelConfirmMsg($order_id)
  443. {
  444. try {
  445. $orderMain = new OrderMain();
  446. $orderInfo = $orderMain->getOrderInfoById($order_id);
  447. if (in_array($orderInfo['category_id'], [3]) == false) {
  448. return Util::returnArrSu();
  449. }
  450. $hotelOrderInfo = $orderMain->getHotelOrderInfo($orderInfo['order_id']);
  451. $night = count(json_decode($hotelOrderInfo['total_details'], true));
  452. $siteConfig = Util::getSiteConfig();
  453. $msg = "预订成功:订单号{$hotelOrderInfo['order_id']},{$hotelOrderInfo['users']}{$hotelOrderInfo['start_date']}入住";
  454. $msg .= "{$hotelOrderInfo['hotel_name']}酒店{$hotelOrderInfo['room_name']}{$hotelOrderInfo['prod_cnt']}间{$night}晚,已支付{$hotelOrderInfo['total_money']}元。房间已预留,入住请出示入住人有效身份证件,酒店地址:{$hotelOrderInfo['address']}。订单不能取消修改。特别提示:请直接报{$hotelOrderInfo['users']}办理入住。";
  455. $msg .= "客服电话:{$siteConfig['kefu_tel']},遇到任何问题可关注微信公众号“{$siteConfig['web_name']}”,咨询在线客服,服务时间:09:00-21:00,祝您旅途愉快!";
  456. return Util::sendMessage($msg, $hotelOrderInfo['contacts_phone']);
  457. } catch (Exception $e) {
  458. return Util::returnArrEr('发送短信通知失败');
  459. }
  460. }
  461. /**
  462. * Des:发送未支付通知
  463. * Name: sendUnPayMsg
  464. * @param $order_id
  465. * @param $phone
  466. * @return array
  467. * @author 倪宗锋
  468. */
  469. public static function sendUnPayMsg($order_id, $phone)
  470. {
  471. try {
  472. $msg = "您有未支付的订单{$order_id}即将超时,请您抓紧时间完成支付。下单后15分钟内未完成支付的订单将被自动取消。";
  473. return Util::sendMessage($msg, $phone);
  474. } catch (Exception $e) {
  475. return Util::returnArrEr('发送短信通知失败');
  476. }
  477. }
  478. /**
  479. * Des:设置订单支付状态
  480. * Name: setOrderPay
  481. * @param $orderId
  482. * @param $params
  483. * @return array
  484. * @author 倪宗锋
  485. */
  486. public static function setOrderPay($orderId, $params)
  487. {
  488. /**获取订单信息**/
  489. $orderMain = new OrderMain();
  490. $orderInfo = $orderMain->getOrderInfoById($orderId);
  491. /**已支付订单处理*/
  492. if (!in_array($orderInfo['order_status'], [1, 5])) {//判断订单是否已支付
  493. if ($params['out_trade_no'] == $orderInfo['pay_order_id']) {//重复请求
  494. return Util::returnArrEr('order have paid ' . $orderId, '', '', '1000');
  495. } else {
  496. static::refundOrderForRepeatPay($params);//订单重复支付退款
  497. return Util::returnArrEr('order is paid by other ' . $orderId);
  498. }
  499. }
  500. /**修改订单主表信息*/
  501. $upArray = [
  502. 'order_id' => $orderId,
  503. 'order_status' => 2,
  504. ];
  505. $upFlag = $orderMain->upOrder($upArray, [$orderId]);
  506. if (!$upFlag) {
  507. return Util::returnArrEr('order_main update error!');
  508. }
  509. /**在支付表添加记录**/
  510. $payMain = new PayMain();
  511. $payArray = [
  512. 'pay_type' => $params['payType'],
  513. 'amount_money' => $params['total_fee'],//支付总金额
  514. 'order_money' => $orderInfo['total_money'],
  515. 'pay_user' => 0,
  516. 'order_id' => $orderId,
  517. 'pay_order_id' => $params['out_trade_no'],
  518. 'app_id' => $params['app_id'],
  519. 'open_id' => $params['openid']
  520. ];
  521. $payMain->attributes = $payArray;
  522. $insertFlag = $payMain->insert();
  523. if (!$insertFlag) {
  524. return Util::returnArrEr('add pay_main fail!');
  525. }
  526. /**在佣金表添加记录**/
  527. if (Util::checkPattern('intVal', $orderInfo['fx_uid'])) {
  528. $orderInfoTable = new OrderInfo();
  529. if ($orderInfo['category_id'] == 4 && empty($orderInfo['sign']) == false) {//巴士自由行产品价格另行计算
  530. $getCommission = static::getFreeWalkCommission($orderInfo);
  531. } elseif ($orderInfo['category_id'] == 3) {
  532. $getCommission = static::getHotelCommission($orderInfo);
  533. } else {
  534. $getCommission = $orderInfoTable->getOrderCommission($orderId);
  535. if (in_array($orderInfo['fx_uid'], [686, 749]) && in_array($orderInfo['prod_cate_id'], [1354, 1346])) {
  536. $getCommission = 5 * intval($orderInfo['prod_cnt']); //人民广场-迪士尼
  537. }
  538. if (in_array($orderInfo['fx_uid'], [222]) && in_array($orderInfo['prod_cate_id'], [1354, 2213])) {
  539. $getCommission = 17 * intval($orderInfo['prod_cnt']); //人民广场-迪士尼
  540. }
  541. if (in_array($orderInfo['fx_uid'], [80]) && in_array($orderInfo['prod_cate_id'], [1346])) {
  542. $getCommission = 5 * intval($orderInfo['prod_cnt']); //人民广场-迪士尼
  543. }
  544. if (in_array($orderInfo['fx_uid'], [80]) && in_array($orderInfo['prod_cate_id'], [1354])) {
  545. $getCommission = 15 * intval($orderInfo['prod_cnt']); //人民广场-迪士尼
  546. }
  547. if (in_array($orderInfo['fx_uid'], [80]) && in_array($orderInfo['prod_cate_id'], [2213])) {
  548. $getCommission = 15 * intval($orderInfo['prod_cnt']); //人民广场-迪士尼
  549. }
  550. if (in_array($orderInfo['fx_uid'], [686, 823]) && in_array($orderInfo['prod_cate_id'], [2218, 2214])) {
  551. $getCommission = 5 * intval($orderInfo['prod_cnt']); //上海火车站-迪士尼 迪士尼-上海火车站
  552. }
  553. if (in_array($orderInfo['fx_uid'], [686, 823]) && in_array($orderInfo['prod_cate_id'], [2213, 1354])) {
  554. $getCommission = 5 * intval($orderInfo['prod_cnt']); //人民广场-迪士尼 迪士尼-人广
  555. }
  556. //瑞景木每子 15000189822 分销线路编号:1354 人民广场-迪士尼 20元 2213 迪士尼-人民广场 20元
  557. if (in_array($orderInfo['fx_uid'], [807]) && in_array($orderInfo['prod_cate_id'], [1354, 2213])) {
  558. $getCommission = 10 * intval($orderInfo['prod_cnt']);
  559. }
  560. }
  561. $fxCommission = new FxCommissionInfo();
  562. $commissionFlag = $fxCommission->add($orderInfo['fx_uid'], $getCommission, $orderId);
  563. if (!$commissionFlag) {
  564. return Util::returnArrEr('add orderInfo fail!');
  565. }
  566. }
  567. /**判断订单需求去cs下单的订单类型*/
  568. $csOrderType = 0;
  569. if ($orderInfo['prod_source'] == 2) {//产品来源2位cs系统
  570. $csOrderType = $orderInfo['category_id'];//分类ID
  571. }
  572. /**发送订单支付成功通知,通知客服*/
  573. if ($csOrderType == 0 || in_array($csOrderType, [2, 4, 5])) {//发送下单成功通知
  574. static::sendMsgForOrderPay($orderInfo);
  575. }
  576. $return = [
  577. 'csOrderType' => $csOrderType
  578. ];
  579. return Util::returnArrSu('', $return);
  580. }
  581. /**
  582. * Des:获取巴士自由行的佣金
  583. * Name: getFreeWalkCommission
  584. * @param $orderInfo
  585. * @return int
  586. * @author 倪宗锋
  587. */
  588. public function getFreeWalkCommission($orderInfo)
  589. {
  590. $orderInfoTable = new OrderInfo();
  591. $data = [];
  592. $data['sign'] = $orderInfo['sign'];
  593. $data['prod_arr'] = json_encode($orderInfoTable->geProdArr($orderInfo['order_id']));//获取票种产品数据
  594. $data['date'] = $orderInfo['start_date'];
  595. $data['action'] = 'get_tourist_pay_total';
  596. $data['org_id'] = '164';
  597. $getTotalCost = Util::sendCs($data, '/api/wx', 2);
  598. if ($getTotalCost['flag'] == true) {
  599. $total_cost = $getTotalCost['data']['list']['extra_info']['total_cost'];//低价
  600. $cs_total_money = $getTotalCost['data']['list']['total_money'];//零售价
  601. $insurance_money = $orderInfo['original_price'] - $cs_total_money;//保险金额 = 订单原价-零售价
  602. //佣金等于 订单金额-零售价-保险金额
  603. $getCommission = intval($orderInfo['total_money']) - intval($total_cost) - $insurance_money;
  604. } else {
  605. $getCommission = 0;
  606. }
  607. return $getCommission;
  608. }
  609. /**
  610. * Des:获取酒店的佣金金额
  611. * Name: getHotelCommission
  612. * @param $orderInfo
  613. * @return float|int
  614. * @author 倪宗锋
  615. */
  616. public static function getHotelCommission($orderInfo)
  617. {
  618. $orderMain = new OrderMain();
  619. $params = $orderMain->getHotelOrderInfo($orderInfo['order_id']);
  620. $roomPrices = json_decode($params['total_details'], true);
  621. foreach ($roomPrices as &$val) {
  622. $val['RunDate'] = $val['date'];
  623. $val['Price'] = $params['prod_cnt'] * $val['price'];
  624. unset($val['date']);
  625. unset($val['price']);
  626. }
  627. $data = [
  628. 'HotelID' => $params['hotel_id'],
  629. 'RoomID' => $params['room_id'],
  630. 'RoomNum' => $params['prod_cnt'],
  631. 'CheckIn' => $params['start_date'],
  632. 'CheckOut' => $params['end_date'],
  633. 'RoomPrices' => $roomPrices,
  634. 'IfCheckPrice' => 0,
  635. ];
  636. $result = Util::sendCs($data, '/hotel/api/get-low-price', 2);
  637. $getCommission = 0;
  638. if ($result['flag'] == true) {
  639. $total_cost = $result['data']['data']['low_price'];//底价
  640. //佣金等于 订单金额-底价
  641. if ($total_cost < $orderInfo['total_money']) {
  642. $getCommission = round($orderInfo['total_money'] - $total_cost, 2);
  643. }
  644. }
  645. return $getCommission;
  646. }
  647. /**
  648. * Des:前往cs下单
  649. * Name: makeCsOrder
  650. * @param $orderArr
  651. * @param $csOrderType
  652. * @param $payType
  653. * @param $trade_no
  654. * @return array
  655. * @author 倪宗锋
  656. */
  657. public static function makeCsOrder($orderArr, $csOrderType, $payType, $trade_no = '')
  658. {
  659. //支付类型 替换成cs
  660. if ($payType == 3) {
  661. $pay_type = 275;
  662. } else if ($payType == 1) {
  663. $pay_type = 278;
  664. } else {
  665. $pay_type = 638;
  666. }
  667. if ($csOrderType == 1) {//车票
  668. $makeOrder = static::makeBusTicket($orderArr, $pay_type);
  669. } elseif ($csOrderType == 2) {//门票
  670. $makeOrder = static::makeMenPTicket($orderArr, $pay_type);
  671. } elseif ($csOrderType == 3) {//酒店
  672. $makeOrder = static::makeHotel($orderArr, $pay_type, $trade_no);
  673. } elseif ($csOrderType == 4) {//巴士自由行
  674. $makeOrder = static::makeFreeWalk($orderArr, $pay_type);
  675. } else {
  676. return Util::returnArrSu();
  677. }
  678. return $makeOrder;
  679. }
  680. /**
  681. * Des:酒店下单
  682. * Name: makeHotel
  683. * @param $orderArr
  684. * @param $pay_type
  685. * @param $trade_no
  686. * @return array
  687. * @author 倪宗锋
  688. */
  689. public static function makeHotel($orderArr, $pay_type, $trade_no)
  690. {
  691. $orderMain = new OrderMain();
  692. $orderId = $orderArr[0];
  693. $orderInfo = $orderMain->getHotelOrderInfo($orderId);
  694. if (empty($orderInfo['order_id'])) {
  695. return Util::returnArrEr('订单数据异常!');
  696. }
  697. // $system = $orderInfo['system'];
  698. $system = 2;//展示写死
  699. $siteConfig = Util::getSiteConfig();
  700. $siteConfig['adm_user_id'] = $siteConfig['adm_user_arr'][$system]['adm_user_id'];//重置配置
  701. $siteConfig['adm_source_id'] = $siteConfig['adm_user_arr'][$system]['adm_source_id'];//重置配置
  702. //出行人信息
  703. $orderContacts = new OrderContacts();
  704. $passArr = $orderContacts->getPassAngerPeople($orderId);
  705. $passengerInfo = [];
  706. if (count($passArr) != 0) {
  707. foreach ($passArr as $key => $v) {
  708. $passengerInfo[]['Name'] = $v['contacts_name'];
  709. }
  710. }
  711. //每日价格信息
  712. $roomPrices = json_decode($orderInfo['total_details'], true);
  713. $sum_price = 0;
  714. foreach ($roomPrices as &$val) {
  715. $val['RunDate'] = $val['date'];
  716. $val['Price'] = round($val['price'] * ($orderInfo['total_money'] / $orderInfo['original_price']), 2);
  717. $sum_price = $sum_price + $val['Price'];
  718. unset($val['date']);
  719. unset($val['price']);
  720. }
  721. $roomPrices[0]['Price'] = round(($orderInfo['total_money'] / $orderInfo['prod_cnt'] - $sum_price + $roomPrices[0]['Price']), 2);
  722. $send_data = [
  723. 'CreateUserID' => $siteConfig['adm_user_id'],
  724. 'OrderID' => 'fx' . $orderId, //渠道订单号
  725. 'HotelID' => $orderInfo['hotel_id'], //酒店ID
  726. 'RoomID' => $orderInfo['room_id'], //房型ID
  727. 'DistribID' => $siteConfig['adm_source_id'],//渠道ID
  728. 'RoomNum' => $orderInfo['prod_cnt'], //房间数量
  729. 'CheckIn' => $orderInfo['start_date'], //入住日期
  730. 'CheckOut' => $orderInfo['end_date'], //离店日期,
  731. 'TotalPrice' => $orderInfo['total_money'],//订单总价
  732. 'Commission' => $orderInfo['commission'],//佣金
  733. 'Currency' => 'RMB', //币种
  734. 'ContactName' => $orderInfo['contacts_name'],//联系人姓名
  735. 'ContactTel' => $orderInfo['contacts_phone'], //联系人电话
  736. 'PayType' => $pay_type, // 638:支付宝支付; 221:现金支付 ;275:授信支付;278:微信支付
  737. 'PayTradeNo' => $trade_no, //支付流水号
  738. 'OrderGuests' => $passengerInfo, //入住人信息
  739. 'Comment' => $orderInfo['remarks'], //客人备注
  740. 'NeedInvoice' => 0,
  741. 'InvoiceInfos' => [ //发票信息
  742. ],
  743. 'RoomPrices' => $roomPrices,
  744. ];
  745. $curlInterface = new CurlInterface($send_data, 4);
  746. $curlInterface->setBaseUrl('');
  747. $ticket_arr_cs = $curlInterface->execute($siteConfig['adm_host1'] . '/hotel/api/book-hotel-order', 'POST');
  748. if (isset($ticket_arr_cs['code']) && $ticket_arr_cs['code'] == 0) {
  749. $orderMain->addSpiderOrder($ticket_arr_cs['data']['order_id'], $orderId);
  750. return Util::returnArrSu();
  751. } else {
  752. return Util::returnArrEr();
  753. }
  754. }
  755. /**
  756. * Des:去cs下车票订单
  757. * Name: makeBusTicket
  758. * @param $orderArr
  759. * @param $pay_type
  760. * @return array
  761. * @author 倪宗锋
  762. */
  763. public static function makeBusTicket($orderArr, $pay_type)
  764. {
  765. $orderMain = new OrderMain();
  766. $orderId = $orderArr[0];
  767. $cs_prod_str = $orderMain->GetCsBusProdInfo($orderId);
  768. $system = $cs_prod_str['system'];
  769. $prod_str = '{1,' . $cs_prod_str['run_id'] . ',' . $cs_prod_str['ticket_id'] . ',' . $cs_prod_str['price'] . ',' . $cs_prod_str['prod_cnt'] . '}';
  770. $outside_no = 'fx' . $orderId;
  771. if (count($orderArr) == 2) {
  772. $orderId = $orderArr[1];
  773. $cs_prod_str = $orderMain->GetCsBusProdInfo($orderId);
  774. $prod_str .= '{2,' . $cs_prod_str['run_id'] . ',' . $cs_prod_str['ticket_id'] . ',' . $cs_prod_str['price'] . ',' . $cs_prod_str['prod_cnt'] . '}';
  775. $outside_no .= '|fx' . $orderId;
  776. }
  777. //联系人信息
  778. $customer_info_str = '{' . $cs_prod_str['contacts_name'] . ',' . $cs_prod_str['contacts_phone'] . ',150,' . '}';
  779. $time = time();
  780. $siteConfig = Util::getSiteConfig();
  781. $siteConfig['adm_user_id'] = $siteConfig['adm_user_arr'][$system]['adm_user_id'];//重置配置
  782. $siteConfig['adm_source_id'] = $siteConfig['adm_user_arr'][$system]['adm_source_id'];//重置配置
  783. //受保人信息
  784. $orderContacts = new OrderContacts();
  785. $result = $orderContacts->getInsuredPeople($orderId);
  786. if (count($result) == 0) {
  787. $buy_insurance = 0;
  788. $insurance = '';
  789. } else {
  790. $j = 0;
  791. $arr1 = array();
  792. foreach ($result as $v) {
  793. $i = 0;
  794. $arr1[$j][$i] = $v['contacts_name'];
  795. $arr1[$j][++$i] = $v['contacts_ID'];
  796. $j++;
  797. }
  798. $buy_insurance = 1;
  799. $insurance = json_encode($arr1);
  800. }
  801. //出行人信息
  802. $orderContacts = new OrderContacts();
  803. $passArr = $orderContacts->getPassAngerPeople($orderId);
  804. if (count($passArr) == 0) {
  805. $passengerInfo = '';
  806. } else {
  807. $arr = array();
  808. foreach ($passArr as $key => $v) {
  809. $arr[$key]['passenger_name'] = $v['contacts_name'];
  810. $arr[$key]['passenger_mobile'] = '';
  811. $arr[$key]['passenger_cardid'] = $v['contacts_ID'];
  812. }
  813. $passengerInfo = json_encode($arr);
  814. }
  815. $send_data = [
  816. 'auth_code' => Util::authCodeForCs($time),
  817. 'user_key' => $siteConfig['adm_user_key'],
  818. 'user' => $siteConfig['adm_user'],
  819. 'user_id' => $siteConfig['adm_user_id'],
  820. 'request_time' => $time,
  821. 'action' => 'submit_bus_order',
  822. 'prod_str' => $prod_str,
  823. 'order_info_str' => "{{$siteConfig['adm_user_id']},0,{$siteConfig['adm_source_id']},$outside_no,0,{$pay_type},1,1}",
  824. 'customer_info_str' => $customer_info_str,
  825. 'buy_insurance' => $buy_insurance,
  826. 'insurance' => $insurance,
  827. 'passenger_info' => $passengerInfo
  828. ];
  829. $curlInterface = new CurlInterface($send_data, 4);
  830. $curlInterface->setBaseUrl('');
  831. $ticket_arr_cs = $curlInterface->execute($siteConfig['adm_host1'] . '/api/submit-order', 'POST');
  832. if (isset($ticket_arr_cs['code']) && $ticket_arr_cs['code'] == 0) {
  833. if (count($orderArr) == 2) {
  834. $order_arr = explode(',', $ticket_arr_cs['data']);
  835. $addSpiderOrder = $orderMain->addSpiderOrder($order_arr[0], $orderArr[0]);
  836. $addSpiderOrder1 = $orderMain->addSpiderOrder($order_arr[1], $orderArr[1]);
  837. if ($addSpiderOrder == 0 || $addSpiderOrder1 == 0) {
  838. file_put_contents(APP_PATH . '/log/order/error' . date('Y-m-d') . '.log', $orderArr[0] . '在cs 下单失败 ' . date('Y-m-d H:i:s') . PHP_EOL, FILE_APPEND);
  839. }
  840. } else {
  841. $addSpiderOrder = $orderMain->addSpiderOrder($ticket_arr_cs['data'], $orderArr[0]);
  842. if ($addSpiderOrder == 0) {
  843. file_put_contents(APP_PATH . '/log/order/error' . date('Y-m-d') . '.log', $orderArr[0] . '在cs 下单失败 ' . date('Y-m-d H:i:s') . PHP_EOL, FILE_APPEND);
  844. }
  845. }
  846. return Util::returnArrSu();
  847. } else {
  848. file_put_contents(APP_PATH . '/log/order/error' . date('Y-m-d') . '.log', $orderArr[0] . '在cs 下单失败 ' . date('Y-m-d H:i:s') . PHP_EOL, FILE_APPEND);
  849. return Util::returnArrEr();
  850. }
  851. }
  852. /**
  853. * Des:去cs下门票订单
  854. * Name: makeBusTicket
  855. * @param $orderArr
  856. * @param $pay_type
  857. * @return array
  858. * @author 倪宗锋
  859. */
  860. public static function makeMenPTicket($orderArr, $pay_type)
  861. {
  862. foreach ($orderArr as $orderId) {
  863. $orderMain = new OrderMain();
  864. $cs_prod_str = $orderMain->getCsUnBusProdInfo($orderId);//获取非巴士产品的下单产品信息
  865. if (empty($cs_prod_str['prod_str'])) {
  866. return Util::returnArrEr('前往cs下单失败');
  867. }
  868. $system = $cs_prod_str['system'];
  869. $outside_no = 'fx' . $orderId;
  870. //联系人信息
  871. $customer_info_str = "{{$cs_prod_str['contacts_name']},{$cs_prod_str['contacts_phone']},150,{$cs_prod_str['contacts_ID']}}";
  872. $time = time();
  873. $siteConfig = Util::getSiteConfig();
  874. $siteConfig['adm_user_id'] = $siteConfig['adm_user_arr'][$system]['adm_user_id'];//重置配置
  875. $siteConfig['adm_source_id'] = $siteConfig['adm_user_arr'][$system]['adm_source_id'];//重置配置
  876. $send_data = [
  877. 'auth_code' => Util::authCodeForCs($time),
  878. 'user_key' => $siteConfig['adm_user_key'],
  879. 'user' => $siteConfig['adm_user'],
  880. 'user_id' => $siteConfig['adm_user_id'],
  881. 'request_time' => $time,
  882. 'action' => 'submit_ticket_order',
  883. 'main_prod_id' => $cs_prod_str['main_prod_id'],
  884. 'prod_str' => $cs_prod_str['prod_str'],
  885. 'run_date' => $cs_prod_str['run_date'],
  886. 'order_info_str' => "{{$siteConfig['adm_user_id']},0,{$siteConfig['adm_source_id']},$outside_no ,0,{$pay_type},1,1}",
  887. 'customer_info_str' => $customer_info_str
  888. ];
  889. $curlInterface = new CurlInterface($send_data, 4);
  890. $curlInterface->setBaseUrl('');
  891. $ticket_arr_cs = $curlInterface->execute($siteConfig['adm_host1'] . '/api/submit-order', 'POST');
  892. if ($ticket_arr_cs['code'] == 0) {
  893. $orderMain->addSpiderOrder($ticket_arr_cs['data'], $orderId);
  894. } else {
  895. return Util::returnArrEr('cs下单失败!');
  896. }
  897. }
  898. return Util::returnArrSu();
  899. }
  900. /**
  901. * Des:巴士自由行订单下单
  902. * Name: makeFreeWalk
  903. * @param $orderArr
  904. * @param $pay_type
  905. * @return array
  906. * @author 倪宗锋
  907. */
  908. public static function makeFreeWalk($orderArr, $pay_type)
  909. {
  910. foreach ($orderArr as $orderId) {
  911. try {
  912. $orderMain = new OrderMain();
  913. $prodCate = new ProdCategory();
  914. $cs_prod_str = $orderMain->getCsFreeWalkProdForMakeOrder($orderId);//获取巴士自由行产品的下单产品信息
  915. if (empty($cs_prod_str)) {
  916. return Util::returnArrEr('前往cs下单失败');
  917. }
  918. $orderInfo = $orderMain->getOrderInfoById($orderId);
  919. $prodInfo = $prodCate->getProdDetail($orderInfo['prod_cate_id']);
  920. //出行人信息
  921. $orderContacts = new OrderContacts();
  922. $passArr = $orderContacts->getPassAngerPeople($orderId);
  923. if (count($passArr) == 0) {
  924. $passengerInfo = '';
  925. } else {
  926. $arr = array();
  927. foreach ($passArr as $key => $v) {
  928. $arr[$key]['passenger_name'] = $v['contacts_name'];
  929. $arr[$key]['passenger_mobile'] = '';
  930. $arr[$key]['passenger_cardid'] = $v['contacts_ID'];
  931. # modify nizf 联系人证件使用第一个出行人的证件
  932. if (empty($v['contacts_ID']) == false && empty($orderInfo['contacts_ID'])) {
  933. $orderInfo['contacts_ID'] = $v['contacts_ID'];
  934. }
  935. }
  936. $passengerInfo = json_encode($arr);
  937. }
  938. //受保人信息
  939. $orderContacts = new OrderContacts();
  940. $result = $orderContacts->getInsuredPeople($orderId);
  941. if (count($result) == 0) {
  942. $buy_insurance = 0;
  943. $insurance = '';
  944. } else {
  945. $j = 0;
  946. $arr1 = array();
  947. foreach ($result as $v) {
  948. $i = 0;
  949. $arr1[$j][$i] = $v['contacts_name'];
  950. $arr1[$j][++$i] = $v['contacts_ID'];
  951. $j++;
  952. }
  953. $buy_insurance = 1;
  954. $insurance = json_encode($arr1);
  955. }
  956. //联系人信息
  957. $customer_info = [
  958. 'customer_name' => $orderInfo['contacts_name'],
  959. 'customer_mobile' => $orderInfo['contacts_phone'],
  960. 'customer_id_type' => '150',
  961. 'customer_id_no' => $orderInfo['contacts_ID'],
  962. 'customer_memo' => '无'
  963. ];
  964. $siteConfig = Util::getSiteConfig();
  965. $system = $orderInfo['system'];
  966. $siteConfig['adm_user_id'] = $siteConfig['adm_user_arr'][$system]['adm_user_id'];//重置配置
  967. $siteConfig['adm_source_id'] = $siteConfig['adm_user_arr'][$system]['adm_source_id'];//重置配置
  968. //订单信息
  969. $orderInfoArr = [
  970. 'user_id' => $siteConfig['adm_user_id'],
  971. 'member_id' => 2,
  972. 'outside_sale_org_id' => $siteConfig['adm_source_id'],
  973. 'outside_sale_order_no' => 'zzcx' . $orderId,
  974. 'total_money' => $orderInfo['total_money'],
  975. 'order_book_status' => 0,
  976. 'pay_type' => $pay_type,
  977. 'order_pay_status' => 1,
  978. 'sales_man' => ''
  979. ];
  980. //发送报文
  981. $time = time();
  982. $data = [
  983. 'auth_code' => Util::authCodeForCs($time),
  984. 'user_key' => $siteConfig['adm_user_key'],
  985. 'user' => $siteConfig['adm_user'],
  986. 'user_id' => $siteConfig['adm_user_id'],
  987. 'request_time' => $time,
  988. 'sign' => $prodInfo['sign'],
  989. 'date' => $orderInfo['start_date'],
  990. 'prod_arr' => json_encode($cs_prod_str),
  991. 'customer_info' => json_encode($customer_info),
  992. 'order_info' => json_encode($orderInfoArr),
  993. 'passenger_info' => $passengerInfo,
  994. 'buy_insurance' => $buy_insurance,
  995. 'insurance' => $insurance,
  996. 'action' => 'submit_tourist_order'
  997. ];
  998. $ticket_arr_cs = Util::sendCs($data, '/api/wx/', 2, $system);
  999. if ($ticket_arr_cs['flag']) {
  1000. $orderMain->addSpiderOrder($ticket_arr_cs['data']['order_title_id'], $orderId);
  1001. //巴士自由行订单发送短信通知
  1002. $smg = "您有新的巴士自由行订单了!{$orderInfo['order_name']},微信:{$orderId},CS:{$ticket_arr_cs['data']['order_title_id']}";
  1003. $siteConfig = Util::getSiteConfig();
  1004. if (empty($siteConfig['freeWalkOrder']) == false) {
  1005. Util::sendMessage($smg, $siteConfig['freeWalkOrder']);
  1006. }
  1007. } else {
  1008. return Util::returnArrEr('cs下单失败!');
  1009. }
  1010. } catch (Exception $e) {
  1011. return Util::returnArrEr('cs下单失败!');
  1012. }
  1013. }
  1014. return Util::returnArrSu();
  1015. }
  1016. /**
  1017. * Des:下单成功 发送短信通知和RTX通知
  1018. * Name: sendMsgForOrderPay
  1019. * @param $orderInfo
  1020. * @author 倪宗锋
  1021. */
  1022. public static function sendMsgForOrderPay($orderInfo)
  1023. {
  1024. $siteConfig = Util::getSiteConfig();
  1025. //发送提示信息
  1026. if (empty($siteConfig['YunYinPhone']) == false ) {//如果保存了运营电话就发送短信通知
  1027. $msg = "您有新订单了:订单号:{$orderInfo['order_id']}
  1028. 订单类型:{$orderInfo['category_name']}
  1029. 预定产品:{$orderInfo['order_name']}
  1030. 数量:{$orderInfo['prod_cnt']}
  1031. 开始日期:{$orderInfo['start_date']}
  1032. 结束日期:{$orderInfo['end_date']}
  1033. 订单金额:¥{$orderInfo['total_money']}
  1034. 联系人:{$orderInfo['contacts_name']}
  1035. 手机:{$orderInfo['contacts_phone']}
  1036. 请注意查看";
  1037. Util::sendMessage($msg, $siteConfig['YunYinPhone']);
  1038. }
  1039. if (empty($siteConfig['YunYinRTX']) == false) {//如果保存运营rtx则发送订单通知
  1040. $title = '【移动分销】您有新订单了';
  1041. $msg = "订单号:{$orderInfo['order_id']}
  1042. 订单类型:{$orderInfo['category_name']}
  1043. 预定产品:{$orderInfo['order_name']}
  1044. 数量:{$orderInfo['prod_cnt']}
  1045. 开始日期:{$orderInfo['start_date']}
  1046. 结束日期:{$orderInfo['end_date']}
  1047. 订单金额:¥{$orderInfo['total_money']}
  1048. 联系人:{$orderInfo['contacts_name']}
  1049. 手机:{$orderInfo['contacts_phone']}
  1050. 请注意查看";
  1051. Util::sendMsgRTX($siteConfig['YunYinRTX'], $title, $msg);
  1052. }
  1053. if($orderInfo['category_id'] == 2) {//给用户发送短信通知
  1054. $msg = "您预定的“{$orderInfo["order_name"]}{$orderInfo["order_id"]}”已成功;为了保障您的出行,请务必至少提前两小时预定;否则订单款项将原路退回;车牌号及司机信息最晚将于发车前一小时发至您手机上,请注意查看;如遇问题请拨打0571-86693985";
  1055. Util::sendMessage($msg, $orderInfo['contacts_phone']);
  1056. }
  1057. }
  1058. /**
  1059. * Des:下单失败短信通知
  1060. * Name: sendMsgForCsAddOrderFail
  1061. * @param $orderId
  1062. * @author 倪宗锋
  1063. */
  1064. public static function sendMsgForCsAddOrderFail($orderId)
  1065. {
  1066. if (empty($siteConfig['YunYinRTX']) == false) {//如果保存运营rtx则发送订单通知
  1067. $title = '【移动分销】下单异常';
  1068. $msg = "订单号:$orderId
  1069. 同步巴士订单失败,且自动退款失败,
  1070. 请立即通知开发人员。
  1071. 请注意查看";
  1072. Util::sendMsgRTX($siteConfig['YunYinRTX'], $title, $msg);
  1073. }
  1074. }
  1075. /**
  1076. * Des:下单
  1077. * Name: makeOrder
  1078. * @param $param_arr
  1079. * @return array
  1080. * @author 倪宗锋
  1081. */
  1082. public static function makeOrder($param_arr)
  1083. {
  1084. $transaction = \Yii::$app->db->beginTransaction();
  1085. try {
  1086. /**去程下单*/
  1087. $order_go = static::createOrder($param_arr['go_params']);//去程下单
  1088. if ($order_go['flag'] == false) {
  1089. $transaction->rollBack();//数据提交
  1090. return $order_go;
  1091. }
  1092. $orderId = $order_go['data']['order_id'];//订单ID
  1093. $param_arr['total_money'] = (int)$order_go['data']['total_money'];//
  1094. if ($param_arr['if_back'] == 1) {
  1095. /**返程下单*/
  1096. $order_back = static::createOrder($param_arr['back_params']);//返程下单
  1097. if ($order_back['flag'] == false) {
  1098. $transaction->rollBack();//数据提交
  1099. return $order_back;
  1100. }
  1101. $orderId .= '-' . $order_back['data']['order_id'];
  1102. $param_arr['total_money'] += $order_back['data']['total_money'];
  1103. }
  1104. $transaction->commit();
  1105. } catch (Exception $e) {
  1106. $transaction->rollBack();//回滚
  1107. return Util::returnArrEr('下单失败[1008]');
  1108. }
  1109. //设置下单成功返回值
  1110. $return = static::setMakeOrderReturn($orderId, $param_arr['total_money'], $param_arr['go_params']['system'], $param_arr['go_params']['contacts_phone'], $param_arr['go_params']['fx_uid']);
  1111. return Util::returnArrSu('', $return);
  1112. }
  1113. /**
  1114. * Des:设置订单返回值
  1115. * Name: setMakeOrderReturn
  1116. * @param $orderId
  1117. * @param $total_money
  1118. * @param $contacts_phone
  1119. * @param $system
  1120. * @param $fx_uid
  1121. * @return array
  1122. * @author 倪宗锋
  1123. */
  1124. public static function setMakeOrderReturn($orderId, $total_money, $contacts_phone, $system, $fx_uid)
  1125. {
  1126. //生成日志-开始 错误不终止程序
  1127. //发送 微信通知 错误不终止程序
  1128. try {
  1129. if ($system == 2) {
  1130. $checkLogin = LoginService::checkLogin();//如果当前用户是登录状态 则用户ID为当前用户 否则根据用户手机号去绑定
  1131. if ($checkLogin['flag'] == true) {
  1132. $u_uid = LoginService::$uid;
  1133. } else {
  1134. $shUser = new ShUser();
  1135. $u_uid = $shUser->getUidByPhone(trim($contacts_phone));
  1136. }
  1137. $u_type = 3;//微信用户下单
  1138. } else {
  1139. $u_uid = $fx_uid;
  1140. $u_type = 2;//分销用户下单
  1141. }
  1142. Util::addOrderLog($u_uid, $u_type, $orderId, '创建时间', 1);
  1143. } catch (Exception $e) {
  1144. }
  1145. //设置返回值
  1146. $siteConfig = Util::getSiteConfig();
  1147. $return = [
  1148. 'order_id' => $orderId,
  1149. 'pay_url' => $siteConfig['host_name'] . $siteConfig['payUrl'] . $orderId,
  1150. 'total_money' => $total_money
  1151. ];
  1152. return $return;
  1153. }
  1154. /**
  1155. * Function Description:本地数据库添加订单数据
  1156. * Function Name: createOrder
  1157. * @param $param_arr
  1158. *
  1159. * @return array
  1160. *
  1161. * @author 娄梦宁
  1162. */
  1163. public static function createOrder($param_arr)
  1164. {
  1165. $order_info = new OrderInfo();
  1166. $order_main = new OrderMain();
  1167. $order_contacts = new OrderContacts();
  1168. $prod_cate = new ProdCategory();
  1169. //获取产品数量
  1170. $prod_cnt = 0;
  1171. foreach ($param_arr['prod_arr'] as $val) {
  1172. $prod_cnt += $val['prod_count'];
  1173. }
  1174. $param_arr['prod_cnt'] = $prod_cnt;
  1175. /*****获取订单信息***/
  1176. $category = $prod_cate->getProdCateInfo($param_arr['pro_cate_id']);
  1177. if (empty($category)) {
  1178. return Util::returnArrEr('下单失败[1001]');
  1179. }
  1180. $param_arr['category_id'] = $category['category_id'];
  1181. if (empty($param_arr['prod_arr'])) {
  1182. return Util::returnArrEr('下单失败[1002]');
  1183. }
  1184. $totalMoney = static::getTotalMoney($param_arr, $category);//获取价格、如有需要计算子产品价格的则返回从cs获取到的产品的产品价格
  1185. if ($totalMoney['flag'] == false) {
  1186. return Util::returnArrEr('下单失败[1003]');
  1187. }
  1188. if (isset($totalMoney['data']['prod_arr'])) {
  1189. $param_arr['prod_arr'] = $totalMoney['data']['prod_arr'];
  1190. }
  1191. //新增保险价格--2017-10-26 娄梦宁
  1192. $param_arr['total_money'] = $totalMoney['data']['total_money'];
  1193. if ($param_arr['category_id'] == 1 && (!empty($param_arr['is_buy_insurance']) && $param_arr['insurance_list'])) {
  1194. $param_arr['insurance_price'] = 3;
  1195. $param_arr['total_money'] = $param_arr['total_money'] + count($param_arr['insurance_list']) * $param_arr['insurance_price'];
  1196. }
  1197. //新增自由行保险价格--2017-12-08 田玲菲
  1198. if ($param_arr['category_id'] == 4 && (!empty($param_arr['is_buy_insurance']) && $param_arr['insurance_list'])) {
  1199. $param_arr['total_money'] = $param_arr['total_money'] + count($param_arr['insurance_list']) * $param_arr['insurance_price'];
  1200. }
  1201. /**********1.插入order_main***************/
  1202. $fxUser = new FxUser();
  1203. $fxUserInfo = $fxUser::findOne($param_arr['fx_uid']);
  1204. $param_arr['main_user_id'] = $fxUserInfo['main_user_id'];//获取运营联系人
  1205. $param_arr['end_date'] = date('Y-m-d', strtotime($param_arr['start_date']) + 3600 * 24 * (intval($param_arr['days']) - 1));
  1206. $param_arr['order_name'] = $category['pro_cate_name'];
  1207. $param_arr['prod_source'] = 1;//产品来源 1、系统自增,2、cs
  1208. $param_arr['start_area'] = $category['start_area'];
  1209. $param_arr['end_area'] = $category['end_area'];
  1210. if ($category['category_id'] == 1 || empty($category['sign']) == false) {
  1211. $param_arr['prod_source'] = 2;
  1212. }
  1213. $shUser = new ShUser();
  1214. $param_arr['sh_uid'] = $shUser->getUidByPhone(trim($param_arr['contacts_phone']));//订单归属于 手机号对应的用户
  1215. $insertOrderMain = $order_main->insertOrder($param_arr);
  1216. if (!$insertOrderMain) {
  1217. return Util::returnArrEr('下单失败[1004]');
  1218. }
  1219. $orderId = $order_main->order_id;
  1220. /**********2.插入order_info***************/
  1221. $freeWalkerProdArr = [];
  1222. if ($category['category_id'] == 4) {//如果是巴士自由行
  1223. $freeWalker = new FreeWalker();
  1224. $getProd = $freeWalker->getProdArr($category, $param_arr['start_date']);
  1225. $freeWalkerProdArr = $getProd['data'];
  1226. }
  1227. foreach ($param_arr['prod_arr'] as $val) {
  1228. if ($val['prod_count'] == 0) {
  1229. continue;
  1230. }
  1231. if (empty($val['prod_price'])) {//没有 价格 则为0
  1232. $val['prod_price'] = 0;
  1233. }
  1234. foreach ($freeWalkerProdArr as $freeWalkProd) {//重置价格
  1235. if ($freeWalkProd['prod_id'] == $val['prod_id']) {
  1236. $val['prod_price'] = $freeWalkProd['prod_price'];
  1237. }
  1238. }
  1239. $insertOrderInfo = $order_info->insertInfo($val, $orderId, $category);
  1240. if (!$insertOrderInfo) {
  1241. return Util::returnArrEr('下单失败[1005]');
  1242. }
  1243. }
  1244. /**********4.插入联系人信息***************/
  1245. $insertOrderContacts = $order_contacts->insertContacts($param_arr, $orderId);
  1246. if (!$insertOrderContacts) {
  1247. return Util::returnArrEr('下单失败[1006]');
  1248. }
  1249. /**********5.产品销售数量+***************/
  1250. $addProdCnt = $prod_cate->addCount($param_arr['pro_cate_id'], $prod_cnt);
  1251. if ($addProdCnt === false) {
  1252. return Util::returnArrEr('下单失败[1007]');
  1253. }
  1254. /**************6.添加受保人信息***********************/
  1255. $addInsured = static::addInsured($param_arr, $orderId, $param_arr['insurance_price']);
  1256. if ($addInsured['flag'] == false) {
  1257. return $addInsured;
  1258. }
  1259. /**************7.添加乘车人信息***********************/
  1260. $addPassAnger = static::addPassAnger($param_arr, $orderId);
  1261. if ($addPassAnger['flag'] == false) {
  1262. return $addPassAnger;
  1263. }
  1264. return Util::returnArrSu('', ['order_id' => $orderId, 'total_money' => $param_arr['total_money']]);
  1265. }
  1266. /**
  1267. * Des:添加保险单出行人信息
  1268. * Name: addInsured
  1269. * @param $param_arr
  1270. * @param $orderId
  1271. * @return array
  1272. * @author 倪宗锋
  1273. */
  1274. public static function addInsured($param_arr, $orderId, $insurance_price = 0)
  1275. {
  1276. if (!empty($param_arr['is_buy_insurance']) && $param_arr['insurance_list']) {
  1277. foreach ($param_arr['insurance_list'] as $v) {
  1278. $arr = array(
  1279. 'contacts_name' => $v['passenger_name'],
  1280. 'contacts_ID' => $v['passenger_cardid'],
  1281. 'insurance_price' => $insurance_price
  1282. );
  1283. $orderContacts = new OrderContacts();
  1284. $res = $orderContacts->addInsuredPeople($arr, $orderId);
  1285. if (!$res) {
  1286. return Util::returnArrEr('下单失败[1008]');
  1287. }
  1288. }
  1289. }
  1290. return Util::returnArrSu();
  1291. }
  1292. /**
  1293. * Des:添加保险单出行人信息
  1294. * Name: addInsured
  1295. * @param $param_arr
  1296. * @param $orderId
  1297. * @return array
  1298. * @author 倪宗锋
  1299. */
  1300. public static function addPassAnger($param_arr, $orderId)
  1301. {
  1302. if (empty($param_arr['passanger_arr']) == false) {
  1303. foreach ($param_arr['passanger_arr'] as $v) {
  1304. $arr = array(
  1305. 'contacts_name' => $v['passenger_name'],
  1306. 'contacts_ID' => $v['passenger_cardid']
  1307. );
  1308. $orderContacts = new OrderContacts();
  1309. $res = $orderContacts->addPassAngerPeople($arr, $orderId);
  1310. if (!$res) {
  1311. return Util::returnArrEr('下单失败[1009]');
  1312. }
  1313. }
  1314. }
  1315. return Util::returnArrSu();
  1316. }
  1317. /**
  1318. * Des:添加酒店拓展信息
  1319. * Name: addHotelExtra
  1320. * @param $param_arr
  1321. * @param $orderId
  1322. * @return array
  1323. * @author 倪宗锋
  1324. */
  1325. public static function addHotelExtra($param_arr, $orderId)
  1326. {
  1327. if (empty($param_arr['hotel_extra']) == false) {
  1328. $data = $param_arr['hotel_extra'];
  1329. $data['main_order_id'] = $orderId;
  1330. $hotelExtra = new OrderHotelExtra();
  1331. $addFlag = $hotelExtra->addRow($data);
  1332. return $addFlag;
  1333. }
  1334. return Util::returnArrSu();
  1335. }
  1336. /**
  1337. * Des:获取订单总价格
  1338. * Name: getTotalMoney
  1339. * @param $params
  1340. * @param $category
  1341. * @return array
  1342. * @author 倪宗锋
  1343. */
  1344. public static function getTotalMoney($params, $category)
  1345. {
  1346. /********如果是cs门票订单* 去CS获取订单价格***********/
  1347. if ($category['category_id'] == 2 && empty($category['sign']) == false) {
  1348. $ticket = new MenP();//门票通用函数
  1349. $getTotalMoney = $ticket->getOrderPriceFromCs($category, $params['start_date'], $params['prod_arr']);
  1350. if ($getTotalMoney['flag'] == false) {
  1351. return $getTotalMoney;
  1352. }
  1353. $totalMoney = $getTotalMoney['data'];
  1354. } elseif ($category['category_id'] == 4 && empty($category['sign']) == false) {
  1355. $ticket = new FreeWalker();//巴士自由行
  1356. $getTotalMoney = $ticket->getPrice($params);
  1357. if ($getTotalMoney['flag'] == false) {
  1358. return $getTotalMoney;
  1359. }
  1360. $totalMoney = $getTotalMoney['data'];
  1361. } /****默认直接读取数据库中产品的数据********/
  1362. else {
  1363. $prod_main = new ProdMain();
  1364. $totalMoney = $prod_main->getTotalMoney($params['prod_arr']);//获取订单总金额
  1365. $totalMoney = ['total_money' => $totalMoney];
  1366. }
  1367. //微信系统的巴士产品打92折
  1368. if ($params['system'] == 2 && $params['category_id'] == 1) {
  1369. $totalMoney['total_money'] = static::getBusDiscountPrice($params['pro_cate_id'], $totalMoney['total_money'], $params['prod_cnt']);
  1370. }
  1371. return Util::returnArrSu('', $totalMoney);
  1372. }
  1373. /**
  1374. * Des:获取巴士票的打折后的价格
  1375. * Name: getBusDiscountPrice
  1376. * @param $pro_cate_id
  1377. * @param $total_money
  1378. * @param $prod_cnt int 产品数量
  1379. * @return float
  1380. * @author 倪宗锋
  1381. */
  1382. public static function getBusDiscountPrice($pro_cate_id, $total_money, $prod_cnt = 1)
  1383. {
  1384. $siteConfig = Util::getSiteConfig();
  1385. foreach ($siteConfig['bus_discount_list'] as $discountVal) {
  1386. if (in_array($pro_cate_id, $discountVal['id'])) {//如果是独立设置的就直接返回
  1387. $total_money = ceil($total_money * $discountVal['discount']);
  1388. return $total_money;
  1389. }
  1390. }
  1391. $total_money = ceil($total_money * $siteConfig['all_discount']);
  1392. $total_money = $total_money - $siteConfig['all_discount_price'] * $prod_cnt;//全局减金额
  1393. if ($total_money <= 0) {
  1394. $total_money = 1;
  1395. }
  1396. return $total_money;
  1397. }
  1398. /**
  1399. * Des:无产品下单
  1400. * Name: makeUnProdOrder
  1401. * @param $data
  1402. * @return array
  1403. * @author 倪宗锋
  1404. */
  1405. public static function makeUnProdOrder($data)
  1406. {
  1407. $param_arr = [
  1408. 'total_money' => $data['total_money'],//总基恩
  1409. 'pro_cate_id' => 0,//产品ID
  1410. 'prod_cnt' => $data['prod_cnt'],//产品数量
  1411. 'order_name' => $data['order_name'],//订单名称
  1412. 'fx_uid' => $data['fx_uid'],//分销商ID
  1413. 'start_date' => $data['start_date'],//开始日期
  1414. 'start_time' => $data['start_time'],//开始时间
  1415. 'sh_uid' => $data['sh_uid'],//用户ID
  1416. 'end_date' => $data['end_date'],//接收日期
  1417. 'end_time' => empty($data['end_time']) ? '00:00:00' : $data['end_time'],//结束时间
  1418. 'category_id' => $data['category_id'],//订单类型
  1419. 'system' => $data['system'],//系统
  1420. 'contacts_name' => $data['contacts_name'],//联系人
  1421. 'contacts_ID' => $data['contacts_ID'],//联系人证件ID
  1422. 'contacts_phone' => $data['contacts_phone'],//联系人手机号
  1423. 'prod_source' => empty($data['prod_source']) ? 1 : $data['prod_source'],//产品来源
  1424. 'start_area' => $data['start_area'],//起始地点
  1425. 'end_area' => $data['end_area'],//结束地点
  1426. 'passanger_arr' => empty($data['passanger_arr']) ? [] : $data['passanger_arr'],
  1427. 'hotel_extra' => empty($data['hotel_extra']) ? [] : $data['hotel_extra'],
  1428. 'remark'=>empty($data['remark'])?"":$data['remark']
  1429. ];
  1430. $order_contacts = new OrderContacts();
  1431. $order_main = new OrderMain();
  1432. $transaction = \Yii::$app->db->beginTransaction();
  1433. try {
  1434. /**********1.插入order_main***************/
  1435. if (empty($param_arr['sh_uid'])) {
  1436. $shUser = new ShUser();
  1437. $param_arr['sh_uid'] = $shUser->getUidByPhone($param_arr['contacts_phone']);
  1438. }
  1439. $insertOrderMain = $order_main->insertOrder($param_arr);
  1440. if (!$insertOrderMain) {
  1441. $transaction->rollBack();//回滚
  1442. return Util::returnArrEr('下单失败[1004]');
  1443. }
  1444. $orderId = $order_main->order_id;
  1445. /**********4.插入联系人信息***************/
  1446. $insertOrderContacts = $order_contacts->insertContacts($param_arr, $orderId);
  1447. if (!$insertOrderContacts) {
  1448. $transaction->rollBack();//回滚
  1449. return Util::returnArrEr('下单失败[1006]');
  1450. }
  1451. /**************7.添加乘车人信息***********************/
  1452. $addPassAnger = static::addPassAnger($param_arr, $orderId);
  1453. if ($addPassAnger['flag'] == false) {
  1454. return $addPassAnger;
  1455. }
  1456. /**************9.添加酒店拓展信息***********************/
  1457. $addPassAnger = static::addHotelExtra($param_arr, $orderId);
  1458. if ($addPassAnger['flag'] == false) {
  1459. return $addPassAnger;
  1460. }
  1461. $transaction->commit();//数据提交
  1462. } catch (Exception $e) {
  1463. $transaction->rollBack();//回滚
  1464. return Util::returnArrEr('下单失败[1008]');
  1465. }
  1466. return Util::returnArrSu('', ['order_id' => $orderId, 'total_money' => $param_arr['total_money']]);
  1467. }
  1468. /**
  1469. * Des:对重复支付的订单进行退款
  1470. * Name: refundOrderForSetPay
  1471. * @param $params
  1472. * pay_type 支付类型 1、微信 2、支付宝 3、余额支付
  1473. * @return array
  1474. * @author 倪宗锋
  1475. */
  1476. public static function refundOrderForRepeatPay($params)
  1477. {
  1478. if ($params['payType'] == 3) {
  1479. return Util::returnArrSu();
  1480. }
  1481. $data = [
  1482. 'order_id' => $params['out_trade_no'],
  1483. 'total_fee' => $params['total_fee'],
  1484. 'refund_fee' => $params['total_fee'],
  1485. 'app_id' => $params['app_id']
  1486. ];
  1487. $payType = $params['payType'];
  1488. $return = PayService::cancel($data, $payType);
  1489. return $return;
  1490. }
  1491. /**
  1492. * Des:发送微信退款通知
  1493. * Name: sendRefundTemplateMsg
  1494. * @param $order_id int
  1495. * @param $total_money int 退款金额
  1496. * @author 倪宗锋
  1497. * @return array
  1498. */
  1499. public static function sendRefundWxMsg($order_id, $total_money)
  1500. {
  1501. $payMain = new PayMain();
  1502. $getInfo = $payMain->getPayInfo($order_id);///获取支付信息
  1503. if ($getInfo['pay_type'] != 1) {
  1504. return Util::returnArrEr('非微信支付订单!');
  1505. }
  1506. $open_id = $getInfo['open_id'];//微信用户OPENID
  1507. $siteConfig = Util::getSiteConfig();
  1508. $url = $siteConfig['host_name'] . $siteConfig['order_detail'] . $order_id;
  1509. /**
  1510. * {{first.DATA}}
  1511. * 订单号:{{keyword1.DATA}}
  1512. * 退款原因:{{keyword2.DATA}}
  1513. * 退款金额:{{keyword3.DATA}}
  1514. * {{remark.DATA}}
  1515. */
  1516. $data = [
  1517. 'first' => ['value' => '您好,您的退款申请已成功退款,请确认查收。', 'color' => '#743A3A'],
  1518. 'keyword1' => ['value' => $order_id, 'color' => '#4191ff'],
  1519. 'keyword2' => ['value' => '订单取消', 'color' => '#4191ff'],
  1520. 'keyword3' => ['value' => $total_money . '元', 'color' => '#4191ff'],
  1521. 'remark' => ['value' => '温馨提示:如有疑问,请咨询在线客服', 'color' => '#743A3A']
  1522. ];
  1523. $flag = WeChatService::sendWxTemplate($open_id, 'sendRefundWxMsg', $url, $data);
  1524. if ($flag == true) {
  1525. return Util::returnArrSu();
  1526. }
  1527. return Util::returnArrEr('发送失败!');
  1528. }
  1529. /**
  1530. * Des:预定成功微信通知
  1531. * Name: sendCreateOrderWxMsg
  1532. * @param $order_id
  1533. * @return array
  1534. * @author 倪宗锋
  1535. */
  1536. public static function sendCreateOrderWxMsg($order_id)
  1537. {
  1538. if (Util::checkPattern('intVal', $order_id) == false) {
  1539. return Util::returnArrEr('params error');
  1540. }
  1541. $orderMain = new OrderMain();
  1542. $getInfo = $orderMain->getSendCreateWxMsg($order_id);
  1543. if (empty($getInfo['open_id'])) {
  1544. return Util::returnArrEr('非微信支付订单!');
  1545. }
  1546. $open_id = $getInfo['open_id'];//微信用户OPENID
  1547. $siteConfig = Util::getSiteConfig();
  1548. $url = $siteConfig['host_name'] . $siteConfig['order_detail'] . $order_id;
  1549. ///汽车票下单通知
  1550. if ($getInfo['category_id'] == 1) {
  1551. $data = [
  1552. 'first' => ['value' => '您的订单已预订成功,马上为您出票。', 'color' => '#743A3A'],
  1553. 'keyword1' => ['value' => $order_id, 'color' => '#4191ff'],
  1554. 'keyword2' => ['value' => $getInfo['users'], 'color' => '#4191ff'],
  1555. 'keyword3' => ['value' => $getInfo['start_area'] . ' - ' . $getInfo['end_area'], 'color' => '#4191ff'],
  1556. 'keyword4' => ['value' => $getInfo['start_date'] . ' ' . $getInfo['start_time'], 'color' => '#4191ff'],
  1557. 'remark' => ['value' => '温馨提示:请提前15分钟到站乘车,上车时请出示订单号进行检票上车,如需帮助,请咨询微信在线客服', 'color' => '#743A3A']
  1558. ];
  1559. $flag = WeChatService::sendWxTemplate($open_id, 'sendCreateOrderWxMsg_1', $url, $data);
  1560. } ///门票下单通知
  1561. else if ($getInfo['category_id'] == 2) {
  1562. $data = [
  1563. 'first' => ['value' => '您好,您的门票订单已预订成功。', 'color' => '#743A3A'],
  1564. 'OrderID' => ['value' => $order_id, 'color' => '#4191ff'],
  1565. 'PkgName' => ['value' => $getInfo['order_name'] . ' ' . $getInfo['prod_cnt'], 'color' => '#4191ff'],
  1566. 'TakeOffDate' => ['value' => $getInfo['start_date'] . ' ' . $getInfo['start_time'], 'color' => '#4191ff'],
  1567. 'remark' => ['value' => '使用方法:凭预订成功后收到的短信提示换票或刷身份证入园,未使用前短信请勿删除、不能转发。如不慎删除,请联系在线客服。', 'color' => '#743A3A']
  1568. ];
  1569. $flag = WeChatService::sendWxTemplate($open_id, 'sendCreateOrderWxMsg_2', $url, $data);
  1570. } else if ($getInfo['category_id'] == 3) {
  1571. $hotelOrder = $orderMain->getHotelOrderInfo($order_id);
  1572. $data = [
  1573. 'first' => ['value' => "您好,您已经成功预订{$hotelOrder['hotel_name']}。等待酒店确认接单。如酒店不接单将全额退款至您的付款账户。", 'color' => '#743A3A'],
  1574. 'keyword1' => ['value' => $order_id, 'color' => '#4191ff'],//订单号
  1575. 'keyword2' => ['value' => $hotelOrder['start_date'], 'color' => '#4191ff'],//入住日期
  1576. 'keyword3' => ['value' => $hotelOrder['all_days'] . '晚', 'color' => '#4191ff'],//入住天数
  1577. 'keyword4' => ['value' => $hotelOrder['room_name'], 'color' => '#4191ff'],//房型名称
  1578. 'keyword5' => ['value' => $hotelOrder['prod_cnt'] . '间', 'color' => '#4191ff'],//房间数
  1579. 'remark' => ['value' => '如有疑问,请致电' . $siteConfig['kefu_tel'] . "或关注微信公众号“{$siteConfig['web_name']}”,咨询在线客服,服务时间:09:00 - 21:00。", 'color' => '#743A3A']
  1580. ];
  1581. $flag = WeChatService::sendWxTemplate($open_id, 'sendCreateOrderWxMsg_3', $url, $data);
  1582. } else {
  1583. return Util::returnArrEr('暂时只支持汽、门票和酒店下单通知!');
  1584. }
  1585. if ($flag == true) {
  1586. return Util::returnArrSu();
  1587. }
  1588. return Util::returnArrEr('发送失败!');
  1589. }
  1590. /**
  1591. * Des:发送佣金变更微信通知信息 发送给分销
  1592. * Name: sendCommissionWxMsg
  1593. * @param $order_id
  1594. * @return array
  1595. * @author 倪宗锋
  1596. */
  1597. public static function sendCommissionWxMsg($order_id)
  1598. {
  1599. if (Util::checkPattern('intVal', $order_id) == false) {
  1600. return Util::returnArrEr('params error');
  1601. }
  1602. $fxCommission = new FxCommissionInfo();
  1603. $getInfo = $fxCommission->getSendWxMsg($order_id);
  1604. if (empty($getInfo['open_id'])) {
  1605. return Util::returnArrEr('非微信支付订单!');
  1606. }
  1607. if (empty($getInfo['commission'])) {
  1608. return Util::returnArrEr('没有佣金不发送通知');
  1609. }
  1610. $open_id = $getInfo['open_id'];//微信open_id
  1611. $siteConfig = Util::getSiteConfig();
  1612. $url = $siteConfig['fx_host'] . '/web/fx/order_detail.html?order_id=' . $order_id;//分销订单详情页面
  1613. $data = [
  1614. 'first' => ['value' => '恭喜你有新的分销佣金入账。', 'color' => '#743A3A'],
  1615. 'keyword1' => ['value' => $order_id, 'color' => '#4191ff'],
  1616. 'keyword2' => ['value' => $getInfo['category_name'], 'color' => '#4191ff'],
  1617. 'keyword3' => ['value' => '已完成', 'color' => '#4191ff'],
  1618. 'keyword4' => ['value' => $getInfo['total_money'] . '元', 'color' => '#4191ff'],
  1619. 'keyword5' => ['value' => $getInfo['commission'] . '元', 'color' => '#4191ff'],
  1620. 'remark' => ['value' => '分销佣金入账,你离月薪十万还差一小步,再接再厉哦!', 'color' => '#743A3A']
  1621. ];
  1622. $flag = WeChatService::sendWxTemplate($open_id, 'sendCommissionWxMsg', $url, $data, '#7B68EE', $siteConfig['fx_wechat']);
  1623. if ($flag == true) {
  1624. return Util::returnArrSu();
  1625. }
  1626. return Util::returnArrEr('发送失败!');
  1627. }
  1628. /**
  1629. * Des:发送巴士出行短信通知
  1630. * Name: sendRunBusWxMsg
  1631. * @param $data
  1632. * @return array
  1633. * @author 倪宗锋
  1634. */
  1635. public static function sendRunBusWxMsg($data)
  1636. {
  1637. $open_id = $data['open_id'];//微信open_id
  1638. $siteConfig = Util::getSiteConfig();
  1639. $url = $siteConfig['host_name'] . $siteConfig['order_detail'] . $data['order_id'];//微信订单详情页
  1640. $data = [
  1641. 'first' => ['value' => '出行车辆通知', 'color' => '#743A3A'],
  1642. 'keyword1' => ['value' => $data['bus_no'], 'color' => '#4191ff'],
  1643. 'keyword2' => ['value' => $data['seat_name'], 'color' => '#4191ff'],
  1644. 'keyword3' => ['value' => $data['area'], 'color' => '#4191ff'],
  1645. 'keyword4' => ['value' => $data['run_date'], 'color' => '#4191ff'],
  1646. 'keyword5' => ['value' => '联系在线客服获取', 'color' => '#4191ff'],
  1647. 'remark' => ['value' => '温馨提示:司机将会在发车前5-10分钟与您联系,请保持手机畅通', 'color' => '#743A3A']
  1648. ];
  1649. $flag = WeChatService::sendWxTemplate($open_id, 'sendRunBusWxMsg', $url, $data);
  1650. if ($flag == true) {
  1651. return Util::returnArrSu();
  1652. }
  1653. return Util::returnArrEr('发送失败!');
  1654. }
  1655. /**
  1656. * Des:发送取消订单分销通知
  1657. * Name: sendCancelOrderWxMsg
  1658. * @param $order_id
  1659. * @return array
  1660. * @author 倪宗锋
  1661. */
  1662. public static function sendCancelOrderWxMsg($order_id)
  1663. {
  1664. if (Util::checkPattern('intVal', $order_id) == false) {
  1665. return Util::returnArrEr('params error');
  1666. }
  1667. $orderMain = new OrderMain();
  1668. $getInfo = $orderMain->getSendCreateWxMsg($order_id);
  1669. if (empty($getInfo['open_id'])) {
  1670. return Util::returnArrEr('非微信支付订单!');
  1671. }
  1672. $open_id = $getInfo['open_id'];//微信用户OPENID
  1673. $siteConfig = Util::getSiteConfig();
  1674. $url = $siteConfig['host_name'] . $siteConfig['order_detail'] . $order_id;
  1675. if ($getInfo['category_id'] == 3) {
  1676. $hotelOrder = $orderMain->getHotelOrderInfo($order_id);
  1677. $star_date = date('m月d日', strtotime($hotelOrder['start_date']));
  1678. $data = [
  1679. 'first' => ['value' => "您预定的{$star_date}入住的{$hotelOrder['room_name']}房型({$hotelOrder['prod_cnt']}间{$hotelOrder['all_days']}晚) 的订单已被酒店确认无房,请您选择其他的房型入住。您所支付的金额将会全额退回您的支付账号。请注意查收。", 'color' => '#743A3A'],
  1680. 'keyword1' => ['value' => $hotelOrder['hotel_name'], 'color' => '#4191ff'],//酒店名称
  1681. 'keyword2' => ['value' => $hotelOrder['start_date'], 'color' => '#4191ff'],//入住日期
  1682. 'keyword3' => ['value' => $hotelOrder['end_date'], 'color' => '#4191ff'],//离店日期
  1683. 'remark' => ['value' => '如有疑问,请致电' . $siteConfig['kefu_tel'] . "或关注微信公众号“{$siteConfig['web_name']}”,咨询在线客服,服务时间:09:00 - 21:00。", 'color' => '#743A3A']
  1684. ];
  1685. $flag = WeChatService::sendWxTemplate($open_id, 'sendCancelOrderWxMsg_3', $url, $data);
  1686. } else {
  1687. return Util::returnArrEr('暂时只支持酒店取消通知!');
  1688. }
  1689. if ($flag == true) {
  1690. return Util::returnArrSu();
  1691. }
  1692. return Util::returnArrEr('发送失败!');
  1693. }
  1694. /**
  1695. * Des:分销下单通知
  1696. * Name: sendFxCreateOrder
  1697. * @param $order_id
  1698. * @return array
  1699. * @author 倪宗锋
  1700. */
  1701. public
  1702. static function sendFxCreateOrder($order_id)
  1703. {
  1704. if (Util::checkPattern('intVal', $order_id) == false) {
  1705. return Util::returnArrEr('params error');
  1706. }
  1707. $fxCommission = new FxCommissionInfo();
  1708. $getInfo = $fxCommission->getSendWxMsg($order_id);
  1709. if (empty($getInfo['open_id'])) {
  1710. return Util::returnArrEr('非微信支付订单!');
  1711. }
  1712. if (empty($getInfo['open_id'])) {
  1713. return Util::returnArrEr('没有分销商不发送通知');
  1714. }
  1715. $open_id = $getInfo['open_id'];//微信open_id
  1716. $siteConfig = Util::getSiteConfig();
  1717. $url = $siteConfig['fx_host'] . '/web/fx/order_detail.html?order_id=' . $order_id;//分销订单详情页面
  1718. $data = [
  1719. 'first' => ['value' => '进单啦!有人通过扫描您的蜘蛛二维码下单成功', 'color' => '#743A3A'],
  1720. 'keyword1' => ['value' => $getInfo['order_name'], 'color' => '#4191ff'],//产品名称
  1721. 'keyword2' => ['value' => $order_id, 'color' => '#4191ff'],//订单号
  1722. 'keyword3' => ['value' => $getInfo['prod_cnt'], 'color' => '#4191ff'],//人数
  1723. 'keyword4' => ['value' => $getInfo['total_money'], 'color' => '#4191ff'],//金额
  1724. 'remark' => ['value' => '详情请查看您的分销订单列表。', 'color' => '#743A3A']
  1725. ];
  1726. $flag = WeChatService::sendWxTemplate($open_id, 'sendFxCreateOrder', $url, $data, '#7B68EE', $siteConfig['fx_wechat']);
  1727. if ($flag == true) {
  1728. return Util::returnArrSu();
  1729. }
  1730. return Util::returnArrEr('发送失败!');
  1731. }
  1732. /**
  1733. * Des:发送酒店订单确认通知
  1734. * Name: sendConfirmWxMsg
  1735. * @param $order_id
  1736. * @return array
  1737. * @author 倪宗锋
  1738. */
  1739. public static function sendConfirmWxMsg($order_id)
  1740. {
  1741. if (Util::checkPattern('intVal', $order_id) == false) {
  1742. return Util::returnArrEr('params error');
  1743. }
  1744. $orderMain = new OrderMain();
  1745. $getInfo = $orderMain->getSendCreateWxMsg($order_id);
  1746. if (empty($getInfo['open_id'])) {
  1747. return Util::returnArrEr('非微信支付订单!');
  1748. }
  1749. $open_id = $getInfo['open_id'];//微信用户OPENID
  1750. $siteConfig = Util::getSiteConfig();
  1751. $url = $siteConfig['host_name'] . $siteConfig['order_detail'] . $order_id;
  1752. $hotelOrder = $orderMain->getHotelOrderInfo($order_id);
  1753. $star_date = date('m月d日', strtotime($hotelOrder['start_date']));
  1754. $data = [
  1755. 'first' => ['value' => "您预定的{$star_date}入住的{$hotelOrder['room_name']}房型({$hotelOrder['prod_cnt']}间{$hotelOrder['all_days']}晚) 的订单已被酒店确认接单,请您于入住当日到酒店前台办理相关手续", 'color' => '#743A3A'],
  1756. 'order' => ['value' => $hotelOrder['order_id'], 'color' => '#4191ff'],//订单号
  1757. 'Name' => ['value' => $hotelOrder['users'], 'color' => '#4191ff'],//入住人
  1758. 'datein' => ['value' => $hotelOrder['start_date'], 'color' => '#4191ff'],//入住日期
  1759. 'dateout' => ['value' => $hotelOrder['end_date'], 'color' => '#4191ff'],//离店日期
  1760. 'number' => ['value' => $hotelOrder['prod_cnt'] . '间', 'color' => '#4191ff'],//房间数量
  1761. 'room type' => ['value' => $hotelOrder['room_name'], 'color' => '#4191ff'],//房型名称
  1762. 'pay' => ['value' => $hotelOrder['total_money'], 'color' => '#4191ff'],//订单总价
  1763. 'remark' => ['value' => '如有疑问,请致电' . $siteConfig['kefu_tel'] . "或关注微信公众号“{$siteConfig['web_name']}”,咨询在线客服,服务时间:09:00 - 21:00。", 'color' => '#743A3A']
  1764. ];
  1765. $flag = WeChatService::sendWxTemplate($open_id, 'sendConfirmWxMsg', $url, $data);
  1766. if ($flag == true) {
  1767. return Util::returnArrSu();
  1768. }
  1769. return Util::returnArrEr('发送失败!');
  1770. }
  1771. /**
  1772. * Des:发送酒店出行通知
  1773. * Name: sendTravelTipsWxMsg
  1774. * @param $params
  1775. * @return array
  1776. * @author 倪宗锋
  1777. */
  1778. public static function sendTravelTipsWxMsg($params)
  1779. {
  1780. $open_id = $params['open_id'];//微信用户OPENID
  1781. $siteConfig = Util::getSiteConfig();
  1782. $url = $siteConfig['host_name'] . $siteConfig['order_detail'] . $params['order_id'];
  1783. $data = [
  1784. 'first' => ['value' => "您好,{$params['hotel_name']}万分期待您的入住,为了让您有更好的入住体验,请您尽量于当天14点-18点到店,错开前台办理入住的高峰时段。", 'color' => '#743A3A'],
  1785. 'OrderID' => ['value' => $params['order_id'], 'color' => '#4191ff'],//订单号
  1786. 'HotelName' => ['value' => $params['hotel_name'], 'color' => '#4191ff'],//入住人
  1787. 'CheckInDate' => ['value' => $params['start_date'], 'color' => '#4191ff'],//入住日期
  1788. 'CheckOutDate' => ['value' => $params['end_date'], 'color' => '#4191ff'],//离店日期
  1789. 'remark' => ['value' => '如有疑问,请致电' . $siteConfig['kefu_tel'] . "或关注微信公众号“{$siteConfig['web_name']}”,咨询在线客服,服务时间:09:00 - 21:00。", 'color' => '#743A3A']
  1790. ];
  1791. $flag = WeChatService::sendWxTemplate($open_id, 'sendTravelTipsWxMsg', $url, $data);
  1792. if ($flag == true) {
  1793. return Util::returnArrSu();
  1794. }
  1795. return Util::returnArrEr('发送失败!');
  1796. }
  1797. /**
  1798. * Des:校验是否可定
  1799. * Name: checkHotel
  1800. * @param $params
  1801. * @return array
  1802. * @author 倪宗锋
  1803. */
  1804. public
  1805. static function checkHotel($params)
  1806. {
  1807. $roomPrices = json_decode($params['total_details'], true);
  1808. foreach ($roomPrices as &$val) {
  1809. $val['RunDate'] = $val['date'];
  1810. $val['Price'] = $val['price'];
  1811. unset($val['date']);
  1812. unset($val['price']);
  1813. }
  1814. $data = [
  1815. 'HotelID' => $params['hotel_id'],
  1816. 'RoomID' => $params['room_id'],
  1817. 'RoomNum' => $params['prod_cnt'],
  1818. 'CheckIn' => $params['start_date'],
  1819. 'CheckOut' => $params['end_date'],
  1820. 'RoomPrices' => $roomPrices,
  1821. 'IfCheckPrice' => 0,
  1822. ];
  1823. $result = Util::sendCs($data, '/hotel/api/check-room-avail', 2);
  1824. if ($result['flag'] == true) {
  1825. return Util::returnArrSu('', $result['data']['data']);
  1826. }
  1827. return Util::returnArrEr($result['msg']);
  1828. }
  1829. }