添加:门店入驻申请通过后添加默认管理员
This commit is contained in:
parent
b975289354
commit
d17c7944ab
|
|
@ -5,6 +5,7 @@
|
||||||
namespace app\common\model\system\merchant;
|
namespace app\common\model\system\merchant;
|
||||||
|
|
||||||
use app\common\model\BaseModel;
|
use app\common\model\BaseModel;
|
||||||
|
use app\common\model\user\User;
|
||||||
|
|
||||||
class MerchantIntention extends BaseModel
|
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']);
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,7 @@ class StoreServiceRepository extends BaseRepository
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common: 判断:指定用户是否为员工
|
* Common: 判断:指定用户是否为有效员工
|
||||||
* Author: wu-hui
|
* Author: wu-hui
|
||||||
* Time: 2024/01/19 15:56
|
* Time: 2024/01/19 15:56
|
||||||
* @param int $uid
|
* @param int $uid
|
||||||
|
|
@ -259,19 +259,36 @@ class StoreServiceRepository extends BaseRepository
|
||||||
*/
|
*/
|
||||||
public function isService(int $uid,int $id = 0):bool{
|
public function isService(int $uid,int $id = 0):bool{
|
||||||
$count = $this->dao->getSearch([])
|
$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){
|
->when($id > 0,function($query) use ($id){
|
||||||
$query->where('service_id','<>',$id);
|
$query->where('StoreService.service_id','<>',$id);
|
||||||
})->count();
|
})->count();
|
||||||
|
|
||||||
return $count > 0;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@
|
||||||
|
|
||||||
namespace app\common\repositories\system\merchant;
|
namespace app\common\repositories\system\merchant;
|
||||||
|
|
||||||
|
use app\common\model\user\User;
|
||||||
use app\common\repositories\BaseRepository;
|
use app\common\repositories\BaseRepository;
|
||||||
|
use app\common\repositories\store\service\StoreServiceRepository;
|
||||||
use crmeb\jobs\SendSmsJob;
|
use crmeb\jobs\SendSmsJob;
|
||||||
use crmeb\services\SmsService;
|
use crmeb\services\SmsService;
|
||||||
use FormBuilder\Factory\Elm;
|
use FormBuilder\Factory\Elm;
|
||||||
|
|
@ -29,7 +31,18 @@ class MerchantIntentionRepository extends BaseRepository
|
||||||
{
|
{
|
||||||
$query = $this->dao->search($where);
|
$query = $this->dao->search($where);
|
||||||
$count = $query->count();
|
$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');
|
return compact('count', 'list');
|
||||||
}
|
}
|
||||||
|
|
@ -107,29 +120,29 @@ class MerchantIntentionRepository extends BaseRepository
|
||||||
$data['margin'] = $margin['margin'] ?? 0;
|
$data['margin'] = $margin['margin'] ?? 0;
|
||||||
$merData = [];
|
$merData = [];
|
||||||
$smsData = [];
|
$smsData = [];
|
||||||
if ($create == 1) {
|
if($create == 1){
|
||||||
$password = substr($intention['phone'], -6);
|
$password = substr($intention['phone'],-6);
|
||||||
$merData = [
|
$merData = [
|
||||||
'mer_name' => $intention['mer_name'],
|
'mer_name' => $intention['mer_name'],
|
||||||
'mer_phone' => $intention['phone'],
|
'mer_phone' => $intention['phone'],
|
||||||
'mer_account' => $intention['phone'],
|
'mer_account' => $intention['phone'],
|
||||||
'category_id' => $intention['merchant_category_id'],
|
'category_id' => $intention['merchant_category_id'],
|
||||||
'type_id' => $intention['mer_type_id'],
|
'type_id' => $intention['mer_type_id'],
|
||||||
'real_name' => $intention['name'],
|
'real_name' => $intention['name'],
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'is_audit' => 1,
|
'is_audit' => 1,
|
||||||
'is_bro_room' => $config['broadcast_room_type'] == 1 ? 0 : 1,
|
'is_bro_room' => $config['broadcast_room_type'] == 1 ? 0 : 1,
|
||||||
'is_bro_goods' => $config['broadcast_goods_type'] == 1 ? 0 : 1,
|
'is_bro_goods' => $config['broadcast_goods_type'] == 1 ? 0 : 1,
|
||||||
'mer_password' => $password,
|
'mer_password' => $password,
|
||||||
'is_margin' => $margin['is_margin'] ?? -1,
|
'is_margin' => $margin['is_margin'] ?? -1,
|
||||||
'margin' => $margin['margin'] ?? 0
|
'margin' => $margin['margin'] ?? 0
|
||||||
];
|
];
|
||||||
$data['fail_msg'] = '';
|
$data['fail_msg'] = '';
|
||||||
$smsData = [
|
$smsData = [
|
||||||
'date' => date('m月d日', strtotime($intention->create_time)),
|
'date' => date('m月d日',strtotime($intention->create_time)),
|
||||||
'mer' => $intention['mer_name'],
|
'mer' => $intention['mer_name'],
|
||||||
'phone' => $intention['phone'],
|
'phone' => $intention['phone'],
|
||||||
'pwd' => $password ?? '',
|
'pwd' => $password ?? '',
|
||||||
'site_name' => systemConfig('site_name'),
|
'site_name' => systemConfig('site_name'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
@ -147,11 +160,37 @@ class MerchantIntentionRepository extends BaseRepository
|
||||||
if ($create == 1) {
|
if ($create == 1) {
|
||||||
$merchant = app()->make(MerchantRepository::class)->createMerchant($merData);
|
$merchant = app()->make(MerchantRepository::class)->createMerchant($merData);
|
||||||
$data['mer_id'] = $merchant->mer_id;
|
$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]);
|
Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_SUCCESS', 'id' => $smsData]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_FAIL', 'id' => $smsData]);
|
Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_FAIL', 'id' => $smsData]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$intention->save($data);
|
$intention->save($data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -168,6 +207,7 @@ class MerchantIntentionRepository extends BaseRepository
|
||||||
$count = $this->dao->getSearch([])
|
$count = $this->dao->getSearch([])
|
||||||
->where('manage_uid',$uid)
|
->where('manage_uid',$uid)
|
||||||
->where('status',0)
|
->where('status',0)
|
||||||
|
->where('is_del',0)
|
||||||
->when($id > 0,function($query) use ($id){
|
->when($id > 0,function($query) use ($id){
|
||||||
$query->where('mer_intention_id','<>',$id);
|
$query->where('mer_intention_id','<>',$id);
|
||||||
})->count();
|
})->count();
|
||||||
|
|
|
||||||
|
|
@ -57,13 +57,17 @@ class MerchantIntention extends BaseController
|
||||||
return app('json')->success('修改成功');
|
return app('json')->success('修改成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function switchStatus($id)
|
// 审核
|
||||||
{
|
public function switchStatus($id){
|
||||||
if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
|
// 判断:信息是否存在
|
||||||
return app('json')->fail('数据不存在');
|
$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 = $this->request->params(['status', 'fail_msg', 'create_mer']);
|
||||||
$data['status'] = $data['status'] == 1 ? 1 : 2;
|
$data['status'] = $data['status'] == 1 ? 1 : 2;
|
||||||
$this->repository->updateStatus($id, $data);
|
$this->repository->updateStatus($id, $data);
|
||||||
|
|
||||||
|
|
||||||
return app('json')->success('修改成功');
|
return app('json')->success('修改成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,23 +74,12 @@ class StoreService extends BaseController
|
||||||
return app('json')->success(formToData($this->repository->form($this->request->merId())));
|
return app('json')->success(formToData($this->repository->form($this->request->merId())));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// 添加员工
|
||||||
* @param StoreServiceValidate $validate
|
public function create(StoreServiceValidate $validate){
|
||||||
* @return mixed
|
|
||||||
* @author xaboy
|
|
||||||
* @day 2020/5/29
|
|
||||||
*/
|
|
||||||
public function create(StoreServiceValidate $validate)
|
|
||||||
{
|
|
||||||
$data = $this->checkParams($validate);
|
$data = $this->checkParams($validate);
|
||||||
$data['mer_id'] = $this->request->merId();
|
$data['mer_id'] = $this->request->merId();
|
||||||
if ($this->repository->issetService($data['mer_id'], $data['uid']))
|
$this->repository->createInfo($data);
|
||||||
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);
|
|
||||||
return app('json')->success('添加成功');
|
return app('json')->success('添加成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,7 +122,7 @@ class StoreService extends BaseController
|
||||||
$validate->check($data);
|
$validate->check($data);
|
||||||
if (!$data['avatar']) $data['avatar'] = $data['uid']['src'];
|
if (!$data['avatar']) $data['avatar'] = $data['uid']['src'];
|
||||||
if ($data['pwd'] && $data['pwd'] != $data['confirm_pwd']) {
|
if ($data['pwd'] && $data['pwd'] != $data['confirm_pwd']) {
|
||||||
throw new ValidateException('客服密码与确认密码不一致');
|
throw new ValidateException('员工密码与确认密码不一致');
|
||||||
}
|
}
|
||||||
$data['uid'] = $data['uid']['id'];
|
$data['uid'] = $data['uid']['id'];
|
||||||
unset($data['confirm_pwd']);
|
unset($data['confirm_pwd']);
|
||||||
|
|
@ -171,7 +160,7 @@ class StoreService extends BaseController
|
||||||
if (!$this->repository->merExists($merId = $this->request->merId(), $id))
|
if (!$this->repository->merExists($merId = $this->request->merId(), $id))
|
||||||
return app('json')->fail('数据不存在');
|
return app('json')->fail('数据不存在');
|
||||||
if ($this->repository->issetService($merId, $data['uid'], $id))
|
if ($this->repository->issetService($merId, $data['uid'], $id))
|
||||||
return app('json')->fail('该用户已绑定客服');
|
return app('json')->fail('该用户已绑定员工');
|
||||||
if ($this->repository->fieldExists('account', $data['account'], $id)) {
|
if ($this->repository->fieldExists('account', $data['account'], $id)) {
|
||||||
return app('json')->fail('账号已存在');
|
return app('json')->fail('账号已存在');
|
||||||
}
|
}
|
||||||
|
|
@ -217,7 +206,7 @@ class StoreService extends BaseController
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO 客服的全部用户
|
* TODO 员工的全部用户
|
||||||
* @param $id
|
* @param $id
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @author Qinii
|
* @author Qinii
|
||||||
|
|
@ -245,7 +234,7 @@ class StoreService extends BaseController
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO 用户与客服聊天记录
|
* TODO 用户与员工聊天记录
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param $uid
|
* @param $uid
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|
@ -256,7 +245,7 @@ class StoreService extends BaseController
|
||||||
{
|
{
|
||||||
[$page, $limit] = $this->getPage();
|
[$page, $limit] = $this->getPage();
|
||||||
if (!$this->repository->getWhereCount(['service_id' => $id, 'mer_id' => $this->request->merId()]))
|
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));
|
return app('json')->success($this->logRepository->getUserMsn($uid, $page, $limit, $this->request->merId(), $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@ class StoreServiceValidate extends Validate
|
||||||
protected $failException = true;
|
protected $failException = true;
|
||||||
|
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'uid|客服' => 'require|array',
|
'uid|员工' => 'require|array',
|
||||||
'uid.id|客服' => 'require|integer',
|
'uid.id|员工' => 'require|integer',
|
||||||
'nickname|客服名称' => 'require|max:12',
|
'nickname|员工名称' => 'require|max:12',
|
||||||
'avatar|客服头像' => 'max:250',
|
'avatar|员工头像' => 'max:250',
|
||||||
'account|客服账号' => 'require|min:5|max:16',
|
'account|员工账号' => 'require|min:5|max:16',
|
||||||
'pwd|客服密码' => 'require|min:6|max:16',
|
'pwd|员工密码' => 'require|min:6|max:16',
|
||||||
'confirm_pwd|确认密码' => 'require|min:6|max:16',
|
'confirm_pwd|确认密码' => 'require|min:6|max:16',
|
||||||
'is_open|状态' => 'require|in:0,1',
|
'is_open|状态' => 'require|in:0,1',
|
||||||
'status|状态' => 'require|in:0,1',
|
'status|状态' => 'require|in:0,1',
|
||||||
|
|
@ -30,14 +30,14 @@ class StoreServiceValidate extends Validate
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $message = [
|
protected $message = [
|
||||||
'account.min' => '客服账号长度不能小于5个字符',
|
'account.min' => '员工账号长度不能小于5个字符',
|
||||||
'uid.require' => '请选择一个用户绑定为客服',
|
'uid.require' => '请选择一个用户绑定为员工',
|
||||||
'uid.id.require' => '用户ID不能为空'
|
'uid.id.require' => '用户ID不能为空'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function update()
|
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';
|
$this->rule['confirm_pwd|确认密码'] = 'min:6|max:16';
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue