添加:提货点管理

This commit is contained in:
wuhui_zzw 2024-01-14 14:15:41 +08:00
parent 3a37efbc2b
commit ede44b963f
5 changed files with 220 additions and 1 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace app\common\dao\user;
use app\common\dao\BaseDao;
use app\common\model\user\ExchangePickupPoint;
class ExchangePickupPointDao extends BaseDao{
protected function getModel(): string{
return ExchangePickupPoint::class;
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace app\common\model\user;
use app\common\model\BaseModel;
class ExchangePickupPoint extends BaseModel
{
public static function tablePk(): string{
return 'id';
}
public static function tableName(): string{
return 'exchange_pickup_point';
}
/**
* Common: 获取器 —— 用户id列表转数组
* Author: wu-hui
* Time: 2024/01/14 11:35
* @param $value
* @return false|string[]
*/
public function getUidListAttr($value){
$value = explode(',',$value);
return array_combine($value,$value);
}
/**
* Common: 获取器 —— 负责人列表
* Author: wu-hui
* Time: 2024/01/14 11:38
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserListAttr(){
return User::whereIn('uid',$this->uid_list)
->column(['uid','real_name','nickname','avatar','phone'],'uid');
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace app\common\repositories\user;
use app\common\dao\user\ExchangePickupPointDao;
use app\common\repositories\BaseRepository;
class ExchangePickupPointRepository extends BaseRepository{
protected $dao;
public function __construct(ExchangePickupPointDao $dao){
$this->dao = $dao;
}
/**
* Common: 编辑信息
* Author: wu-hui
* Time: 2024/01/14 10:52
* @param $params
*/
public function editInfo($params){
$info = $this->dao->getSearch([])->where('id',(int)$params['id'])->findOrEmpty();
$info->address = $params['address'];
$info->is_show = $params['is_show'];
$info->uid_list = implode(',',$params['uid_list']);
$info->save();
}
/**
* Common: 获取信息列表
* Author: wu-hui
* Time: 2024/01/14 10:47
* @param array $params
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $params,int $page,int $limit):array{
$query = $this->dao->getSearch([])
->when((int)$params['uid'] > 0,function($query) use ($params){
$query->where('find_in_set(' . $params['uid'] . ',`uid_list`)');
})
->when(!empty($params['address']),function($query) use ($params){
$query->where('address', "like", "%{$params['address']}%");
})
->order('create_time DESC,id DESC');
$count = $query->count();
$list = $query->page($page,$limit)->append(['user_list'])->select();
return compact('count','list');
}
/**
* Common: 获取单条信息
* Author: wu-hui
* Time: 2024/01/14 11:31
* @param $id
* @return array
*/
public function getInfo($id){
return $this->dao->getSearch([])
->append(['user_list'])
->where('id',$id)
->findOrEmpty()
->toArray();
}
}

View File

@ -2,7 +2,9 @@
namespace app\controller\admin\user;
use app\common\model\user\ExchangePickupPoint;
use app\common\repositories\user\ExchangeIntegralRecordRepository;
use app\common\repositories\user\ExchangePickupPointRepository;
use app\common\repositories\user\ExchangeQuotaRecordRepository;
use app\common\repositories\user\ExchangeQuotaRepository;
use crmeb\basic\BaseController;
@ -116,6 +118,62 @@ class ExchangeQuota extends BaseController
}
/**
* Common: 提货点编辑
* Author: wu-hui
* Time: 2024/01/14 10:53
* @return mixed
*/
public function pickupPointEdit(){
// 参数获取
$params = $this->request->params(['id','address','is_show','uid_list']);
if(empty($params['address'])) return app('json')->fail('请输入提货点地址!');
if(!is_array($params['uid_list']) || count($params['uid_list']) <= 0) return app('json')->fail('请至少选择一个负责人!');
// 判断:地址是否已经存在
$isHave = ExchangePickupPoint::where('address',$params['address'])
->when((int)$params['id'] > 0,function($query) use ($params){
$query->where('id','<>',$params['id']);
})
->count();
if($isHave > 0) return app('json')->fail('地址已经存在,请勿重复添加!');
// 信息添加 || 编辑
app()->make(ExchangePickupPointRepository::class)->editInfo($params);
return app('json')->success('success');
}
/**
* Common: 提货点列表
* Author: wu-hui
* Time: 2024/01/14 10:53
* @return mixed
*/
public function pickupPointList(){
[$page, $limit] = $this->getPage();
$params = $this->request->params(['uid','address']);
$data = app()->make(ExchangePickupPointRepository::class)->getList((array)$params,(int)$page,(int)$limit);
return app('json')->success($data);
}
/**
* Common: 提货点信息
* Author: wu-hui
* Time: 2024/01/14 11:30
* @return mixed
*/
public function pickupPointInfo($id){
$data = app()->make(ExchangePickupPointRepository::class)->getInfo($id);
return app('json')->success($data);
}
// 提货记录
public function pickupPointRecord(){
debug('开发中...');
}

View File

@ -447,7 +447,19 @@ Route::group(function () {
Route::get('integral_record_list', '.ExchangeQuota/integralRecordList')->name('systemUserExchangeIntegralRecordList')->option([
'_alias' => '额度变更记录',
]);
// 提货点管理
Route::get('pickup_point_edit', '.ExchangeQuota/pickupPointEdit')->name('systemUserExchangePickupPointEdit')->option([
'_alias' => '提货点编辑',
]);
Route::get('pickup_point_list', '.ExchangeQuota/pickupPointList')->name('systemUserExchangePickupPointList')->option([
'_alias' => '提货点列表',
]);
Route::get('pickup_point_info/:id', '.ExchangeQuota/pickupPointInfo')->name('systemUserExchangePickupPointInfo')->option([
'_alias' => '提货点信息',
]);
Route::get('pickup_point_record', '.ExchangeQuota/pickupPointRecord')->name('systemUserExchangePickupPointRecord')->option([
'_alias' => '提货记录',
]);