ZopOrderService.php 25 KB

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