Browse Source

fix:测试

super-yimizi 1 month ago
parent
commit
8c78febce5

+ 28 - 27
application/api/controller/Goods.php

@@ -19,6 +19,8 @@ use app\common\Service\SkuSpec as SkuSpecService;
 use app\common\Service\Goods\CategoryService;
 use app\common\Service\DiscountService;
 use app\common\Service\Goods\CommentService;
+use app\common\facade\Wechat;
+use app\common\library\easywechatPlus\WechatService;
 /**
  * 商品接口
  */
@@ -281,44 +283,43 @@ class Goods extends Base
         if ($this->auth->isLogin()) {
             $user_id = $this->auth->id;
         }
-        $resource = '';
-        $fileStream = (new \app\common\library\message\Mini)->getWxCodeUnlimited([
+        
+        $result = (new WechatService(Wechat::miniProgram()))->getWxCodeUnlimited([
             'scene'       => "invite_id={$user_id}&goods_id={$goods_id}",
             'env_version' => $version, //要打开的小程序版本。正式版为 release,体验版为 trial,开发版为 develop
             'page'        => 'pages/goods/detail',
             'check_path'  => false
         ]);
-        if (is_null(json_decode($fileStream))) {
-            try {
-                $img = imagecreatefromstring($fileStream);
-                ob_start();
-                imagepng($img);
-                $resource = ob_get_clean();
-            } catch (\Exception $e) {
-                \think\Log::write($e->getMessage());
-                $this->error("获取微信二维码失败!");
+        
+        // 检查返回结果是否为错误信息(数组格式)
+        if (is_array($result)) {
+            Log::write('微信小程序码获取失败: ' . json_encode($result));
+            $this->error("获取微信二维码失败!" . ($result['errmsg'] ?? ''));
+        }
+        
+        // 如果返回的是二进制流,处理图片
+        $resource = '';
+        try {
+            $img = imagecreatefromstring($result);
+            if ($img === false) {
+                throw new \Exception('图片数据格式错误');
             }
+            ob_start();
+            imagepng($img);
+            $resource = ob_get_clean();
+            imagedestroy($img);
+        } catch (\Exception $e) {
+            Log::write('处理微信二维码图片失败: ' . $e->getMessage());
+            $this->error("处理微信二维码失败!");
         }
-        // } else {
-        //     $config = get_addon_config('shop');
-        //     if ($config['wxapp']) {
-        //         $localFile = ROOT_PATH . 'public' . $config['wxapp'];
-        //         if (is_file($localFile)) {
-        //             $resource = file_get_contents($localFile);
-        //         } else {
-        //             $resource = Http::get(cdnurl($config['wxapp'], true));
-        //         }
-        //     }
-        //     if (config('app_debug')) {
-        //         Log::write($fileStream);
-        //     }
-        // }
+        
         if (!$resource) {
-            Log::write($fileStream);
+            Log::write('微信二维码资源为空');
             $this->error("获取二维码失败!");
         }
+        
         $base64_data = base64_encode($resource);
-        $base64_file = 'data:image/jpg;base64,' . $base64_data;
+        $base64_file = 'data:image/png;base64,' . $base64_data;
         $this->success('获取成功', $base64_file);
     }
 }

+ 8 - 7
application/api/controller/Login.php

@@ -11,10 +11,11 @@ use think\Validate;
 use fast\Http;
 use addons\third\library\Service;
 use app\common\Enum\StatusEnum;
+use app\common\facade\Wechat;
 use think\Config;
 use think\Env;
 use think\Session;
-
+use app\common\library\easywechatPlus\WechatService;
 class Login extends Base
 {
 
@@ -221,7 +222,7 @@ class Login extends Base
             $this->error("请在后台配置微信小程序参数");
         }
 
-        $json = (new \addons\shop\library\Wechat\Service())->getWechatSession($code);
+        $json = (new WechatService(Wechat::miniProgram()))->getWechatSession($code);
         if (isset($json['openid'])) {
             $userinfo = [
                 'platform'      => 'wechat',
@@ -270,11 +271,11 @@ class Login extends Base
         $code = $this->request->post("code");
         $logincode = $this->request->post("logincode");
         $bind = $this->request->post("bind");
-        $data = (new \app\common\library\Wechat\Service())->getWechatMobile($code);
+        $data = (new WechatService(Wechat::miniProgram()))->getWechatMobile($code);
         if ($data) {
             $mobile = $data['phoneNumber'];
             //获取openid和unionid
-            $json = (new \app\common\library\Wechat\Service())->getWechatSession($logincode);
+            $json = (new WechatService(Wechat::miniProgram()))->getWechatSession($logincode);
             $openid = $json['openid'] ?? '';
             $unionid = $json['unionid'] ?? '';
 
@@ -312,7 +313,7 @@ class Login extends Base
     }
 
     /**
-     * APP登录
+     * APP登录  todo  需要修改
      */
     public function appLogin()
     {
@@ -362,8 +363,8 @@ class Login extends Base
      */
     public function getWechatOpenid()
     {
-        $code = $this->request->post("logincode");
-        $json = (new \addons\shop\library\Wechat\Service())->getWechatSession($code);
+        $code = $this->request->post("login_code");
+        $json = (new WechatService(Wechat::miniProgram()))->getWechatSession($code);
         $this->success('获取成功!', ['openid' => $json['openid'] ?? '']);
     }
 

+ 138 - 0
application/api/controller/inspection/Auth.php

@@ -0,0 +1,138 @@
+<?php
+
+namespace app\api\controller\inspection;
+
+use app\common\controller\InspectionApi;
+use app\common\library\InspectionAuth;
+
+/**
+ * 验货员认证接口
+ */
+class Auth extends InspectionApi
+{
+    // 不需要登录的方法
+    protected $noNeedLogin = ['login', 'setPassword'];
+    // 不需要权限的方法
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 验货员登录
+     */
+    public function login()
+    {
+        $phone = $this->request->post('phone');
+        $password = $this->request->post('password', '');
+
+        if (!$phone) {
+            $this->error('手机号不能为空');
+        }
+
+        $auth = InspectionAuth::instance();
+        $result = $auth->login($phone, $password);
+        
+        if ($result) {
+            $this->success('登录成功', [
+                'inspector' => $auth->getInspectorInfo(),
+                'token' => $auth->getToken()
+            ]);
+        } else {
+            $this->error($auth->getError() ?: '登录失败');
+        }
+    }
+
+    /**
+     * 验货员退出登录
+     */
+    public function logout()
+    {
+        if ($this->auth->logout()) {
+            $this->success('退出成功');
+        } else {
+            $this->error($this->auth->getError() ?: '退出失败');
+        }
+    }
+
+    /**
+     * 获取验货员信息
+     */
+    public function info()
+    {
+        $this->success('获取成功', $this->getInspectorInfo());
+    }
+
+    /**
+     * 检查登录状态
+     */
+    public function check()
+    {
+        if ($this->auth->isLogin()) {
+            $this->success('已登录', [
+                'inspector' => $this->getInspectorInfo(),
+                'token' => $this->auth->getToken()
+            ]);
+        } else {
+            $this->error('未登录', null, 401);
+        }
+    }
+
+    /**
+     * 修改密码
+     */
+    public function changepwd()
+    {
+        $oldpassword = $this->request->post('oldpassword');
+        $newpassword = $this->request->post('newpassword');
+        $renewpassword = $this->request->post('renewpassword');
+
+        if (!$oldpassword) {
+            $this->error('旧密码不能为空');
+        }
+        if (!$newpassword) {
+            $this->error('新密码不能为空');
+        }
+        if ($newpassword !== $renewpassword) {
+            $this->error('两次输入的密码不一致');
+        }
+        if (strlen($newpassword) < 6) {
+            $this->error('密码长度不能少于6位');
+        }
+
+        $result = $this->auth->changepwd($newpassword, $oldpassword);
+        if ($result) {
+            $this->success('密码修改成功,请重新登录');
+        } else {
+            $this->error($this->auth->getError() ?: '密码修改失败');
+        }
+    }
+
+    /**
+     * 设置初始密码(验货员首次设置密码)
+     */
+    public function setPassword()
+    {
+        $password = $this->request->post('password');
+        $repassword = $this->request->post('repassword');
+
+        if (!$password) {
+            $this->error('密码不能为空');
+        }
+        if ($password !== $repassword) {
+            $this->error('两次输入的密码不一致');
+        }
+        if (strlen($password) < 6) {
+            $this->error('密码长度不能少于6位');
+        }
+
+        // 检查是否已设置过密码
+        if ($this->application->password) {
+            $this->error('密码已设置,请使用修改密码功能');
+        }
+
+        $result = $this->auth->setPassword($password);
+        if ($result) {
+            $this->success('密码设置成功');
+        } else {
+            $this->error($this->auth->getError() ?: '密码设置失败');
+        }
+    }
+} 

+ 2 - 2
application/api/controller/inspection/Index.php

@@ -115,9 +115,9 @@ class Index extends Base
              
              $resultData[] = $resultItem;
          }
-         
+         $inspectUid = $this->auth->id;
          // 调用服务提交验货任务
-         list($code, $msg, $data) = InspectService::submitInspectionTask($taskData, $resultData);
+         list($code, $msg, $data) = InspectService::submitInspectionTask($taskData, $resultData,$inspectUid);
          
          if ($code == 1) {
              $this->success($msg, $data);

+ 2 - 2
application/common/Service/InspectService.php

@@ -172,7 +172,7 @@ class InspectService
      * @param array $resultData 验货结果数据
      * @return array
      */
-    public static function submitInspectionTask($taskData, $resultData)
+    public static function submitInspectionTask($taskData, $resultData,$inspectUid = 0)
     {
         Db::startTrans();
         
@@ -228,7 +228,7 @@ class InspectService
 
             // 5. 更新订单商品的验收状态
             $inspectStatus = $isPass ? 1 : 2; // 1:验收通过 2:验收不通过
-            OrderService::updateOrderGoodsInspectStatus($taskData['order_goods_id'], $inspectStatus);
+            OrderService::updateOrderGoodsInspectStatus($taskData['order_goods_id'], $inspectStatus,$inspectUid);
             
             // 6. 检查订单是否所有商品都验收完成,决定是否更新订单状态
             OrderService::updateOrderStatusByInspectResult($taskData['order_id'], 0);

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

@@ -923,11 +923,12 @@ class OrderService
      * @param int $inspectStatus 验收状态 0:待验收 1:验收通过 2:验收不通过
      * @return bool
      */
-    public static function updateOrderGoodsInspectStatus($orderGoodsId, $inspectStatus)
+    public static function updateOrderGoodsInspectStatus($orderGoodsId, $inspectStatus,$inspectUid = 0)
     {
         return OrderGoods::where('id', $orderGoodsId)->update([
             'inspect_status' => $inspectStatus,
-            'inspect_time' => time()
+            'inspect_time' => time(),
+            'inspect_id' => $inspectUid
         ]);
     }
 

+ 72 - 16
application/common/controller/InspectionApi.php

@@ -17,6 +17,8 @@ class InspectionApi
     protected $application = null;
     protected $user = null;
     protected $responseType = 'json';
+    protected $noNeedLogin = [];
+    protected $noNeedRight = [];
 
     public function __construct(Request $request = null)
     {
@@ -32,24 +34,49 @@ class InspectionApi
         check_ip_allowed();
         // 过滤请求
         $this->request->filter('trim,strip_tags,htmlspecialchars');
+        
         $this->auth = InspectionAuth::instance();
-        // token
-        $token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token')));
-        // 初始化验货员身份
-        $this->auth->init($token);
-        if (!$this->auth->isLogin()) {
-            $this->error('请先登录', null, 401);
-        }
-        $this->application = $this->auth->getApplication();
-        $this->user = $this->auth->getUser();
-        // 检查审核状态
-        if (!$this->application || $this->application->audit_status != 2) {
-            $this->error('验货员未通过审核', null, 403);
-        }
-        // 检查供应商绑定
-        if (!$this->application->supplier_id) {
-            $this->error('未绑定供应商', null, 403);
+        
+        // 检查是否需要登录
+        $action = $this->request->action();
+        if (!$this->auth->match($this->noNeedLogin)) {
+            // token获取
+            $token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('inspection_token')));
+            
+            // 初始化验货员身份
+            if (!$this->auth->init($token)) {
+                $this->error($this->auth->getError() ?: '请先登录', null, 401);
+            }
+            
+            if (!$this->auth->isLogin()) {
+                $this->error('请先登录', null, 401);
+            }
+            
+            $this->application = $this->auth->getApplication();
+            $this->user = $this->auth->getUser();
+            
+            // 检查审核状态
+            if (!$this->application || $this->application->audit_status != 2) {
+                $this->error('验货员未通过审核', null, 403);
+            }
+            
+            // 检查启用状态
+            if (!$this->application || $this->application->status != 1) {
+                $this->error('验货员账号已被禁用', null, 403);
+            }
+            
+            // 检查供应商绑定
+            if (!$this->application->supplier_id) {
+                $this->error('未绑定供应商', null, 403);
+            }
+            
+            // 检查权限
+            if (!$this->auth->match($this->noNeedRight)) {
+                // 这里可以添加具体的权限检查逻辑
+                // 暂时允许所有已登录的验货员访问
+            }
         }
+        
         // 加载语言包
         $controllername = strtolower($this->request->controller());
         $lang = $this->request->langset();
@@ -57,6 +84,29 @@ class InspectionApi
         Lang::load(ADDON_PATH . 'shop/lang/' . $lang . '/' . str_replace('.', '/', $controllername) . '.php');
     }
 
+    /**
+     * 获取验货员信息
+     * @return array
+     */
+    protected function getInspectorInfo()
+    {
+        if (!$this->auth || !$this->auth->isLogin()) {
+            return null;
+        }
+        return $this->auth->getInspectorInfo();
+    }
+
+    /**
+     * 检查验货员权限
+     * @param string $path
+     * @param string $module
+     * @return bool
+     */
+    protected function checkAuth($path = null, $module = null)
+    {
+        return $this->auth->check($path, $module);
+    }
+
     protected function success($msg = '', $data = null, $code = 1, $type = null, array $header = [])
     {
         $this->result($msg, $data, $code, $type, $header);
@@ -75,6 +125,12 @@ class InspectionApi
             'time' => Request::instance()->server('REQUEST_TIME'),
             'data' => $data,
         ];
+        
+        // 添加验货员信息到响应中(如果已登录)
+        if ($this->auth && $this->auth->isLogin()) {
+            $result['inspector'] = $this->getInspectorInfo();
+        }
+        
         $type = $type ?: $this->responseType;
         if (isset($header['statuscode'])) {
             $code = $header['statuscode'];

+ 349 - 49
application/common/library/InspectionAuth.php

@@ -21,11 +21,19 @@ class InspectionAuth
     protected $_user = null;
     protected $_token = '';
     protected $keeptime = 2592000;
-    protected $allowFields = ['id', 'user_id', 'name', 'phone', 'supplier_id', 'audit_status', 'status'];
+    protected $requestUri = '';
+    protected $rules = [];
+    //默认配置
+    protected $config = [];
+    protected $options = [];
+    protected $allowFields = ['id', 'user_id', 'name', 'phone', 'supplier_id', 'audit_status', 'status', 'region_full', 'address'];
 
     public function __construct($options = [])
     {
-        // 可扩展配置
+        if ($config = Config::get('inspection')) {
+            $this->config = array_merge($this->config, $config);
+        }
+        $this->options = array_merge($this->config, $options);
     }
 
     public static function instance($options = [])
@@ -37,7 +45,26 @@ class InspectionAuth
     }
 
     /**
-     * 初始化验货员身份(通过token)
+     * 兼容调用application模型的属性
+     *
+     * @param string $name
+     * @return mixed
+     */
+    public function __get($name)
+    {
+        return $this->_application ? $this->_application->$name : null;
+    }
+
+    /**
+     * 兼容调用application模型的属性
+     */
+    public function __isset($name)
+    {
+        return isset($this->_application) ? isset($this->_application->$name) : false;
+    }
+
+    /**
+     * 根据Token初始化验货员身份
      * @param string $token
      * @return bool
      */
@@ -49,49 +76,232 @@ class InspectionAuth
         if ($this->_error) {
             return false;
         }
-        $application = InspectionApplication::where('token', $token)
-            ->where('audit_status', 2)
-            ->where('status', 1)
-            ->find();
+        
+        if (!$token) {
+            return false;
+        }
+
+        $application = InspectionApplication::where([
+            'token' => $token,
+            'audit_status' => 2,
+            'status' => 1
+        ])->where('token_expire_time', '>', time())->find();
+            
         if (!$application) {
-            $this->setError('验货员未登录或未通过审核');
+            $this->setError('验货员未登录或登录已过期');
+            return false;
+        }
+
+        $user = User::get($application->user_id);
+        if (!$user) {
+            $this->setError('用户不存在');
             return false;
         }
+
+        if ($user->status != 1) {
+            $this->setError('用户已被禁用');
+            return false;
+        }
+
         $this->_application = $application;
-        $this->_user = User::get($application->user_id);
+        $this->_user = $user;
         $this->_logined = true;
         $this->_token = $token;
+
+        //初始化成功的事件
+        Hook::listen("inspection_init_successed", $this->_application);
+
         return true;
     }
 
     /**
+     * 验货员登录
+     * @param string $phone 手机号
+     * @param string $password 密码(实际项目中可能需要验证码等)
+     * @return bool
+     */
+    public function login($phone, $password = '')
+    {
+        $application = InspectionApplication::where([
+            'phone' => $phone,
+            'audit_status' => 2,
+            'status' => 1
+        ])->find();
+            
+        if (!$application) {
+            $this->setError('验货员不存在或未通过审核');
+            return false;
+        }
+
+        $user = User::get($application->user_id);
+        if (!$user) {
+            $this->setError('关联用户不存在');
+            return false;
+        }
+
+        if ($user->status != 1) {
+            $this->setError('用户已被禁用');
+            return false;
+        }
+
+        // 检查登录失败次数
+        if ($application->login_failure >= 10 && time() - $application->login_failure_time < 86400) {
+            $this->setError('登录失败次数过多,请24小时后重试');
+            return false;
+        }
+
+        // 验证密码
+        if ($password && $application->password != $this->getEncryptPassword($password, $application->salt)) {
+            $application->save(['login_failure' => $application->login_failure + 1, 'login_failure_time' => time()]);
+            $this->setError('密码错误');
+            return false;
+        }
+
+        //直接登录验货员
+        return $this->direct($application->user_id);
+    }
+
+    /**
      * 直接登录验货员
      * @param int $user_id
      * @return bool
      */
     public function direct($user_id)
     {
-        $application = InspectionApplication::where('user_id', $user_id)
-            ->where('audit_status', 2)
-            ->where('status', 1)
-            ->find();
+        $application = InspectionApplication::where([
+            'user_id' => $user_id,
+            'audit_status' => 2,
+            'status' => 1
+        ])->find();
+            
         if (!$application) {
             $this->setError('验货员未通过审核');
             return false;
         }
-        $token = Random::uuid();
-        $expire = time() + $this->keeptime;
-        $application->token = $token;
-        $application->token_expiretime = $expire;
-        $application->save();
-        $this->_application = $application;
-        $this->_user = User::get($application->user_id);
-        $this->_logined = true;
-        $this->_token = $token;
+
+        $user = User::get($application->user_id);
+        if (!$user) {
+            $this->setError('关联用户不存在');
+            return false;
+        }
+
+        Db::startTrans();
+        try {
+            $ip = request()->ip();
+            $time = time();
+            $token = Random::uuid();
+            $expire = $time + $this->keeptime;
+
+            //判断连续登录和最大连续登录
+            if ($application->login_time < \fast\Date::unixtime('day')) {
+                $application->successions = $application->login_time < \fast\Date::unixtime('day', -1) ? 1 : $application->successions + 1;
+                $application->max_successions = max($application->successions, $application->max_successions);
+            }
+
+            $application->prev_time = $application->login_time;
+            //记录本次登录的IP和时间
+            $application->login_ip = $ip;
+            $application->login_time = $time;
+            //重置登录失败次数
+            $application->login_failure = 0;
+            //设置token
+            $application->token = $token;
+            $application->token_expire_time = $expire;
+            
+            $application->save();
+
+            $this->_application = $application;
+            $this->_user = $user;
+            $this->_logined = true;
+            $this->_token = $token;
+
+            //登录成功的事件
+            Hook::listen("inspection_login_successed", $this->_application);
+            Db::commit();
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->setError($e->getMessage());
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * 退出登录
+     * @return bool
+     */
+    public function logout()
+    {
+        if (!$this->_logined) {
+            $this->setError('未登录');
+            return false;
+        }
+        
+        Db::startTrans();
+        try {
+            $this->_application->token = null;
+            $this->_application->token_expire_time = null;
+            $this->_application->save();
+            
+            $this->_logined = false;
+            $this->_token = '';
+            
+            //退出成功的事件
+            Hook::listen("inspection_logout_successed", $this->_application);
+            Db::commit();
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->setError($e->getMessage());
+            return false;
+        }
         return true;
     }
 
     /**
+     * 修改密码
+     * @param string $newpassword       新密码
+     * @param string $oldpassword       旧密码
+     * @param bool   $ignoreoldpassword 忽略旧密码
+     * @return boolean
+     */
+    public function changepwd($newpassword, $oldpassword = '', $ignoreoldpassword = false)
+    {
+        if (!$this->_logined) {
+            $this->setError('您尚未登录');
+            return false;
+        }
+        //判断旧密码是否正确
+        if ($this->_application->password == $this->getEncryptPassword($oldpassword, $this->_application->salt) || $ignoreoldpassword) {
+            Db::startTrans();
+            try {
+                $salt = Random::alnum();
+                $newpassword = $this->getEncryptPassword($newpassword, $salt);
+                
+                // 更新验货员申请表的密码和salt
+                $this->_application->password = $newpassword;
+                $this->_application->salt = $salt;
+                $this->_application->login_failure = 0;
+                // 清除当前token,强制重新登录
+                $this->_application->token = null;
+                $this->_application->token_expire_time = null;
+                $this->_application->save();
+                
+                //修改密码成功的事件
+                Hook::listen("inspection_changepwd_successed", $this->_application);
+                Db::commit();
+            } catch (Exception $e) {
+                Db::rollback();
+                $this->setError($e->getMessage());
+                return false;
+            }
+            return true;
+        } else {
+            $this->setError('旧密码错误');
+            return false;
+        }
+    }
+
+    /**
      * 判断是否已登录
      * @return bool
      */
@@ -128,50 +338,50 @@ class InspectionAuth
     }
 
     /**
-     * 获取供应商ID
-     * @return int
+     * 获取验货员基本信息
      */
-    public function getSupplierId()
+    public function getInspectorInfo()
     {
-        return $this->_application ? $this->_application->supplier_id : 0;
+        if (!$this->_application) {
+            return null;
+        }
+        
+        $data = $this->_application->toArray();    
+        $allowFields = $this->getAllowFields();
+        $inspectorInfo = array_intersect_key($data, array_flip($allowFields));
+        
+        // 添加token信息
+        $inspectorInfo['token'] = $this->_token;
+        $inspectorInfo['token_expire_time'] = $this->_application->token_expire_time;
+        
+        return $inspectorInfo;
     }
 
     /**
-     * 退出登录
-     * @return bool
+     * 获取供应商ID
+     * @return int
      */
-    public function logout()
+    public function getSupplierId()
     {
-        if (!$this->_logined) {
-            $this->setError('未登录');
-            return false;
-        }
-        $this->_application->token = null;
-        $this->_application->token_expiretime = null;
-        $this->_application->save();
-        $this->_logined = false;
-        $this->_token = '';
-        return true;
+        return $this->_application ? $this->_application->supplier_id : 0;
     }
 
     /**
-     * 设置错误信息
-     * @param string $error
-     * @return $this
+     * 获取当前请求的URI
+     * @return string
      */
-    public function setError($error)
+    public function getRequestUri()
     {
-        $this->_error = $error;
-        return $this;
+        return $this->requestUri;
     }
 
     /**
-     * 获取错误信息
-     * @return string
+     * 设置当前请求的URI
+     * @param string $uri
      */
-    public function getError()
+    public function setRequestUri($uri)
     {
-        return $this->_error;
+        $this->requestUri = $uri;
     }
 
     /**
@@ -191,4 +401,94 @@ class InspectionAuth
     {
         $this->allowFields = $fields;
     }
+
+    /**
+     * 检测当前控制器和方法是否匹配传递的数组
+     *
+     * @param array $arr 需要验证权限的数组
+     * @return boolean
+     */
+    public function match($arr = [])
+    {
+        $request = Request::instance();
+        $arr = is_array($arr) ? $arr : explode(',', $arr);
+        if (!$arr) {
+            return false;
+        }
+        $arr = array_map('strtolower', $arr);
+        // 是否存在
+        if (in_array(strtolower($request->action()), $arr) || in_array('*', $arr)) {
+            return true;
+        }
+
+        // 没找到匹配
+        return false;
+    }
+
+    /**
+     * 设置会话有效时间
+     * @param int $keeptime 默认为永久
+     */
+    public function keeptime($keeptime = 0)
+    {
+        $this->keeptime = $keeptime;
+    }
+
+    /**
+     * 设置初始密码
+     * @param string $password 密码
+     * @return boolean
+     */
+    public function setPassword($password)
+    {
+        if (!$this->_application) {
+            $this->setError('验货员信息不存在');
+            return false;
+        }
+        
+        try {
+            $salt = Random::alnum();
+            $encryptPassword = $this->getEncryptPassword($password, $salt);
+            
+            $this->_application->password = $encryptPassword;
+            $this->_application->salt = $salt;
+            $this->_application->save();
+            
+            return true;
+        } catch (Exception $e) {
+            $this->setError($e->getMessage());
+            return false;
+        }
+    }
+
+    /**
+     * 获取密码加密后的字符串
+     * @param string $password 密码
+     * @param string $salt     密码盐
+     * @return string
+     */
+    public function getEncryptPassword($password, $salt = '')
+    {
+        return md5(md5($password) . $salt);
+    }
+
+    /**
+     * 设置错误信息
+     * @param string $error
+     * @return $this
+     */
+    public function setError($error)
+    {
+        $this->_error = $error;
+        return $this;
+    }
+
+    /**
+     * 获取错误信息
+     * @return string
+     */
+    public function getError()
+    {
+        return $this->_error ? __($this->_error) : '';
+    }
 } 

+ 95 - 0
application/common/library/easywechatPlus/WechatService.php

@@ -0,0 +1,95 @@
+<?php
+
+namespace app\common\library\easywechatPlus;
+
+use fast\Http;
+use think\Log;
+use think\Config;
+use app\common\exception\BusinessException;
+use app\common\facade\HttpClient;
+
+/**
+ * 微信服务类 - 继承EasywechatPlus,支持facade配置
+ */
+class WechatService extends EasywechatPlus
+{
+
+
+    /**
+     * 生成小程序码
+     * @param array $param
+     * @return string
+     */
+    public function getWxCodeUnlimited($param)
+    {
+        $access_token = $this->getAccessToken();
+        $url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit';
+        $data = array_merge([
+            'width' => 280
+        ], $param);
+        $result = HttpClient::request('post', $url, [
+            'body' => json_encode($data, JSON_UNESCAPED_UNICODE),
+            'query' => ["access_token" => $access_token['access_token']],
+            'headers' => ['Content-Type' => 'application/json']
+        ]);
+
+        $result = $result->getBody()->getContents();
+        // Log::write('getWxCodeUnlimited:'.$result);
+        return  json_decode($result);
+    }
+
+    /**
+     * 获取手机号
+     * @param string $code
+     * @return array
+     */
+    public function getWechatMobile($code)
+    {
+        $access_token = $this->getAccessToken();
+        $url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber";
+        $res = HttpClient::request('post', $url, [
+            'body' => json_encode(['code' => $code]),
+            'query' => ["access_token" => $access_token['access_token']],
+            'headers' => ['Content-Type' => 'application/json']
+        ]);
+        $res = $res->getBody()->getContents();
+        $res = (array)json_decode($res, true);
+        
+        if (!isset($res['phone_info']) && Config::get('app_debug')) {
+            Log::write($res, 'get_phone');
+        }
+        return $res['phone_info'] ?? [];
+    }
+
+    /**
+     * 获取Session信息
+     * @param string $code
+     * @return array
+     */
+    public function getWechatSession($code)
+    {
+        $access_token = $this->getAccessToken();
+        $url = "https://api.weixin.qq.com/sns/jscode2session";
+        $result = HttpClient::request('get', $url, [
+            'query' => [
+                "access_token" => $access_token['access_token'],
+                'appid'      => $this->app->app_id,
+                'secret'     => $this->app->app_secret,
+                'js_code'    => $code,
+                'grant_type' => 'authorization_code'
+            ],
+        ]);
+        $result = $result->getBody()->getContents();
+        $result = json_decode($result, true);
+        if ($result['errcode'] == 0) {
+            return $result;
+        }
+        
+        if (Config::get('app_debug')) {
+            Log::write($result, 'get_session');
+        }
+        return ['errmsg' => Config::get('app_debug') ? $result['errmsg'] : '网络错误'];
+    }
+
+   
+} 

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

@@ -923,11 +923,12 @@ class OrderService
      * @param int $inspectStatus 验收状态 0:待验收 1:验收通过 2:验收不通过
      * @return bool
      */
-    public static function updateOrderGoodsInspectStatus($orderGoodsId, $inspectStatus)
+    public static function updateOrderGoodsInspectStatus($orderGoodsId, $inspectStatus,$inspectUid = 0)
     {
         return OrderGoods::where('id', $orderGoodsId)->update([
             'inspect_status' => $inspectStatus,
-            'inspect_time' => time()
+            'inspect_time' => time(),
+            'inspect_id' => $inspectUid
         ]);
     }