Browse Source

fix:订单发货

super-yimizi 1 month ago
parent
commit
71f1d3bb84

+ 1 - 1
application/admin/lang/zh-cn/content/article/category.php

@@ -2,7 +2,7 @@
 
 return [
     'Category list' => '分类列表',
-    'Id'          => 'ID',
+    'Id'          => '序号',
     'Parent_id'   => '父级',
     'Title'       => '分类标题',
     'Brief_intr'  => '分类简介',

+ 1 - 1
application/admin/lang/zh-cn/content/article/index.php

@@ -1,7 +1,7 @@
 <?php
 
 return [
-    'Id'             => '文章管理ID',
+    'Id'             => '序号',
     'Category_id'    => '分类ID',
     'Title'          => '文章标题',
     'Author'         => '文章作者',

+ 138 - 64
application/api/controller/inspection/Order.php

@@ -3,11 +3,17 @@
 namespace app\api\controller\inspection;
 
 use app\api\controller\inspection\Base;
+use app\common\Enum\PayEnum;
 use app\common\Service\OrderService;
 use app\common\Enum\OrderEnum;
 use app\common\Service\OrderActionService;
 use app\common\Enum\OrderActionEnum;
+use app\common\Enum\OrderGoodsEnum;
+use app\common\model\OrderGoods;
 use app\common\Service\Order\OrderShipService;
+use think\Db;
+use app\common\library\easywechatPlus\WechatMiniProgramShop;
+use app\common\facade\Wechat;
 /**
  * 验货端订单接口
  * 
@@ -96,70 +102,138 @@ class Order extends Base
       //确认发货
       public function send()
       {
-          // 验证请求参数
-          $userId = 0;
-          $validate = new \app\api\validate\inspection\Order();
-          $params = [
-              'order_id' => $this->request->post('order_id'),
-              'order_goods_id' => $this->request->post('order_goods_id'),
-              'express_name' => $this->request->post('express_name'),
-              'express_no' => $this->request->post('express_no'),
-              'express_image' => $this->request->post('express_image/a', [])
-          ];
-          if (!$validate->scene('send')->check($params)) {
-              $this->error($validate->getError());
-          }        
-          
-          $orderId = intval($params['order_id'] ?? 0);
-          $orderGoodsId = intval($params['order_goods_id'] ?? 0);
-          
-          if (empty($orderId)) {
-              $this->error('订单ID不能为空');
-          }
-          
-          if (empty($orderGoodsId)) {
-              $this->error('订单商品ID不能为空');
-          }        
-          // 验证订单商品是否可以发货
-          $orderData = OrderService::validateOrderGoodsForDelivery($orderId, $orderGoodsId);
-          if (!$orderData) {
-              $this->error('订单或订单商品不存在,或不允许发货');
-          }
-          
-          $order = $orderData['order'];
-          $orderGoods = $orderData['order_goods'];
-          
-          $expressName = trim($params['express_name'] ?? '');
-          $expressNo = trim($params['express_no'] ?? '');
-          $expressImage = $params['express_image'] ?? [];
-         
-          // 事务处理
-          // 1. 更新订单商品发货状态
-          $result = OrderService::updateOrderGoodsDeliveryStatus($orderGoodsId, $expressName, $expressNo, $expressImage);
-          if (!$result) {
-              $this->error('更新订单商品发货状态失败');
-          }
-          
-          // 2. 检查并更新订单状态
-          OrderService::updateOrderStatusByDeliveryResult($orderId);
-          
-          // 3. 记录操作日志
-          $orderActionService = new OrderActionService();
-          $orderActionService->addInspectionAction(
-              $order->order_sn,
-              OrderActionEnum::ACTION_SHIP,
-              $userId,
-              '订单商品发货,商品:' . $orderGoods->goods_title . ',快递公司:' . $expressName . ',快递单号:' . $expressNo,
-              $userId,   
-              [
-                  'order_goods_id' => $orderGoodsId,
-                  'goods_title' => $orderGoods->goods_title,
-                  'express_name' => $expressName,
-                  'express_no' => $expressNo,
-              ]
-          );             
-          
-          $this->success('发货成功');
+        // 验证请求参数
+        $userId = 0;
+        $validate = new \app\api\validate\inspection\Order();
+        $params = [
+            'order_id' => $this->request->post('order_id'),
+            'order_goods_id' => $this->request->post('order_goods_id'),
+            'express_id' => $this->request->post('express_id'),
+            'express_no' => $this->request->post('express_no'),
+            'express_image' => $this->request->post('express_image/a', [])
+        ];
+        if (!$validate->scene('send')->check($params)) {
+            $this->error($validate->getError());
+        }
+        
+        //根据ID 查询快递公司
+        $expressId = intval($params['express_id'] ?? 0);
+        $express = OrderShipService::getExpressById($expressId);
+        if (empty($express)) {
+            $this->error('快递公司不存在');
+        }         
+        $orderId = intval($params['order_id'] ?? 0);
+        $orderGoodsId = intval($params['order_goods_id'] ?? 0);
+        
+        if (empty($orderId)) {
+            $this->error('订单ID不能为空');
+        }
+        
+        if (empty($orderGoodsId)) {
+            $this->error('订单商品ID不能为空');
+        }        
+        // 验证订单商品是否可以发货
+        $orderData = OrderService::validateOrderGoodsForDelivery($orderId, $orderGoodsId);
+        if (!$orderData) {
+            $this->error('订单或订单商品不存在,或不允许发货');
+        }
+        
+        $order = $orderData['order'];
+        $orderGoods = $orderData['order_goods'];
+        $expressName = $express->name;
+        $expressCode = $express->code;
+        $expressNo = trim($params['express_no'] ?? '');
+        $expressImage = $params['express_image'] ?? [];         
+        // 事务处理
+        Db::startTrans();
+        try{
+           // 创建包裹
+        $orderExpress = OrderShipService::createOrderExpress($orderId, $order['user_id'], $expressName, $expressCode, $expressNo, 'input', '', [], $expressImage);
+        if (!$orderExpress) {
+            Db::rollback();
+            $this->error('创建包裹失败');
+        }
+        // 1. 更新订单商品发货状态
+        $result = OrderService::updateOrderGoodsDeliveryStatus($orderGoodsId, $expressName, $expressNo, $expressImage,$orderExpress->id);
+        if (!$result) {
+            Db::rollback();
+            $this->error('更新订单商品发货状态失败');
+        }
+          
+        // 2. 检查并更新订单状态
+        OrderService::updateOrderStatusByDeliveryResult($orderId);
+          
+        // 3. 记录操作日志
+        $orderActionService = new OrderActionService();
+        $orderActionService->addInspectionAction(
+            $order->order_sn,
+            OrderActionEnum::ACTION_SHIP,
+            $userId,
+            '订单商品发货,商品:' . $orderGoods->goods_title . ',快递公司:' . $expressName . ',快递单号:' . $expressNo,
+            $userId,   
+            [
+                'order_goods_id' => $orderGoodsId,
+                'goods_title' => $orderGoods->goods_title,
+                'express_name' => $expressName,
+                'express_no' => $expressNo,
+            ]
+        ); 
+    
+        // 提交事务
+        Db::commit();   
+        } catch (\Exception $e) {
+            // 回滚事务
+            Db::rollback();
+            $this->error('发货失败'.$e->getMessage());
+        }
+         // 4. 同步微信小程序订单发货状态  todo 队列处理
+        $data = [
+            'order' => $order,
+            'items' => $orderGoods,
+            'express' => $orderExpress,
+            'delivery_type' => 'express',
+        ];
+        $this->syncWechatMiniProgramOrderDispatch($data,'send');
+        $this->success('发货成功');
+      }
+
+      private function syncWechatMiniProgramOrderDispatch($params =[],$type='send'){
+
+        $order = $params['order'];
+        $items = $params['items'];
+        $express = $params['express'];
+        $dispatch_type = $params['delivery_type'];
+        $uploadshoppingInfo = new WechatMiniProgramShop(Wechat::miniProgram());
+        // 微信小程序,并且存在微信发货管理权限时,才推送发货消息
+        if ($order['platform'] == 'WechatMiniProgram' && $uploadshoppingInfo->isTradeManaged()) {
+            $hasNosend = OrderGoods::where('order_id', $order['id'])
+            // ->where('refund_status', OrderGoodsEnum::REFUND_STATUS_NOREFUND)
+            ->where('delivery_status', OrderGoodsEnum::DELIVERY_STATUS_NOSEND)->count();
+            if ($type == 'send') {
+                // if (!$hasNosend && in_array('wechat', $order->pay_type)) {
+                if (!$hasNosend && $order->pay_type == PayEnum::METHOD_WECHAT) {
+                    // 所有 items 都已经发货,将交易信息上传微信
+                    $uploadshoppingInfo->uploadShippingInfos($order);
+                }
+            } else {
+                // 修改物流单
+                // if (!$hasNosend && in_array('wechat', $order->pay_types)) {
+                if (!$hasNosend && $order->pay_type == PayEnum::METHOD_WECHAT) {
+                    // 所有 items 都已经发货,将交易信息上传微信
+                    $uploadshoppingInfo->uploadShippingInfos($order, $express, 'change');
+                }
+            }
+        }
+
+        // 添加自动确认收货队列,这个队列只自动确认 本次发货的 items
+        // $confirm_days = Config::getConfigField('shop.order.auto_confirm');
+        // $confirm_days = $confirm_days > 0 ? $confirm_days : 0;
+        // if ($confirm_days) {
+        //     // 小于等于0, 不自动确认收货
+        //     \think\Queue::later(($confirm_days * 86400), '\addons\shopro\job\OrderAutoOper@autoConfirm', $params, 'shopro');
+        // }
+           
+        
       }
 
       // 统计订单 

+ 5 - 4
application/api/validate/inspection/Order.php

@@ -53,7 +53,7 @@ class Order extends Validate
         
         // 发货相关
         'order_goods_id'  => 'require|integer|gt:0',
-        'express_name'    => 'require|max:50',
+        'express_id'      => 'require|integer|gt:0',
         'express_no'      => 'require|alphaNum|max:50', 
         'express_image'   => 'require|array|max:9|checkExpressImages',
     ];
@@ -121,8 +121,9 @@ class Order extends Validate
         'order_goods_id.require'    => '订单商品ID不能为空',
         'order_goods_id.integer'    => '订单商品ID必须是整数',
         'order_goods_id.gt'         => '订单商品ID必须大于0',
-        'express_name.require'      => '快递公司不能为空',
-        'express_name.max'          => '快递公司名称不能超过50个字符',
+        'express_id.require'        => '快递公司不能为空',
+        'express_id.integer'        => '快递公司ID必须是整数',
+        'express_id.gt'             => '快递公司ID必须大于0',
         'express_no.require'        => '快递单号不能为空',
         'express_no.alphaNum'       => '快递单号只能包含字母和数字',
         'express_no.max'            => '快递单号不能超过50个字符',
@@ -153,7 +154,7 @@ class Order extends Validate
         'trend'       => ['type', 'days'],
         
         // 发货相关场景
-        'send'        => ['order_id', 'order_goods_id', 'express_name', 'express_no', 'express_image'],
+        'send'        => ['order_id', 'order_goods_id', 'express_id', 'express_no', 'express_image'],
     ];
 
 

+ 8 - 0
application/common/Enum/GoodsEnum.php

@@ -148,6 +148,14 @@ class GoodsEnum
             // self::DELIVERY_TYPE_SELF => '门店自提',
         ];
     }
+    public static function getDeliveryTypeList()
+    {
+        return [
+            self::DELIVERY_TYPE_EXPRESS,
+            // self::DELIVERY_TYPE_CITY,
+            // self::DELIVERY_TYPE_SELF,
+        ];
+    }
 
     public static function getDeliveryTypeText($deliveryType)
     {

+ 40 - 4
application/common/Service/Order/OrderShipService.php

@@ -1,7 +1,7 @@
 <?php
 namespace app\common\Service\Order;
-use app\common\model\Shipper;
-
+use app\common\model\Shipper as ShipperModel;
+use app\common\model\OrderExpress as OrderExpressModel;
 class OrderShipService
 {
     /**
@@ -9,9 +9,45 @@ class OrderShipService
      * @return bool|string|\PDOStatement|\think\Collection
      */
     public static function getExpressCompany(){
-        $list = Shipper::order('id desc')->select();
+        $list = (new ShipperModel())->order('id desc')->select();
         return $list;
     }
-    
 
+    /**
+     * Summary of getExpressById
+     * @param mixed $expressId
+     * @return array|bool|string|\PDOStatement|\think\Model
+     */
+    public static function getExpressById($expressId = 0){
+        $express = (new ShipperModel())->where('id', $expressId)->find();
+        return $express;
+    }
+    
+    /**
+     * 创建订单快递记录
+     * @param int $orderId 订单ID
+     * @param int $userId 用户ID
+     * @param string $expressName 快递公司名称
+     * @param string $expressCode 快递公司代码
+     * @param string $expressNo 快递单号
+     * @param string $method 发货方式
+     * @param string|null $driver 快递驱动
+     * @param array $ext 扩展信息
+     * @param array $expressImage 快递图片
+     * @return object 快递记录对象
+     */
+    public static function createOrderExpress($orderId = 0, $userId = 0, $expressName ="", $expressCode = "", $expressNo = "", $method = 'input', $driver = null, $ext = [], $expressImage = []   ){
+        $orderExpress = OrderExpressModel::create([
+            'user_id' => $userId,
+            'order_id' => $orderId,
+            'express_name' => $expressName,
+            'express_code' => $expressCode,
+            'express_no' => $expressNo,
+            'express_image' => $expressImage,
+            'method' => $method,
+            'driver' => $driver,
+            'ext' => $ext
+        ]);
+        return $orderExpress;
+    }
 }

+ 7 - 5
application/common/Service/Order/shippingInfo/Base.php

@@ -6,14 +6,15 @@ use app\common\Enum\PayEnum;
 use app\common\exception\BusinessException;
 use app\common\model\pay\Index as PayModel;
 use think\helper\Str;
-
+use app\common\Enum\GoodsEnum;
 class Base
 {
     protected $order = null;
-
+    //protected $deliveryTypes = [];
     public function __construct($order)
     {
-        $this->order = $order;       
+        $this->order = $order; 
+       // $this->deliveryTypes = GoodsEnum::getDeliveryTypeList();
         
     }
     
@@ -57,8 +58,9 @@ class Base
         $wechatPay = PayModel::where('order_type', $type)
             ->where('order_id', $this->order['id'])
             ->where('status', '<>', PayEnum::PAY_STATUS_UNPAID)
-            ->where('pay_type', PayEnum::METHOD_WECHAT)->order('id', 'desc')->find();
-
+            ->where('pay_type', PayEnum::METHOD_WECHAT)
+            ->order('id', 'desc')->find();
+      
         if (!$wechatPay) {
             throw new BusinessException('未找到订单微信支付记录');
         }

+ 5 - 11
application/common/Service/Order/shippingInfo/OrderShippingInfo.php

@@ -6,13 +6,13 @@ use app\common\model\OrderGoods as OrderGoodsModel;
 use app\common\model\OrderExpress as OrderExpressModel;
 use app\common\model\OrderAddress as OrderAddressModel;
 use app\common\Enum\OrderGoodsEnum;
-
+use app\common\Enum\GoodsEnum;
 class OrderShippingInfo extends Base
 {
 
     protected $orderItems = null;
-    
     protected $deliveryTypes = [];
+   
 
 
     /**
@@ -27,7 +27,7 @@ class OrderShippingInfo extends Base
         $this->setSendOrderItems();
 
         $uploadParams = [];
-        if (in_array('express', $this->deliveryTypes)) {
+        if (in_array(GoodsEnum::DELIVERY_TYPE_EXPRESS, $this->deliveryTypes)) {
             // 有 快递物流 商品
             $expressUploadParams = $this->getExpressShippingParams();
             $uploadParams = array_merge($uploadParams, $expressUploadParams);
@@ -51,7 +51,6 @@ class OrderShippingInfo extends Base
             $storeDeliveryParams = $this->getStoreDeliveryShippingParams();
             $uploadParams[] = $storeDeliveryParams;
         }
-
         // 处理微信相关参数
         return $this->setWechatParams($uploadParams, $wechatPay);
     }
@@ -91,7 +90,6 @@ class OrderShippingInfo extends Base
     private function getExpressShippingParams()
     {
         $orderExpresses = collection(OrderExpressModel::where('order_id', $this->order['id'])->select());
-
         return $this->getExpressShippingParamsByExpresses($orderExpresses);
     }
 
@@ -109,16 +107,14 @@ class OrderShippingInfo extends Base
         $uploadParams = [];
         if (!$orderExpresses->isEmpty()) {
             $orderAddress = OrderAddressModel::where('order_id', $this->order['id'])->find();
-
             $receiver_contact = $orderAddress ? mb_substr($orderAddress->mobile, 0, 3) . '****' . mb_substr($orderAddress->mobile, -4) : '130****0000';
 
             $shippingList = [];
             foreach ($orderExpresses as $orderExpress) {
                 $currentItems = $this->getItemsByCondition('order_express_id', $orderExpress->id);
-
                 $item_desc = [];
                 foreach ($currentItems as $currentItem) {
-                    $item_desc[] = $currentItem['goods_title'] . '*' . $currentItem['goods_num'];
+                    $item_desc[] = $currentItem['goods_title'] . '*' . $currentItem['nums'];
                 }
 
                 $item_desc = join(', ', $item_desc);
@@ -133,7 +129,6 @@ class OrderShippingInfo extends Base
                     ]
                 ];
             }
-
             if ($shippingList) {
                 // 发货
                 $uploadParams[] = [
@@ -142,7 +137,6 @@ class OrderShippingInfo extends Base
                 ];
             }
         }
-
         return $uploadParams;
     }
 
@@ -273,7 +267,7 @@ class OrderShippingInfo extends Base
                 ])
             ->select();
 
-        $this->orderItems = $orderItems instanceof \think\Collection ? $orderItems : collection($orderItems);
+        $this->orderItems = $orderItems instanceof \think\Collection ? $orderItems : collection($orderItems);  
 
         $this->deliveryTypes = array_values(array_unique(array_filter($this->orderItems->column('delivery_type'))));
     }

+ 7 - 3
application/common/Service/OrderService.php

@@ -1004,14 +1004,15 @@ class OrderService
      * @param array $expressImage 快递图片
      * @return bool
      */
-    public static function updateOrderGoodsDeliveryStatus($orderGoodsId, $expressName, $expressNo, $expressImage = [])
+    public static function updateOrderGoodsDeliveryStatus($orderGoodsId, $expressName, $expressNo, $expressImage = [],$orderExpressId = 0)
     {
         $updateData = [
             'express_name' => $expressName,
             'express_no' => $expressNo,
             'express_image' => is_array($expressImage) ? json_encode($expressImage) : $expressImage,
             'delivery_status' => 1, // 已发货
-            'updatetime' => time()
+            'updatetime' => time(),
+            'order_express_id' =>$orderExpressId
         ];
         
         return OrderGoods::where('id', $orderGoodsId)->update($updateData);
@@ -1078,7 +1079,10 @@ class OrderService
     
         $orderGoods = $orderData['order_goods'];
         // 检查订单商品的状态是都验货通过才可以发货
-        if ($orderGoods['inspect_status'] !== 1) {
+        // if ($orderGoods['inspect_status'] !== 1) {
+        //     return false;
+        // }
+        if (empty($orderGoods['inspect_time'])) {
             return false;
         }
         // 检查该订单商品是否已经发货

+ 24 - 22
application/common/library/easywechatPlus/WechatMiniProgramShop.php

@@ -6,6 +6,8 @@ use app\common\exception\ShoproException;
 use app\common\service\order\shippingInfo\OrderShippingInfo;
 use app\commom\model\data\WechatExpress;
 use app\common\exception\BusinessException;
+use app\common\facade\HttpClient;
+use think\Cache;
 
 /**
  * 补充 小程序购物订单
@@ -30,7 +32,6 @@ class WechatMiniProgramShop extends EasywechatPlus
             } else {
                 $uploadParams = $orderShippingInfo->getShippingParams();
             }
-
             // 设置消息跳转地址
             $this->setMessageJumpPath();
 
@@ -54,10 +55,11 @@ class WechatMiniProgramShop extends EasywechatPlus
                 }
 
                 $params['upload_time'] = date(DATE_RFC3339);
-
-                \think\Log::error('发货信息录入' . json_encode($params));
+                
+                \think\Log::info('发货信息录入参数' . json_encode($params));
+               
                 $result = $this->uploadShippingInfo($params);
-
+               
                 if ($result['errcode'] != 0) {
                     throw new BusinessException('获取失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
                 }
@@ -79,7 +81,7 @@ class WechatMiniProgramShop extends EasywechatPlus
         $access_token = $this->getAccessToken();
 
         $add_template_url = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info";
-        $result = \addons\shopro\facade\HttpClient::request('post', $add_template_url, [
+        $result = HttpClient::request('post', $add_template_url, [
             'body' => json_encode($params, JSON_UNESCAPED_UNICODE),
             'query' => ["access_token" => $access_token['access_token']],
             'headers' => ['Content-Type' => 'application/json']
@@ -112,7 +114,7 @@ class WechatMiniProgramShop extends EasywechatPlus
             format_log_error($e, 'checkAndSetMessageJumpPath', '自动设置微信小程序发货信息管理消息跳转路径失败');
             if ($exception) {
                 // 抛出异常
-                throw new ShoproException($e->getMessage());
+                throw new BusinessException($e->getMessage());
             }
         }
 
@@ -129,23 +131,23 @@ class WechatMiniProgramShop extends EasywechatPlus
     public function isTradeManaged($is_force = false)
     {
         $key = 'wechat:is_trade_managed';
-        if (!$is_force && redis_cache('?' . $key)) {
-            return redis_cache($key);     // 直接返回是否有权限
+        if (!$is_force && Cache::get($key)) {
+            return Cache::get($key);     // 直接返回是否有权限
         }
 
         $access_token = $this->getAccessToken();
         $add_template_url = "https://api.weixin.qq.com/wxa/sec/order/is_trade_managed";
 
-        $mini_appid = sheep_config('shop.platform.WechatMiniProgram.app_id');
+        $mini_appid = shop_config('shop.platform.wechat_mini_program.app_id');
         if (!$mini_appid) {
             // 没有配置微信小程序参数
-            throw new ShoproException('微信小程序发货管理查询失败,没有配置微信小程序');
+            throw new BusinessException('微信小程序发货管理查询失败,没有配置微信小程序');
         }
 
         $params = [
             'appid' => $mini_appid
         ];
-        $result = \addons\shopro\facade\HttpClient::request('post', $add_template_url, [
+        $result = HttpClient::request('post', $add_template_url, [
             'body' => json_encode($params, JSON_UNESCAPED_UNICODE),
             'query' => ["access_token" => $access_token['access_token']],
             'headers' => ['Content-Type' => 'application/json']
@@ -156,12 +158,12 @@ class WechatMiniProgramShop extends EasywechatPlus
 
         if ($result['errcode'] != 0 && $result['errcode'] != '48001') {
             // 48001 时不抛出异常,当没有权限处理
-            throw new ShoproException('查询是否有微信发货信息管理权限失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
+            throw new BusinessException('查询是否有微信发货信息管理权限失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
         }
 
         $is_trade_managed = isset($result['is_trade_managed']) ? intval($result['is_trade_managed']) : 0;
 
-        redis_cache($key, $is_trade_managed, 7200);       // 缓存结果,两小时
+        Cache::set($key, $is_trade_managed, 7200);       // 缓存结果,两小时
 
         return $is_trade_managed;
     }
@@ -176,7 +178,7 @@ class WechatMiniProgramShop extends EasywechatPlus
      */
     public function setMessageJumpPath($is_force = false, $path = 'pages/order/detail?comein_type=wechat')
     {
-        if (!$is_force && redis_cache('?wechat:set_message_jump_path')) {
+        if (!$is_force && cache('?wechat:set_message_jump_path')) {
             // 已经设置过了,无需再次设置
             return true;
         }
@@ -187,7 +189,7 @@ class WechatMiniProgramShop extends EasywechatPlus
         $params = [
             'path' => $path
         ];
-        $result = \addons\shopro\facade\HttpClient::request('post', $add_template_url, [
+        $result = HttpClient::request('post', $add_template_url, [
             'body' => json_encode($params, JSON_UNESCAPED_UNICODE),
             'query' => ["access_token" => $access_token['access_token']],
             'headers' => ['Content-Type' => 'application/json']
@@ -197,14 +199,14 @@ class WechatMiniProgramShop extends EasywechatPlus
         $result = json_decode($result, true);
 
         if ($result['errcode'] != 0) {
-            throw new ShoproException('设置微信发货消息跳转地址失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
+            throw new BusinessException('设置微信发货消息跳转地址失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
         }
 
         if ($is_force) {
             // 充值订单发货时,清掉缓存
-            redis_cache('wechat:set_message_jump_path', null);      // 清除缓存
+            cache('wechat:set_message_jump_path', null);      // 清除缓存
         } else {
-            redis_cache('wechat:set_message_jump_path', time());      // 永久有效
+            cache('wechat:set_message_jump_path', time());      // 永久有效
         }
 
         return $result;
@@ -220,7 +222,7 @@ class WechatMiniProgramShop extends EasywechatPlus
      */
     public function getDelivery($is_force = false)
     {
-        if (!$is_force && redis_cache('?wechat:get_delivery_list')) {
+        if (!$is_force && cache('?wechat:get_delivery_list')) {
             // 已经设置过了,无需再次设置
             return true;
         }
@@ -228,7 +230,7 @@ class WechatMiniProgramShop extends EasywechatPlus
         $access_token = $this->getAccessToken();
         $get_delivery_url = "https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/get_delivery_list";
 
-        $result = \addons\shopro\facade\HttpClient::request('post', $get_delivery_url, [
+        $result = HttpClient::request('post', $get_delivery_url, [
             'body' => '{}',
             'query' => ["access_token" => $access_token['access_token']],
             'headers' => ['Content-Type' => 'application/json']
@@ -238,7 +240,7 @@ class WechatMiniProgramShop extends EasywechatPlus
         $result = json_decode($result, true);
 
         if ($result['errcode'] != 0) {
-            throw new ShoproException('获取微信 delivery 列表失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
+            throw new BusinessException('获取微信 delivery 列表失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
         }
 
         // 存库
@@ -257,7 +259,7 @@ class WechatMiniProgramShop extends EasywechatPlus
             $wechatExpress->save($current);
         }
 
-        redis_cache('wechat:get_delivery_list', time());      // 永久有效
+        cache('wechat:get_delivery_list', time());      // 永久有效
 
         return $result;
     }

+ 1 - 1
application/common/model/OrderExpress.php

@@ -10,7 +10,7 @@ use think\Model;
 class OrderExpress extends Model
 {
 
-    protected $name = 'shopro_order_express';
+    protected $name = 'shop_order_express';
 
     protected $type = [
         'ext' => 'json'

+ 1 - 1
application/common/model/OrderExpressLog.php

@@ -9,7 +9,7 @@ use think\Model;
  */
 class OrderExpressLog extends Model
 {
-    protected $name = 'shopro_order_express_log';
+    protected $name = 'shop_order_express_log';
 
     protected $type = [
 

+ 7 - 3
application/common/service/OrderService.php

@@ -1004,14 +1004,15 @@ class OrderService
      * @param array $expressImage 快递图片
      * @return bool
      */
-    public static function updateOrderGoodsDeliveryStatus($orderGoodsId, $expressName, $expressNo, $expressImage = [])
+    public static function updateOrderGoodsDeliveryStatus($orderGoodsId, $expressName, $expressNo, $expressImage = [],$orderExpressId = 0)
     {
         $updateData = [
             'express_name' => $expressName,
             'express_no' => $expressNo,
             'express_image' => is_array($expressImage) ? json_encode($expressImage) : $expressImage,
             'delivery_status' => 1, // 已发货
-            'updatetime' => time()
+            'updatetime' => time(),
+            'order_express_id' =>$orderExpressId
         ];
         
         return OrderGoods::where('id', $orderGoodsId)->update($updateData);
@@ -1078,7 +1079,10 @@ class OrderService
     
         $orderGoods = $orderData['order_goods'];
         // 检查订单商品的状态是都验货通过才可以发货
-        if ($orderGoods['inspect_status'] !== 1) {
+        // if ($orderGoods['inspect_status'] !== 1) {
+        //     return false;
+        // }
+        if (empty($orderGoods['inspect_time'])) {
             return false;
         }
         // 检查该订单商品是否已经发货