ZopOrderService.php 24 KB

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