feat: 添加设置配送员功能
This commit is contained in:
parent
4056fff9c1
commit
6049aca86f
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\delivery_service;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\delivery_service\DeliveryServiceLists;
|
||||
use app\admin\logic\delivery_service\DeliveryServiceLogic;
|
||||
use app\admin\validate\delivery_service\DeliveryServiceValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 配送员控制器
|
||||
* Class DeliveryServiceController
|
||||
* @package app\admin\controller\delivery_service
|
||||
*/
|
||||
class DeliveryServiceController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取配送员列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new DeliveryServiceLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加配送员
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new DeliveryServiceValidate())->post()->goCheck('add');
|
||||
$result = DeliveryServiceLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(DeliveryServiceLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑配送员
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new DeliveryServiceValidate())->post()->goCheck('edit');
|
||||
$result = DeliveryServiceLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(DeliveryServiceLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除配送员
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new DeliveryServiceValidate())->post()->goCheck('delete');
|
||||
DeliveryServiceLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取配送员详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new DeliveryServiceValidate())->goCheck('detail');
|
||||
$result = DeliveryServiceLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -123,4 +123,17 @@ class StoreOrderController extends BaseAdminController
|
||||
return $this->success('退款成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置配送员
|
||||
*/
|
||||
public function set_delivery(){
|
||||
$id=$this->request->post('id');
|
||||
$delivery_uid=$this->request->post('delivery_uid');
|
||||
$res=StoreOrder::where('id',$id)->update(['delivery_uid'=>$delivery_uid]);
|
||||
if($res){
|
||||
return $this->success('设置成功');
|
||||
}
|
||||
return $this->success('设置失败');
|
||||
|
||||
}
|
||||
}
|
65
app/admin/lists/delivery_service/DeliveryServiceLists.php
Normal file
65
app/admin/lists/delivery_service/DeliveryServiceLists.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\delivery_service;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\delivery_service\DeliveryService;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* 配送员列表
|
||||
* Class DeliveryServiceLists
|
||||
* @package app\admin\listsdelivery_service
|
||||
*/
|
||||
class DeliveryServiceLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['uid', 'nickname', 'phone', 'status'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取配送员列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return DeliveryService::where($this->searchWhere)
|
||||
->field(['id', 'uid', 'nickname', 'phone', 'status'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取配送员数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return DeliveryService::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
100
app/admin/logic/delivery_service/DeliveryServiceLogic.php
Normal file
100
app/admin/logic/delivery_service/DeliveryServiceLogic.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\delivery_service;
|
||||
|
||||
|
||||
use app\common\model\delivery_service\DeliveryService;
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 配送员逻辑
|
||||
* Class DeliveryServiceLogic
|
||||
* @package app\admin\logic\delivery_service
|
||||
*/
|
||||
class DeliveryServiceLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加配送员
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
DeliveryService::create([
|
||||
'uid' => $params['uid'],
|
||||
'nickname' => $params['nickname'],
|
||||
'phone' => $params['phone'],
|
||||
'status' => $params['status']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑配送员
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
DeliveryService::where('id', $params['id'])->update([
|
||||
'uid' => $params['uid'],
|
||||
'nickname' => $params['nickname'],
|
||||
'phone' => $params['phone'],
|
||||
'status' => $params['status']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除配送员
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return DeliveryService::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取配送员详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return DeliveryService::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
@ -157,13 +157,15 @@ class WarehouseProductLogic extends BaseLogic
|
||||
} elseif ($res['financial_pm'] == 0) {
|
||||
$find = SystemStoreStorage::where(['outbound_id' => $res['id']])->find();
|
||||
if ($find) {
|
||||
$stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock');
|
||||
if ($stock < $res['nums']) {
|
||||
self::setError('商品库存不足,无法退回');
|
||||
return false;
|
||||
if($find['status']==1){
|
||||
$stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock');
|
||||
if ($stock < $res['nums']) {
|
||||
self::setError('商品库存不足,无法退回');
|
||||
return false;
|
||||
}
|
||||
StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update();
|
||||
}
|
||||
$find->delete();
|
||||
StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update();
|
||||
}
|
||||
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->inc('nums', $res['nums'])->update();
|
||||
}
|
||||
|
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate\delivery_service;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 配送员验证器
|
||||
* Class DeliveryServiceValidate
|
||||
* @package app\admin\validate\delivery_service
|
||||
*/
|
||||
class DeliveryServiceValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'uid' => 'require',
|
||||
'nickname' => 'require',
|
||||
'phone' => 'require',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'uid' => '配送员uid',
|
||||
'nickname' => '配送员名称',
|
||||
'phone' => '手机号码',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return DeliveryServiceValidate
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['uid','nickname','phone']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return DeliveryServiceValidate
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','uid','nickname','phone']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return DeliveryServiceValidate
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return DeliveryServiceValidate
|
||||
* @author admin
|
||||
* @date 2024/08/08 14:07
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
}
|
22
app/common/model/delivery_service/DeliveryService.php
Normal file
22
app/common/model/delivery_service/DeliveryService.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\delivery_service;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 配送员模型
|
||||
* Class DeliveryService
|
||||
* @package app\common\model\delivery_service
|
||||
*/
|
||||
class DeliveryService extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'delivery_service';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user