FengSu.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <?php
  2. /**
  3. * ----------------------------------------------------------------------------
  4. * 行到水穷处,坐看云起时
  5. * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
  6. * ----------------------------------------------------------------------------
  7. * Author: 老成
  8. * email:85556713@qq.com
  9. */
  10. declare(strict_types=1);
  11. namespace app\admin\command;
  12. use app\common\model\FengsuShip;
  13. use think\console\Command;
  14. use think\console\Input;
  15. use think\console\Output;
  16. use GuzzleHttp\Client;
  17. use app\common\model\CrontabLog;
  18. use app\common\model\ImportSku;
  19. use app\common\model\ShopList;
  20. use app\common\model\ProductConfig;
  21. use app\common\model\ShopDelivery;
  22. use app\common\model\CustomerSpec;
  23. use app\admin\service\FengsuService;
  24. use GuzzleHttp\Psr7\Request;
  25. use app\common\model\ImportList;
  26. use app\admin\service\JuShuiTanService;
  27. use think\facade\Cache;
  28. //抖音
  29. class FengSu extends Command
  30. {
  31. //抖音请求地址
  32. protected $url = 'https://fsdy2.fengsutb.com/amount/ship-list-new';
  33. //抖音请求头部
  34. protected $headers = [
  35. 'Host' => 'fsdy2.fengsutb.com',
  36. 'Accept' => 'application/json, text/plain, */*',
  37. 'Authorization' => 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxODYwNTQ1MTExNSIsImRhdGFfcGVybWlzc2lvbiI6InByb2R1Y3RDb3N0IiwibmlrZSI6IjE4NjA1NDUxMTE1IiwiY3JlYXRlZCI6MTc2NDEyNTQwMzQ0OSwiZHBJZCI6MTAwNjczLCJleHAiOjE3NjQ3MzAyMDMsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTAwNjczfQ.ihv6NRfD2hzU1NQoqttTaZ-mPxqAEXIUICM8MuxVx2tVLEPW9j-uPhHoFz4T3-lH07wTt2ORf1k_SPOQP4PuQg',
  38. 'Content-Type' => 'application/json',
  39. // 'platform' => 'dy',
  40. ];
  41. // 打单平台 1:风速 2:聚水潭
  42. protected $type_id = 1;
  43. // 指令配置
  44. protected function configure()
  45. {
  46. $this->setName('feng_su')->setDescription('the task command');
  47. }
  48. //根据shop_id
  49. protected function execute(Input $input, Output $output)
  50. {
  51. $output->writeln('开始同步订单');
  52. $resquet = $this->getOrderList('');
  53. if ($resquet['code'] == 0) {
  54. $fengsu=[];
  55. $fengsu=Cache::get('fengsu');
  56. if ($resquet['data']['total'] > 0) {
  57. $fengsu_pageNum=$fengsu['pageNum'];
  58. $fengsu_pageNum=$fengsu_pageNum+1;
  59. $fengsu=[
  60. 'startTime'=>$fengsu['startTime'],
  61. 'endTime'=>$fengsu['endTime'],
  62. 'pageNum'=>$fengsu_pageNum,
  63. 'next_time_space'=>$fengsu['next_time_space']
  64. ];
  65. Cache::set('fengsu',$fengsu);
  66. $list = $resquet['data']['list'];
  67. dump($list);
  68. return;
  69. $this->insertOrder($list);
  70. //dump($resquet);
  71. } else {
  72. $fengsu=[
  73. 'startTime'=>$fengsu['startTime']+$fengsu['next_time_space'],
  74. 'endTime'=>$fengsu['endTime']+$fengsu['next_time_space'],
  75. 'pageNum'=>1,
  76. 'next_time_space'=>$fengsu['next_time_space']
  77. ];
  78. Cache::set('fengsu',$fengsu);
  79. $output->writeln('没有数据');
  80. }
  81. } else {
  82. $output->writeln('接口错误: ' . $resquet['message']);
  83. }
  84. $output->writeln('ok');
  85. }
  86. public function getOrderList($platform = '')
  87. {
  88. $client = new \GuzzleHttp\Client([
  89. 'verify' => false,
  90. // 或指定证书路径
  91. // 'verify' => '/path/to/cacert.pem'
  92. ]);
  93. $headers = [
  94. 'Accept' => ' application/json, text/plain, */*',
  95. 'Authorization' => site_config("addonsd.authorization_token"),
  96. 'Host' => ' fsdy2.fengsutb.com',
  97. 'platform' => $platform,
  98. 'Content-Type' => ' application/json'
  99. ];
  100. //时间间隔
  101. $start_end_space_time=10*60;
  102. //下一次时间间隔
  103. $next_time_space=7*60;
  104. //将查询分为,"2026-01-05 00:00:00~2026-01-05 00:05:00",查询该区间的订单,但是该时间区间单独数量可能超过50条,为了性能又不能一次性查询太多,从而进行分页查询,
  105. //查询不到数据,就往下一个时间区间查询
  106. $todayTime = date("Y-m-d");
  107. $startTime_stamp = strtotime($todayTime . ' 00:00:00');
  108. // $startTime_stamp = strtotime($todayTime . ' 07:20:00');
  109. $endTime_stamp=$startTime_stamp+$start_end_space_time;
  110. $pageNum=1;
  111. $fengsu=[
  112. 'startTime'=>$startTime_stamp,
  113. 'endTime'=>$endTime_stamp,
  114. 'pageNum'=>$pageNum,
  115. 'next_time_space'=>$next_time_space
  116. ];
  117. $fengsu_cache_data=Cache::get('fengsu');
  118. if(empty($fengsu_cache_data)||$fengsu_cache_data==null){
  119. Cache::set('fengsu',$fengsu);
  120. }
  121. $fengsu=Cache::get('fengsu');
  122. $startTime = date('Y-m-d H:i:s', $fengsu['startTime']);
  123. $endTime = date('Y-m-d H:i:s', $fengsu['endTime']);
  124. $pageNum=(int)$fengsu['pageNum'];
  125. $body = [
  126. 'startTime' => $startTime,//时间区间
  127. 'endTime' => $endTime,
  128. 'sort' => 'CONSIGN_TIME',
  129. 'sortAsc' => false,
  130. 'current' => $pageNum,//页数
  131. 'size' => 50,//每页多少条
  132. 'tradeStatus' => 2,
  133. 'fromAccountId' => [],
  134. 'goodType' => 2,
  135. 'goodsFlag' => 2,
  136. 'waybillNos' => ['73589756512463']
  137. ];
  138. $body = json_encode($body);
  139. $request = new Request('POST', 'https://fsdy2.fengsutb.com/amount/ship-list-new', $headers, $body);
  140. $res = $client->sendAsync($request)->wait();
  141. $json = [];
  142. if ($res->getStatusCode() == 200) {
  143. $json = json_decode($res->getBody()->getContents(), true);
  144. } else {
  145. dump($res->getStatusCode(), '接口返回结果');
  146. }
  147. return $json;
  148. }
  149. public function insertOrder($order_list)
  150. {
  151. if (!(count($order_list) > 0)) {
  152. return false;
  153. }
  154. $queue = [];
  155. $shopList = new ShopList();
  156. $importSku = new ImportSku();
  157. $productConfig = new ProductConfig();
  158. $shopDelivery = new ShopDelivery();
  159. $customerSpec = new CustomerSpec();
  160. $shopDelivery_list = [];
  161. foreach ($order_list as $item) {
  162. $goods_id = $item['tradeOrderPrintVos'][0]['goodsId'];
  163. $oid = $item['tradeOrderPrintVos'][0]['oid'];
  164. $sku_id = $item['tradeOrderPrintVos'][0]['skuId'];
  165. $waybill_no = $item['waybillNo'];
  166. if (empty($waybill_no)) continue;
  167. $add_status = JuShuiTanService::prevent_duplicate_additions($sku_id, $waybill_no);
  168. if ($add_status) continue;
  169. // $status = FengsuService::getAdditionalPrice( $shopList, $importSku, $productConfig, $shopDelivery, $customerSpec, $item);
  170. $res = FengsuService::getAdditionalPrice($shopList, $importSku, $productConfig, $shopDelivery, $customerSpec, $item);
  171. $status = $res['status'];
  172. $shopDelivery_list[] = $res['shopDelivery'];
  173. $weight = $item['tradeOrderPrintVos'][0]['weight'];
  174. $weight = strval($weight);
  175. $weight = bcdiv($weight, '500', 2);
  176. $weight = (float)$weight;
  177. $price = $item['tradeOrderPrintVos'][0]['payment'];
  178. $price = strval($price);
  179. $price = bcdiv($price, '100', 2);
  180. $price = (float)$price;
  181. $getPackSpecsFee = JuShuiTanService::getPackSpecsFee($importSku, $item['shopId'], $item['tradeOrderPrintVos'][0]['skuId'], $item['receiverProvince']);
  182. $queue[] = [
  183. 'type_id' => $this->type_id,
  184. 'shop_id' => $item['shopId'],
  185. 'order_id' => $oid,
  186. 'trade_from' => $item['tradeFrom'],
  187. 'province' => $item['receiverProvince'],
  188. 'city' => $item['receiverCity'],
  189. 'company_name' => $item['companyName'],
  190. 'waybill_no' => $waybill_no,
  191. 'consign_time' => $item['consignTime'],
  192. 'goods_id' => $goods_id,
  193. 'sku_id' => $item['tradeOrderPrintVos'][0]['skuId'],
  194. 'num' => $item['tradeOrderPrintVos'][0]['total'],
  195. 'goods_title' => $item['tradeOrderPrintVos'][0]['goodsTitle'],
  196. 'goods_info' => $item['tradeOrderPrintVos'][0]['skuProp'],
  197. 'weight' => $weight,
  198. 'price' => $price,
  199. 'status' => $status,
  200. 'specs_name' => $getPackSpecsFee['data']['title'],
  201. 'pack_specs_id' => $getPackSpecsFee['data']['id'],
  202. 'labor_cost_money' => $getPackSpecsFee['data']['labor_cost_money'],
  203. 'one_surcharge_money' => $getPackSpecsFee['one_surcharge_money'],
  204. 'two_surcharge_money' => $getPackSpecsFee['two_surcharge_money'],
  205. 'order_status' => $item['tradeOrderPrintVos'][0]['orderStatus']
  206. ];
  207. }
  208. // 保存到数据库
  209. $shopDelivery->saveAll($shopDelivery_list);
  210. (new ImportList())->saveAll($queue);
  211. // 更新最后执行时间
  212. CrontabLog::create(['type_id' => 2, 'last_time' => date('Y-m-d H:i:s')]);
  213. }
  214. }
  215. //风速接口返回格式
  216. // {
  217. // "shopId": "DY117939700",
  218. // "sysNum": "3908161982177974",
  219. // "groupId": "g3908162034664709",
  220. // "tradeFrom": "dy",
  221. // "tid": "6948414820472788426",
  222. // "fromAccountId": 0,
  223. // "createTime": "2025-11-26 21:27:53",
  224. // "payTime": "2025-11-26 21:27:55",
  225. // "inserTime": "2025-11-27 15:11:27",
  226. // "inventoryPrintTime": null,
  227. // "consignTime": "2025-11-27 15:11:27",
  228. // "refunding": 0,
  229. // "buyerId": "1@#MhctHqbGY6MptrPvaPcNSU6JEPT1RwM+zhPxvrsCvBSVf2u9/qsla+xb9Fu81aUBMmCH",
  230. // "buyerNick": null,
  231. // "buyerMessage": "",
  232. // "sellerFlag": 0,
  233. // "localFlag": 0,
  234. // "sellerMemo": null,
  235. // "localMemo": null,
  236. // "offlineMemo": null,
  237. // "offlineFlag": null,
  238. // "receiverProvince": "黑龙江省",
  239. // "receiverCity": "哈尔滨市",
  240. // "receiverDistrict": "依兰县",
  241. // "receiverTown": "依兰镇",
  242. // "desensitizationName": "昕*",
  243. // "desensitizationPhone": null,
  244. // "desensitizationAddress": "*******",
  245. // "desensitizationMobile": "1**********",
  246. // "modifyAddr": 0,
  247. // "invoiceType": null,
  248. // "invoiceTitle": null,
  249. // "invoiceTaxId": null,
  250. // "promiseShipTime": "2025-12-01 21:27:56",
  251. // "tradeStatus": "WAIT_CONFIRM",
  252. // "payment": 9440,
  253. // "receiptAmount": 9440,
  254. // "postFee": 0,
  255. // "splitType": 1,
  256. // "packageNum": 1,
  257. // "dpAccountId": 100673,
  258. // "bizDpAccountId": 100673,
  259. // "uid": "117939700",
  260. // "bizShopId": "DY117939700",
  261. // "companyName": "中通快递",
  262. // "waybillNo": null,
  263. // "companyId": 3,
  264. // "templateId": 145375,
  265. // "printSize": 1,
  266. // "mergeHash": "6BC35CF08C74762098670BB71B38F77C387FB374",
  267. // "mergeHash2": "AC9CEFB7FD89A32A1AA235A9E09BD69FE838D08D",
  268. // "mergeable": 0,
  269. // "handDeliverFlag": 0,
  270. // "tradeAttr": "{\"promise_type\":1,\"recommend_logistics_list\":\"[]\"}",
  271. // "localAttr": null,
  272. // "senderAddressEntity": null,
  273. // "outChannel": null,
  274. // "tradeFlag": null,
  275. // "link": "",
  276. // "roleFlg": true,
  277. // "shopFlg": true,
  278. // "saleFlg": true,
  279. // "picUrlFlag": true,
  280. // "preSale": 1,
  281. // "preSaleTime": null,
  282. // "splitFailReason": null,
  283. // "businessTag": 0,
  284. // "locked": 0,
  285. // "tradeOrderPrintVos": [
  286. // {
  287. // "distTime": null,
  288. // "orderStatus": "WAIT_CONFIRM",
  289. // "goodsTitle": "田与薯云南圆圆果·榴莲蜜薯软糯蜜甜新鲜高原黄心番薯地瓜粗粮",
  290. // "goodsId": "3665081518029678296",
  291. // "skuProp": "{\"65\":\"小糖豆(50g-150g)\",\"66\":\"5斤(精品装(带箱5斤))\",\"67\":\"5天内发货\"}",
  292. // "companyName": "中通快递",
  293. // "waybillNo": "76767227765924",
  294. // "outerId": null,
  295. // "refundStatus": null,
  296. // "picUrl": "https://p3-aio.ecombdimg.com/obj/ecom-shop-material/jpeg_m_e379a8d857f16246745a757892497184_sx_320989_www1668-1668",
  297. // "total": 1,
  298. // "price": 3980,
  299. // "payment": 3780,
  300. // "receiptAmount": null,
  301. // "orderType": 0,
  302. // "consignTime": "2025-11-27 15:11:27",
  303. // "signTime": null,
  304. // "weight": 0,
  305. // "goodShortName": null,
  306. // "skuShortName": null,
  307. // "oid": "6948414820472788426",
  308. // "packageNum": 1,
  309. // "splitType": 1,
  310. // "companyId": 3,
  311. // "templateId": 145375,
  312. // "outerSkuId": "LFT-LLSPK-4.5-SC-CX",
  313. // "skuId": "3617103894193922",
  314. // "printSize": 1,
  315. // "printTime": "2025-11-27 15:11:22",
  316. // "roleType": 1,
  317. // "roleName": "田与薯官方旗舰店",
  318. // "lastFactoryId": 100673,
  319. // "inventoryPrintSize": 0,
  320. // "inventoryPrintTime": null,
  321. // "platCode": "ZJ",
  322. // "purchaseAttr": null,
  323. // "shelfPosition": "",
  324. // "pushTime": null,
  325. // "orderAttr": "{\"author_name\":\"田与薯官方旗舰店\",\"order_goods_type\":0,\"order_biz\":2,\"pre_sale_label\":\"全款预售\",\"compensate_for_rotten_platform_guarantee\":\"坏了包退官方保障\",\"quick_refund_label\":\"极速退\",\"unsupport_7days_refund\":\"不支持7天\",\"c_biz_self_sell\":\"小店自卖\",\"compass_source_not_ad_mark\":\"非广告\",\"compass_source_content_type_live\":\"直播\",\"afterSaleType\":\"refund\",\"source_platform\":\"\",\"period_purchase_info\":{},\"pack_id\":\"147242304405974025\"}",
  326. // "freeze": 0,
  327. // "freezeReason": null,
  328. // "auditStatus": 2,
  329. // "payStatus": null,
  330. // "settleStatus": null,
  331. // "settleRefundStatus": null,
  332. // "settleAmount": null,
  333. // "templateType": "1",
  334. // "productSkuName": null,
  335. // "productSkuCode": null
  336. // }
  337. // ],
  338. // "tradePrintList": null,
  339. // "platCode": "ZJ",
  340. // "purchaseId": null,
  341. // "purchaseStatus": null,
  342. // "supplierName": null,
  343. // "supplierId": null,
  344. // "purchaseName": null,
  345. // "offerId": null,
  346. // "specId": null,
  347. // "tradeClassify": "NORMAL",
  348. // "payType": "NORMAL",
  349. // "expressType": "NORMAL",
  350. // "msgTradeAttr": null,
  351. // "logisticsNames": null,
  352. // "logisticsTag": 0,
  353. // "tradeSource": null,
  354. // "printBatch": null,
  355. // "printBatchSn": 0,
  356. // "assignDeliveryId": null,
  357. // "factoryId": 100673,
  358. // "prepareShipGroupId": null,
  359. // "prepareShipDeliverStatus": null,
  360. // "prepareShipErrorMsg": null,
  361. // "prepareShipStatus": 0,
  362. // "prepareShipCreateTime": null,
  363. // "prepareShipUpdateTime": null,
  364. // "waybillEntities": [
  365. // {
  366. // "id": 7671095,
  367. // "dpAccountId": 100673,
  368. // "relationId": 3909499998804122,
  369. // "deliveryId": 3,
  370. // "waybillNo": "76767227765924",
  371. // "createdTime": "2025-11-27 15:11:27",
  372. // "recycleFlag": 0
  373. // }
  374. // ],
  375. // "relationId": 3909499998804122,
  376. // "optType": 0,
  377. // "obsStatus": 0,
  378. // "obsTime": null,
  379. // "obsReason": null,
  380. // "printFailReason": null
  381. // },