瀏覽代碼

增加公司修改用户信息

林海涛 1 年之前
父節點
當前提交
cbf46a3866

+ 12 - 1
app/api/controller/FirmController.php

@@ -6,7 +6,9 @@ use app\api\lists\FirmGoodLists;
 use app\api\lists\recharge\FirmOrderLists;
 use app\api\logic\FirmLogic;
 use app\api\logic\GoodsLogic;
+use app\api\logic\UserLogic;
 use app\api\validate\FirmRegisterValidate;
+use app\api\validate\FirmValidate;
 use app\api\validate\GoodsValidate;
 
 class FirmController extends BaseApiController
@@ -55,7 +57,6 @@ class FirmController extends BaseApiController
     }
     public function submitGood()
     {
-
         $params = (new GoodsValidate())->post()->goCheck('add');
         $result = GoodsLogic::sync($params,$this->userId);
         if (true === $result) {
@@ -63,4 +64,14 @@ class FirmController extends BaseApiController
         }
         return $this->fail(FirmLogic::getError());
     }
+
+    public function saveUserInfo()
+    {
+        $params = (new FirmValidate())->post()->goCheck('saveUserInfo');
+        $result = UserLogic::saveFirmUserInfo($params,$this->userId);
+        if (true === $result) {
+            return $this->success('已提交', [], 1, 1);
+        }
+        return $this->fail(FirmLogic::getError());
+    }
 }

+ 5 - 0
app/api/controller/UserController.php

@@ -144,4 +144,9 @@ class UserController extends BaseApiController
         }
         return $this->fail(UserLogic::getError());
     }
+
+    public function saveFirmInfo()
+    {
+        $params = (new UserValidate())->post()->goCheck();
+    }
 }

+ 50 - 0
app/api/logic/UserLogic.php

@@ -30,6 +30,7 @@ use app\common\{enum\notice\NoticeEnum,
     service\sms\SmsDriver,
     service\wechat\WeChatMnpService};
 use think\facade\Config;
+use think\facade\Db;
 
 /**
  * 会员逻辑层
@@ -299,4 +300,53 @@ class UserLogic extends BaseLogic
         }
     }
 
+    public static function saveFirmUserInfo(array $params,int $userId)
+    {
+        Db::startTrans();
+        try {
+            $user = User::findOrEmpty($userId);
+            if ($user->isEmpty()) {
+                throw new \Exception('用户不存在');
+            }
+            if (!empty($params['password'])) {
+                // 密码盐
+                $passwordSalt = Config::get('project.unique_identification');
+                if (empty($params['old_password'])) {
+                    throw new \Exception('请填写旧密码');
+                }
+                $oldPassword = create_password($params['old_password'], $passwordSalt);
+                if ($oldPassword != $user['password']) {
+                    throw new \Exception('原密码不正确');
+                }
+                if($params['password'] !== $params['password_confirm']){
+                    throw new \Exception('输入的确认密码不一致');
+                }
+                // 保存密码
+                $password = create_password($params['password'], $passwordSalt);
+                $user->password = $password;
+            }
+            $user->avatar = $params['avatar'];
+            $user->real_name = $params['real_name'];
+            $user->nickname = $params['nickname'];
+            $user->sex = $params['sex'];
+            $user->save();
+            if(!empty($params['firmRegister'])){
+                $firmRegisterModer = FirmRegister::where(['user_id'=>$userId,'status'=>YesNoEnum::YES])->findOrEmpty();
+                if($firmRegisterModer->isEmpty()){
+                    throw new \Exception('公司信息不存在');
+                }
+                $firmRegisterModer->firm_name = $params['firmRegister']['firm_name'];
+                $firmRegisterModer->user_name = $params['firmRegister']['user_name'];
+                $firmRegisterModer->mobile = $params['firmRegister']['mobile'];
+                $firmRegisterModer->address = $params['firmRegister']['address'];
+                $firmRegisterModer->cooperate_description = $params['firmRegister']['cooperate_description'];
+            }
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
 }

+ 44 - 0
app/api/validate/FirmValidate.php

@@ -0,0 +1,44 @@
+<?php
+/**
+ * @author 林海涛
+ * @date 2024/7/29 下午2:35
+ */
+namespace app\api\validate;
+use app\common\model\user\User;
+use app\common\validate\BaseValidate;
+
+class FirmValidate extends BaseValidate
+{
+    protected $rule = [
+        'nickname' => 'require',
+        'avatar' => 'require',
+        'account' => 'require',
+        'sex' => 'require',
+        'contact_people' => 'require',
+        'firmRegister.address' => 'require',
+        'firmRegister.firm_name' => 'require'
+//        'firmRegister' => [
+//            'address' => 'require',
+//            'firm_name' => 'require'
+//        ]
+
+    ];
+
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'nickname' => '昵称',
+        'avatar' => '头像',
+        'account' => '账户',
+        'sex' => '性别',
+        'firmRegister.address' => '公司地址',
+        'firmRegister.firm_name' => '公司名称',
+    ];
+    public function sceneSaveUserInfo()
+    {
+        return $this->only(['nickname','avatar','account','sex','firmRegister.address','firmRegister.firm_name']);
+    }
+}