添加:供应商管理(列表查看&信息修改)
This commit is contained in:
parent
601c27c1ca
commit
cc882b1b33
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
namespace app\controller\admin\system\supplier;
|
namespace app\controller\admin\supplier;
|
||||||
|
|
||||||
|
|
||||||
use app\services\supplier\SystemSupplierServices;
|
use app\services\supplier\SystemSupplierServices;
|
||||||
|
|
@ -19,11 +19,16 @@ class Supplier extends BaseController{
|
||||||
* Time: 2024/01/17 11:43
|
* Time: 2024/01/17 11:43
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function accountCreate(){
|
public function editInfo(){
|
||||||
// 参数获取
|
// 参数获取
|
||||||
$data = $this->checkParam();
|
$data = $this->checkParam();
|
||||||
// 添加账号
|
if((int)$data['supplierId'] > 0){
|
||||||
$this->services->create((array)$data);
|
// 编辑账号信息
|
||||||
|
$this->services->editInfo((array)$data);
|
||||||
|
}else{
|
||||||
|
// 添加账号
|
||||||
|
$this->services->create((array)$data);
|
||||||
|
}
|
||||||
|
|
||||||
return app('json')->success('添加成功');
|
return app('json')->success('添加成功');
|
||||||
}
|
}
|
||||||
|
|
@ -35,7 +40,7 @@ class Supplier extends BaseController{
|
||||||
*/
|
*/
|
||||||
private function checkParam():array{
|
private function checkParam():array{
|
||||||
// 接收表单参数
|
// 接收表单参数
|
||||||
$supplierId = (int)$this->request->param('supplier_id');
|
$supplierId = (int)$this->request->param('id');
|
||||||
$accountInfo = $this->request->params([
|
$accountInfo = $this->request->params([
|
||||||
'supplier_name',
|
'supplier_name',
|
||||||
'detailed_address',
|
'detailed_address',
|
||||||
|
|
@ -46,6 +51,8 @@ class Supplier extends BaseController{
|
||||||
'is_show',
|
'is_show',
|
||||||
'is_examine',
|
'is_examine',
|
||||||
'mark',
|
'mark',
|
||||||
|
['invite_agent_id',''],
|
||||||
|
['invite_uid',''],
|
||||||
]);
|
]);
|
||||||
$accountPassword = $this->request->params([
|
$accountPassword = $this->request->params([
|
||||||
'supplier_account',
|
'supplier_account',
|
||||||
|
|
@ -73,11 +80,23 @@ class Supplier extends BaseController{
|
||||||
$search = $this->request->params(['supplier_name','name','phone','is_show']);
|
$search = $this->request->params(['supplier_name','name','phone','is_show']);
|
||||||
[$page, $limit] = $this->getPage();
|
[$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);
|
$data = $this->services->supplierList($search, $page, $limit, $field);
|
||||||
|
|
||||||
return app('json')->success($data);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +53,11 @@ class SystemSupplierDao extends BaseDao
|
||||||
|
|
||||||
// 公共搜索模型
|
// 公共搜索模型
|
||||||
public function searchModel(array $search){
|
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) {
|
->when(isset($search['supplier_name']) && $search['supplier_name'] !== '', function ($query) use ($search) {
|
||||||
$query->where('supplier_name','like', "%{$search['supplier_name']}%");
|
$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) {
|
->when(isset($search['is_show']) && $search['is_show'] !== '', function ($query) use ($search) {
|
||||||
$query->where('is_show', $search['is_show']);
|
$query->where('is_show', $search['is_show']);
|
||||||
})
|
})
|
||||||
->where('is_del',0);
|
->with([
|
||||||
|
'inviteUser' => function($query){
|
||||||
return $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']);
|
||||||
|
},
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace app\model\supplier;
|
namespace app\model\supplier;
|
||||||
|
|
||||||
|
use app\common\model\marketing\Agent;
|
||||||
use app\common\model\system\admin\Admin;
|
use app\common\model\system\admin\Admin;
|
||||||
|
use app\common\model\user\User;
|
||||||
use crmeb\basic\BaseModel;
|
use crmeb\basic\BaseModel;
|
||||||
use crmeb\traits\ModelTrait;
|
use crmeb\traits\ModelTrait;
|
||||||
use think\Model;
|
use think\Model;
|
||||||
|
|
@ -72,4 +74,21 @@ class SystemSupplier extends BaseModel
|
||||||
{
|
{
|
||||||
$query->where('is_del', $value ?? 0);
|
$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');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -296,6 +296,42 @@ class SystemSupplierServices extends BaseServices{
|
||||||
return $relation_id;
|
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: 某个数据是否已经存在
|
* Common: 某个数据是否已经存在
|
||||||
* Author: wu-hui
|
* Author: wu-hui
|
||||||
|
|
@ -352,13 +388,23 @@ class SystemSupplierServices extends BaseServices{
|
||||||
$query = $this->dao->searchModel($search);
|
$query = $this->dao->searchModel($search);
|
||||||
$list = $query
|
$list = $query
|
||||||
->field($field)
|
->field($field)
|
||||||
->order('add_time desc,id desc')
|
->order('sort desc,add_time desc,id desc')
|
||||||
->page($page, $limit)
|
->page($page, $limit)
|
||||||
->select();
|
->select();
|
||||||
$count = $query->count();
|
$count = $query->count();
|
||||||
|
|
||||||
return compact('count', 'list');
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,26 +7,21 @@ use app\common\middleware\AllowOriginMiddleware;
|
||||||
use app\common\middleware\LogMiddleware;
|
use app\common\middleware\LogMiddleware;
|
||||||
|
|
||||||
Route::group(function () {
|
Route::group(function () {
|
||||||
|
// 供应商
|
||||||
Route::group('system/supplier', function () {
|
Route::group('system/supplier', function () {
|
||||||
// 账号管理
|
Route::post('edit_info', '/editInfo')->name('systemSupplierCreate')->option([
|
||||||
Route::post('accountCreate', '/accountCreate')->name('systemSupplierAccountCreate')->option([
|
'_alias' => '添加供应商',
|
||||||
'_alias' => '账号添加',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 供应商信息
|
|
||||||
Route::get('list', '/getList')->name('systemSupplierList')->option([
|
Route::get('list', '/getList')->name('systemSupplierList')->option([
|
||||||
'_alias' => '供应商列表',
|
'_alias' => '供应商列表',
|
||||||
]);
|
]);
|
||||||
|
Route::post('info/:id', '/supplierInfo')->name('systemSupplierInfo')->option([
|
||||||
|
'_alias' => '获取信息',
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})->prefix('admin.supplier.Supplier')->option([
|
||||||
|
|
||||||
})
|
|
||||||
->prefix('admin.system.supplier.Supplier')
|
|
||||||
->option([
|
|
||||||
'_path' => '/supplier/supplier',
|
'_path' => '/supplier/supplier',
|
||||||
'_auth' => true,
|
'_auth' => true,
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue