ThirdOrderLogic.php 27 KB

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