修改:商户入驻申请时 - 管理员必须唯一且必须存在

添加:管理员是否有效判断、用户搜索接口
This commit is contained in:
wuhui_zzw 2024-01-19 17:08:48 +08:00
parent 8c8eb991fb
commit b975289354
6 changed files with 161 additions and 48 deletions

View File

@ -61,7 +61,6 @@ class StoreServiceRepository extends BaseRepository
$list = $query->page($page, $limit)->select();
return compact('count', 'list');
}
/**
* @return Form
* @throws FormBuilderException
@ -113,7 +112,6 @@ class StoreServiceRepository extends BaseRepository
Elm::switches('is_open', '账号状态', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8)->control([$filed]),
], $adminRule))->setTitle('添加员工');
}
/**
* @param $id
* @return Form
@ -137,7 +135,6 @@ class StoreServiceRepository extends BaseRepository
unset($service['user'], $service['pwd']);
return $this->form($service['mer_id'], true)->formData($service)->setTitle('编辑表单')->setAction(Route::buildUrl('merchantServiceUpdate', compact('id'))->build());
}
/**
* @param $merId
* @param $uid
@ -162,7 +159,6 @@ class StoreServiceRepository extends BaseRepository
$service = $this->dao->getRandService($merId);
if ($service) return $service;
}
public function getServices($uid, array $where = [],$is_sys = 1)
{
$order = $is_sys ? 'ASC' : 'DESC';
@ -183,7 +179,6 @@ class StoreServiceRepository extends BaseRepository
unset($item);
return $list;
}
public function createToken(StoreService $admin)
{
$service = new JwtTokenService();
@ -192,7 +187,6 @@ class StoreServiceRepository extends BaseRepository
$this->cacheToken($token['token'], $token['out']);
return $token;
}
/**
* @param string $token
* @param int $exp
@ -203,7 +197,6 @@ class StoreServiceRepository extends BaseRepository
{
Cache::set('service_' . $token, time() + $exp, $exp);
}
public function checkToken(string $token)
{
$has = Cache::has('service_' . $token);
@ -213,18 +206,14 @@ class StoreServiceRepository extends BaseRepository
if (($lastTime + (intval(Config::get('admin.token_valid_exp', 15))) * 60) < time())
throw new AuthException('token 已过期');
}
public function updateToken(string $token)
{
Cache::set('service_' . $token, time(), intval(Config::get('admin.token_valid_exp', 15)) * 60);
}
public function clearToken(string $token)
{
Cache::delete('service_' . $token);
}
/**
* 检测验证码
* @param string $key key
@ -246,8 +235,6 @@ class StoreServiceRepository extends BaseRepository
//删除code
Cache::delete('ser_captcha' . $key);
}
/**
* @param string $code
* @return string
@ -260,4 +247,31 @@ class StoreServiceRepository extends BaseRepository
Cache::set('ser_captcha' . $key, $code, Config::get('admin.captcha_exp', 5) * 60);
return $key;
}
/**
* Common: 判断:指定用户是否为员工
* Author: wu-hui
* Time: 2024/01/19 15:56
* @param int $uid
* @param int $id
* @return bool
*/
public function isService(int $uid,int $id = 0):bool{
$count = $this->dao->getSearch([])
->where('uid',$uid)
->when($id > 0,function($query) use ($id){
$query->where('service_id','<>',$id);
})->count();
return $count > 0;
}
}

View File

@ -156,4 +156,28 @@ class MerchantIntentionRepository extends BaseRepository
});
}
/**
* Common: 判断:指定用户是否存在审核中店铺的管理员信息
* Author: wu-hui
* Time: 2024/01/19 15:59
* @param int $uid
* @param int $id
* @return bool
*/
public function isManage(int $uid,int $id = 0):bool{
$count = $this->dao->getSearch([])
->where('manage_uid',$uid)
->where('status',0)
->when($id > 0,function($query) use ($id){
$query->where('mer_intention_id','<>',$id);
})->count();
return $count > 0;
}
}

View File

@ -728,5 +728,27 @@ class Auth extends BaseController
return app('json')->fail(400336);
}
}
/**
* Common: 搜索用户
* Author: wu-hui
* Time: 2024/01/19 15:08
* @return mixed
*/
public function searchUser(){
$search = $this->request->params(['id_and_phone']);
$userInfo = app()->make(UserRepository::class)
->getSearch([])
->field(['uid','real_name','nickname','avatar','phone'])
// 用户ID/联系电话
->when(!empty($search['id_and_phone']),function($query) use ($search){
$query->where(function($query) use ($search){
$query->where('uid',$search['id_and_phone'])->whereOr('phone',$search['id_and_phone']);
});
})
->findOrEmpty();
return app('json')->success($userInfo);
}
}

View File

@ -4,6 +4,7 @@
namespace app\controller\api\store\merchant;
use app\common\repositories\store\service\StoreServiceRepository;
use app\common\repositories\system\merchant\MerchantAdminRepository;
use app\common\repositories\system\merchant\MerchantCategoryRepository;
use app\common\repositories\system\merchant\MerchantRepository;
@ -29,44 +30,39 @@ class MerchantIntention extends BaseController
$this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
}
public function create()
{
// 提交入驻申请
public function create(){
// 参数获取
if(!systemConfig('mer_intention_open')) return app('json')->fail('未开启商户入驻');
$data = $this->checkParams();
if (!systemConfig('mer_intention_open')) {
return app('json')->fail('未开启商户入驻');
}
if ($this->userInfo) $data['uid'] = $this->userInfo->uid;
if($this->userInfo) $data['uid'] = $this->userInfo->uid;
$make = app()->make(MerchantRepository::class);
if ($make->fieldExists('mer_name', $data['mer_name']))
throw new ValidateException('商户名称已存在,不可申请');
if ($make->fieldExists('mer_phone', $data['phone']))
throw new ValidateException('手机号已存在,不可申请');
if($make->fieldExists('mer_name',$data['mer_name'])) throw new ValidateException('商户名称已存在,不可申请');
if($make->fieldExists('mer_phone',$data['phone'])) throw new ValidateException('手机号已存在,不可申请');
$adminRepository = app()->make(MerchantAdminRepository::class);
if ($adminRepository->fieldExists('account', $data['phone']))
throw new ValidateException('手机号已是管理员,不可申请');
if($adminRepository->fieldExists('account',$data['phone'])) throw new ValidateException('手机号已是管理员,不可申请');
$intention = $this->repository->create($data);
SwooleTaskService::admin('notice', [
SwooleTaskService::admin('notice',[
'type' => 'new_intention',
'data' => [
'title' => '商户入驻申请',
'title' => '商户入驻申请',
'message' => '您有一个新的商户入驻申请',
'id' => $intention->mer_intention_id
'id' => $intention->mer_intention_id
]
]);
return app('json')->success('提交成功');
}
public function update($id)
{
if (!$this->repository->getWhere(['mer_intention_id' => (int)$id, 'uid' => $this->userInfo->uid, 'is_del' => 0]))
return app('json')->fail('数据不存在');
$data = $this->checkParams();
if (!systemConfig('mer_intention_open')) {
return app('json')->fail('未开启商户入驻');
}
$data['create_time'] = date('Y-m-d H:i:s', time());
$this->repository->updateIntention((int)$id, $data);
SwooleTaskService::admin('notice', [
// 修改入驻申请
public function update($id){
if(!systemConfig('mer_intention_open')) return app('json')->fail('未开启商户入驻');
// 数据是否存在
$isHas = $this->repository->getWhere(['mer_intention_id' => (int)$id,'uid' => $this->userInfo->uid,'is_del' => 0]);
if(!$isHas) return app('json')->fail('数据不存在');
// 参数处理
$data = $this->checkParams($id);
$data['create_time'] = date('Y-m-d H:i:s',time());
$this->repository->updateIntention((int)$id,$data);
SwooleTaskService::admin('notice',[
'type' => 'new_intention',
'data' => [
'title' => '商户入驻申请',
@ -96,16 +92,27 @@ class MerchantIntention extends BaseController
return app('json')->success($data);
}
protected function checkParams()
{
$data = $this->request->params(['phone', 'mer_name', 'name', 'code', 'images', 'merchant_category_id', 'mer_type_id']);
// 接收参数处理
protected function checkParams($id = 0){
// 参数获取
$data = $this->request->params(['phone','mer_name','name','code','images','merchant_category_id','mer_type_id','manage_uid']);
app()->make(MerchantIntentionValidate::class)->check($data);
$check = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['code'], 'intention');
$check = app()->make(SmsService::class)->checkSmsCode($data['phone'],$data['code'],'intention');
$data['mer_type_id'] = (int)$data['mer_type_id'];
if (!$check) throw new ValidateException('验证码不正确');
if (!app()->make(MerchantCategoryRepository::class)->get($data['merchant_category_id'])) throw new ValidateException('商户分类不存在');
if ($data['mer_type_id'] && !app()->make(MerchantTypeRepository::class)->exists($data['mer_type_id']))
throw new ValidateException('店铺类型不存在');
if(!$check) throw new ValidateException('验证码不正确');
// 判断:商户分类是否存在
$cateIsHas = app()->make(MerchantCategoryRepository::class)->get($data['merchant_category_id']);
if(!$cateIsHas) throw new ValidateException('商户分类不存在');
// 判断:商户类型是否存在
$typeIsHas = app()->make(MerchantTypeRepository::class)->exists($data['mer_type_id']);
if($data['mer_type_id'] && !$typeIsHas) throw new ValidateException('店铺类型不存在');
// 判断:当前管理员身份是否有效
$isService = app()->make(StoreServiceRepository::class)->isService($data['manage_uid'], $id);// 是否存在店员信息
if($isService) throw new ValidateException('管理员身份无效,已成为其他商户管理员或店员!');
$isManage = app()->make(repository::class)->isManage($data['manage_uid'], $id);// 是否存在审核中店长信息
if($isManage) throw new ValidateException('管理员身份无效,已成为其他商户管理员!');
unset($data['code']);
return $data;
}
@ -127,5 +134,41 @@ class MerchantIntention extends BaseController
$lst = app()->make(MerchantTypeRepository::class)->getSelect();
return app('json')->success($lst);
}
/**
* Common: 管理员身份是否有效
* Author: wu-hui
* Time: 2024/01/19 16:20
* @return mixed
*/
public function manageIsEligible(){
$data = $this->request->params(['service_id', 'mer_intention_id' ,'manage_uid']);
$returnData = [
'is_eligible' => true,
'msg' => '有效'
];
// 判断:当前管理员身份是否有效
$isService = app()->make(StoreServiceRepository::class)->isService((int)$data['manage_uid'], (int)$data['service_id']);// 是否存在店员信息
if($isService){
$returnData = [
'is_eligible' => false,
'msg' => '管理员身份无效,已成为其他商户管理员或店员!'
];
}
$isManage = app()->make(repository::class)->isManage((int)$data['manage_uid'], (int)$data['mer_intention_id']);// 是否存在审核中店长信息
if($isManage) {
$returnData = [
'is_eligible' => false,
'msg' => '管理员身份无效,已成为其他商户管理员!'
];
}
return app('json')->success($returnData);
}
}

View File

@ -19,5 +19,12 @@ class MerchantIntentionValidate extends Validate
'mer_type_id|店铺类型' => 'integer',
'code|验证码' => 'require',
'images|资质' => 'array',
'manage_uid|管理员' => 'require',
];
}

View File

@ -28,6 +28,8 @@ Route::group('api/', function () {
Route::get('user', 'api.Auth/userInfo');
//绑定推荐人
Route::post('user/spread', 'api.Auth/spread');
//用户信息
Route::get('searchUser', 'api.Auth/searchUser');
//优惠券
Route::group('coupon', function () {
Route::post('receive/:id', 'api.store.product.StoreCoupon/receiveCoupon');
@ -523,6 +525,7 @@ Route::group('api/', function () {
Route::post('intention/create', 'api.store.merchant.MerchantIntention/create');
Route::get('intention/cate', 'api.store.merchant.MerchantIntention/cateLst');
Route::get('intention/type', 'api.store.merchant.MerchantIntention/typeLst');
Route::get('intention/manageIsEligible', 'api.store.merchant.MerchantIntention/manageIsEligible');
//浏览
Route::post('common/visit', 'api.Common/visit');
Route::get('store/product/assist/count', 'api.store.product.StoreProductAssist/userCount');