添加:门店入驻申请通过后添加默认管理员

This commit is contained in:
wuhui_zzw 2024-01-22 10:31:12 +08:00
parent b975289354
commit d17c7944ab
6 changed files with 126 additions and 59 deletions

View File

@ -5,6 +5,7 @@
namespace app\common\model\system\merchant;
use app\common\model\BaseModel;
use app\common\model\user\User;
class MerchantIntention extends BaseModel
{
@ -47,4 +48,20 @@ class MerchantIntention extends BaseModel
{
return $this->hasOne(MerchantType::class, 'mer_type_id', 'mer_type_id')->bind(['type_name']);
}
// 申请人
public function applicant(){
return $this->hasOne(User::class,'uid','uid');
}
// 默认管理员
public function manage(){
return $this->hasOne(User::class,'uid','manage_uid');
}
}

View File

@ -250,7 +250,7 @@ class StoreServiceRepository extends BaseRepository
/**
* Common: 判断:指定用户是否为员工
* Common: 判断:指定用户是否为有效员工
* Author: wu-hui
* Time: 2024/01/19 15:56
* @param int $uid
@ -259,19 +259,36 @@ class StoreServiceRepository extends BaseRepository
*/
public function isService(int $uid,int $id = 0):bool{
$count = $this->dao->getSearch([])
->where('uid',$uid)
->hasWhere('merchant',function($query){
$query->where('is_del', 0);
})
->where('StoreService.uid',$uid)
->where('StoreService.is_del', 0)
->when($id > 0,function($query) use ($id){
$query->where('service_id','<>',$id);
$query->where('StoreService.service_id','<>',$id);
})->count();
return $count > 0;
}
/**
* Common: 添加信息
* Author: wu-hui
* Time: 2024/01/22 9:16
* @param $data
* @return \app\common\dao\BaseDao|\think\Model
*/
public function createInfo($data){
// 判断当前用户是否已经成为员工
if($this->isService($data['uid'])) throw new ValidateException('该用户已绑定商户!');
if($this->dao->fieldExists('account', $data['account'])) throw new ValidateException('账号已存在!');
// 数据添加
$data['pwd'] = password_hash($data['pwd'], PASSWORD_BCRYPT);
return $this->dao->create($data);
}
}

View File

@ -4,7 +4,9 @@
namespace app\common\repositories\system\merchant;
use app\common\model\user\User;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\service\StoreServiceRepository;
use crmeb\jobs\SendSmsJob;
use crmeb\services\SmsService;
use FormBuilder\Factory\Elm;
@ -29,7 +31,18 @@ class MerchantIntentionRepository extends BaseRepository
{
$query = $this->dao->search($where);
$count = $query->count();
$list = $query->page($page, $limit)->order('create_time DESC , status ASC')->with(['merchantCategory', 'merchantType'])->select();
$list = $query->page($page, $limit)->order('create_time DESC , status ASC')
->with([
'merchantCategory',
'merchantType',
'applicant' => function($query){
$query->field('uid,nickname,avatar,real_name,phone');
},
'manage' => function($query){
$query->field('uid,nickname,avatar,real_name,phone');
}
])
->select();
return compact('count', 'list');
}
@ -107,29 +120,29 @@ class MerchantIntentionRepository extends BaseRepository
$data['margin'] = $margin['margin'] ?? 0;
$merData = [];
$smsData = [];
if ($create == 1) {
$password = substr($intention['phone'], -6);
$merData = [
'mer_name' => $intention['mer_name'],
'mer_phone' => $intention['phone'],
'mer_account' => $intention['phone'],
'category_id' => $intention['merchant_category_id'],
'type_id' => $intention['mer_type_id'],
'real_name' => $intention['name'],
'status' => 1,
'is_audit' => 1,
'is_bro_room' => $config['broadcast_room_type'] == 1 ? 0 : 1,
if($create == 1){
$password = substr($intention['phone'],-6);
$merData = [
'mer_name' => $intention['mer_name'],
'mer_phone' => $intention['phone'],
'mer_account' => $intention['phone'],
'category_id' => $intention['merchant_category_id'],
'type_id' => $intention['mer_type_id'],
'real_name' => $intention['name'],
'status' => 1,
'is_audit' => 1,
'is_bro_room' => $config['broadcast_room_type'] == 1 ? 0 : 1,
'is_bro_goods' => $config['broadcast_goods_type'] == 1 ? 0 : 1,
'mer_password' => $password,
'is_margin' => $margin['is_margin'] ?? -1,
'margin' => $margin['margin'] ?? 0
'is_margin' => $margin['is_margin'] ?? -1,
'margin' => $margin['margin'] ?? 0
];
$data['fail_msg'] = '';
$smsData = [
'date' => date('m月d日', strtotime($intention->create_time)),
'mer' => $intention['mer_name'],
'phone' => $intention['phone'],
'pwd' => $password ?? '',
$smsData = [
'date' => date('m月d日',strtotime($intention->create_time)),
'mer' => $intention['mer_name'],
'phone' => $intention['phone'],
'pwd' => $password ?? '',
'site_name' => systemConfig('site_name'),
];
}
@ -147,11 +160,37 @@ class MerchantIntentionRepository extends BaseRepository
if ($create == 1) {
$merchant = app()->make(MerchantRepository::class)->createMerchant($merData);
$data['mer_id'] = $merchant->mer_id;
// 存在默认管理员信息 生成管理员
if($intention->manage_uid > 0){
$staffUserInfo = User::where('uid',$intention->manage_uid)->findOrEmpty()->toArray();
$staffData = [
'uid' => $intention->manage_uid,
'nickname' => $staffUserInfo['nickname'] ?? $staffUserInfo['real_name'],
'account' => $intention->phone,
'pwd' => substr($intention->phone,-6,6),
'is_open' => 1,
'status' => 1,
'customer' => 1,
'is_verify' => 1,
'is_goods' => 1,
'is_user' => 1,
'staff_manage' => 1,
'notify' => 1,
'avatar' => $staffUserInfo['avatar'] ?? '',
'phone' => $intention->phone,
'sort' => 1,
'mer_id' => $merchant->mer_id,
'is_manage' => 1
];
app()->make(StoreServiceRepository::class)->createInfo($staffData);
}
Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_SUCCESS', 'id' => $smsData]);
}
} else {
Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_FAIL', 'id' => $smsData]);
}
$intention->save($data);
});
}
@ -168,6 +207,7 @@ class MerchantIntentionRepository extends BaseRepository
$count = $this->dao->getSearch([])
->where('manage_uid',$uid)
->where('status',0)
->where('is_del',0)
->when($id > 0,function($query) use ($id){
$query->where('mer_intention_id','<>',$id);
})->count();

View File

@ -57,13 +57,17 @@ class MerchantIntention extends BaseController
return app('json')->success('修改成功');
}
public function switchStatus($id)
{
if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
return app('json')->fail('数据不存在');
// 审核
public function switchStatus($id){
// 判断:信息是否存在
$isHas = $this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]);
if (!$isHas) return app('json')->fail('数据不存在');
// 参数获取
$data = $this->request->params(['status', 'fail_msg', 'create_mer']);
$data['status'] = $data['status'] == 1 ? 1 : 2;
$this->repository->updateStatus($id, $data);
return app('json')->success('修改成功');
}

View File

@ -74,23 +74,12 @@ class StoreService extends BaseController
return app('json')->success(formToData($this->repository->form($this->request->merId())));
}
/**
* @param StoreServiceValidate $validate
* @return mixed
* @author xaboy
* @day 2020/5/29
*/
public function create(StoreServiceValidate $validate)
{
// 添加员工
public function create(StoreServiceValidate $validate){
$data = $this->checkParams($validate);
$data['mer_id'] = $this->request->merId();
if ($this->repository->issetService($data['mer_id'], $data['uid']))
return app('json')->fail('该用户已绑定客服');
if ($this->repository->fieldExists('account', $data['account'])) {
return app('json')->fail('账号已存在');
}
$data['pwd'] = password_hash($data['pwd'], PASSWORD_BCRYPT);
$this->repository->create($data);
$this->repository->createInfo($data);
return app('json')->success('添加成功');
}
@ -133,7 +122,7 @@ class StoreService extends BaseController
$validate->check($data);
if (!$data['avatar']) $data['avatar'] = $data['uid']['src'];
if ($data['pwd'] && $data['pwd'] != $data['confirm_pwd']) {
throw new ValidateException('客服密码与确认密码不一致');
throw new ValidateException('员工密码与确认密码不一致');
}
$data['uid'] = $data['uid']['id'];
unset($data['confirm_pwd']);
@ -171,7 +160,7 @@ class StoreService extends BaseController
if (!$this->repository->merExists($merId = $this->request->merId(), $id))
return app('json')->fail('数据不存在');
if ($this->repository->issetService($merId, $data['uid'], $id))
return app('json')->fail('该用户已绑定客服');
return app('json')->fail('该用户已绑定员工');
if ($this->repository->fieldExists('account', $data['account'], $id)) {
return app('json')->fail('账号已存在');
}
@ -217,7 +206,7 @@ class StoreService extends BaseController
}
/**
* TODO 客服的全部用户
* TODO 员工的全部用户
* @param $id
* @return mixed
* @author Qinii
@ -245,7 +234,7 @@ class StoreService extends BaseController
}
/**
* TODO 用户与客服聊天记录
* TODO 用户与员工聊天记录
* @param $id
* @param $uid
* @return mixed
@ -256,7 +245,7 @@ class StoreService extends BaseController
{
[$page, $limit] = $this->getPage();
if (!$this->repository->getWhereCount(['service_id' => $id, 'mer_id' => $this->request->merId()]))
return app('json')->fail('客服不存在');
return app('json')->fail('员工不存在');
return app('json')->success($this->logRepository->getUserMsn($uid, $page, $limit, $this->request->merId(), $id));
}

View File

@ -13,12 +13,12 @@ class StoreServiceValidate extends Validate
protected $failException = true;
protected $rule = [
'uid|客服' => 'require|array',
'uid.id|客服' => 'require|integer',
'nickname|客服名称' => 'require|max:12',
'avatar|客服头像' => 'max:250',
'account|客服账号' => 'require|min:5|max:16',
'pwd|客服密码' => 'require|min:6|max:16',
'uid|员工' => 'require|array',
'uid.id|员工' => 'require|integer',
'nickname|员工名称' => 'require|max:12',
'avatar|员工头像' => 'max:250',
'account|员工账号' => 'require|min:5|max:16',
'pwd|员工密码' => 'require|min:6|max:16',
'confirm_pwd|确认密码' => 'require|min:6|max:16',
'is_open|状态' => 'require|in:0,1',
'status|状态' => 'require|in:0,1',
@ -30,14 +30,14 @@ class StoreServiceValidate extends Validate
];
protected $message = [
'account.min' => '客服账号长度不能小于5个字符',
'uid.require' => '请选择一个用户绑定为客服',
'account.min' => '员工账号长度不能小于5个字符',
'uid.require' => '请选择一个用户绑定为员工',
'uid.id.require' => '用户ID不能为空'
];
public function update()
{
$this->rule['pwd|客服密码'] = 'min:6|max:16';
$this->rule['pwd|员工密码'] = 'min:6|max:16';
$this->rule['confirm_pwd|确认密码'] = 'min:6|max:16';
return $this;
}