diff --git a/app/controller/admin/supplier/Apply.php b/app/controller/admin/supplier/Apply.php new file mode 100644 index 0000000..cba51a6 --- /dev/null +++ b/app/controller/admin/supplier/Apply.php @@ -0,0 +1,55 @@ +services = $services; + } + /** + * Common: 列表获取 + * Author: wu-hui + * Time: 2024/01/30 15:13 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function applyList(){ + $search = $this->request->params(['winery_name','contacts_name','contacts_phone','invite_agent_id','status']); + [$page, $limit] = $this->getPage(); + $data = $this->services->getList($search, $page, $limit); + + return app('json')->success($data); + } + /** + * Common: 审核 + * Author: wu-hui + * Time: 2024/01/30 15:53 + * @return mixed + */ + public function toExamine(){ + // 参数获取 + $params = $this->request->params(['id','status','reason']); + if($params['id'] <= 0) throw new ValidateException('方法请求,信息不明确!'); + // 审核通过 主动生成账号 + if((int)$params['status'] === 1){ + // 审核通过 + $this->services->toExaminePass((array)$params); + }else{ + // 驳回 + $this->services->update($params['id'],['status'=>$params['status'],'reason'=>$params['reason']]); + } + + return app('json')->success('操作成功'); + } + + +} diff --git a/app/controller/api/Supplier.php b/app/controller/api/Supplier.php index 78df55e..4187618 100644 --- a/app/controller/api/Supplier.php +++ b/app/controller/api/Supplier.php @@ -85,13 +85,17 @@ class Supplier extends BaseController{ // 联系人及联系人手机号 $isHas = app()->make(SystemSupplierApplyServices::class)->searchModel(['contacts_phone'=>$applyInfo['contacts_phone']])->count(); if($isHas >= 1) throw new ValidateException('联系人已经存在,请勿重复申请!'); + // 酒厂是否已经存在 + $isHas = app()->make(SystemSupplierApplyServices::class)->searchModel(['winery_name'=>$applyInfo['winery_name']])->count(); + if($isHas >= 1) throw new ValidateException('酒厂已经存在,请勿重复申请!'); + $isHas = app()->make(SystemSupplierApplyServices::class)->searchModel(['winery_name'=>$applyInfo['winery_name']])->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'); } - - - - } diff --git a/app/dao/supplier/SystemSupplierApplyDao.php b/app/dao/supplier/SystemSupplierApplyDao.php index 5861130..2ca4e72 100644 --- a/app/dao/supplier/SystemSupplierApplyDao.php +++ b/app/dao/supplier/SystemSupplierApplyDao.php @@ -14,12 +14,34 @@ class SystemSupplierApplyDao extends BaseDao{ // 公共搜索模型 public function searchModel(array $search){ return $this->getModel() - ->when(isset($search['id']) && $search['id'] !== '', function ($query) use ($search) { + ->when(isset($search['id']) && $search['id'] !== '',function($query) use ($search){ $query->where('id',$search['id']); }) - ->when(isset($search['contacts_phone']) && $search['contacts_phone'] !== '', function ($query) use ($search) { - $query->where('contacts_phone', $search['contacts_phone']); - }); + ->when(isset($search['contacts_phone']) && $search['contacts_phone'] !== '',function($query) use ($search){ + $query->where('contacts_phone',$search['contacts_phone']); + }) + ->when(isset($search['winery_name']) && $search['winery_name'] !== '',function($query) use ($search){ + $query->where('winery_name','like',"%{$search['winery_name']}%"); + }) + ->when(isset($search['contacts_name']) && $search['contacts_name'] !== '',function($query) use ($search){ + $query->where('contacts_name','like',"%{$search['contacts_name']}%"); + }) + ->when(isset($search['invite_agent_id']) && $search['invite_agent_id'] !== '',function($query) use ($search){ + $query->where('invite_agent_id',$search['invite_agent_id']); + }) + ->when(isset($search['status']) && $search['status'] !== '',function($query) use ($search){ + $query->where('status',$search['status']); + }) + ->with([ + 'agent' => function($query){ + $query->field('id,uid') + ->with([ + 'user' => function($query){ + $query->field('uid,nickname,avatar')->bind(['nickname','avatar']); + } + ]); + } + ]); } diff --git a/app/model/supplier/SystemSupplierApply.php b/app/model/supplier/SystemSupplierApply.php index 6a83741..340a290 100644 --- a/app/model/supplier/SystemSupplierApply.php +++ b/app/model/supplier/SystemSupplierApply.php @@ -1,6 +1,7 @@ hasOne(Agent::class,'id','invite_agent_id'); + } } diff --git a/app/services/supplier/SystemSupplierApplyServices.php b/app/services/supplier/SystemSupplierApplyServices.php index 0d6a505..5d34a6b 100644 --- a/app/services/supplier/SystemSupplierApplyServices.php +++ b/app/services/supplier/SystemSupplierApplyServices.php @@ -20,6 +20,32 @@ class SystemSupplierApplyServices extends BaseServices{ public function searchModel($where){ return $this->dao->searchModel($where); } + + + /** + * Common: 获取列表信息 + * Author: wu-hui + * Time: 2024/01/30 15:13 + * @param $search + * @param $page + * @param $limit + * @param string $field + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getList($search, $page, $limit, $field = '*'){ + $query = $this->dao->searchModel($search); + $list = $query + ->field($field) + ->order('create_time desc,id desc') + ->page($page, $limit) + ->select(); + $count = $query->count(); + + return compact('count', 'list'); + } /** * Common: 添加申请信息 * Author: wu-hui @@ -36,7 +62,36 @@ class SystemSupplierApplyServices extends BaseServices{ return $relation_id; }); } - + /** + * Common: 审核通过的操作 + * Author: wu-hui + * Time: 2024/01/30 16:54 + * @param $params + * @return mixed + */ + public function toExaminePass($params){ + return $this->transaction(function() use ($params){ + // 修改状态 + $this->update($params['id'],['status'=>$params['status']]); + // 自动生成账号信息 + $applyInfo = $this->searchModel(['id'=>$params['id']])->findOrEmpty()->toArray(); + app()->make(SystemSupplierServices::class)->create([ + 'accountInfo' => [ + 'supplier_name' => $applyInfo['winery_name'], + 'detailed_address' => '', + 'name' => $applyInfo['contacts_name'], + 'phone' => $applyInfo['contacts_phone'], + 'is_show' => 1, + 'invite_agent_id' => $applyInfo['agent']['id'] ?? 0, + 'invite_uid' => $applyInfo['agent']['uid'] ?? 0, + ], + 'accountPassword' => [ + 'supplier_account' => $applyInfo['contacts_phone'], + 'supplier_password' => substr($applyInfo['contacts_phone'],-6), + ], + ]); + }); + } diff --git a/route/admin/supplier.php b/route/admin/supplier.php index b0ff2a4..21b7f15 100644 --- a/route/admin/supplier.php +++ b/route/admin/supplier.php @@ -9,19 +9,29 @@ use app\common\middleware\LogMiddleware; Route::group(function () { // 供应商 Route::group('system/supplier', function () { - Route::post('edit_info', '/editInfo')->name('systemSupplierCreate')->option([ + // 列表相关 + Route::post('edit_info', 'Supplier/editInfo')->name('systemSupplierCreate')->option([ '_alias' => '添加供应商', ]); - Route::get('list', '/getList')->name('systemSupplierList')->option([ + Route::get('list', 'Supplier/getList')->name('systemSupplierList')->option([ '_alias' => '供应商列表', ]); - Route::post('info/:id', '/supplierInfo')->name('systemSupplierInfo')->option([ + Route::post('info/:id', 'Supplier/supplierInfo')->name('systemSupplierInfo')->option([ '_alias' => '获取信息', ]); + // 申请审核 + Route::get('apply_list', 'Apply/applyList')->name('systemSupplierApplyList')->option([ + '_alias' => '供应商申请列表', + ]); + Route::post('apply_to_examine', 'Apply/toExamine')->name('systemSupplierApplyToExamine')->option([ + '_alias' => '供应商申请审核', + ]); - })->prefix('admin.supplier.Supplier')->option([ + + + })->prefix('admin.supplier.')->option([ '_path' => '/supplier/supplier', '_auth' => true, ]);