138 lines
5.8 KiB
PHP
138 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace app\controller\api;
|
|
|
|
|
|
use app\services\supplier\SystemSupplierApplyServices;
|
|
use app\services\supplier\SystemSupplierServices;
|
|
use crmeb\basic\BaseController;
|
|
use think\App;
|
|
use think\exception\ValidateException;
|
|
|
|
class Supplier extends BaseController{
|
|
|
|
protected $services;
|
|
|
|
public function __construct(App $app, SystemSupplierServices $services){
|
|
parent::__construct($app);
|
|
$this->services = $services;
|
|
}
|
|
|
|
/**
|
|
* Common: 申请入驻
|
|
* Author: wu-hui
|
|
* Time: 2024/01/30 14:28
|
|
* @return mixed
|
|
*/
|
|
public function applyJoin(){
|
|
// 参数获取
|
|
$data = $this->checkParam();
|
|
if((int)$data['supplierApplyId'] > 0){
|
|
// 编辑账号信息
|
|
app()->make(SystemSupplierApplyServices::class)->editApplyInfo((array)$data);
|
|
}else{
|
|
// 添加账号
|
|
app()->make(SystemSupplierApplyServices::class)->createApplyInfo((array)$data);
|
|
}
|
|
|
|
return app('json')->success('操作成功');
|
|
}
|
|
/**
|
|
* Common: 申请信息接收
|
|
* Author: wu-hui
|
|
* Time: 2024/01/30 14:18
|
|
* @return array
|
|
*/
|
|
private function checkParam():array{
|
|
// 接收表单参数
|
|
$supplierApplyId = (int)$this->request->param('id');
|
|
$applyInfo = $this->request->params([
|
|
'invite_agent_id',
|
|
'winery_name',
|
|
'scale',
|
|
'cellar_size',
|
|
'corporation_name',
|
|
'corporation_phone',
|
|
['corporation_id_card',[]],
|
|
'chairman_name',
|
|
'chairman_phone',
|
|
['chairman_id_card',[]],
|
|
'contacts_name',
|
|
'contacts_phone',
|
|
'business_license',
|
|
'production_icense',
|
|
'circulative_license',
|
|
]);
|
|
$applyInfo['uid'] = $this->request->uid();
|
|
// 数据校验
|
|
if (empty($applyInfo['invite_agent_id'])) throw new ValidateException('非法请求,无有效邀请人!');
|
|
if (empty($applyInfo['winery_name'])) throw new ValidateException('请输入酒厂名称!');
|
|
if (empty($applyInfo['scale'])) throw new ValidateException('请输入年产量多少吨!');
|
|
if (empty($applyInfo['cellar_size'])) throw new ValidateException('请输入窖池大小!');
|
|
if (empty($applyInfo['corporation_name'])) throw new ValidateException('请输入法人姓名!');
|
|
if (empty($applyInfo['corporation_phone'])) throw new ValidateException('请输入法人电话!');
|
|
if (isPhone($applyInfo['corporation_phone'])) throw new ValidateException('请输入正确的法人电话!');
|
|
if (empty($applyInfo['corporation_id_card'])) throw new ValidateException('请上传法人身份证正反面图片!');
|
|
if (empty($applyInfo['chairman_name'])) throw new ValidateException('请输入董事长姓名!');
|
|
if (empty($applyInfo['chairman_phone'])) throw new ValidateException('请输入董事长电话!');
|
|
if (isPhone($applyInfo['chairman_phone'])) throw new ValidateException('请输入正确的董事长电话!');
|
|
if (empty($applyInfo['chairman_id_card'])) throw new ValidateException('请上传董事长身份证正反面图片!');
|
|
if (empty($applyInfo['contacts_name'])) throw new ValidateException('请输入联系人姓名!');
|
|
if (empty($applyInfo['contacts_phone'])) throw new ValidateException('请输入联系人电话!');
|
|
if (isPhone($applyInfo['contacts_phone'])) throw new ValidateException('请输入正确的联系人电话!');
|
|
if (empty($applyInfo['business_license'])) throw new ValidateException('请上传营业执照!');
|
|
if (empty($applyInfo['production_icense'])) throw new ValidateException('请上传生产许可证!');
|
|
if (empty($applyInfo['circulative_license'])) throw new ValidateException('请上传流通许可证!');
|
|
// 联系人及联系人手机号
|
|
$isHas = app()->make(SystemSupplierApplyServices::class)
|
|
->searchModel(['contacts_phone'=>$applyInfo['contacts_phone']])
|
|
->when($supplierApplyId > 0,function($query) use ($supplierApplyId){
|
|
$query->where('id','<>', $supplierApplyId);
|
|
})
|
|
->count();
|
|
if($isHas >= 1) throw new ValidateException('联系人已经存在,请勿重复申请!');
|
|
// 酒厂是否已经存在
|
|
$isHas = app()->make(SystemSupplierApplyServices::class)
|
|
->searchModel(['winery_name'=>$applyInfo['winery_name']])
|
|
->when($supplierApplyId > 0,function($query) use ($supplierApplyId){
|
|
$query->where('id','<>', $supplierApplyId);
|
|
})
|
|
->count();
|
|
if($isHas >= 1) throw new ValidateException('酒厂已经存在,请勿重复申请!');
|
|
$nameIsHave = $this->services->isHave('supplier_name',$applyInfo['winery_name']);
|
|
if($nameIsHave) throw new ValidateException('该酒厂已经入驻,请勿重复申请!');
|
|
|
|
|
|
return compact('supplierApplyId','applyInfo');
|
|
}
|
|
/**
|
|
* Common: 申请记录
|
|
* Author: wu-hui
|
|
* Time: 2024/01/30 17:11
|
|
* @return mixed
|
|
*/
|
|
public function applyRecord(){
|
|
$search = $this->request->params(['winery_name','contacts_name','contacts_phone','invite_agent_id','status']);
|
|
$search['uid'] = $this->request->uid();
|
|
[$page, $limit] = $this->getPage();
|
|
$data = app()->make(SystemSupplierApplyServices::class)->getList($search, $page, $limit);
|
|
|
|
return app('json')->success($data);
|
|
}
|
|
/**
|
|
* Common: 获取单条申请信息
|
|
* Author: wu-hui
|
|
* Time: 2024/01/30 17:35
|
|
* @return mixed
|
|
*/
|
|
public function applyInfo(){
|
|
$applyId = $this->request->param('apply_id');
|
|
$data = app()->make(SystemSupplierApplyServices::class)->getSingleInfo(['id'=>$applyId]);
|
|
|
|
return app('json')->success($data);
|
|
}
|
|
|
|
|
|
|
|
}
|