Browse Source

fix:默认头像问题

super-yimizi 1 month ago
parent
commit
7053b0dd68

+ 12 - 0
README.md

@@ -4,6 +4,7 @@ FastAdmin是一款基于ThinkPHP+Bootstrap的极速后台开发框架。
 ## 清空数据SQL
 ## 清空数据SQL
 
 
  ```
  ```
+# 订单数据
 truncate fa_shop_order;
 truncate fa_shop_order;
 truncate fa_shop_order_goods;
 truncate fa_shop_order_goods;
 truncate fa_shop_order_action;
 truncate fa_shop_order_action;
@@ -12,6 +13,17 @@ truncate fa_shop_order_action;
 truncate fa_shop_order_electronics;
 truncate fa_shop_order_electronics;
 truncate fa_shop_order_invoice;
 truncate fa_shop_order_invoice;
 truncate fa_shop_order_aftersales;
 truncate fa_shop_order_aftersales;
+truncate fa_shop_order_express;
+truncate fa_shop_order_express_log;
+truncate fa_shop_order_express_log;
+
+# 支付数据
+truncate fa_shop_pay;
+# 验货端数据
+truncate inspection_application;
+truncate inspection_task;
+truncate inspection_result;
+truncate inspection_photo;
  ```
  ```
 
 
 
 

+ 3 - 1
application/api/controller/User.php

@@ -11,6 +11,8 @@ use app\common\library\Ems;
 use app\common\model\Third;
 use app\common\model\Third;
 use think\Validate;
 use think\Validate;
 use think\Env;
 use think\Env;
+use app\common\facade\Wechat;
+use app\common\library\easywechatPlus\WechatService;
 /**
 /**
  * 会员
  * 会员
  */
  */
@@ -48,7 +50,7 @@ class User extends Base
         $openid = '';
         $openid = '';
         //如果有传登录code,则获取openid
         //如果有传登录code,则获取openid
         if ($logincode) {
         if ($logincode) {
-            $json = (new \addons\shop\library\Wechat\Service())->getWechatSession($logincode);
+            $json = (new WechatService(Wechat::miniProgram()))->getWechatSession($logincode);
             $openid = $json['openid'] ?? '';
             $openid = $json['openid'] ?? '';
         }
         }
 
 

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

@@ -135,4 +135,68 @@ class Auth extends InspectionApi
             $this->error($this->auth->getError() ?: '密码设置失败');
             $this->error($this->auth->getError() ?: '密码设置失败');
         }
         }
     }
     }
+
+    /**
+     * 上传头像
+     */
+    public function uploadAvatar()
+    {
+        $file = $this->request->file('avatar');
+        if (!$file) {
+            $this->error('请选择头像文件');
+        }
+
+        // 移动到框架应用根目录/uploads/ 目录下
+        $info = $file->validate(['size' => 2 * 1024 * 1024, 'ext' => 'jpg,jpeg,png,gif'])
+                    ->move(ROOT_PATH . 'public' . DS . 'uploads' . DS . 'avatar' . DS . 'inspection');
+        
+        if (!$info) {
+            $this->error($file->getError());
+        }
+        
+        // 获取上传文件的相对路径
+        $avatar = '/uploads/avatar/inspection/' . $info->getSaveName();
+        
+        // 更新头像
+        $result = $this->auth->updateAvatar($avatar);
+        if ($result) {
+            $this->success('头像上传成功', [
+                'avatar' => cdnurl($avatar, true)
+            ]);
+        } else {
+            $this->error($this->auth->getError() ?: '头像更新失败');
+        }
+    }
+
+    /**
+     * 更新个人信息
+     */
+    public function updateProfile()
+    {
+        $name = $this->request->post('name');
+        $avatar = $this->request->post('avatar');
+        
+        if ($name) {
+            $this->application->name = $name;
+        }
+        
+        if ($avatar) {
+            // 处理头像路径,去除域名部分
+            $avatar = str_replace(request()->domain(), '', $avatar);
+            $result = $this->auth->updateAvatar($avatar);
+            if (!$result) {
+                $this->error($this->auth->getError() ?: '头像更新失败');
+            }
+        }
+        
+        if ($name) {
+            try {
+                $this->application->save();
+            } catch (\Exception $e) {
+                $this->error('信息更新失败:' . $e->getMessage());
+            }
+        }
+        
+        $this->success('信息更新成功', $this->getInspectorInfo());
+    }
 } 
 } 

+ 5 - 0
application/common/library/Auth.php

@@ -12,6 +12,7 @@ use think\Hook;
 use think\Request;
 use think\Request;
 use think\Validate;
 use think\Validate;
 use app\common\Enum\StatusEnum;
 use app\common\Enum\StatusEnum;
+use app\common\Service\ShopConfigService;
 class Auth
 class Auth
 {
 {
     protected static $instance = null;
     protected static $instance = null;
@@ -173,6 +174,10 @@ class Auth
             'prevtime'  => $time,
             'prevtime'  => $time,
             'status'    => StatusEnum::ENABLED
             'status'    => StatusEnum::ENABLED
         ]);
         ]);
+        //注册默认头像
+        //查询配置 
+        $defaultavatar = ShopConfigService::getConfigs('shop.basic.default_user_avator',false) ?? "";
+        $params['avatar'] = $defaultavatar;
         $params['password'] = $this->getEncryptPassword($password, $params['salt']);
         $params['password'] = $this->getEncryptPassword($password, $params['salt']);
         $params = array_merge($params, $extend);
         $params = array_merge($params, $extend);
 
 

+ 38 - 1
application/common/library/InspectionAuth.php

@@ -26,7 +26,7 @@ class InspectionAuth
     //默认配置
     //默认配置
     protected $config = [];
     protected $config = [];
     protected $options = [];
     protected $options = [];
-    protected $allowFields = ['id', 'user_id', 'name', 'phone', 'supplier_id', 'audit_status', 'status', 'region_full', 'address'];
+    protected $allowFields = ['id', 'user_id', 'name', 'phone', 'supplier_id', 'audit_status', 'status', 'region_full', 'address', 'avatar'];
 
 
     public function __construct($options = [])
     public function __construct($options = [])
     {
     {
@@ -462,6 +462,43 @@ class InspectionAuth
     }
     }
 
 
     /**
     /**
+     * 更新头像
+     * @param string $avatar 头像路径
+     * @return boolean
+     */
+    public function updateAvatar($avatar)
+    {
+        if (!$this->_logined) {
+            $this->setError('您尚未登录');
+            return false;
+        }
+        
+        try {
+            $this->_application->avatar = $avatar;
+            $this->_application->save();
+            
+            //更新头像成功的事件
+            Hook::listen("inspection_update_avatar_successed", $this->_application);
+            return true;
+        } catch (Exception $e) {
+            $this->setError($e->getMessage());
+            return false;
+        }
+    }
+
+    /**
+     * 获取头像完整URL
+     * @return string
+     */
+    public function getAvatar()
+    {
+        if (!$this->_application || !$this->_application->avatar) {
+            return '';
+        }
+        return cdnurl($this->_application->avatar, true);
+    }
+
+    /**
      * 获取密码加密后的字符串
      * 获取密码加密后的字符串
      * @param string $password 密码
      * @param string $password 密码
      * @param string $salt     密码盐
      * @param string $salt     密码盐