| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- /**
- * ----------------------------------------------------------------------------
- * 行到水穷处,坐看云起时
- * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
- * ----------------------------------------------------------------------------
- * Author: 老成
- * email:85556713@qq.com
- */
- declare(strict_types=1);
- namespace app\admin\command;
- use app\common\model\FengsuShip;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use GuzzleHttp\Client;
- use app\common\model\CrontabLog;
- use app\common\model\FengsuSku;
- use app\common\model\ShopList;
- use app\common\model\ProductConfig;
- use app\common\model\ShopDelivery;
- use app\common\model\CustomerSpec;
- use app\admin\service\JuShuiTanService;
- use GuzzleHttp\Psr7\Request;
- use app\common\model\ImportList;
- //抖音
- class JuShuiTan extends Command
- {
- //抖音请求地址
- protected $url = 'https://innerapi.scm121.com/api/inner/supOrder/getErpNormalOrders';
- //抖音请求头部
- protected $headers = [
- //'Host' => 'fsdy2.fengsutb.com',
- 'Accept' => 'application/json, text/plain, */*',
- 'Authorization' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIyMTk0MzA5MSIsInJvbGVJZHMiOltdLCJ1c2VyX25hbWUiOiIxODE4MjY2OTkzNSIsImNvSWQiOiIxNDc5MjIyMiIsImV4cGlyYXRpb24iOjE3NjYyMTg0NDM1MzQsInVzZXIiOnsiY29JZCI6IjE0NzkyMjIyIiwiY29OYW1lIjoi5LqR5Y2X5LmQ55Wq55Sw5L6b5bqU6ZO-5pyJ6ZmQ5YWs5Y-4IiwibG9naW5OYW1lIjoiMTgxODI2Njk5MzUiLCJsb2dpbldheSI6IlVTRVJOQU1FIiwibmlja05hbWUiOiLmnY4iLCJyb2xlSWRzIjoiMTEsMTIsMTMsMTQsMTUsMTYsMTcsMTgsMjIsMjMsMjcsMjgsMjksMzAsMzEsMzIsMzMsMzQsMzUsMzYsMzksNDAsNDEsNTIsNTMsNTQsNjEsNjIsNjMsNjQsNjUsNjYsNjcsNzAsNzEsNzIsNzMsNzYsOTAsMTAxLDEwMiwxMDMsMTA0LDEwNSwxMDYsMTA3LDEwOCwxMDkiLCJ1aWQiOiIyMTk0MzA5MSJ9LCJhdXRob3JpdGllcyI6WyJKU1QtY2hhbm5lbCIsIm11bHRpTG9naW4iLCJKU1Qtc3VwcGxpZXIiXSwiY2xpZW50X2lkIjoicGMiLCJqdGkiOiIxYjNhZjA4OC04ZDhiLTRhNzMtYjcwNC1lYzhhY2QwNzU1ODUiLCJleHAiOjE3NjYyMTg0NDN9.fXIP-yUlJDIfd49QgxjTQXUlRka2gpw0NrfY7lB50sU',
- 'Content-Type' => 'application/json',
- // 'platform' => 'dy',
- ];
- // 打单平台 1:风速 2:聚水潭
- protected $type_id=2;
- // 指令配置
- protected function configure()
- {
- $this->setName('ju_shui_tan')->setDescription('the task command');
- }
- //根据shop_id
- protected function execute(Input $input, Output $output)
- {
- $output->writeln('开始同步聚水潭订单');
- $resquet = $this->getOrderList('dy');
- if($resquet['success']){
- if(count($resquet['data']) > 0){
- $list = $resquet['data'];
- // dump($list);
- // return;
- $this->insertOrder($list);
- //dump($resquet);
- }else{
- $output->writeln('没有数据');
- }
- }else{
- $output->writeln('接口错误: ' .$resquet['message']);
- }
- $output->writeln('ok');
- }
- public function getOrderList($platform = 'dy')
- {
- $client = new \GuzzleHttp\Client([
- 'verify' => false,
- // 或指定证书路径
- // 'verify' => '/path/to/cacert.pem'
- ]);
- $headers = [
- 'Accept' => ' application/json, text/plain, */*',
- 'Authorization' =>site_config('addonsd.ju_shui_tan_authorization_toke'),
- 'Content-Type' => ' application/json'
- ];
- $todayTime=date("Y-m-d");
-
- $startTime = strtotime($todayTime . ' 00:00:00');
- $startTime=date('Y-m-d H:i:s', $startTime);
- // $startTime='2025-01-01 08:59:21';
- $endTime = strtotime($todayTime . ' 23:59:59');
- $endTime=date('Y-m-d H:i:s', $endTime);
- $body = '{
- "startTime": "'.$startTime.'",
- "endTime": "'.$endTime.'",
- "dateQueryType": "DeliveryDate",
- "coId": "14792222",
- "uid": "21943091",
- "upSendFailed": false,
- "isExceptAddress": "Except",
- "pageNum": 1,
- "pageSize": 50,
- "searchType": 1,
- "orderStatus": [
- "Sent"
- ]
- }';
- // "orderFrom":"PINDUODUO"
- //"trackNo":"@SF3278427215674"
- $request = new Request('POST', 'https://innerapi.scm121.com/api/inner/supOrder/getErpNormalOrders', $headers, $body);
- $res = $client->sendAsync($request)->wait();
- $json = [];
- if($res->getStatusCode() == 200) {
- $json = json_decode($res->getBody()->getContents(), true);
- }else{
- dump($res->getStatusCode(), '接口返回结果');
- }
- return $json;
- }
- public function insertOrder($order_list)
- {
- if(!(count($order_list) > 0)){
- return false;
- }
- $queue = [];
- $shopList = new ShopList();
- $fengsuSku = new FengsuSku();
- $productConfig = new ProductConfig();
- $shopDelivery = new ShopDelivery();
- $customerSpec = new CustomerSpec();
-
- usort($order_list, function($a, $b) {
- // 将create_time转换为时间戳比较(支持字符串时间戳)
- $timeA = strtotime($a['deliveryDate']);
- $timeB = strtotime($b['deliveryDate']);
-
- // 降序排序(从新到旧)
- // return $timeB - $timeA;
-
- // 升序排序(从旧到新)可改为:
- return $timeA - $timeB;
- });
- foreach($order_list as $item) {
- // dump($item['shopId'], '店铺id');
- // 防止重复记录,订单号+快递单号
- $goods_id=$item['disInnerOrderGoodsViewList'][0]['shopIid'];
- $oid=$item['oid'];
- $waybill_no=ltrim($item['trackNo'], '@');
- $add_status = JuShuiTanService::prevent_duplicate_additions($oid,$waybill_no);
- if($add_status) continue;
- $status = JuShuiTanService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
- $queue[] = [
- 'type_id' => $this->type_id,
- 'shop_id' => $item['shopId'],
- 'order_id' => $oid,
- 'trade_from' => $item['orderFrom'],
- 'province' => $item['receiverState'],
- 'city' => $item['receiverCity'],
- 'company_name' => $item['expressCompany'],
- 'waybill_no' => $waybill_no,
- 'consign_time' => $item['deliveryDate'],
- 'goods_id' => $goods_id,
- 'sku_id' => $item['disInnerOrderGoodsViewList'][0]['shopSkuId'],
- 'num' => $item['disInnerOrderGoodsViewList'][0]['itemCount'],
- 'goods_title' => $item['disInnerOrderGoodsViewList'][0]['itemName'],
- 'goods_info' => $item['disInnerOrderGoodsViewList'][0]['properties'],
- 'weigh' => $item['weight'],
- 'price' => bcdiv((string)$item['disInnerOrderGoodsViewList'][0]['price'], '1', 2),
- 'status' => $status,
- ];
- }
- // 保存到数据库
- (new ImportList())->saveAll($queue);
- // 更新最后执行时间
- CrontabLog::create(['type_id' => 2,'last_time' => date('Y-m-d H:i:s')]);
- }
- }
|