181 lines
7.2 KiB
PHP
181 lines
7.2 KiB
PHP
<?php
|
|
|
|
|
|
|
|
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;
|
|
use app\common\repositories\system\merchant\MerchantTypeRepository;
|
|
use app\validate\api\MerchantIntentionValidate;
|
|
use crmeb\services\SmsService;
|
|
use crmeb\services\SwooleTaskService;
|
|
use crmeb\services\YunxinSmsService;
|
|
use think\App;
|
|
use crmeb\basic\BaseController;
|
|
use app\common\repositories\system\merchant\MerchantIntentionRepository as repository;
|
|
use think\exception\ValidateException;
|
|
|
|
class MerchantIntention extends BaseController
|
|
{
|
|
protected $repository;
|
|
protected $userInfo;
|
|
|
|
public function __construct(App $app, repository $repository)
|
|
{
|
|
parent::__construct($app);
|
|
$this->repository = $repository;
|
|
$this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
|
|
}
|
|
|
|
// 提交入驻申请
|
|
public function create(){
|
|
// 参数获取
|
|
if(!systemConfig('mer_intention_open')) return app('json')->fail('未开启商户入驻');
|
|
$data = $this->checkParams();
|
|
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('手机号已存在,不可申请');
|
|
$adminRepository = app()->make(MerchantAdminRepository::class);
|
|
if($adminRepository->fieldExists('account',$data['phone'])) throw new ValidateException('手机号已是管理员,不可申请');
|
|
$intention = $this->repository->create($data);
|
|
SwooleTaskService::admin('notice',[
|
|
'type' => 'new_intention',
|
|
'data' => [
|
|
'title' => '商户入驻申请',
|
|
'message' => '您有一个新的商户入驻申请',
|
|
'id' => $intention->mer_intention_id
|
|
]
|
|
]);
|
|
return app('json')->success('提交成功');
|
|
}
|
|
// 修改入驻申请
|
|
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' => '商户入驻申请',
|
|
'message' => '您有一个新的商户入驻申请',
|
|
'id' => $id
|
|
]
|
|
]);
|
|
return app('json')->success('修改成功');
|
|
}
|
|
|
|
public function lst(){
|
|
$merchantType = $this->request->param('merchant_type', 0);
|
|
|
|
[$page, $limit] = $this->getPage();
|
|
$data = $this->repository->getList([
|
|
'uid' => $this->userInfo->uid,
|
|
'merchant_type' => $merchantType
|
|
],$page,$limit);
|
|
return app('json')->success($data);
|
|
}
|
|
|
|
function detail($id)
|
|
{
|
|
$data = $this->repository->detail((int)$id, $this->userInfo->uid);
|
|
if (!$data) {
|
|
return app('json')->fail('数据不存在');
|
|
}
|
|
if ($data->status == 1) {
|
|
$data['login_url'] = rtrim(systemConfig('site_url'), '/') . '/' . config('admin.merchant_prefix');
|
|
}
|
|
return app('json')->success($data);
|
|
}
|
|
|
|
// 接收参数处理
|
|
protected function checkParams($id = 0){
|
|
// 参数获取
|
|
$data = $this->request->params(['phone','mer_name','name','code','images','merchant_category_id','mer_type_id','manage_uid',['agent_id', 0],['merchant_type',0],['merchant_sub_type',0]]);
|
|
app()->make(MerchantIntentionValidate::class)->check($data);
|
|
// $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(!in_array((int)$data['merchant_type'],[1,3,4,5,6,7])){
|
|
// 判断:商户分类是否存在
|
|
$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, 1);// 是否存在店员信息
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* 商户分类
|
|
* @Author:Qinii
|
|
* @Date: 2020/9/15
|
|
* @return mixed
|
|
*/
|
|
public function cateLst()
|
|
{
|
|
$lst = app()->make(MerchantCategoryRepository::class)->getSelect();
|
|
return app('json')->success($lst);
|
|
}
|
|
|
|
public function typeLst()
|
|
{
|
|
$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', 'merchant_type']);
|
|
$returnData = [
|
|
'is_eligible' => true,
|
|
'msg' => '有效'
|
|
];
|
|
// 判断:当前管理员身份是否有效
|
|
$isService = app()->make(StoreServiceRepository::class)->isService((int)$data['manage_uid'], (int)$data['service_id'], 1, $data['merchant_type']);// 是否存在店员信息
|
|
if($isService){
|
|
$returnData = [
|
|
'is_eligible' => false,
|
|
'msg' => '管理员身份无效,已成为其他商户管理员或店员!'
|
|
];
|
|
}
|
|
$isManage = app()->make(repository::class)->isManage((int)$data['manage_uid'], (int)$data['mer_intention_id'], $data['merchant_type']);// 是否存在审核中店长信息
|
|
if($isManage) {
|
|
$returnData = [
|
|
'is_eligible' => false,
|
|
'msg' => '管理员身份无效,已成为其他商户管理员!'
|
|
];
|
|
}
|
|
|
|
|
|
return app('json')->success($returnData);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|