feat(admin): 添加商品缺库存管理功能
- 新增商品缺库存控制器、列表、逻辑和验证器
This commit is contained in:
parent
a001ab233c
commit
19b9c98582
@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller\store_product_low_stock;
|
||||||
|
|
||||||
|
|
||||||
|
use app\admin\controller\BaseAdminController;
|
||||||
|
use app\admin\lists\store_product_low_stock\StoreProductLowStockLists;
|
||||||
|
use app\admin\logic\store_product_low_stock\StoreProductLowStockLogic;
|
||||||
|
use app\admin\validate\store_product_low_stock\StoreProductLowStockValidate;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品缺库存控制器
|
||||||
|
* Class StoreProductLowStockController
|
||||||
|
* @package app\admin\controller\store_product_low_stock
|
||||||
|
*/
|
||||||
|
class StoreProductLowStockController extends BaseAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取商品缺库存列表
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public function lists()
|
||||||
|
{
|
||||||
|
return $this->dataLists(new StoreProductLowStockLists());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加商品缺库存
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public function add()
|
||||||
|
{
|
||||||
|
$params = (new StoreProductLowStockValidate())->post()->goCheck('add');
|
||||||
|
$result = StoreProductLowStockLogic::add($params);
|
||||||
|
if (true === $result) {
|
||||||
|
return $this->success('添加成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
return $this->fail(StoreProductLowStockLogic::getError());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 编辑商品缺库存
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public function edit()
|
||||||
|
{
|
||||||
|
$params = (new StoreProductLowStockValidate())->post()->goCheck('edit');
|
||||||
|
$result = StoreProductLowStockLogic::edit($params);
|
||||||
|
if (true === $result) {
|
||||||
|
return $this->success('编辑成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
return $this->fail(StoreProductLowStockLogic::getError());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 删除商品缺库存
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$params = (new StoreProductLowStockValidate())->post()->goCheck('delete');
|
||||||
|
StoreProductLowStockLogic::delete($params);
|
||||||
|
return $this->success('删除成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取商品缺库存详情
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public function detail()
|
||||||
|
{
|
||||||
|
$params = (new StoreProductLowStockValidate())->goCheck('detail');
|
||||||
|
$result = StoreProductLowStockLogic::detail($params);
|
||||||
|
return $this->data($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\lists\store_product_low_stock;
|
||||||
|
|
||||||
|
|
||||||
|
use app\admin\lists\BaseAdminDataLists;
|
||||||
|
use app\common\model\store_product_low_stock\StoreProductLowStock;
|
||||||
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
|
use app\common\model\store_product\StoreProduct;
|
||||||
|
use app\common\model\system_store\SystemStore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品缺库存列表
|
||||||
|
* Class StoreProductLowStockLists
|
||||||
|
* @package app\admin\listsstore_product_low_stock
|
||||||
|
*/
|
||||||
|
class StoreProductLowStockLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 设置搜索条件
|
||||||
|
* @return \string[][]
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public function setSearch(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'=' => ['product_id', 'store_id', 'status'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取商品缺库存列表
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public function lists(): array
|
||||||
|
{
|
||||||
|
return StoreProductLowStock::where($this->searchWhere)
|
||||||
|
->field(['id', 'product_id', 'store_id', 'status'])
|
||||||
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
|
->order(['id' => 'desc'])
|
||||||
|
->select()->each(function ($item) {
|
||||||
|
$find = StoreBranchProduct::where('product_id', $item->product_id)->where('store_id', $item->store_id)->withTrashed()->find();
|
||||||
|
$item->product_name = $find->store_name.'|'.$item->product_id;
|
||||||
|
$item->system_store_name = SystemStore::where('id', $item->store_id)->value('name').'|'.$item->store_id;
|
||||||
|
$item->image = $find->image;
|
||||||
|
$item->stock = $find->stock;
|
||||||
|
})
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取商品缺库存数量
|
||||||
|
* @return int
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public function count(): int
|
||||||
|
{
|
||||||
|
return StoreProductLowStock::where($this->searchWhere)->count();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\logic\store_product_low_stock;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\store_product_low_stock\StoreProductLowStock;
|
||||||
|
use app\common\logic\BaseLogic;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品缺库存逻辑
|
||||||
|
* Class StoreProductLowStockLogic
|
||||||
|
* @package app\admin\logic\store_product_low_stock
|
||||||
|
*/
|
||||||
|
class StoreProductLowStockLogic extends BaseLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加商品缺库存
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public static function add(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
StoreProductLowStock::create([
|
||||||
|
'product_id' => $params['product_id'],
|
||||||
|
'store_id' => $params['store_id'],
|
||||||
|
'status' => $params['status']
|
||||||
|
]);
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Db::rollback();
|
||||||
|
throw new BusinessException($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 编辑商品缺库存
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public static function edit(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
StoreProductLowStock::where('id', $params['id'])->update([
|
||||||
|
'product_id' => $params['product_id'],
|
||||||
|
'store_id' => $params['store_id'],
|
||||||
|
'status' => $params['status']
|
||||||
|
]);
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Db::rollback();
|
||||||
|
throw new BusinessException($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 删除商品缺库存
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public static function delete(array $params): bool
|
||||||
|
{
|
||||||
|
return StoreProductLowStock::destroy($params['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取商品缺库存详情
|
||||||
|
* @param $params
|
||||||
|
* @return array
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public static function detail($params): array
|
||||||
|
{
|
||||||
|
return StoreProductLowStock::findOrEmpty($params['id'])->toArray();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\validate\store_product_low_stock;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品缺库存验证器
|
||||||
|
* Class StoreProductLowStockValidate
|
||||||
|
* @package app\admin\validate\store_product_low_stock
|
||||||
|
*/
|
||||||
|
class StoreProductLowStockValidate extends BaseValidate
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置校验规则
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected $rule = [
|
||||||
|
'id' => 'require',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数描述
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected $field = [
|
||||||
|
'id' => 'id',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加场景
|
||||||
|
* @return StoreProductLowStockValidate
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public function sceneAdd()
|
||||||
|
{
|
||||||
|
return $this->remove('id', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 编辑场景
|
||||||
|
* @return StoreProductLowStockValidate
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public function sceneEdit()
|
||||||
|
{
|
||||||
|
return $this->only(['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 删除场景
|
||||||
|
* @return StoreProductLowStockValidate
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public function sceneDelete()
|
||||||
|
{
|
||||||
|
return $this->only(['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 详情场景
|
||||||
|
* @return StoreProductLowStockValidate
|
||||||
|
* @author admin
|
||||||
|
* @date 2025/01/07 16:39
|
||||||
|
*/
|
||||||
|
public function sceneDetail()
|
||||||
|
{
|
||||||
|
return $this->only(['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model\store_product_low_stock;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
use think\model\concern\SoftDelete;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品缺库存模型
|
||||||
|
* Class StoreProductLowStock
|
||||||
|
* @package app\common\model\store_product_low_stock
|
||||||
|
*/
|
||||||
|
class StoreProductLowStock extends BaseModel
|
||||||
|
{
|
||||||
|
use SoftDelete;
|
||||||
|
protected $name = 'store_product_low_stock';
|
||||||
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user