ThirdOrderLogic.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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. return true;
  215. }
  216. //手动添加订单
  217. public static function submitOrders(array $message)
  218. {
  219. //查询用户是否存在
  220. $userName = $message['userName'];
  221. $mobile = $message['mobile'];
  222. $user = User::where(['mobile' =>$mobile])->findOrEmpty();
  223. if($user->isEmpty()){
  224. $user = LoginLogic::register([
  225. 'password'=>'123456',
  226. 'account'=>$userName,
  227. 'mobile'=>$mobile,
  228. 'channel'=>1,
  229. 'user_type'=>0,
  230. ]);
  231. }
  232. $goods = Goods::findOrEmpty($message['goods_id']);
  233. $pattern = '/(?:省|市)([\w\s]+市)/u';
  234. Db::startTrans();
  235. try {
  236. if (preg_match($pattern, $message['userAddress'], $matches)) {
  237. $city = $matches[1];
  238. }
  239. $area_city = PostageRegion::where(['level'=>2,'name'=>$city])->value('id');
  240. //生成服务工单
  241. $work_data = [
  242. 'work_sn' => generate_sn(ServiceWork::class, 'work_sn'),
  243. 'real_name' => $userName,
  244. 'mobile' => $mobile,
  245. 'address' => $message['userAddress'],
  246. 'province' => 0,
  247. 'city' => $area_city??0,
  248. 'area_name' => $area_city??'',
  249. 'title' => $goods->goods_name,
  250. 'category_type' => $goods['category_type'],
  251. 'goods_category_ids' => $goods['goods_category_ids'],
  252. 'goods_category_id' => $goods['goods_category_id'],
  253. 'base_service_fee' => $goods['base_service_fee'],
  254. 'service_fee' => $message['amount'],
  255. 'work_pay_status'=>WorkEnum::IS_PAY_STATUS,
  256. 'appointment_time' => strtotime($message['appointment_time']),
  257. 'user_id'=>$user['id'],
  258. 'lon'=>$message['lon'],
  259. 'lat'=>$message['lat'],
  260. 'property_activity_id'=>0,
  261. 'user_equity_id'=>0,
  262. 'third_type'=>1,
  263. 'work_total'=>$goods['base_service_fee'],
  264. 'work_amount'=>$goods['base_service_fee']
  265. ];
  266. $service_area_id = ServiceArea::serviceAreaId(['lon' => $work_data['lon'], 'lat' => $work_data['lat']]);
  267. $work_data['service_area_id'] = $service_area_id;
  268. $service_work = ServiceWork::create($work_data);
  269. //生成服务订单
  270. $data = [
  271. 'work_id'=> $service_work['id'],
  272. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  273. 'order_type'=>0,//服务订单
  274. 'order_terminal' => 1,
  275. 'payment_type'=>$goods['goods_payment_type']==GoodsEnum::ISGOODS_PAYMENT_TYPE?0:1,
  276. 'user_id' => $user['id'],
  277. 'pay_status' => PayEnum::ISPAID,
  278. 'coupon_id'=>0,
  279. 'coupon_price'=>0,
  280. 'pay_way' => 4,
  281. 'order_total' => $message['amount'],
  282. 'order_amount' => $message['amount'],
  283. 'paid_amount'=>$message['amount']
  284. ];
  285. $order = RechargeOrder::create($data);
  286. //生成订单服务详情
  287. OrderGoods::create([
  288. 'sn' => $order['sn'],
  289. 'goods_id' => $goods['id'],
  290. 'category_type' => $goods['category_type'],
  291. 'goods_category_ids' => $goods['goods_category_ids'],
  292. 'goods_category_id' => $goods['goods_category_id'],
  293. 'goods_name' => $goods['goods_name'],
  294. 'goods_image' => $goods['goods_image'],
  295. 'goods_video' => $goods['goods_video'],
  296. 'goods_number' => $goods['goods_number'],
  297. 'good_unit' => $goods['good_unit'],
  298. 'goods_size' => $goods['goods_size'],
  299. 'goods_type' => $goods['goods_type'],
  300. 'goods_brand' => $goods['goods_brand'],
  301. 'install_guide' => $goods['install_guide'],
  302. 'goods_payment_type'=>$goods['goods_payment_type'],
  303. 'base_service_fee' => $goods['base_service_fee'],
  304. 'service_total' => $goods['service_total'],
  305. 'service_fee' => $message['amount'],
  306. 'service_image' => $goods['service_image'],
  307. 'warranty_period'=>$goods['warranty_period'],
  308. 'fee_schedule' => $goods['fee_schedule'],
  309. 'goods_status' => $goods['goods_status'],
  310. ]);
  311. //判断是否是一口价预支付订单,支付成功后生成尾款订单
  312. if(!$goods->isEmpty() and $goods->goods_payment_type == 3 and bcsub($goods->base_service_fee,$goods->service_fee,2)>=0){
  313. //新增待支付尾款
  314. $order_weikuan_data = [
  315. 'order_type'=>$order['order_type'],
  316. 'sn'=>generate_sn(\app\common\model\orders\RechargeOrder::class, 'sn'),
  317. 'work_id'=>$order['work_id'],
  318. 'user_id'=>$order['user_id'],
  319. 'payment_type'=>2,
  320. 'order_total'=>bcsub($goods->base_service_fee,$message['amount'],2),
  321. 'order_amount'=>bcsub($goods->base_service_fee,$message['amount'],2),
  322. 'order_terminal'=>$order['order_terminal']
  323. ];
  324. \app\common\model\recharge\RechargeOrder::create($order_weikuan_data);
  325. }
  326. Db::commit();
  327. } catch (\Exception $e) {
  328. Db::rollback();
  329. self::setError($e->getMessage());
  330. return false;
  331. }
  332. return true;
  333. }
  334. public static function get_sign($sign_key, $data)
  335. {
  336. if ($data == null) {
  337. return null;
  338. }
  339. ksort($data);
  340. $result_str = "";
  341. foreach ($data as $key => $val) {
  342. if ($key != "sign" && $val != null && $val != "") {
  343. $result_str = $result_str . $key . $val;
  344. }
  345. }
  346. $result_str = $sign_key . $result_str;
  347. $ret = bin2hex(sha1($result_str, true));
  348. return $ret;
  349. }
  350. /**
  351. * 商家接单接口
  352. * @param $orderId
  353. * @param $bookStatus
  354. * @return string
  355. */
  356. public static function bookresultcallback($opBizCode,$orderId,$bookStatus=2)
  357. {
  358. //预订结果,2-预订成功,3-预订失败
  359. $url = 'https://api-open-cater.meituan.com/ddzh/yuding/bookresultcallback';
  360. $accessToken = $opBizCode == 'AE7MKOJAV67338LIC3UD0K5TGIO' ? self::shop_token2['accessToken'] : self::shop_token1['accessToken'];
  361. $data = [
  362. 'timestamp'=>time(),
  363. 'appAuthToken'=>$accessToken,
  364. 'charset'=>'utf-8',
  365. 'version'=>'2',
  366. 'developerId'=>self::developerId,
  367. 'businessId'=>58,
  368. 'biz'=>json_encode([
  369. 'orderId'=>$orderId,
  370. 'bookStatus'=>$bookStatus,
  371. "code"=>200,
  372. "type"=>2
  373. ],JSON_UNESCAPED_UNICODE)
  374. ];
  375. $sign_data = self::get_sign(self::assessKey, $data);
  376. $data['sign'] = $sign_data;
  377. return http_request($url,http_build_query($data));
  378. }
  379. /**
  380. * 取消预订
  381. * @param array
  382. * $order
  383. * @return bool
  384. */
  385. public static function cancelOrderHandle(array $order)
  386. {
  387. $message = json_decode($order['message'], true);
  388. Db::startTrans();
  389. try {
  390. $thirdOrders = ThirdOrders::where('orderId',$message['orderId'])->findOrEmpty();
  391. if(!$thirdOrders->isEmpty()){
  392. $thirdOrders->bookStatus = 3;
  393. $thirdOrders->save();
  394. $serviceWorkInfo = ServiceWork::find($thirdOrders->work_id);
  395. if(!empty($serviceWorkInfo)){
  396. $appointment_time = '2099-12-31 23:59:59';
  397. ServiceWorkAppointmentLog::create([
  398. 'work_id'=>$serviceWorkInfo->id,
  399. 'last_appointment_time'=>strtotime($serviceWorkInfo->appointment_time),
  400. 'this_appointment_time'=>strtotime($appointment_time),
  401. ]);
  402. //修改预计完成时间
  403. if ($serviceWorkInfo->estimated_finish_time) {
  404. $serviceWorkInfo->estimated_finish_time = strtotime($appointment_time) + (strtotime($serviceWorkInfo->estimated_finish_time) - strtotime($serviceWorkInfo->appointment_time));
  405. }
  406. $serviceWorkInfo->appointment_time = strtotime($appointment_time);
  407. $serviceWorkInfo->save();
  408. }
  409. }
  410. Db::commit();
  411. return true;
  412. } catch (\Exception $e) {
  413. Db::rollback();
  414. self::setError($e->getMessage());
  415. return false;
  416. }
  417. }
  418. /**
  419. * 美团改约通知
  420. * @param array $order
  421. * @return bool
  422. */
  423. public static function updateOrderHandle(array $order)
  424. {
  425. $message = json_decode($order['message'], true);
  426. Db::startTrans();
  427. try {
  428. $thirdOrders = ThirdOrders::where('orderId',$message['orderId'])->findOrEmpty();
  429. if(!$thirdOrders->isEmpty()){
  430. $thirdOrders->bookStatus = 2;
  431. $thirdOrders->save();
  432. $serviceWorkInfo = ServiceWork::find($thirdOrders->work_id);
  433. if(!empty($serviceWorkInfo)){
  434. $appointment_time = $message['reserveEndtime'];
  435. ServiceWorkAppointmentLog::create([
  436. 'work_id'=>$serviceWorkInfo->id,
  437. 'last_appointment_time'=>strtotime($serviceWorkInfo->appointment_time),
  438. 'this_appointment_time'=>strtotime($appointment_time),
  439. ]);
  440. //修改预计完成时间
  441. if ($serviceWorkInfo->estimated_finish_time) {
  442. $serviceWorkInfo->estimated_finish_time = strtotime($appointment_time) + (strtotime($serviceWorkInfo->estimated_finish_time) - strtotime($serviceWorkInfo->appointment_time));
  443. }
  444. $serviceWorkInfo->appointment_time = strtotime($appointment_time);
  445. $serviceWorkInfo->save();
  446. }
  447. }
  448. Db::commit();
  449. return true;
  450. } catch (\Exception $e) {
  451. Db::rollback();
  452. self::setError($e->getMessage());
  453. return false;
  454. }
  455. }
  456. /**
  457. * 获取美团商品信息
  458. * @param $offset
  459. * @return string
  460. */
  461. public static function queryshopdeal($offset=1)
  462. {
  463. $url = 'https://api-open-cater.meituan.com/ddzh/tuangou/deal/queryshopdeal';
  464. $data = [
  465. 'timestamp'=>time(),
  466. 'appAuthToken'=>self::shop_token2['accessToken'],
  467. 'charset'=>'utf-8',
  468. 'version'=>'2',
  469. 'developerId'=>self::developerId,
  470. 'businessId'=>58,
  471. 'biz'=>json_encode([
  472. 'offset'=>$offset,
  473. 'limit'=>100,
  474. "source"=>2,
  475. ],JSON_UNESCAPED_UNICODE)
  476. ];
  477. $sign_data = self::get_sign(self::assessKey, $data);
  478. $data['sign'] = $sign_data;
  479. return http_request($url,http_build_query($data));
  480. }
  481. /**
  482. * 获取美团商品信息
  483. * @param $offset
  484. * @return string
  485. */
  486. public static function queryshopdeal1($offset=1)
  487. {
  488. $url = 'https://api-open-cater.meituan.com/ddzh/tuangou/deal/queryshopdeal';
  489. $data = [
  490. 'timestamp'=>time(),
  491. 'appAuthToken'=>self::shop_token1['accessToken'],
  492. 'charset'=>'utf-8',
  493. 'version'=>'2',
  494. 'developerId'=>self::developerId,
  495. 'businessId'=>58,
  496. 'biz'=>json_encode([
  497. 'offset'=>$offset,
  498. 'limit'=>100,
  499. "source"=>2,
  500. ],JSON_UNESCAPED_UNICODE)
  501. ];
  502. $sign_data = self::get_sign(self::assessKey, $data);
  503. $data['sign'] = $sign_data;
  504. return http_request($url,http_build_query($data));
  505. }
  506. /**
  507. * 商家改约
  508. * @param $offset
  509. * @return string
  510. */
  511. public static function merchantmodify($data)
  512. {
  513. $url = 'https://api-open-cater.meituan.com/ddzh/yuding/lifereserve/merchantmodify';
  514. $opBizCode = !empty($data['request_msg'])?json_decode($data['request_msg'],true)['opBizCode']:'';
  515. $accessToken = $opBizCode == 'AE7MKOJAV67338LIC3UD0K5TGIO' ? self::shop_token2['accessToken'] : self::shop_token1['accessToken'];
  516. $data = [
  517. 'timestamp'=>time(),
  518. 'appAuthToken'=>$accessToken,
  519. 'charset'=>'utf-8',
  520. 'version'=>'2',
  521. 'developerId'=>self::developerId,
  522. 'businessId'=>58,
  523. 'biz'=>json_encode([
  524. 'reserveOrderId'=>$data['reserveOrderId'],
  525. 'reserveUserName'=>$data['reserveUserName'],
  526. "reservePhone"=>$data['reservePhone'],
  527. "reserveAddress"=>$data['reserveAddress'],
  528. "bookStartTime"=>$data['bookStartTime'],
  529. "bookEndTime"=>$data['bookEndTime'],
  530. ],JSON_UNESCAPED_UNICODE)
  531. ];
  532. $sign_data = self::get_sign(self::assessKey, $data);
  533. $data['sign'] = $sign_data;
  534. return http_request($url,http_build_query($data));
  535. }
  536. /**
  537. * 商家取消预定
  538. * @param $params
  539. * @return string|true
  540. */
  541. public static function merchantcancelorder($work_id)
  542. {
  543. $third_order = ThirdOrders::where('work_id',$work_id)->findOrEmpty();
  544. if(!$third_order->isEmpty() && !empty($third_order['request_msg'])){
  545. $third_order->bookStatus = 3;
  546. $third_order->save();
  547. $url = 'https://api-open-cater.meituan.com/ddzh/yuding/merchantcancelorder';
  548. $opBizCode = !empty($third_order['request_msg'])?json_decode($third_order['request_msg'],true)['opBizCode']:'';
  549. $accessToken = $opBizCode == 'AE7MKOJAV67338LIC3UD0K5TGIO' ? self::shop_token2['accessToken'] : self::shop_token1['accessToken'];
  550. $data = [
  551. 'timestamp'=>time(),
  552. 'appAuthToken'=>$accessToken,
  553. 'charset'=>'utf-8',
  554. 'version'=>'2',
  555. 'developerId'=>self::developerId,
  556. 'businessId'=>58,
  557. 'biz'=>json_encode([
  558. 'orderId'=>$third_order['orderId'],
  559. 'cancelReason'=>'取消预定',
  560. "type"=>2,
  561. ],JSON_UNESCAPED_UNICODE)
  562. ];
  563. $sign_data = self::get_sign(self::assessKey, $data);
  564. $data['sign'] = $sign_data;
  565. return http_request($url,http_build_query($data));
  566. }
  567. return true;
  568. }
  569. }