zory 3 napja
szülő
commit
96a7974cac

+ 8 - 1
README.md

@@ -11,4 +11,11 @@ use Webman\Route;
 Route::options('[{path:.+}]', function (){
     return response('',204);
 });
-```
+```
+
+### 合并
+
+````
+git fetch origin
+git reset --hard origin/master
+````

+ 1 - 0
app/extra/service/saas/OrderService.php

@@ -66,6 +66,7 @@ class OrderService extends Service
         !empty($param['store']) && $filter[] = ["store_id", '=', $param['store']];
         !empty($param['open_id']) && $filter[] = ["open_id", '=', $param['open_id']];
         !empty($param['statusLt']) && $filter[] = ["status", '=', ($param['statusLt']-1)];
+        !empty($param['auto']) && $filter[] = ["auto", '=', ($param['auto']-1)];
         !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
         !empty($param['ex_status']) && $filter[] = ["express_status", '=', ($param['ex_status']-1)];
         !empty($param['orderid']) && $filter[] = ["order_id", 'like', "%{$param['orderid']}%"];

+ 214 - 0
app/extra/tools/SfExpress.php

@@ -0,0 +1,214 @@
+<?php
+
+namespace app\extra\tools;
+
+use support\think\Cache;
+use yzh52521\EasyHttp\Http;
+
+class SfExpress
+{
+
+    /**
+     * 接口地址
+     * @var string
+     */
+    protected string $gateway = "https://sfapi-sbox.sf-express.com/std/service";
+
+    protected array $config = [];
+
+    /**
+     * 设置配置权限
+     * @param array $data
+     * @return $this
+     */
+    public function config(array $data = [])
+    {
+        $this->config = $data;
+        if ($data['version'] == "test")
+        {
+            $this->gateway = "https://sfapi-sbox.sf-express.com/std/service";
+        } else {
+            $this->gateway = "https://bspgw.sf-express.com/std/service";
+        }
+        return $this;
+    }
+
+    /**
+     * 下单
+     * @param array $sendData 发货信息
+     * @param array $endData 收件人信息
+     * @return array
+     */
+    public function createOrder(array $sendData = [],array $endData = [],string $orderId = "",int $expressType = 1): array
+    {
+        $param = [
+            "partnerID"     => $this->config['appid'],
+            "requestID"     => strtoupper(CodeExtend::random(12,3)),
+            "serviceCode"   => "EXP_RECE_CREATE_ORDER",
+            "timestamp"     => time(),
+            "accessToken"   => $this->getAccessToken(),
+            "msgData"       => json_encode([
+                "language"  => "zh-CN",
+                "orderId"   => $orderId,
+                "monthlyCard"   => intval($this->config['account']), // 月结账号
+                "payMethod"     => 1,
+                "expressTypeId" => intval($expressType),
+                "isReturnRoutelabel"=> 1,
+                "cargoDetails"  => [
+                    [
+                        "name"      => $sendData['express_name'],
+                        "unit"      => $sendData['express_unit'],
+                        "currency"  => "CNY",
+                        "weight"    => 1
+                    ]
+                ],
+                "contactInfoList"   => [
+                    [
+                        "country"   => "CN",
+                        "mobile"   => $sendData['express_mobile'],
+                        "contact"   => $sendData['express_contact'],
+                        "contactType"   => 1,
+                        "address"   => $sendData['express_address'],
+                    ],
+                    [
+                        "country"   => "CN",
+                        "mobile"   => $endData['mobile'],
+                        "contact"   => $endData['username'],
+                        "contactType"   => 2,
+                        "address"   => $endData['address'],
+                    ]
+                ]
+            ])
+        ];
+        print_r($this->config);
+        print_r($param);
+        echo getDateFull()."===uri==={$this->gateway}\n";
+        $resp = Http::post($this->gateway,$param)->array();
+        print_r($resp);
+        if ($resp['apiResultCode'] == "A1000") {
+            return json_decode($resp['apiResultData'],true);
+        }
+        return [];
+    }
+
+    /**
+     * 取消订单
+     */
+    public function cancelOrder(array $data = [])
+    {
+        $param = [
+            "partnerID"     => $this->config['appid'],
+            "requestID"     => strtoupper(CodeExtend::random(12,3)),
+            "serviceCode"   => "EXP_RECE_UPDATE_ORDER",
+            "timestamp"     => time(),
+            "accessToken"   => $this->getAccessToken(),
+            "msgData"       => json_encode([
+                "dealType"  => 2,
+                "orderId"   => $data['orderId'],
+                "waybillNoInfoList" => [
+                    [
+                        "waybillNo"     => $data['number'],
+                        "waybillType"   => 1
+                    ]
+                ]
+            ])
+        ];
+        $resp = Http::post($this->gateway,$param)->array();
+        if ($resp['apiResultCode'] == "A1000") {
+            return json_decode($resp['apiResultData'],true);
+        }
+        return [];
+    }
+
+    /**
+     * 云打印面单打印2.0接口-面单类API
+     */
+    public function orderExpress2Pdf(array $data = [])
+    {
+        $param = [
+            "partnerID"     => $this->config['appid'],
+            "requestID"     => strtoupper(CodeExtend::random(12,3)),
+            "serviceCode"   => "COM_RECE_CLOUD_PRINT_WAYBILLS",
+            "timestamp"     => time(),
+            "accessToken"   => $this->getAccessToken(),
+            "msgData"       => json_encode([
+                "templateCode"  => "fm_76130_standard_ZSWHCLLWAGK7",
+                "fileType"      => "pdf",
+                "sync"          => true,
+                "documents"   => [
+                    [
+                        "masterWaybillNo" => $data['number']
+                    ]
+                ],
+                "version"   => "1.0",
+            ])
+        ];
+        $resp = Http::post($this->gateway,$param)->array();
+        if ($resp['apiResultCode'] == "A1000") {
+            return $resp['apiResultData'];
+        }
+        return [];
+    }
+
+    /**
+     * 获取运费
+     * @param string $orderId
+     * @return array|mixed
+     */
+    public function getOrderFee(string $orderId = "")
+    {
+        $param = [
+            "partnerID"     => $this->config['appid'],
+            "requestID"     => strtoupper(CodeExtend::random(12,3)),
+            "serviceCode"   => "EXP_RECE_QUERY_SFWAYBILL",
+            "timestamp"     => time(),
+            "accessToken"   => $this->getAccessToken(),
+            "msgData"       => json_encode([
+                "trackingType"  => 1,
+                "trackingNum"   => "SF7444497015623"
+            ])
+        ];
+        $resp = Http::post($this->gateway,$param)->array();
+        if ($resp['apiResultCode'] == "A1000") {
+            return json_decode($resp['apiResultData'],true);
+        }
+        return [];
+    }
+
+
+    /**
+     * 获取AccessToken
+     * @return string
+     */
+    public function getAccessToken(): string
+    {
+        try {
+            $sfToken = Cache::get($this->config['appid']."-sf-token");
+            if (!empty($sfToken)) return $sfToken;
+            $param = [
+                "partnerID" => $this->config['appid'],
+                "secret"    => $this->config['secret'],
+                "grantType" => "password"
+            ];
+            if ($this->config['version'] == "test") {
+                $gateway = "https://sfapi-sbox.sf-express.com/";
+            } else {
+                $gateway = "https://sfapi.sf-express.com/";
+            }
+            print_r($this->config);
+            print_r($param);
+            echo getDateFull()."===uri==={$gateway}\n";
+
+            $resp = Http::post($gateway."oauth2/accessToken",$param)->array();
+            print_r($resp);
+            if ($resp['apiResultCode'] == "A1000") {
+                Cache::set($this->config['appid']."-sf-token",$resp['accessToken'],$resp['expiresIn']);
+                return $resp['accessToken'];
+            }
+            return "";
+        } catch (\Throwable $throwable) {
+            return "";
+        }
+    }
+
+}

+ 31 - 0
app/queue/redis/AutoExpress.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace app\queue\redis;
+
+use Webman\RedisQueue\Consumer;
+
+/**
+ * 自动呼叫快递
+ */
+class AutoExpress implements Consumer
+{
+
+
+    public $queue = "auto-express";
+
+    public $connection = "default";
+
+
+    /**
+     * @param $data
+     * @return bool
+     */
+    public function consume($data): bool
+    {
+        try {
+
+        } catch (\Throwable $throwable) {
+            return true;
+        }
+    }
+}

+ 32 - 0
app/queue/redis/AutoPrint.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace app\queue\redis;
+
+use Webman\RedisQueue\Consumer;
+
+/**
+ * 打印面单
+ */
+class AutoPrint implements Consumer
+{
+
+
+    public $queue = "auto-print";
+
+    public $connection = "default";
+
+
+    /**
+     * @param $data
+     * @return bool
+     */
+    public function consume($data): bool
+    {
+        try {
+
+        } catch (\Throwable $throwable) {
+            return true;
+        }
+    }
+
+}