ThirdOrderLogic.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. <?php
  2. namespace app\common\logic;
  3. use app\api\logic\LoginLogic;
  4. use app\common\{enum\GoodsEnum,
  5. enum\PayEnum,
  6. enum\WorkEnum,
  7. model\goods\Goods,
  8. model\orders\RechargeOrder,
  9. model\recharge\OrderGoods,
  10. model\setting\PostageRegion,
  11. model\third\ThirdGoods,
  12. model\third\ThirdOrders,
  13. model\user\User,
  14. model\works\ServiceWork,
  15. model\works\ServiceWorkAppointmentLog,
  16. model\works\ServiceWorkLog};
  17. use think\facade\Db;
  18. use app\common\model\service_area\ServiceArea;
  19. /**
  20. * 第三方平台下单逻辑层
  21. * Class UserLogic
  22. * @package app\shopapi\logic
  23. */
  24. class ThirdOrderLogic extends BaseLogic
  25. {
  26. protected const user_token = [
  27. "accessToken"=>"V2-29d801e316e9ec4eb88b3b9abd8dbda490367af539d97d754420056dc5c1329a2c1aff7d4d54729ff622d96ff7c9910aa930f7b7ad27910d199c15029ffc71aa4a84142d75b60f4a34b71a8390a89d8c01a4dd385232e4e9c9204fb5934eda89",
  28. "expireIn"=> 2592000,
  29. "opBizCode"=> "AG5MALO18KG6I5DL8LVONRSRF5G",
  30. "opBizName"=> "武汉开源节流科技有限公司",
  31. "refreshToken"=> "ab8d15b4028b7bd6aca383d230b87450436d301a2996b6bb3151d668dd2d015d68d8393e66fb2a59aa10146c70dd30728b473358ec0d156dc0bc5cc5e574a109a5680ab49c393fa9d2693ef5519ff41a16115b81259b58c71a54d79e23f26381",
  32. "scope"=> "dingdan,generalreserve,merchantreceipt,shangpin"
  33. ];
  34. protected const shop_token1 = [
  35. "accessToken"=> "V2-9667b1ce4ffaabe453d4ce847888c788c9c61762df9230ab342caf33e2b4a735a384288379641f64bb2f4272c88d44db42b080ef237cb0c5e3ae49466d72f5c1b17e8a34991e131e91a24e9947f046027af6bbbbc24e0155f6cd4d738e19b5c0",
  36. "expireIn"=> 2592000,
  37. "opBizCode"=> "AH14KGRJ76O8PFH4GCO67F0CUKC",
  38. "opBizName"=> "众盾闪修 家电清洗 武汉",
  39. "refreshToken"=> "fd3da11174eed4c3d6b4d117f87ab7b62a72603627d2d597bed82dddb1036943b8e76e2959c0c4b3cf7b33ec4664bedbca3ef14dd070f662582a1b6695077577e2268c6a42ca519fda331c7e1cdbc0919af8052151ce9ae0a658d346307ca0c1",
  40. "scope"=> "merchantdata,poiqrcode,tuangou,ugc,yuding"
  41. ];
  42. protected const shop_token2 = [
  43. "accessToken"=> "V2-26f91ef8b515c59b97b9b4404e77dc2b2fc14b9715e3be7edb9f3f86178e193ec380e1ef5a9ab7a877120a94bcae4586707c51ab5e56cfeb4cd91d4fb2983babbbfd2fda0f77353eb21b105fd14299aea392a706589a422baec961b6cc255191",
  44. "expireIn"=> 2592000,
  45. "opBizCode"=> "AE7MKOJAV67338LIC3UD0K5TGIO",
  46. "opBizName"=> "众盾闪修 家电维修 武汉",
  47. "refreshToken"=> "bd57846c8817125f8ad7f4eb4ccad4af80c808f30c8b22e38476fc78c008b568ca8bcd8a027740023f2bcab5c0f6f062fb8a6e8f588cff53512a057c2e97a7b1789fb9fe9dc4b3fc2abf42dd753341c455e6eacb7a5e19dd4894bf1d93db9abf",
  48. "scope"=> "merchantdata,poiqrcode,tuangou,ugc,yuding"
  49. ];
  50. protected const developerId = 114657;
  51. protected const assessKey = '8471lgvnv0qcjpx6';
  52. /**
  53. * 处理订单
  54. * @param array $order
  55. * @return bool
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\DbException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. */
  60. public static function orderhandle(array $order)
  61. {
  62. $message = json_decode($order['message'], true);
  63. //查询用户是否存在
  64. $userName = $message['userName'];
  65. $mobile = $message['mobile'];
  66. $userAddress = json_decode($message['userAddress']);
  67. $user = User::where(['mobile' =>$mobile])->findOrEmpty();
  68. $product_message = json_decode($message['products'],true);
  69. if($user->isEmpty()){
  70. $user = LoginLogic::register([
  71. 'password'=>'123456',
  72. 'account'=>$userName,
  73. 'mobile'=>$mobile,
  74. 'channel'=>1,
  75. 'user_type'=>0
  76. ]);
  77. }
  78. //查询美团商品和平台商品的对应关系
  79. $productId = $message['productId'];
  80. $product = ThirdGoods::where(['third_type'=>1,'product_id'=>$productId])->findOrEmpty();
  81. //生成第三方订单信息
  82. $orderData = [
  83. 'orderId'=>$message['orderId'],
  84. 'uni_order_id'=>$product_message[0]['uni_order_id'],
  85. 'productId'=>$message['productId'],
  86. 'productName'=>$message['productName'],
  87. 'request_msg'=>json_encode($order,JSON_UNESCAPED_UNICODE),
  88. 'bookStatus'=>1,
  89. 'third_type'=>1,//美团
  90. ];
  91. //判断美团的预约订单是否生成
  92. if(!$product->isEmpty()){
  93. //查询美团预约订单是否生成
  94. $thirdOrder = ThirdOrders::where(['uni_order_id'=>$product_message[0]['uni_order_id']])->findOrEmpty();
  95. if(!$thirdOrder->isEmpty() and $thirdOrder['work_id'] != 0){
  96. //生成第三方订单信息
  97. $orderData['sync_status'] = 1;
  98. $orderData['work_id'] = $thirdOrder['work_id'];
  99. }
  100. }
  101. $thirdOrders = ThirdOrders::where('orderId',$message['orderId'])->findOrEmpty();
  102. //生成未同步预约订单信息
  103. if($thirdOrders->isEmpty()){
  104. $thirdOrders = ThirdOrders::create($orderData);
  105. }
  106. if(!$thirdOrders->isEmpty()){
  107. $orderData['work_id'] = $thirdOrders->work_id;
  108. }
  109. if(empty($orderData['work_id']) and !$product->isEmpty() and !empty($product['goods_id'])){
  110. $goods = Goods::findOrEmpty($product['goods_id']);
  111. $pattern = '/(?:省|市)([\w\s]+市)/u';
  112. Db::startTrans();
  113. try {
  114. if (preg_match($pattern, $userAddress->receiver_address, $matches)) {
  115. $city = $matches[1];
  116. }
  117. $area_city = PostageRegion::where(['level'=>2,'name'=>$city])->value('id');
  118. //生成服务工单
  119. $work_data = [
  120. 'work_sn' => generate_sn(ServiceWork::class, 'work_sn'),
  121. 'real_name' => $userName,
  122. 'mobile' => $mobile,
  123. 'address' => $userAddress->receiver_address,
  124. 'province' => 0,
  125. 'city' => $area_city??0,
  126. 'area_name' => $userAddress->receiver_address,
  127. 'title' => $goods->goods_name,
  128. 'category_type' => $goods['category_type'],
  129. 'goods_category_ids' => $goods['goods_category_ids'],
  130. 'goods_category_id' => $goods['goods_category_id'],
  131. 'base_service_fee' => $goods['base_service_fee'],
  132. 'service_fee' => $product['product_price'],
  133. 'work_pay_status'=>WorkEnum::IS_PAY_STATUS,
  134. 'appointment_time' => strtotime($message['begintime']),
  135. 'user_id'=>$user['id'],
  136. 'lon'=>!empty($userAddress->longitude)?$userAddress->longitude:0,
  137. 'lat'=>!empty($userAddress->latitude)?$userAddress->latitude:0,
  138. 'property_activity_id'=>0,
  139. 'user_equity_id'=>0,
  140. 'third_type'=>1,
  141. 'work_total'=>$product['product_price'],
  142. 'work_amount'=>$product['product_price']
  143. ];
  144. $service_area_id = ServiceArea::serviceAreaId(['lon' => $work_data['lon'], 'lat' => $work_data['lat']]);
  145. $work_data['service_area_id'] = $service_area_id;
  146. $service_work = ServiceWork::create($work_data);
  147. //生成服务订单
  148. $data = [
  149. 'work_id'=> $service_work['id'],
  150. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  151. 'order_type'=>0,//服务订单
  152. 'order_terminal' => 1,
  153. 'payment_type'=>$goods['goods_payment_type']==GoodsEnum::ISGOODS_PAYMENT_TYPE?0:1,
  154. 'user_id' => $user['id'],
  155. 'pay_status' => PayEnum::ISPAID,
  156. 'coupon_id'=>0,
  157. 'coupon_price'=>0,
  158. 'pay_way' => 4,
  159. 'order_total' => $product['product_price'],
  160. 'order_amount' => $product['product_price'],
  161. 'paid_amount'=> $product['product_price'],
  162. ];
  163. $order = RechargeOrder::create($data);
  164. //生成订单服务详情
  165. OrderGoods::create([
  166. 'sn' => $order['sn'],
  167. 'goods_id' => $goods['id'],
  168. 'category_type' => $goods['category_type'],
  169. 'goods_category_ids' => $goods['goods_category_ids'],
  170. 'goods_category_id' => $goods['goods_category_id'],
  171. 'goods_name' => $goods['goods_name'],
  172. 'goods_image' => $goods['goods_image'],
  173. 'goods_video' => $goods['goods_video'],
  174. 'goods_number' => $goods['goods_number'],
  175. 'good_unit' => $goods['good_unit'],
  176. 'goods_size' => $goods['goods_size'],
  177. 'goods_type' => $goods['goods_type'],
  178. 'goods_brand' => $goods['goods_brand'],
  179. 'install_guide' => $goods['install_guide'],
  180. 'goods_payment_type'=>$goods['goods_payment_type'],
  181. 'base_service_fee' => $goods['base_service_fee'],
  182. 'service_total' => $goods['service_total'],
  183. 'service_fee' => $product['product_price'],
  184. 'service_image' => $goods['service_image'],
  185. 'warranty_period'=>$goods['warranty_period'],
  186. 'fee_schedule' => $goods['fee_schedule'],
  187. 'goods_status' => $goods['goods_status'],
  188. ]);
  189. //判断是否是一口价预支付订单,支付成功后生成尾款订单
  190. if(!$goods->isEmpty() and $goods->goods_payment_type == 3 and bcsub($goods->base_service_fee,$goods->service_fee,2)>=0){
  191. //新增待支付尾款
  192. $order_weikuan_data = [
  193. 'order_type'=>$order['order_type'],
  194. 'sn'=>generate_sn(\app\common\model\orders\RechargeOrder::class, 'sn'),
  195. 'work_id'=>$order['work_id'],
  196. 'user_id'=>$order['user_id'],
  197. 'payment_type'=>2,
  198. 'order_total'=>bcsub($goods->base_service_fee,$product['product_price'],2),
  199. 'order_amount'=>bcsub($goods->base_service_fee,$product['product_price'],2),
  200. 'order_terminal'=>$order['order_terminal']
  201. ];
  202. \app\common\model\recharge\RechargeOrder::create($order_weikuan_data);
  203. }
  204. $thirdOrders->work_id = $service_work->id;
  205. $thirdOrders->save();
  206. self::bookresultcallback($order['opBizCode'],$message['orderId'],2);
  207. Db::commit();
  208. } catch (\Exception $e) {
  209. Db::rollback();
  210. self::setError($e->getMessage());
  211. return false;
  212. }
  213. }
  214. if(!empty($orderData['work_id']) and !$product->isEmpty() and !empty($product['goods_id'])) {
  215. //更改预约时间
  216. $serviceWorkInfo = ServiceWork::find($orderData['work_id']);
  217. if(!empty($serviceWorkInfo)){
  218. $appointment_time = $message['begintime'];
  219. ServiceWorkAppointmentLog::create([
  220. 'work_id'=>$serviceWorkInfo->id,
  221. 'last_appointment_time'=>strtotime($serviceWorkInfo->appointment_time),
  222. 'this_appointment_time'=>strtotime($appointment_time),
  223. ]);
  224. //修改预计完成时间
  225. if ($serviceWorkInfo->estimated_finish_time) {
  226. $serviceWorkInfo->estimated_finish_time = strtotime($appointment_time) + (strtotime($serviceWorkInfo->estimated_finish_time) - strtotime($serviceWorkInfo->appointment_time));
  227. }
  228. $serviceWorkInfo->appointment_time = strtotime($appointment_time);
  229. $serviceWorkInfo->save();
  230. }
  231. }
  232. return true;
  233. }
  234. //手动添加订单
  235. public static function submitOrders(array $message)
  236. {
  237. //查询用户是否存在
  238. $userName = $message['userName'];
  239. $mobile = $message['mobile'];
  240. $user = User::where(['mobile' =>$mobile])->findOrEmpty();
  241. if($user->isEmpty()){
  242. $user = LoginLogic::register([
  243. 'password'=>'123456',
  244. 'account'=>$userName,
  245. 'mobile'=>$mobile,
  246. 'channel'=>1,
  247. 'user_type'=>0,
  248. ]);
  249. }
  250. $goods = Goods::findOrEmpty($message['goods_id']);
  251. $pattern = '/(?:省|市)([\w\s]+市)/u';
  252. Db::startTrans();
  253. try {
  254. if (preg_match($pattern, $message['userAddress'], $matches)) {
  255. $city = $matches[1];
  256. }
  257. $area_city = PostageRegion::where(['level'=>2,'name'=>$city])->value('id');
  258. //生成服务工单
  259. $work_data = [
  260. 'work_sn' => generate_sn(ServiceWork::class, 'work_sn'),
  261. 'real_name' => $userName,
  262. 'mobile' => $mobile,
  263. 'address' => $message['userAddress'],
  264. 'province' => 0,
  265. 'city' => $area_city??0,
  266. 'area_name' => $area_city??'',
  267. 'title' => $goods->goods_name,
  268. 'category_type' => $goods['category_type'],
  269. 'goods_category_ids' => $goods['goods_category_ids'],
  270. 'goods_category_id' => $goods['goods_category_id'],
  271. 'base_service_fee' => $goods['base_service_fee'],
  272. 'service_fee' => $message['amount'],
  273. 'work_pay_status'=>WorkEnum::IS_PAY_STATUS,
  274. 'appointment_time' => strtotime($message['appointment_time']),
  275. 'user_id'=>$user['id'],
  276. 'lon'=>$message['lon'],
  277. 'lat'=>$message['lat'],
  278. 'property_activity_id'=>0,
  279. 'user_equity_id'=>0,
  280. 'third_type'=>1,
  281. 'work_total'=>$goods['base_service_fee'],
  282. 'work_amount'=>$goods['base_service_fee']
  283. ];
  284. $service_area_id = ServiceArea::serviceAreaId(['lon' => $work_data['lon'], 'lat' => $work_data['lat']]);
  285. $work_data['service_area_id'] = $service_area_id;
  286. $service_work = ServiceWork::create($work_data);
  287. //生成服务订单
  288. $data = [
  289. 'work_id'=> $service_work['id'],
  290. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  291. 'order_type'=>0,//服务订单
  292. 'order_terminal' => 1,
  293. 'payment_type'=>$goods['goods_payment_type']==GoodsEnum::ISGOODS_PAYMENT_TYPE?0:1,
  294. 'user_id' => $user['id'],
  295. 'pay_status' => PayEnum::ISPAID,
  296. 'coupon_id'=>0,
  297. 'coupon_price'=>0,
  298. 'pay_way' => 4,
  299. 'order_total' => $message['amount'],
  300. 'order_amount' => $message['amount'],
  301. 'paid_amount'=>$message['amount']
  302. ];
  303. $order = RechargeOrder::create($data);
  304. //生成订单服务详情
  305. OrderGoods::create([
  306. 'sn' => $order['sn'],
  307. 'goods_id' => $goods['id'],
  308. 'category_type' => $goods['category_type'],
  309. 'goods_category_ids' => $goods['goods_category_ids'],
  310. 'goods_category_id' => $goods['goods_category_id'],
  311. 'goods_name' => $goods['goods_name'],
  312. 'goods_image' => $goods['goods_image'],
  313. 'goods_video' => $goods['goods_video'],
  314. 'goods_number' => $goods['goods_number'],
  315. 'good_unit' => $goods['good_unit'],
  316. 'goods_size' => $goods['goods_size'],
  317. 'goods_type' => $goods['goods_type'],
  318. 'goods_brand' => $goods['goods_brand'],
  319. 'install_guide' => $goods['install_guide'],
  320. 'goods_payment_type'=>$goods['goods_payment_type'],
  321. 'base_service_fee' => $goods['base_service_fee'],
  322. 'service_total' => $goods['service_total'],
  323. 'service_fee' => $message['amount'],
  324. 'service_image' => $goods['service_image'],
  325. 'warranty_period'=>$goods['warranty_period'],
  326. 'fee_schedule' => $goods['fee_schedule'],
  327. 'goods_status' => $goods['goods_status'],
  328. ]);
  329. //判断是否是一口价预支付订单,支付成功后生成尾款订单
  330. if(!$goods->isEmpty() and $goods->goods_payment_type == 3 and bcsub($goods->base_service_fee,$goods->service_fee,2)>=0){
  331. //新增待支付尾款
  332. $order_weikuan_data = [
  333. 'order_type'=>$order['order_type'],
  334. 'sn'=>generate_sn(\app\common\model\orders\RechargeOrder::class, 'sn'),
  335. 'work_id'=>$order['work_id'],
  336. 'user_id'=>$order['user_id'],
  337. 'payment_type'=>2,
  338. 'order_total'=>bcsub($goods->base_service_fee,$message['amount'],2),
  339. 'order_amount'=>bcsub($goods->base_service_fee,$message['amount'],2),
  340. 'order_terminal'=>$order['order_terminal']
  341. ];
  342. \app\common\model\recharge\RechargeOrder::create($order_weikuan_data);
  343. }
  344. Db::commit();
  345. } catch (\Exception $e) {
  346. Db::rollback();
  347. self::setError($e->getMessage());
  348. return false;
  349. }
  350. return true;
  351. }
  352. public static function get_sign($sign_key, $data)
  353. {
  354. if ($data == null) {
  355. return null;
  356. }
  357. ksort($data);
  358. $result_str = "";
  359. foreach ($data as $key => $val) {
  360. if ($key != "sign" && $val != null && $val != "") {
  361. $result_str = $result_str . $key . $val;
  362. }
  363. }
  364. $result_str = $sign_key . $result_str;
  365. $ret = bin2hex(sha1($result_str, true));
  366. return $ret;
  367. }
  368. /**
  369. * 商家接单接口
  370. * @param $orderId
  371. * @param $bookStatus
  372. * @return string
  373. */
  374. public static function bookresultcallback($opBizCode,$orderId,$bookStatus=2)
  375. {
  376. //预订结果,2-预订成功,3-预订失败
  377. $url = 'https://api-open-cater.meituan.com/ddzh/yuding/bookresultcallback';
  378. $accessToken = $opBizCode == 'AE7MKOJAV67338LIC3UD0K5TGIO' ? self::shop_token2['accessToken'] : self::shop_token1['accessToken'];
  379. $data = [
  380. 'timestamp'=>time(),
  381. 'appAuthToken'=>$accessToken,
  382. 'charset'=>'utf-8',
  383. 'version'=>'2',
  384. 'developerId'=>self::developerId,
  385. 'businessId'=>58,
  386. 'biz'=>json_encode([
  387. 'orderId'=>$orderId,
  388. 'bookStatus'=>$bookStatus,
  389. "code"=>200,
  390. "type"=>2
  391. ],JSON_UNESCAPED_UNICODE)
  392. ];
  393. $sign_data = self::get_sign(self::assessKey, $data);
  394. $data['sign'] = $sign_data;
  395. return http_request($url,http_build_query($data));
  396. }
  397. /**
  398. * 取消预订
  399. * @param array
  400. * $order
  401. * @return bool
  402. */
  403. public static function cancelOrderHandle(array $order)
  404. {
  405. $message = json_decode($order['message'], true);
  406. Db::startTrans();
  407. try {
  408. $thirdOrders = ThirdOrders::where('orderId',$message['orderId'])->findOrEmpty();
  409. if(!$thirdOrders->isEmpty()){
  410. $thirdOrders->bookStatus = 3;
  411. $thirdOrders->save();
  412. $serviceWorkInfo = ServiceWork::find($thirdOrders->work_id);
  413. if(!empty($serviceWorkInfo)){
  414. $appointment_time = '2099-12-31 23:59:59';
  415. ServiceWorkAppointmentLog::create([
  416. 'work_id'=>$serviceWorkInfo->id,
  417. 'last_appointment_time'=>strtotime($serviceWorkInfo->appointment_time),
  418. 'this_appointment_time'=>strtotime($appointment_time),
  419. ]);
  420. //修改预计完成时间
  421. if ($serviceWorkInfo->estimated_finish_time) {
  422. $serviceWorkInfo->estimated_finish_time = strtotime($appointment_time) + (strtotime($serviceWorkInfo->estimated_finish_time) - strtotime($serviceWorkInfo->appointment_time));
  423. }
  424. $serviceWorkInfo->appointment_time = strtotime($appointment_time);
  425. $serviceWorkInfo->save();
  426. }
  427. }
  428. Db::commit();
  429. return true;
  430. } catch (\Exception $e) {
  431. Db::rollback();
  432. self::setError($e->getMessage());
  433. return false;
  434. }
  435. }
  436. /**
  437. * 美团改约通知
  438. * @param array $order
  439. * @return bool
  440. */
  441. public static function updateOrderHandle(array $order)
  442. {
  443. $message = json_decode($order['message'], true);
  444. Db::startTrans();
  445. try {
  446. $thirdOrders = ThirdOrders::where('orderId',$message['orderId'])->findOrEmpty();
  447. if(!$thirdOrders->isEmpty()){
  448. $thirdOrders->bookStatus = 2;
  449. $thirdOrders->save();
  450. $serviceWorkInfo = ServiceWork::find($thirdOrders->work_id);
  451. if(!empty($serviceWorkInfo)){
  452. $appointment_time = $message['reserveEndtime'];
  453. ServiceWorkAppointmentLog::create([
  454. 'work_id'=>$serviceWorkInfo->id,
  455. 'last_appointment_time'=>strtotime($serviceWorkInfo->appointment_time),
  456. 'this_appointment_time'=>strtotime($appointment_time),
  457. ]);
  458. //修改预计完成时间
  459. if ($serviceWorkInfo->estimated_finish_time) {
  460. $serviceWorkInfo->estimated_finish_time = strtotime($appointment_time) + (strtotime($serviceWorkInfo->estimated_finish_time) - strtotime($serviceWorkInfo->appointment_time));
  461. }
  462. $serviceWorkInfo->appointment_time = strtotime($appointment_time);
  463. $serviceWorkInfo->save();
  464. }
  465. }
  466. Db::commit();
  467. return true;
  468. } catch (\Exception $e) {
  469. Db::rollback();
  470. self::setError($e->getMessage());
  471. return false;
  472. }
  473. }
  474. /**
  475. * 获取美团商品信息
  476. * @param $offset
  477. * @return string
  478. */
  479. public static function queryshopdeal($offset=1)
  480. {
  481. $url = 'https://api-open-cater.meituan.com/ddzh/tuangou/deal/queryshopdeal';
  482. $data = [
  483. 'timestamp'=>time(),
  484. 'appAuthToken'=>self::shop_token2['accessToken'],
  485. 'charset'=>'utf-8',
  486. 'version'=>'2',
  487. 'developerId'=>self::developerId,
  488. 'businessId'=>58,
  489. 'biz'=>json_encode([
  490. 'offset'=>$offset,
  491. 'limit'=>100,
  492. "source"=>2,
  493. ],JSON_UNESCAPED_UNICODE)
  494. ];
  495. $sign_data = self::get_sign(self::assessKey, $data);
  496. $data['sign'] = $sign_data;
  497. return http_request($url,http_build_query($data));
  498. }
  499. /**
  500. * 获取美团商品信息
  501. * @param $offset
  502. * @return string
  503. */
  504. public static function queryshopdeal1($offset=1)
  505. {
  506. $url = 'https://api-open-cater.meituan.com/ddzh/tuangou/deal/queryshopdeal';
  507. $data = [
  508. 'timestamp'=>time(),
  509. 'appAuthToken'=>self::shop_token1['accessToken'],
  510. 'charset'=>'utf-8',
  511. 'version'=>'2',
  512. 'developerId'=>self::developerId,
  513. 'businessId'=>58,
  514. 'biz'=>json_encode([
  515. 'offset'=>$offset,
  516. 'limit'=>100,
  517. "source"=>2,
  518. ],JSON_UNESCAPED_UNICODE)
  519. ];
  520. $sign_data = self::get_sign(self::assessKey, $data);
  521. $data['sign'] = $sign_data;
  522. return http_request($url,http_build_query($data));
  523. }
  524. /**
  525. * 商家改约
  526. * @param $offset
  527. * @return string
  528. */
  529. public static function merchantmodify($data)
  530. {
  531. $url = 'https://api-open-cater.meituan.com/ddzh/yuding/lifereserve/merchantmodify';
  532. $opBizCode = !empty($data['request_msg'])?json_decode($data['request_msg'],true)['opBizCode']:'';
  533. $accessToken = $opBizCode == 'AE7MKOJAV67338LIC3UD0K5TGIO' ? self::shop_token2['accessToken'] : self::shop_token1['accessToken'];
  534. $data = [
  535. 'timestamp'=>time(),
  536. 'appAuthToken'=>$accessToken,
  537. 'charset'=>'utf-8',
  538. 'version'=>'2',
  539. 'developerId'=>self::developerId,
  540. 'businessId'=>58,
  541. 'biz'=>json_encode([
  542. 'reserveOrderId'=>$data['reserveOrderId'],
  543. 'reserveUserName'=>$data['reserveUserName'],
  544. "reservePhone"=>$data['reservePhone'],
  545. "reserveAddress"=>$data['reserveAddress'],
  546. "bookStartTime"=>$data['bookStartTime'],
  547. "bookEndTime"=>$data['bookEndTime'],
  548. ],JSON_UNESCAPED_UNICODE)
  549. ];
  550. $sign_data = self::get_sign(self::assessKey, $data);
  551. $data['sign'] = $sign_data;
  552. return http_request($url,http_build_query($data));
  553. }
  554. /**
  555. * 商家取消预定
  556. * @param $params
  557. * @return string|true
  558. */
  559. public static function merchantcancelorder($work_id)
  560. {
  561. $third_order = ThirdOrders::where('work_id',$work_id)->findOrEmpty();
  562. if(!$third_order->isEmpty() && !empty($third_order['request_msg'])){
  563. $third_order->bookStatus = 3;
  564. $third_order->save();
  565. $url = 'https://api-open-cater.meituan.com/ddzh/yuding/merchantcancelorder';
  566. $opBizCode = !empty($third_order['request_msg'])?json_decode($third_order['request_msg'],true)['opBizCode']:'';
  567. $accessToken = $opBizCode == 'AE7MKOJAV67338LIC3UD0K5TGIO' ? self::shop_token2['accessToken'] : self::shop_token1['accessToken'];
  568. $data = [
  569. 'timestamp'=>time(),
  570. 'appAuthToken'=>$accessToken,
  571. 'charset'=>'utf-8',
  572. 'version'=>'2',
  573. 'developerId'=>self::developerId,
  574. 'businessId'=>58,
  575. 'biz'=>json_encode([
  576. 'orderId'=>$third_order['orderId'],
  577. 'cancelReason'=>'取消预定',
  578. "type"=>2,
  579. ],JSON_UNESCAPED_UNICODE)
  580. ];
  581. $sign_data = self::get_sign(self::assessKey, $data);
  582. $data['sign'] = $sign_data;
  583. return http_request($url,http_build_query($data));
  584. }
  585. return true;
  586. }
  587. }