ZopOrderService.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\Area;
  4. use app\common\model\MobileOrder;
  5. use app\common\model\Produce;
  6. use app\common\model\ProduceGzdx;
  7. /**
  8. * 联通商城zop订单统一接入文档
  9. */
  10. class ZopOrderService extends ZopBaseService
  11. {
  12. const PUSH_STATE = [
  13. '1' => '激活',
  14. '2' => '退单(激活前)',
  15. '3' => '转套餐',
  16. '4' => '销户(激活后)',
  17. '6' => '首充数据同步',
  18. 'C1' => '开户完成',
  19. 'E0' => '发货',
  20. ];
  21. /**
  22. * 推送订单到联通商城
  23. *
  24. * @param integer $orderId
  25. * @return array
  26. */
  27. public static function push($orderId = 0)
  28. {
  29. // 获取订单信息
  30. $order = MobileOrder::where('id', $orderId)->with('produce')->find();
  31. if (empty($order)) {
  32. return self::error('订单不存在');
  33. }
  34. $produce = $order->produce ?? null;
  35. if (empty($produce)) {
  36. return self::error('商品不存在');
  37. }
  38. if ($order->is_cancel == 1) {
  39. return self::error('订单已取消');
  40. }
  41. // 根据商品类型, 调用不同的推送方法
  42. // $operator = $produce->operator ?? '';
  43. $produceType = $order->produce_type ?? '';
  44. $result = [];
  45. switch ($produceType) {
  46. case 'cucc':
  47. $result = self::cuccPush($order, $produce);
  48. break;
  49. case 'cmcc':
  50. break;
  51. case 'ctcc':
  52. break;
  53. case 'gz_ctcc':
  54. $result = self::gzCtccPush($order, $produce);
  55. default:
  56. $result = self::error('运营商类型错误');
  57. }
  58. return $result;
  59. }
  60. /**
  61. * 广州电信推送
  62. *
  63. * @param MobileOrder $order
  64. * @param ProduceGzdx $produce
  65. * @return void
  66. */
  67. public static function gzCtccPush(MobileOrder $order, ProduceGzdx $produce)
  68. {
  69. }
  70. /**
  71. * 联通推送
  72. *
  73. * @param MobileOrder $order
  74. * @param Produce $produce
  75. * @return void
  76. */
  77. public static function cuccPush(MobileOrder $order, Produce $produce)
  78. {
  79. // 1. 资源上传
  80. $goodsId = $produce->api_goods_id ?? 0;
  81. $channel = $produce->contact_code ?? '';
  82. $images = $produce->images ?? '';
  83. $resourceId = $produce->resource_id ?? 0;
  84. // 发展人编码
  85. $developingNo = $produce->developing_no ?? '';
  86. // 合约ID
  87. $contractId = $produce->contract_id ?? '';
  88. // if (empty($resourceId)) {
  89. if (empty($goodsId)) {
  90. return self::error('上游编码为空');
  91. }
  92. if (empty($channel)) {
  93. return self::error('触点编码为空');
  94. }
  95. if (empty($images)) {
  96. return self::error('图片为空');
  97. }
  98. // 如果图片是地址的话, 就转换成base64
  99. if (strpos($images, 'http') === 0) {
  100. $imagesBase = base64_encode(file_get_contents($images));
  101. // 获取图片 MIME 类型
  102. $sizeInfo = getimagesize($images);
  103. $mimeType = $sizeInfo['mime'];
  104. // 构建数据 URI
  105. $images = 'data:' . $mimeType . ';base64,' . $imagesBase;
  106. }
  107. $resourceParams = [
  108. 'goodsId' => $goodsId,
  109. 'channel' => $channel,
  110. 'resourceContents' => [
  111. [
  112. 'content' => $images,
  113. 'sort' => 0
  114. ]
  115. ],
  116. ];
  117. $resourceResult = self::resourceUpload($resourceParams, $order);
  118. if ($resourceResult['code'] != 0) {
  119. // 写入订单错误信息
  120. $order->failure_reason = $resourceResult['message'];
  121. $order->save();
  122. return $resourceResult;
  123. }
  124. // 获取资源ID
  125. $resourceId = $resourceResult['data']['resourceId'] ?? '';
  126. $produce->resource_id = $resourceId;
  127. $produce->save();
  128. // }
  129. // 2. 客户资料校验
  130. $cityData = $order->city ?? '';
  131. $cityData = explode(',', $cityData);
  132. if (count($cityData) < 2) {
  133. return self::error('城市信息不完整');
  134. }
  135. $province = $cityData[0] ?? 0;
  136. $city = $cityData[1] ?? 0;
  137. $district = $cityData[2] ?? 0;
  138. $provinceNumCode = Area::where('id', $province)->value('num_code');
  139. $cityNumCode = Area::where('id', $city)->value('num_code');
  140. $certName = $order->name ?? '';
  141. $certNum = $order->id_no ?? '';
  142. if (empty($provinceNumCode) || empty($cityNumCode) || empty($certName) || empty($certNum)) {
  143. return self::error('客户信息不完整');
  144. }
  145. $identityParams = [
  146. 'province' => $provinceNumCode,
  147. 'city' => $cityNumCode,
  148. 'certName' => $certName,
  149. 'certNum' => $certNum,
  150. ];
  151. $identityResult = self::identityCust($identityParams, $order);
  152. if ($identityResult['code'] != 0) {
  153. // 写入订单错误信息
  154. $order->failure_reason = $identityResult['message'];
  155. $order->save();
  156. return $identityResult;
  157. }
  158. // 获取uuid
  159. $uuid = $identityResult['data']['uuid'] ?? '';
  160. // 3.0 判断有没有手机号, 如果没有手机号, 则走自动选好接口
  161. $orderId = $order->order_no ?? '';
  162. $contactNum = $order->phone ?? '';
  163. $postProvinceCode = Area::where('id', $province)->value('post_code');
  164. $postCityCode = Area::where('id', $city)->value('post_code');
  165. $postDistrictCode = Area::where('id', $district)->value('post_code');
  166. $postAddr = $order->address ?? '';
  167. $createTime = $order->create_time ?? '';
  168. $updateTime = $order->update_time ?? '';
  169. $amount = $order->amount ?? 0;
  170. $orderTotalFee = bcmul($amount, 1000, 0);
  171. $pageUrl = $produce->link ?? '';
  172. // 判断产品是否使用用户收货地址区号
  173. $homeLocationType = $produce->home_location_type ?? 'address';
  174. $numProvinceCode = $produce->home_location_province ?? 0;
  175. $numCityCode = $produce->home_location_city ?? 0;
  176. $no = $order['no'];
  177. if ($homeLocationType == 'address') {
  178. // 自动选号-订单同步接口
  179. $autoOrderParams = [
  180. 'orderId' => $orderId,
  181. 'goodsId' => $goodsId,
  182. 'certName' => $certName,
  183. 'certNo' => $certNum,
  184. 'contactNum' => $contactNum,
  185. 'numProvinceCode' => $numProvinceCode,
  186. 'numCityCode' => $numCityCode,
  187. 'postProvinceCode' => $postProvinceCode,
  188. 'postCityCode' => $postCityCode,
  189. 'postDistrictCode' => $postDistrictCode,
  190. 'postAddr' => $postAddr,
  191. 'channel' => $channel,
  192. 'createTime' => $createTime,
  193. 'updateTime' => $updateTime,
  194. 'orderTotalFee' => $orderTotalFee,
  195. 'pageUrl' => $pageUrl,
  196. 'resourceId' => $resourceId,
  197. 'referrerCode' => $developingNo,
  198. ];
  199. $orderResult = self::autoNumSync($autoOrderParams, $order);
  200. if ($orderResult['code'] != 0) {
  201. // 写入订单错误信息
  202. $order->failure_reason = $orderResult['message'];
  203. $order->save();
  204. return $orderResult;
  205. }
  206. $no = $orderResult['data']['preNumber'] ?? '';
  207. $order->no = $no;
  208. $order->save();
  209. } else {
  210. // 3. 选号后置-意向单同步
  211. $preOrderParams = [
  212. 'orderId' => $orderId,
  213. 'goodsId' => $goodsId,
  214. 'certName' => $certName,
  215. 'certNo' => $certNum,
  216. 'contactNum' => $contactNum,
  217. 'postProvinceCode' => $postProvinceCode,
  218. 'postCityCode' => $postCityCode,
  219. 'postDistrictCode' => $postDistrictCode,
  220. 'postAddr' => $postAddr,
  221. 'channel' => $channel,
  222. 'createTime' => $createTime,
  223. 'updateTime' => $updateTime,
  224. 'orderTotalFee' => $orderTotalFee,
  225. 'pageUrl' => $pageUrl,
  226. 'resourceId' => $resourceId,
  227. 'referrerCode' => $developingNo,
  228. ];
  229. if (!empty($contractId)) {
  230. $preOrderParams['contractId'] = $contractId;
  231. }
  232. $preOrderResult = self::preOrdersync($preOrderParams, $order);
  233. if ($preOrderResult['code'] != 0) {
  234. // 写入订单错误信息
  235. $order->failure_reason = $preOrderResult['message'];
  236. $order->save();
  237. return $preOrderResult;
  238. }
  239. $token = $preOrderResult['data']['token'] ?? '';
  240. // 4. 选号服务
  241. // 判断如果用户没有手机号, 则调用选号服务, 如果有手机号, 则跳过选号服务
  242. if (empty($no)) {
  243. $numSelectType = $produce->num_select_type ?? 1;
  244. $numSelectParams = [
  245. 'goodsId' => $goodsId,
  246. 'provinceCode' => $numProvinceCode,
  247. 'cityCode' => $numCityCode,
  248. 'searchCategory' => $numSelectType,
  249. ];
  250. $numSelectResult = self::linkNumSelect($numSelectParams, $order);
  251. if ($numSelectResult['code']!= 0) {
  252. // 写入订单错误信息
  253. $order->failure_reason = $numSelectResult['message'];
  254. $order->save();
  255. return $numSelectResult;
  256. }
  257. $numArray = $numSelectResult['data'] ?? [];
  258. if (count($numArray) > 0) {
  259. // 随机获取一个号码
  260. $no = $numArray[array_rand($numArray)]?? '';
  261. }
  262. if (empty($no)) {
  263. // 写入订单错误信息
  264. $order->failure_reason = '选号服务: 获取号码为空';
  265. $order->save();
  266. return self::error('选号服务: 获取号码为空');
  267. }
  268. $order->no = $no;
  269. $order->save();
  270. }
  271. // 5. 选号后置-正式单同步(非提前预占版)
  272. $phoneNum = $order->no ?? '';
  273. $isOpenCF = 0;
  274. $orderParams = [
  275. 'goodsId' => $goodsId,
  276. 'provinceCode' => $numProvinceCode,
  277. 'cityCode' => $numCityCode,
  278. 'phoneNum' => $phoneNum,
  279. 'token' => $token,
  280. 'createTime' => $createTime,
  281. 'isOpenCF' => $isOpenCF,
  282. ];
  283. $orderResult = self::ordersync($orderParams, $order);
  284. if ($orderResult['code'] != 0) {
  285. // 写入订单错误信息
  286. $order->failure_reason = $orderResult['message'];
  287. $order->save();
  288. return $orderResult;
  289. }
  290. }
  291. $order->failure_reason = '操作成功';
  292. $order->is_push_zop = 1;
  293. $order->save();
  294. return $orderResult;
  295. }
  296. /**
  297. * 资源上传
  298. *
  299. * @param array $params [channel: 渠道, goodsId: 商品ID, resourceContents: [content: 资源内容, sort: 排序]]]
  300. * @return array
  301. */
  302. public static function resourceUpload($params = [], $order = null)
  303. {
  304. $url = '/link/king/resource/upload/v1';
  305. $data = array_only($params, [
  306. 'channel',
  307. 'goodsId',
  308. 'resourceContents'
  309. ]);
  310. $result = self::send($url, $data, $order);
  311. if (empty($result)) {
  312. return self::error('资源上传请求失败');
  313. }
  314. $resArr = json_decode($result, true);
  315. if ($resArr['rspCode'] != '0000') {
  316. return self::error('资源上传请求失败, 错误编码为: ' . $resArr['rspCode'] . '错误信息为: ' . $resArr['rspDesc']);
  317. }
  318. $body = $resArr['body'];
  319. return self::success($body);
  320. }
  321. /**
  322. * 客户资料校验
  323. *
  324. * @param array $params [province: 省份编码, city.地市编码, certName. 证件姓名, certNum. 证件编码]
  325. * @return array
  326. */
  327. public static function identityCust($params = [], $order = null)
  328. {
  329. $url = '/link/king/identity/cust/v2';
  330. $data = array_only($params, [
  331. 'province',
  332. 'city',
  333. 'certName',
  334. 'certNum'
  335. ]);
  336. $result = self::send($url, $data, $order);
  337. if (empty($result)) {
  338. return self::error('客户资料校验请求失败');
  339. }
  340. $resArr = json_decode($result, true);
  341. if ($resArr['aCode'] != '0000') {
  342. return self::error('客户资料校验请求失败, 错误编码为: ' . $resArr['aCode'] . '错误信息为: ' . $resArr['aDesc']);
  343. }
  344. if ($resArr['bCode'] != '0000') {
  345. return self::error('客户资料校验请求失败, 错误编码为: ' . $resArr['bCode'] . '错误信息为: ' . $resArr['bDesc']);
  346. }
  347. $uuid = $resArr['uuid'] ?? '';
  348. return self::success(['uuid' => $uuid]);
  349. }
  350. /**
  351. * 选号后置-意向单同步
  352. *
  353. * @param array $params [orderId: 订单ID, goodsId: 商品ID, certName: 证件姓名, certNo: 证件编码, contactNum: 联系电话, postProvinceCode: 省份编码, postCityCode: 地市编码, postDistrictCode: 区县编码, postAddr: 详细地址, channel: 渠道, createTime: 创建时间, updateTime: 更新时间, orderTotalFee: 订单总金额, pageUrl: 页面地址, resourceId: 资源ID]
  354. * @return array
  355. */
  356. public static function preOrdersync($params = [], $order = null)
  357. {
  358. $url = '/link/king/card/preOrder/preOrdersync';
  359. $data = array_only($params, [
  360. 'orderId',
  361. 'goodsId',
  362. 'certName',
  363. 'certNo',
  364. 'contactNum',
  365. 'postProvinceCode',
  366. 'postCityCode',
  367. 'postDistrictCode',
  368. 'postAddr',
  369. 'channel',
  370. 'createTime',
  371. 'updateTime',
  372. 'orderTotalFee',
  373. 'pageUrl',
  374. 'resourceId',
  375. 'referrerCode',
  376. ]);
  377. $data['launchPlatform'] = self::getRandLaunchPlatform();
  378. $result = self::send($url, $data, $order);
  379. if (empty($result)) {
  380. return self::error('意向单同步请求失败');
  381. }
  382. $resArr = json_decode($result, true);
  383. if ($resArr['rspCode'] != '0000') {
  384. return self::error('意向单同步请求失败, 错误编码为: ' . $resArr['rspCode'] . '错误信息为: ' . $resArr['rspDesc']);
  385. }
  386. $body = $resArr['body'] ?? '';
  387. if (is_string($body)) {
  388. $body = json_decode($body, true);
  389. }
  390. return self::success($body);
  391. }
  392. /**
  393. * 随机获取投放平台
  394. *
  395. * @return void
  396. */
  397. public static function getRandLaunchPlatform()
  398. {
  399. $data = [
  400. '抖音APP',
  401. '快手APP',
  402. '拼多多APP',
  403. '腾讯视频APP',
  404. '手淘APP',
  405. '百度APP',
  406. '美团APP',
  407. '拼团微信小程序',
  408. '生态合作',
  409. '广点通',
  410. '巨量引擎'
  411. ];
  412. $randKey = array_rand($data);
  413. $platform = $data[$randKey];
  414. return $platform;
  415. }
  416. /**
  417. * 选号服务
  418. *
  419. * @param array $params [goodsId: 商品ID, provinceCode: 省份编码, cityCode: 地市编码, searchCategory: 搜索类别: 1、普通选号 2、靓号选号 3、全部(普通、靓号都包括)]
  420. * @return array
  421. */
  422. public static function linkNumSelect($params = [], $order = null)
  423. {
  424. $url = '/link/num/select/v1';
  425. $data = array_only($params ,[
  426. 'goodsId',
  427. 'provinceCode',
  428. 'cityCode',
  429. 'searchCategory',
  430. ]);
  431. $data['qryType'] = '02';
  432. $result = self::send($url, $data, $order);
  433. if (empty($result)) {
  434. return self::error('选号服务请求失败');
  435. }
  436. $resArr = json_decode($result, true);
  437. if ($resArr['rspCode'] != 'M0') {
  438. return self::error('选号服务请求失败: ' . $resArr['rspDesc']);
  439. }
  440. $body = $resArr['body'] ?? '';
  441. $numArray = $body['numArray'] ?? [];
  442. $splitLen = $body['splitLen'] ?? 12;
  443. if (!empty($numArray)) {
  444. $numArray = array_column(array_chunk($numArray, $splitLen), 0);
  445. }
  446. return self::success($numArray);
  447. }
  448. /**
  449. * 选号后置-正式单同步(非提前预占版)
  450. *
  451. * @param array $params
  452. * @return array
  453. */
  454. public static function ordersync($params = [], $order = null)
  455. {
  456. $url = '/link/king/card/preOrder/ordersync/v2';
  457. $data = array_only($params, [
  458. 'goodsId',
  459. 'provinceCode',
  460. 'cityCode',
  461. 'phoneNum',
  462. 'token',
  463. 'createTime',
  464. 'isOpenCF'
  465. ]);
  466. $result = self::send($url, $data, $order);
  467. if (empty($result)) {
  468. return self::error('正式单同步请求失败');
  469. }
  470. $resArr = json_decode($result, true);
  471. if ($resArr['rspCode'] != '0000') {
  472. return self::error('正式单同步请求失败, 错误编码为: ' . $resArr['rspCode'] . '错误信息为: ' . $resArr['rspDesc']);
  473. }
  474. $body = $resArr['body'] ?? '';
  475. if (is_string($body)) {
  476. $body = json_decode($body, true);
  477. }
  478. return self::success($body);
  479. }
  480. /**
  481. * 查询省市区信息
  482. *
  483. * @param array $params
  484. * @return array
  485. */
  486. public static function postInfo($params = [], $order = null)
  487. {
  488. $url = '/link/king/postInfo/qry';
  489. $data = array_only($params, [
  490. 'provinceCode'
  491. ]);
  492. $result = self::send($url, $data, $order);
  493. if (empty($result)) {
  494. return self::error('查询省市区信息请求失败');
  495. }
  496. $resArr = json_decode($result, true);
  497. if ($resArr['rspCode'] != '0000') {
  498. return self::error('查询省市区信息请求失败, 错误编码为: ' . $resArr['rspCode'] . '错误信息为: ' . $resArr['rspDesc']);
  499. }
  500. $body = $resArr['body'] ?? '';
  501. if (is_string($body)) {
  502. $body = json_decode($body, true);
  503. }
  504. return self::success($body);
  505. }
  506. /**
  507. * 获取订单消息
  508. *
  509. * @return void
  510. */
  511. public static function orderMsg($type = 4)
  512. {
  513. // $messageChannelCode = config('site.message_channel_code');
  514. $messageChannelCode = 'mass';
  515. if (empty($messageChannelCode)) {
  516. common_log('获取订单消息请求失败: 消息渠道编码为空');
  517. return self::error('获取订单消息请求失败: 消息渠道编码为空');
  518. }
  519. $url = '/link/king/card/msg/get/v1';
  520. $data = [
  521. 'msgChannel' => $messageChannelCode,
  522. 'type' => $type,
  523. ];
  524. $result = self::send($url, $data);
  525. if (empty($result)) {
  526. common_log('获取订单消息请求失败');
  527. return self::error('获取订单消息请求失败');
  528. }
  529. $resArr = json_decode($result, true);
  530. if ($resArr['rspCode'] != '0000') {
  531. common_log('获取订单消息请求失败, 错误编码为: ' . $resArr['rspCode'] . '错误信息为: ' . $resArr['rspDesc']);
  532. return self::error('获取订单消息请求失败, 错误编码为: ' . $resArr['rspCode'] . '错误信息为: ' . $resArr['rspDesc']);
  533. }
  534. $body = $resArr['body'] ?? '';
  535. if (is_string($body)) {
  536. $body = json_decode($body, true);
  537. }
  538. $delMsgIds = [];
  539. $delMsgVal = [];
  540. foreach ($body as $val) {
  541. // 根据返回信息, 更新订单状态
  542. $orderNo = $val['order'] ?? '';
  543. // 订单变更类型:1:激活,2:退单(激活前),3:转套餐(要根据产品id判断是否为享有特权的套餐),4:销户(激活后),6:首充数据同步,C1:开户完成,E0:发货,SX:未支付超期,AX:未支付用户取消,SX和AX状态目前仅支持3.27接口同步订单
  544. $state = $val['state'] ?? '';
  545. $id = $val['id'] ?? '';
  546. $order = MobileOrder::where('order_no', $orderNo)->find();
  547. if (empty($order)) {
  548. $delMsgIds[] = $id;
  549. continue;
  550. }
  551. $order->state = $state;
  552. $order->state_name = self::PUSH_STATE[$state] ?? '';
  553. $order->save();
  554. if ($state == 1) {
  555. // 激活
  556. $order->produce_activation = 1;
  557. $order->save();
  558. } else if ($state == 6) {
  559. // 首充
  560. $amount = $val['lgtsId'] ?? 0;
  561. $order->produce_is_recharge = 1;
  562. $order->first_amount = $amount;
  563. $order->first_time = date('Y-m-d H:i:s');
  564. $order->save();
  565. } else if ($state == 'C1') {
  566. // 开户
  567. $order->produce_status = 1;
  568. $order->save();
  569. } else if ($state == 'E0') {
  570. // 发货
  571. $order->logistics_numbers = $val['trackingNumber'] ?? '';
  572. $order->save();
  573. }
  574. $delMsgIds[] = $id;
  575. $delMsgVal[] = $val;
  576. }
  577. $delMsgIds = implode(',', $delMsgIds);
  578. if (!empty($delMsgIds)) {
  579. common_log('删除订单消息ID: ' . $delMsgIds);
  580. common_log('删除消息内容: ' . json_encode($delMsgVal, JSON_UNESCAPED_UNICODE));
  581. self::delOrderMsg($delMsgIds, $type);
  582. }
  583. return self::success();
  584. }
  585. /**
  586. * 删除订单消息
  587. *
  588. * @return void
  589. */
  590. public static function delOrderMsg($msgId = '', $type = 4)
  591. {
  592. $url = '/link/king/card/msg/del/v1';
  593. $data = [
  594. 'msgId' => $msgId,
  595. 'type' => $type,
  596. ];
  597. $result = self::send($url, $data);
  598. if (empty($result)) {
  599. common_log('删除订单消息请求失败');
  600. return self::error('删除订单消息请求失败');
  601. }
  602. $resArr = json_decode($result, true);
  603. if ($resArr['rspCode'] != '0000') {
  604. common_log('删除订单消息请求失败, 错误编码为: ' . $resArr['rspCode'] . '错误信息为: ' . $resArr['rspDesc']);
  605. return self::error('删除订单消息请求失败, 错误编码为: ' . $resArr['rspCode'] . '错误信息为: ' . $resArr['rspDesc']);
  606. }
  607. $body = $resArr['body'] ?? '';
  608. if (is_string($body)) {
  609. $body = json_decode($body, true);
  610. }
  611. $delSuccessNum = $body['delSuccessNum'] ?? 0;
  612. common_log('删除成功数量: ' . $delSuccessNum . ', 删除成功ID: ' . $msgId);
  613. return self::success('删除成功数量: ' . $delSuccessNum);
  614. }
  615. /**
  616. * 自动选号-订单同步接口
  617. *
  618. * @param array $params [orderId: 订单ID, goodsId: 商品ID, certName: 证件姓名, certNo: 证件编码, contactNum: 联系电话, postProvinceCode: 省份编码, postCityCode: 地市编码, postDistrictCode: 区县编码, postAddr: 详细地址, channel: 渠道, createTime: 创建时间, updateTime: 更新时间, orderTotalFee: 订单总金额, pageUrl: 页面地址, resourceId: 资源ID]
  619. * @return array
  620. */
  621. public static function autoNumSync($params = [], $order = null)
  622. {
  623. $url = '/link/king/card/preOrder/autoNumSync';
  624. $data = array_only($params, [
  625. 'orderId',
  626. 'goodsId',
  627. 'certName',
  628. 'certNo',
  629. 'contactNum',
  630. 'numProvinceCode',
  631. 'numCityCode',
  632. 'postProvinceCode',
  633. 'postCityCode',
  634. 'postDistrictCode',
  635. 'postAddr',
  636. 'channel',
  637. 'createTime',
  638. 'updateTime',
  639. 'orderTotalFee',
  640. 'pageUrl',
  641. 'resourceId',
  642. 'referrerCode'
  643. ]);
  644. $data['launchPlatform'] = self::getRandLaunchPlatform();
  645. // 额外加
  646. $data['contractId'] = '91200266';
  647. $result = self::send($url, $data, $order);
  648. if (empty($result)) {
  649. return self::error('自动选号请求失败');
  650. }
  651. $resArr = json_decode($result, true);
  652. if ($resArr['rspCode'] != '0000') {
  653. return self::error('自动选号请求失败, 错误编码为: ' . $resArr['rspCode'] . '错误信息为: ' . $resArr['rspDesc']);
  654. }
  655. $body = $resArr['body'] ?? '';
  656. if (is_string($body)) {
  657. $body = json_decode($body, true);
  658. }
  659. return self::success($body);
  660. }
  661. }