From cc882b1b33fe7eeb0f7ecef466615e20f74f688b Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Mon, 29 Jan 2024 14:16:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E4=BE=9B=E5=BA=94?= =?UTF-8?q?=E5=95=86=E7=AE=A1=E7=90=86(=E5=88=97=E8=A1=A8=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B&=E4=BF=A1=E6=81=AF=E4=BF=AE=E6=94=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/{system => }/supplier/Supplier.php | 31 +++++++++--- app/dao/supplier/SystemSupplierDao.php | 20 ++++++-- app/model/supplier/SystemSupplier.php | 19 ++++++++ .../supplier/SystemSupplierServices.php | 48 ++++++++++++++++++- route/admin/supplier.php | 19 +++----- 5 files changed, 114 insertions(+), 23 deletions(-) rename app/controller/admin/{system => }/supplier/Supplier.php (76%) diff --git a/app/controller/admin/system/supplier/Supplier.php b/app/controller/admin/supplier/Supplier.php similarity index 76% rename from app/controller/admin/system/supplier/Supplier.php rename to app/controller/admin/supplier/Supplier.php index ec28293..7223dcc 100644 --- a/app/controller/admin/system/supplier/Supplier.php +++ b/app/controller/admin/supplier/Supplier.php @@ -1,5 +1,5 @@ checkParam(); - // 添加账号 - $this->services->create((array)$data); + if((int)$data['supplierId'] > 0){ + // 编辑账号信息 + $this->services->editInfo((array)$data); + }else{ + // 添加账号 + $this->services->create((array)$data); + } return app('json')->success('添加成功'); } @@ -35,7 +40,7 @@ class Supplier extends BaseController{ */ private function checkParam():array{ // 接收表单参数 - $supplierId = (int)$this->request->param('supplier_id'); + $supplierId = (int)$this->request->param('id'); $accountInfo = $this->request->params([ 'supplier_name', 'detailed_address', @@ -46,6 +51,8 @@ class Supplier extends BaseController{ 'is_show', 'is_examine', 'mark', + ['invite_agent_id',''], + ['invite_uid',''], ]); $accountPassword = $this->request->params([ 'supplier_account', @@ -73,11 +80,23 @@ class Supplier extends BaseController{ $search = $this->request->params(['supplier_name','name','phone','is_show']); [$page, $limit] = $this->getPage(); - $field = 'id,supplier_name,avatar,name,phone,is_show,add_time'; + $field = 'id,supplier_name,avatar,name,phone,is_show,add_time,sort,add_time,invite_uid,invite_agent_id'; $data = $this->services->supplierList($search, $page, $limit, $field); return app('json')->success($data); } + /** + * Common: 获取单条供应商信息 + * Author: wu-hui + * Time: 2024/01/29 11:40 + * @param $id + * @return mixed + */ + public function supplierInfo($id){ + $info = $this->services->getSingleInfo(['id'=>$id]); + + return app('json')->success($info); + } } diff --git a/app/dao/supplier/SystemSupplierDao.php b/app/dao/supplier/SystemSupplierDao.php index ab92b2e..83c8673 100644 --- a/app/dao/supplier/SystemSupplierDao.php +++ b/app/dao/supplier/SystemSupplierDao.php @@ -53,7 +53,11 @@ class SystemSupplierDao extends BaseDao // 公共搜索模型 public function searchModel(array $search){ - $query = $this->getModel() + return $this->getModel() + ->where('is_del',0) + ->when(isset($search['id']) && $search['id'] !== '', function ($query) use ($search) { + $query->where('id',$search['id']); + }) ->when(isset($search['supplier_name']) && $search['supplier_name'] !== '', function ($query) use ($search) { $query->where('supplier_name','like', "%{$search['supplier_name']}%"); }) @@ -66,9 +70,17 @@ class SystemSupplierDao extends BaseDao ->when(isset($search['is_show']) && $search['is_show'] !== '', function ($query) use ($search) { $query->where('is_show', $search['is_show']); }) - ->where('is_del',0); - - return $query; + ->with([ + 'inviteUser' => function($query){ + $query->field('uid,nickname,avatar'); + }, + 'inviteAgent' => function($query){ + $query->field('id,agent_type')->bind(['agent_type']); + }, + 'admin' => function($query){ + $query->field('admin_id,account as supplier_account')->bind(['supplier_account']); + }, + ]); } diff --git a/app/model/supplier/SystemSupplier.php b/app/model/supplier/SystemSupplier.php index 4bc6ff1..25b5995 100644 --- a/app/model/supplier/SystemSupplier.php +++ b/app/model/supplier/SystemSupplier.php @@ -10,7 +10,9 @@ // +---------------------------------------------------------------------- namespace app\model\supplier; +use app\common\model\marketing\Agent; use app\common\model\system\admin\Admin; +use app\common\model\user\User; use crmeb\basic\BaseModel; use crmeb\traits\ModelTrait; use think\Model; @@ -72,4 +74,21 @@ class SystemSupplier extends BaseModel { $query->where('is_del', $value ?? 0); } + + + + + + public function inviteAgent(){ + return $this->hasOne(Agent::class,'id','invite_agent_id'); + } + + public function inviteUser(){ + return $this->hasOne(User::class,'uid', 'invite_uid'); + } + + + + + } diff --git a/app/services/supplier/SystemSupplierServices.php b/app/services/supplier/SystemSupplierServices.php index 2dc830b..70dfaca 100644 --- a/app/services/supplier/SystemSupplierServices.php +++ b/app/services/supplier/SystemSupplierServices.php @@ -296,6 +296,42 @@ class SystemSupplierServices extends BaseServices{ return $relation_id; }); } + /** + * Common: 修改供应商信息 + * Author: wu-hui + * Time: 2024/01/29 13:46 + * @param array $data + * @return mixed + */ + public function editInfo(array $data){ + return $this->transaction(function() use ($data){ + // 修改供应商信息 + $res = $this->dao->update($data['supplierId'],$data['accountInfo']); + if(!$res) throw new AdminException('供应商信息修改失败'); + // 修改账号信息 + $accountPassword = $data['accountPassword']; + if(!empty($accountPassword['supplier_account']) && !empty($accountPassword['supplier_password'])){ + + debug("开发中......"); + // $systemAdmin = + // $this->adminDao->update(); + // $adminId = (int)$this->adminDao->getModel()->insertGetId([ + // 'pwd' => $this->passwordHash($accountPassword['supplier_password']), + // 'admin_type' => 4, + // 'account' => $accountPassword['supplier_account'], + // 'roles' => 1, + // 'real_name' => $data['accountInfo']['supplier_name'], + // 'phone' => $data['accountInfo']['phone'], + // 'level' => 0, + // 'relation_id' => $relation_id + // ]); + // if($adminId <= 0) throw new AdminException('管理员添加失败'); + + } + + return true; + }); + } /** * Common: 某个数据是否已经存在 * Author: wu-hui @@ -352,13 +388,23 @@ class SystemSupplierServices extends BaseServices{ $query = $this->dao->searchModel($search); $list = $query ->field($field) - ->order('add_time desc,id desc') + ->order('sort desc,add_time desc,id desc') ->page($page, $limit) ->select(); $count = $query->count(); return compact('count', 'list'); } + /** + * Common: 获取单条信息 + * Author: wu-hui + * Time: 2024/01/29 11:33 + * @param $search + * @return array + */ + public function getSingleInfo($search){ + return $this->dao->searchModel($search)->findOrEmpty()->toArray(); + } diff --git a/route/admin/supplier.php b/route/admin/supplier.php index 4660059..b0ff2a4 100644 --- a/route/admin/supplier.php +++ b/route/admin/supplier.php @@ -7,26 +7,21 @@ use app\common\middleware\AllowOriginMiddleware; use app\common\middleware\LogMiddleware; Route::group(function () { + // 供应商 Route::group('system/supplier', function () { - // 账号管理 - Route::post('accountCreate', '/accountCreate')->name('systemSupplierAccountCreate')->option([ - '_alias' => '账号添加', + Route::post('edit_info', '/editInfo')->name('systemSupplierCreate')->option([ + '_alias' => '添加供应商', ]); - - - - // 供应商信息 Route::get('list', '/getList')->name('systemSupplierList')->option([ '_alias' => '供应商列表', ]); + Route::post('info/:id', '/supplierInfo')->name('systemSupplierInfo')->option([ + '_alias' => '获取信息', + ]); - - - }) - ->prefix('admin.system.supplier.Supplier') - ->option([ + })->prefix('admin.supplier.Supplier')->option([ '_path' => '/supplier/supplier', '_auth' => true, ]);