FengSu.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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\FengsuSku;
  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. //抖音
  26. class FengSu extends Command
  27. {
  28. //抖音请求地址
  29. protected $url = 'https://fsdy2.fengsutb.com/amount/ship-list-new';
  30. //抖音请求头部
  31. protected $headers = [
  32. 'Host' => 'fsdy2.fengsutb.com',
  33. 'Accept' => 'application/json, text/plain, */*',
  34. 'Authorization' => 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxODYwNTQ1MTExNSIsImRhdGFfcGVybWlzc2lvbiI6InByb2R1Y3RDb3N0IiwibmlrZSI6IjE4NjA1NDUxMTE1IiwiY3JlYXRlZCI6MTc2NDEyNTQwMzQ0OSwiZHBJZCI6MTAwNjczLCJleHAiOjE3NjQ3MzAyMDMsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTAwNjczfQ.ihv6NRfD2hzU1NQoqttTaZ-mPxqAEXIUICM8MuxVx2tVLEPW9j-uPhHoFz4T3-lH07wTt2ORf1k_SPOQP4PuQg',
  35. 'Content-Type' => 'application/json',
  36. 'platform' => 'dy',
  37. ];
  38. // 指令配置
  39. protected function configure()
  40. {
  41. $this->setName('feng_su')->setDescription('the task command');
  42. }
  43. //根据shop_id
  44. protected function execute(Input $input, Output $output)
  45. {
  46. $output->writeln('开始同步订单');
  47. $resquet = $this->getOrderList('dy');
  48. if($resquet['code'] == 0){
  49. if($resquet['data']['total'] > 0){
  50. $list = $resquet['data']['list'];
  51. $this->insertOrder($list);
  52. //dump($resquet);
  53. }else{
  54. $output->writeln('没有数据');
  55. }
  56. }else{
  57. $output->writeln('接口错误: ' .$resquet['message']);
  58. }
  59. $output->writeln('ok');
  60. }
  61. public function getOrderList($platform = 'dy')
  62. {
  63. $client = new \GuzzleHttp\Client([
  64. 'verify' => false,
  65. // 或指定证书路径
  66. // 'verify' => '/path/to/cacert.pem'
  67. ]);
  68. $headers = [
  69. 'Accept' => ' application/json, text/plain, */*',
  70. 'Authorization' => 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxODYwNTQ1MTExNSIsImRhdGFfcGVybWlzc2lvbiI6InByb2R1Y3RDb3N0IiwibmlrZSI6IjE4NjA1NDUxMTE1IiwiY3JlYXRlZCI6MTc2NDEyNTQwMzQ0OSwiZHBJZCI6MTAwNjczLCJleHAiOjE3NjQ3MzAyMDMsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTAwNjczfQ.ihv6NRfD2hzU1NQoqttTaZ-mPxqAEXIUICM8MuxVx2tVLEPW9j-uPhHoFz4T3-lH07wTt2ORf1k_SPOQP4PuQg',
  71. 'Host' => ' fsdy2.fengsutb.com',
  72. 'platform' => $platform,
  73. 'Content-Type' => ' application/json'
  74. ];
  75. $body = '{
  76. "sort": "CONSIGN_TIME",
  77. "sortAsc": false,
  78. "current": 1,
  79. "size": 100,
  80. "tradeStatus": 2,
  81. "fromAccountId": [],
  82. "goodType": 3,
  83. "goodsFlag": 1
  84. }';
  85. $request = new Request('POST', 'https://fsdy2.fengsutb.com/amount/ship-list-new', $headers, $body);
  86. $res = $client->sendAsync($request)->wait();
  87. $json = [];
  88. if($res->getStatusCode() == 200) {
  89. $json = json_decode($res->getBody()->getContents(), true);
  90. }else{
  91. dump($res->getStatusCode(), '接口返回结果');
  92. }
  93. return $json;
  94. }
  95. public function insertOrder($order_list)
  96. {
  97. if(!(count($order_list) > 0)){
  98. return false;
  99. }
  100. $queue = [];
  101. $shopList = new ShopList();
  102. $fengsuSku = new FengsuSku();
  103. $productConfig = new ProductConfig();
  104. $shopDelivery = new ShopDelivery();
  105. $customerSpec = new CustomerSpec();
  106. foreach($order_list as $item) {
  107. dump($item['shopId'], '店铺id');
  108. $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
  109. $queue[] = [
  110. 'shop_id' => $item['shopId'],
  111. 'trade_from' => $item['tradeFrom'],
  112. 'province' => $item['receiverProvince'],
  113. 'city' => $item['receiverCity'],
  114. 'company_name' => $item['tradeOrderPrintVos'][0]['companyName'],
  115. 'waybill_no' => $item['waybillNo'],
  116. 'consign_time' => $item['consignTime'],
  117. 'goods_id' => $item['tradeOrderPrintVos'][0]['goodsId'],
  118. 'sku_id' => $item['tradeOrderPrintVos'][0]['skuId'],
  119. 'num' => $item['tradeOrderPrintVos'][0]['total'],
  120. 'goods_title' => $item['tradeOrderPrintVos'][0]['goodsTitle'],
  121. 'weigh' => $item['tradeOrderPrintVos'][0]['weight'],
  122. 'price' => bcdiv((string)$item['payment'], '100', 2),
  123. 'status' => $status,
  124. ];
  125. }
  126. // 保存到数据库
  127. (new FengsuShip())->saveAll($queue);
  128. // 更新最后执行时间
  129. CrontabLog::create(['type_id' => 2,'last_time' => date('Y-m-d H:i:s')]);
  130. }
  131. }
  132. //风速接口返回格式
  133. // {
  134. // "shopId": "DY117939700",
  135. // "sysNum": "3908161982177974",
  136. // "groupId": "g3908162034664709",
  137. // "tradeFrom": "dy",
  138. // "tid": "6948414820472788426",
  139. // "fromAccountId": 0,
  140. // "createTime": "2025-11-26 21:27:53",
  141. // "payTime": "2025-11-26 21:27:55",
  142. // "inserTime": "2025-11-27 15:11:27",
  143. // "inventoryPrintTime": null,
  144. // "consignTime": "2025-11-27 15:11:27",
  145. // "refunding": 0,
  146. // "buyerId": "1@#MhctHqbGY6MptrPvaPcNSU6JEPT1RwM+zhPxvrsCvBSVf2u9/qsla+xb9Fu81aUBMmCH",
  147. // "buyerNick": null,
  148. // "buyerMessage": "",
  149. // "sellerFlag": 0,
  150. // "localFlag": 0,
  151. // "sellerMemo": null,
  152. // "localMemo": null,
  153. // "offlineMemo": null,
  154. // "offlineFlag": null,
  155. // "receiverProvince": "黑龙江省",
  156. // "receiverCity": "哈尔滨市",
  157. // "receiverDistrict": "依兰县",
  158. // "receiverTown": "依兰镇",
  159. // "desensitizationName": "昕*",
  160. // "desensitizationPhone": null,
  161. // "desensitizationAddress": "*******",
  162. // "desensitizationMobile": "1**********",
  163. // "modifyAddr": 0,
  164. // "invoiceType": null,
  165. // "invoiceTitle": null,
  166. // "invoiceTaxId": null,
  167. // "promiseShipTime": "2025-12-01 21:27:56",
  168. // "tradeStatus": "WAIT_CONFIRM",
  169. // "payment": 9440,
  170. // "receiptAmount": 9440,
  171. // "postFee": 0,
  172. // "splitType": 1,
  173. // "packageNum": 1,
  174. // "dpAccountId": 100673,
  175. // "bizDpAccountId": 100673,
  176. // "uid": "117939700",
  177. // "bizShopId": "DY117939700",
  178. // "companyName": "中通快递",
  179. // "waybillNo": null,
  180. // "companyId": 3,
  181. // "templateId": 145375,
  182. // "printSize": 1,
  183. // "mergeHash": "6BC35CF08C74762098670BB71B38F77C387FB374",
  184. // "mergeHash2": "AC9CEFB7FD89A32A1AA235A9E09BD69FE838D08D",
  185. // "mergeable": 0,
  186. // "handDeliverFlag": 0,
  187. // "tradeAttr": "{\"promise_type\":1,\"recommend_logistics_list\":\"[]\"}",
  188. // "localAttr": null,
  189. // "senderAddressEntity": null,
  190. // "outChannel": null,
  191. // "tradeFlag": null,
  192. // "link": "",
  193. // "roleFlg": true,
  194. // "shopFlg": true,
  195. // "saleFlg": true,
  196. // "picUrlFlag": true,
  197. // "preSale": 1,
  198. // "preSaleTime": null,
  199. // "splitFailReason": null,
  200. // "businessTag": 0,
  201. // "locked": 0,
  202. // "tradeOrderPrintVos": [
  203. // {
  204. // "distTime": null,
  205. // "orderStatus": "WAIT_CONFIRM",
  206. // "goodsTitle": "田与薯云南圆圆果·榴莲蜜薯软糯蜜甜新鲜高原黄心番薯地瓜粗粮",
  207. // "goodsId": "3665081518029678296",
  208. // "skuProp": "{\"65\":\"小糖豆(50g-150g)\",\"66\":\"5斤(精品装(带箱5斤))\",\"67\":\"5天内发货\"}",
  209. // "companyName": "中通快递",
  210. // "waybillNo": "76767227765924",
  211. // "outerId": null,
  212. // "refundStatus": null,
  213. // "picUrl": "https://p3-aio.ecombdimg.com/obj/ecom-shop-material/jpeg_m_e379a8d857f16246745a757892497184_sx_320989_www1668-1668",
  214. // "total": 1,
  215. // "price": 3980,
  216. // "payment": 3780,
  217. // "receiptAmount": null,
  218. // "orderType": 0,
  219. // "consignTime": "2025-11-27 15:11:27",
  220. // "signTime": null,
  221. // "weight": 0,
  222. // "goodShortName": null,
  223. // "skuShortName": null,
  224. // "oid": "6948414820472788426",
  225. // "packageNum": 1,
  226. // "splitType": 1,
  227. // "companyId": 3,
  228. // "templateId": 145375,
  229. // "outerSkuId": "LFT-LLSPK-4.5-SC-CX",
  230. // "skuId": "3617103894193922",
  231. // "printSize": 1,
  232. // "printTime": "2025-11-27 15:11:22",
  233. // "roleType": 1,
  234. // "roleName": "田与薯官方旗舰店",
  235. // "lastFactoryId": 100673,
  236. // "inventoryPrintSize": 0,
  237. // "inventoryPrintTime": null,
  238. // "platCode": "ZJ",
  239. // "purchaseAttr": null,
  240. // "shelfPosition": "",
  241. // "pushTime": null,
  242. // "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\"}",
  243. // "freeze": 0,
  244. // "freezeReason": null,
  245. // "auditStatus": 2,
  246. // "payStatus": null,
  247. // "settleStatus": null,
  248. // "settleRefundStatus": null,
  249. // "settleAmount": null,
  250. // "templateType": "1",
  251. // "productSkuName": null,
  252. // "productSkuCode": null
  253. // }
  254. // ],
  255. // "tradePrintList": null,
  256. // "platCode": "ZJ",
  257. // "purchaseId": null,
  258. // "purchaseStatus": null,
  259. // "supplierName": null,
  260. // "supplierId": null,
  261. // "purchaseName": null,
  262. // "offerId": null,
  263. // "specId": null,
  264. // "tradeClassify": "NORMAL",
  265. // "payType": "NORMAL",
  266. // "expressType": "NORMAL",
  267. // "msgTradeAttr": null,
  268. // "logisticsNames": null,
  269. // "logisticsTag": 0,
  270. // "tradeSource": null,
  271. // "printBatch": null,
  272. // "printBatchSn": 0,
  273. // "assignDeliveryId": null,
  274. // "factoryId": 100673,
  275. // "prepareShipGroupId": null,
  276. // "prepareShipDeliverStatus": null,
  277. // "prepareShipErrorMsg": null,
  278. // "prepareShipStatus": 0,
  279. // "prepareShipCreateTime": null,
  280. // "prepareShipUpdateTime": null,
  281. // "waybillEntities": [
  282. // {
  283. // "id": 7671095,
  284. // "dpAccountId": 100673,
  285. // "relationId": 3909499998804122,
  286. // "deliveryId": 3,
  287. // "waybillNo": "76767227765924",
  288. // "createdTime": "2025-11-27 15:11:27",
  289. // "recycleFlag": 0
  290. // }
  291. // ],
  292. // "relationId": 3909499998804122,
  293. // "optType": 0,
  294. // "obsStatus": 0,
  295. // "obsTime": null,
  296. // "obsReason": null,
  297. // "printFailReason": null
  298. // },