FengSu.php 15 KB

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