UserLogic.php 3.7 KB
<?php

namespace App\Http\Logic\Bside\User;

use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\SmsLog;
use App\Models\User\ProjectRole as ProjectRoleModel;
use App\Models\User\User;
use Illuminate\Support\Facades\Cache;

class UserLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->model = new User();
        $this->param = $this->requestAll;
    }

    /**
     * @remark :获取用户详情
     * @name   :User_info
     * @author :lyh
     * @method :post
     * @time   :2023/6/17 16:42
     */
    public function user_info(){
        $info = $this->model->read($this->param);
        return $this->success($info);
    }

    /**
     * @remark :添加用户
     * @name   :user_add
     * @author :lyh
     * @method :post
     * @time   :2023/6/17 16:42
     */
    public function user_add(){
        //验证当前用户是否存在
        $info = $this->model->read(['mobile'=>$this->param['mobile']]);
        if($info !== false){
            $this->fail('当前手机号码已注册');
        }
        $this->param['create_id'] = $this->user['id'];
        $this->param['operator_id'] = $this->user['id'];
        $this->param['project_id'] = $this->user['project_id'];
        $this->param['type'] = 1;
        //密码加密
        $this->param['password'] = base64_encode(md5($this->param['password']));
        $rs = $this->model->add($this->param);
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @remark :编辑用户
     * @name   :user_edit
     * @author :lyh
     * @method :post
     * @time   :2023/6/17 16:42
     */
    public function user_edit(){
        $condition = [
            'id'=>['!=',$this->param['id']],
            'mobile'=>$this->param['mobile']
        ];
        $info = $this->model->read($condition);
        if($info !== false){
            $this->fail('当前编辑的手机号码已存在');
        }
        $this->param['type'] = 1;
        $this->param['operator_id'] = $this->user['id'];
        $this->edits($this->param);
        return $this->success();
    }

    /**
     * @remark :编辑状态与排序
     * @name   :user_status
     * @author :lyh
     * @method :post
     * @time   :2023/6/17 16:41
     */
    public function user_status(){
        $this->param['operator_id'] = $this->user['id'];
        $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
        if($rs === false){
            $this->fail('error',Code::USER_ERROR);
        }
        return $this->success();
    }

    /**
     * @remark :删除用户
     * @name   :user_del
     * @author :lyh
     * @method :post
     * @time   :2023/6/17 16:41
     */
    public function user_del(){
        $this->param['id'] = ['in',$this->param['id']];
        $this->model->del($this->param);
        //对应删除组织架构
        return $this->success();
    }

    /**
     * @param $param
     * @remark :编辑用户
     * @name   :edits
     * @author :lyh
     * @method :post
     * @time   :2023/6/17 16:41
     */
    public function edits($param){
        //查看密码是否修改
        $info = $this->model->read(['id'=>$param['id']]);
        $param['password'] = base64_encode(md5($param['password']));
        if($param['password'] == $info['password']){
            unset($param['password']);
        }
        //密码加密
        $rs = $this->model->edit($param,['id'=>$param['id']]);
        if($rs === false){
            $this->fail('系统错误,请联系管理员');
        }
        //清空当前用户登录缓存
        Cache::pull($info['token']);
        return $this->success();
    }
}