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

WxTripApi.php 14 KiB

3 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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/07/06
  14. */
  15. namespace backend\modules\api\logic;
  16. use backend\modules\api\models\ErrorOrderLog;
  17. use backend\modules\api\models\OperaLine;
  18. use backend\modules\api\models\OperaProductRun;
  19. use backend\modules\api\models\OperaTouristCommon;
  20. use backend\modules\api\models\OrderMain;
  21. use backend\modules\api\models\RunMain;
  22. use backend\modules\api\util\Util;
  23. use backend\modules\zzcs\models\OperaTouristRun;
  24. use Yii;
  25. use yii\base\Exception;
  26. use yii\db\Expression;
  27. class WxTripApi
  28. {
  29. #渠道ID
  30. public $supplier_id = 164;
  31. public function __construct($supplier_id = '')
  32. {
  33. if (empty($supplier_id) == false) {
  34. $this->supplier_id = $supplier_id;
  35. }
  36. }
  37. /**
  38. * Function Description:我要找车,获取巴士位置信息
  39. * Function Name: GetBusPosition
  40. * @param $order_id
  41. * @param $run_date
  42. *
  43. * @return array
  44. *
  45. * @author 娄梦宁
  46. */
  47. public function GetBusPosition($order_id, $run_date)
  48. {
  49. if (preg_match("/^[1-9][0-9]{0,10}$/", $order_id) == false || preg_match("/^[0-9]{4}-(((0[13578]|(10|12))-(0[1-9]|[1-2][0-9]|3[0-1]))|(02-(0[1-9]|[1-2][0-9]))|((0[469]|11)-(0[1-9]|[1-2][0-9]|30)))$/", $run_date) == false) {
  50. return [
  51. 'code' => 1,
  52. 'info' => '参数错误',
  53. 'list' => [],
  54. ];
  55. }
  56. $order_main = new OrderMain();
  57. $res = $order_main->get_bus_position_info($order_id, $run_date);
  58. $list = [
  59. 'res' => [
  60. 'address' => $res['address'] == null ? '' : $res['address'],
  61. 'res_id' => $res['res_id'],
  62. 'res_name' => $res['res_name'],
  63. 'longitude' => $res['longitude'],
  64. 'latitude' => $res['latitude'],
  65. ],
  66. 'bus' => [
  67. 'bus_id' => $res['bus_id'] == null ? '' : $res['res_id'],
  68. 'bus_no' => $res['bus_no'],
  69. 'seat_no' => explode(",", $res['seat_list']),
  70. 'driver_name' => $res['driver_name'],
  71. 'driver_mobile' => $res['driver_mobile'],
  72. 'color' => $res['color'] == null ? '' : $res['color'],
  73. 'img_url' => $res['img_url'] == null ? '' : $res['img_url'],
  74. 'bus_name' => $res['bus_name'],
  75. 'lng' => $res['lng'] == null ? '' : $res['lng'],
  76. 'lat' => $res['lat'] == null ? '' : $res['lat'],
  77. ],
  78. 'wx_flag' => [
  79. 'appoint_message' => $res['appoint_message'],
  80. 'click_send_message' => $res['click_send_message']
  81. ],
  82. "send_bus_flag" => 1
  83. ];
  84. if ($res['bus_id'] == null || $res['bus_no'] == "") {
  85. $list["send_bus_flag"] = 0;
  86. }
  87. return [
  88. 'code' => 0,
  89. 'info' => '数据获取成功',
  90. 'list' => $list,
  91. ];
  92. }
  93. /**
  94. * Function Description:获取产品某一天的票种价格
  95. * Function Name: GetPriceDateOne
  96. * @param $tourist_id
  97. * @param $run_date
  98. *
  99. * @return array
  100. *
  101. * @author 娄梦宁
  102. */
  103. public function GetPriceDateOne($tourist_id, $run_date,$userId)
  104. {
  105. $list = $this->GetPriceDate($tourist_id, $run_date,$userId);
  106. if (!$list) {
  107. return [
  108. 'code' => 1,
  109. 'info' => '数据获取失败'
  110. ];
  111. }
  112. return [
  113. 'code' => 0,
  114. 'info' => '数据获取成功',
  115. 'list' => array_values($list)
  116. ];
  117. }
  118. public function addMinPriceToTouristArray($tourist_array, $next_days = 14,$userId=2)
  119. {
  120. $return_array = array();
  121. foreach ($tourist_array as $tourist_id => $tourist_info) {
  122. $mini_price = $this->getMiniPriceNextDays($tourist_id, $next_days,$userId);
  123. if ($mini_price == -1) {
  124. continue;
  125. }
  126. $tourist_info["mini_price"] = $mini_price;
  127. $return_array[$tourist_id] = $tourist_info;
  128. }
  129. return $return_array;
  130. }
  131. public function getMiniPriceNextDays($tourist_id, $next_days,$userId=2)
  132. {
  133. $mini_price = 99999;
  134. $price_array = $this->GetPriceNextDays($tourist_id, $next_days,$userId);
  135. if ($price_array["code"] == 0) {
  136. if (count($price_array["list"]) <= 0) {
  137. return -1;
  138. }
  139. foreach ($price_array["list"] as $price_info) {
  140. $mini_price = $price_info["mini_price"] < $mini_price ? $price_info["mini_price"] : $mini_price;
  141. }
  142. }
  143. return $mini_price;
  144. }
  145. public function GetPriceNextDays($tourist_id, $next_days,$userId = 2)
  146. {
  147. $next_days = $next_days < 1 ? 1 : $next_days;
  148. $list = [];
  149. for ($i = 1; $i < $next_days; $i++) {
  150. $tmp_date = date('Y-m-d', strtotime("+$i day"));
  151. $tmp_list = $this->GetPriceDate($tourist_id, $tmp_date,$userId);
  152. if (!$tmp_list) {
  153. // $list[]=[
  154. // 'ticket_date'=>$tmp_date,
  155. // 'mini_price'=>99999,
  156. // 'ticket_num'=>0,
  157. // ];
  158. } else {
  159. $list[] = [
  160. 'ticket_date' => $tmp_date,
  161. 'mini_price' => $tmp_list['adult']['ticket_price'],
  162. 'child_price' => $tmp_list['child']['ticket_price'],
  163. 'ticket_num' => $tmp_list['adult']['ticket_num'],
  164. ];
  165. }
  166. }
  167. return [
  168. 'code' => 0,
  169. 'info' => '数据获取成功',
  170. 'list' => $list,
  171. ];
  172. }
  173. public function GetPriceDateMonth($tourist_id,$userId=2)
  174. {
  175. return $this->GetPriceNextDays($tourist_id, 60,$userId);
  176. }
  177. /**
  178. * Function Description:获取特定日期产品价格通用方法
  179. * Function Name: GetPriceDate
  180. * @param $tourist_id
  181. * @param $run_date
  182. * @param $userId
  183. *
  184. * @return array|bool
  185. *
  186. * @author 娄梦宁
  187. */
  188. public function GetPriceDate($tourist_id, $run_date,$userId =2)
  189. {
  190. $get_tourist_stock = new GetTouristStock;
  191. $opera_tourist_run = new OperaTouristRun();
  192. //调用组合产品库存成本接口
  193. $stock = $get_tourist_stock->getTouristStock($tourist_id, $run_date, $this->supplier_id, $userId);
  194. if ($stock['code'] != 0) {
  195. return false;
  196. }
  197. $sale_type = $opera_tourist_run->get_sale_type($tourist_id, $run_date,$this->supplier_id);
  198. $list = [
  199. 'prod_id' => 'TR-' . $tourist_id . '-1',
  200. 'ticket_price' => $stock['list']['adult_cost'],
  201. 'ticket_num' => $stock['list']['limit_adult_num'],
  202. 'ticket_all_num' => $stock['list']['limit_total_num'],
  203. ];
  204. $list1 = [
  205. 'prod_id' => 'TR-' . $tourist_id . '-2',
  206. 'ticket_price' => $stock['list']['child_cost'],
  207. 'ticket_num' => $stock['list']['limit_adult_num'],
  208. 'ticket_all_num' => $stock['list']['limit_total_num'],
  209. ];
  210. $is_booking = Util::checkBookTime($sale_type['pre_days'], $sale_type['pre_time'], $run_date);
  211. //预订时间已过
  212. if (!$is_booking) {
  213. //产品当天下架
  214. $list['ticket_num'] = 0;
  215. $list['ticket_all_num'] = 0;
  216. $list1['ticket_num'] = 0;
  217. $list1['ticket_all_num'] = 0;
  218. return [
  219. 'adult' => $list,
  220. 'child' => $list1,
  221. ];
  222. }
  223. if (empty($sale_type)) {
  224. //当天没有价格日历,直接用默认值
  225. $tourist_profit = Yii::$app->params['tourist_profit'];
  226. $list['ticket_price'] = floor($stock['list']['adult_cost'] * (1 + $tourist_profit * 0.01));
  227. $list1['ticket_price'] = floor($stock['list']['child_cost'] * (1 + $tourist_profit * 0.01));
  228. } else {
  229. if ($sale_type['is_onsale'] == 0) {
  230. //产品当天下架
  231. $list['ticket_num'] = 0;
  232. $list['ticket_all_num'] = 0;
  233. $list1['ticket_num'] = 0;
  234. $list1['ticket_all_num'] = 0;
  235. } else {
  236. //产品正常可售
  237. if ($sale_type['sale_type_child'] == 2) {
  238. //百分比加价
  239. $list1['ticket_price'] = floor($stock['list']['child_cost'] * ($sale_type['diff_para_child'] * 0.01 + 1));
  240. } else {
  241. //固定加价
  242. $list1['ticket_price'] = floor($stock['list']['child_cost'] + $sale_type['diff_para_child']);
  243. }
  244. if ($sale_type['sale_type_adult'] == 2) {
  245. //百分比加价
  246. $list['ticket_price'] = floor($stock['list']['adult_cost'] * ($sale_type['diff_para_adult'] * 0.01 + 1));
  247. } else {
  248. //固定加价
  249. $list['ticket_price'] = floor($stock['list']['adult_cost'] + $sale_type['diff_para_adult']);
  250. }
  251. }
  252. }
  253. return [
  254. 'adult' => $list,
  255. 'child' => $list1,
  256. ];
  257. }
  258. /**
  259. * Function Description:获取可否换座类型
  260. * Function Name: getChangeSeatType
  261. * @param $order_id
  262. *
  263. * @return array
  264. *
  265. * @author 娄梦宁
  266. */
  267. public function getChangeSeatType($order_id)
  268. {
  269. $order_main = new OrderMain();
  270. $opera_line = new OperaLine();
  271. $run_main = new RunMain();
  272. $order_info = $order_main->getOrderInfoForGetSeat($order_id);
  273. try {
  274. #1:判断线路、巴士是否支持选座#
  275. $line_allow_seat = $opera_line->getLineSeatAllow($order_info['line_id']);
  276. if ($line_allow_seat['allow_select_seat'] == 0) {
  277. return [
  278. 'code' => 0,
  279. 'info' => '该线路不支持换座!',
  280. 'data' => [
  281. 'change_seat_type' => 1
  282. ]
  283. ];
  284. }
  285. #2:判断是否选过座#
  286. #run_x表表名#
  287. $run_x = 'run_' . substr($order_info['run_date'], 0, 4) . substr($order_info['run_date'], 5, 2);
  288. #endregion
  289. $is_choose = $run_main->GetRunxAllowSelectSeat($run_x, $order_info['run_id'], explode(',', $order_info['son_order']));
  290. foreach ($is_choose as $val) {
  291. if ($val['allow_select_seat'] != 156) {
  292. return [
  293. 'code' => 0,
  294. 'info' => '该订单已经进行过选座!',
  295. 'data' => [
  296. 'change_seat_type' => 2,
  297. ]
  298. ];
  299. }
  300. }
  301. #3:判断是否在选座时间内#
  302. #发车前一个小时的时间戳
  303. $bus_start_time = strtotime($order_info['run_date'] . ' ' . $order_info['prod_start_station_time']) - 3600;
  304. #发车前一天晚上六点的时间戳
  305. $start_change_seat_time = strtotime($order_info['run_date']) - 19800;
  306. if (time() < $start_change_seat_time) {
  307. return [
  308. 'code' => 0,
  309. 'info' => '乘坐车辆暂未派车,请在发车前一天18点30分后进行选座!',
  310. 'data' => [
  311. 'change_seat_type' => 3
  312. ]
  313. ];
  314. } elseif (time() > $bus_start_time) {
  315. return [
  316. 'code' => 0,
  317. 'info' => '座位已经自动选择',
  318. 'data' => [
  319. 'change_seat_type' => 4
  320. ]
  321. ];
  322. }
  323. return [
  324. 'code' => 0,
  325. 'info' => '可以选座',
  326. 'data' => [
  327. 'change_seat_type' => 0
  328. ]
  329. ];
  330. } catch (Exception $e) {
  331. return [
  332. 'code' => 1,
  333. 'info' => '后台接口错误!',
  334. ];
  335. }
  336. }
  337. /**
  338. * Function Description:获取自由行保险价格
  339. * Function Name: getFreeWalkDays
  340. * @param $tourist_id
  341. * @param $run_date
  342. * @return array
  343. * @author 田玲菲
  344. */
  345. public function getFreeWalkDays($tourist_id, $run_date)
  346. {
  347. //获取行程天数
  348. $operaTouristCommon = new OperaTouristCommon();
  349. $result = $operaTouristCommon->getDays($tourist_id);
  350. $days = $result['day_num'];
  351. if (empty($days)) {
  352. return [
  353. 'code' => 1,
  354. 'info' => '获取出行天数失败'
  355. ];
  356. }
  357. //根据天数获取prod_id
  358. $params = Yii::$app->params;
  359. $prod_id = $params['tourist_insurance']['sun_prod_id'][$days - 1];
  360. if (!$prod_id) {
  361. return [
  362. 'code' => 2,
  363. 'info' => '获取保险产品id失败',
  364. 'prod_id' => $prod_id,
  365. 'days' => $days,
  366. ];
  367. }
  368. //根据prod_id和run_date去取保险价格
  369. $operaProductRun = new OperaProductRun();
  370. $rst = $operaProductRun->getRunInfoByProdIdAndDate($prod_id, $run_date);
  371. if (count($rst) > 0 && $rst['is_onsale'] == 1) {
  372. return [
  373. 'code' => 0,
  374. 'info' => '获取价格成功',
  375. 'price' => $rst['cus_price']
  376. ];
  377. } else {
  378. return [
  379. 'code' => 3,
  380. 'info' => '获取价格失败',
  381. ];
  382. }
  383. }
  384. }