Browse Source

发货时默认是否同步至微信小程序

萤火科技 1 năm trước cách đây
mục cha
commit
399f5c2e6c
2 tập tin đã thay đổi với 22 bổ sung và 3 xóa
  1. 13 0
      app/common/model/wxapp/Setting.php
  2. 9 3
      app/common/service/order/Shipping.php

+ 13 - 0
app/common/model/wxapp/Setting.php

@@ -76,6 +76,19 @@ class Setting extends BaseModel
         return static::getItem('basic', $storeId);
     }
 
+    /**
+     * 获取是否开启发货信息管理
+     * @param int|null $storeId
+     * @return bool
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function isEnableShipping(?int $storeId = null): bool
+    {
+        return static::getConfigBasic($storeId)['enableShipping'];
+    }
+
     /**
      * 获取全部设置
      * @param int|null $storeId

+ 9 - 3
app/common/service/order/Shipping.php

@@ -66,22 +66,23 @@ class Shipping extends BaseService
             throwError('很抱歉,该订单不存在微信支付交易记录');
         }
         // 请求微信API接口
-        return $this->request($this->buildApiParam($completed, $param));
+        return $this->request($this->buildApiParam($completed, $param), $completed['store_id']);
     }
 
     /**
      * 请求微信API接口
      * @param array $apiParam
+     * @param int $storeId
      * @return true
      * @throws BaseException
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    private function request(array $apiParam): bool
+    private function request(array $apiParam, int $storeId): bool
     {
         // 小程序配置信息
-        $wxConfig = WxappSettingModel::getConfigBasic();
+        $wxConfig = WxappSettingModel::getConfigBasic($storeId);
         // 请求API数据
         $WechatShippingApi = new WechatShippingApi($wxConfig['app_id'], $wxConfig['app_secret']);
         // 处理返回结果
@@ -95,6 +96,9 @@ class Shipping extends BaseService
      * @param $completed
      * @param array $param
      * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
     private function buildParam($completed, array $param): array
     {
@@ -109,6 +113,8 @@ class Shipping extends BaseService
             // 物流单号
             'expressNo' => '',
         ]);
+        // 是否开启发货信息管理
+        !WxappSettingModel::isEnableShipping($completed['store_id']) && $param['syncMpWeixinShipping'] = 0;
         return $param;
     }