feat: 添加仓库和商品仓储信息的管理功能

This commit is contained in:
mkm 2024-07-31 18:07:22 +08:00
parent ddaef44baf
commit a441b94e94
10 changed files with 760 additions and 0 deletions

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller\warehouse;
use app\admin\controller\BaseAdminController;
use app\admin\lists\warehouse\WarehouseLists;
use app\admin\logic\warehouse\WarehouseLogic;
use app\admin\validate\warehouse\WarehouseValidate;
/**
* 仓库信息控制器
* Class WarehouseController
* @package app\admin\controller\warehouse
*/
class WarehouseController extends BaseAdminController
{
/**
* @notes 获取仓库信息列表
* @return \think\response\Json
* @author admin
* @date 2024/07/31 16:10
*/
public function lists()
{
return $this->dataLists(new WarehouseLists());
}
/**
* @notes 添加仓库信息
* @return \think\response\Json
* @author admin
* @date 2024/07/31 16:10
*/
public function add()
{
$params = (new WarehouseValidate())->post()->goCheck('add');
$result = WarehouseLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(WarehouseLogic::getError());
}
/**
* @notes 编辑仓库信息
* @return \think\response\Json
* @author admin
* @date 2024/07/31 16:10
*/
public function edit()
{
$params = (new WarehouseValidate())->post()->goCheck('edit');
$result = WarehouseLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(WarehouseLogic::getError());
}
/**
* @notes 删除仓库信息
* @return \think\response\Json
* @author admin
* @date 2024/07/31 16:10
*/
public function delete()
{
$params = (new WarehouseValidate())->post()->goCheck('delete');
WarehouseLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取仓库信息详情
* @return \think\response\Json
* @author admin
* @date 2024/07/31 16:10
*/
public function detail()
{
$params = (new WarehouseValidate())->goCheck('detail');
$result = WarehouseLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller\warehouse_product;
use app\admin\controller\BaseAdminController;
use app\admin\lists\warehouse_product\WarehouseProductLists;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\admin\validate\warehouse_product\WarehouseProductValidate;
/**
* 商品仓储信息控制器
* Class WarehouseProductController
* @package app\admin\controller\warehouse_product
*/
class WarehouseProductController extends BaseAdminController
{
/**
* @notes 获取商品仓储信息列表
* @return \think\response\Json
* @author admin
* @date 2024/07/31 16:55
*/
public function lists()
{
return $this->dataLists(new WarehouseProductLists());
}
/**
* @notes 添加商品仓储信息
* @return \think\response\Json
* @author admin
* @date 2024/07/31 16:55
*/
public function add()
{
$params = (new WarehouseProductValidate())->post()->goCheck('add');
$result = WarehouseProductLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(WarehouseProductLogic::getError());
}
/**
* @notes 编辑商品仓储信息
* @return \think\response\Json
* @author admin
* @date 2024/07/31 16:55
*/
public function edit()
{
$params = (new WarehouseProductValidate())->post()->goCheck('edit');
$result = WarehouseProductLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(WarehouseProductLogic::getError());
}
/**
* @notes 删除商品仓储信息
* @return \think\response\Json
* @author admin
* @date 2024/07/31 16:55
*/
public function delete()
{
$params = (new WarehouseProductValidate())->post()->goCheck('delete');
WarehouseProductLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取商品仓储信息详情
* @return \think\response\Json
* @author admin
* @date 2024/07/31 16:55
*/
public function detail()
{
$params = (new WarehouseProductValidate())->goCheck('detail');
$result = WarehouseProductLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace app\admin\lists\warehouse;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\warehouse\Warehouse;
use app\common\lists\ListsSearchInterface;
/**
* 仓库信息列表
* Class WarehouseLists
* @package app\admin\listswarehouse
*/
class WarehouseLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/07/31 16:10
*/
public function setSearch(): array
{
return [
'=' => ['name', 'contacts', 'tel'],
];
}
/**
* @notes 获取仓库信息列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2024/07/31 16:10
*/
public function lists(): array
{
return Warehouse::where($this->searchWhere)
->field(['id', 'name', 'code', 'contacts', 'tel', 'address', 'notes', 'sort'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取仓库信息数量
* @return int
* @author admin
* @date 2024/07/31 16:10
*/
public function count(): int
{
return Warehouse::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace app\admin\lists\warehouse_product;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\lists\ListsSearchInterface;
/**
* 商品仓储信息列表
* Class WarehouseProductLists
* @package app\admin\listswarehouse_product
*/
class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/07/31 16:55
*/
public function setSearch(): array
{
return [
'=' => ['warehouse_id', 'product_id', 'financial_pm'],
];
}
/**
* @notes 获取商品仓储信息列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2024/07/31 16:55
*/
public function lists(): array
{
return WarehouseProduct::where($this->searchWhere)
->field(['id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'total_price', 'status'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取商品仓储信息数量
* @return int
* @author admin
* @date 2024/07/31 16:55
*/
public function count(): int
{
return WarehouseProduct::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,106 @@
<?php
namespace app\admin\logic\warehouse;
use app\common\model\warehouse\Warehouse;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 仓库信息逻辑
* Class WarehouseLogic
* @package app\admin\logic\warehouse
*/
class WarehouseLogic extends BaseLogic
{
/**
* @notes 添加仓库信息
* @param array $params
* @return bool
* @author admin
* @date 2024/07/31 16:10
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Warehouse::create([
'name' => $params['name'],
'code' => $params['code'],
'contacts' => $params['contacts'],
'tel' => $params['tel'],
'address' => $params['address'],
'notes' => $params['notes'],
'sort' => $params['sort']
]);
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/07/31 16:10
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Warehouse::where('id', $params['id'])->update([
'name' => $params['name'],
'code' => $params['code'],
'contacts' => $params['contacts'],
'tel' => $params['tel'],
'address' => $params['address'],
'notes' => $params['notes'],
'sort' => $params['sort']
]);
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/07/31 16:10
*/
public static function delete(array $params): bool
{
return Warehouse::destroy($params['id']);
}
/**
* @notes 获取仓库信息详情
* @param $params
* @return array
* @author admin
* @date 2024/07/31 16:10
*/
public static function detail($params): array
{
return Warehouse::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,108 @@
<?php
namespace app\admin\logic\warehouse_product;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 商品仓储信息逻辑
* Class WarehouseProductLogic
* @package app\admin\logic\warehouse_product
*/
class WarehouseProductLogic extends BaseLogic
{
/**
* @notes 添加商品仓储信息
* @param array $params
* @return bool
* @author admin
* @date 2024/07/31 16:55
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
WarehouseProduct::create([
'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'],
'financial_pm' => $params['financial_pm'],
'batch' => $params['batch'],
'nums' => $params['nums'],
'price' => $params['price'],
'total_price' => $params['total_price'],
'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/07/31 16:55
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
WarehouseProduct::where('id', $params['id'])->update([
'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'],
'financial_pm' => $params['financial_pm'],
'batch' => $params['batch'],
'nums' => $params['nums'],
'price' => $params['price'],
'total_price' => $params['total_price'],
'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/07/31 16:55
*/
public static function delete(array $params): bool
{
return WarehouseProduct::destroy($params['id']);
}
/**
* @notes 获取商品仓储信息详情
* @param $params
* @return array
* @author admin
* @date 2024/07/31 16:55
*/
public static function detail($params): array
{
return WarehouseProduct::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,84 @@
<?php
namespace app\admin\validate\warehouse;
use app\common\validate\BaseValidate;
/**
* 仓库信息验证器
* Class WarehouseValidate
* @package app\admin\validate\warehouse
*/
class WarehouseValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'name' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'name' => '仓库名称',
];
/**
* @notes 添加场景
* @return WarehouseValidate
* @author admin
* @date 2024/07/31 16:10
*/
public function sceneAdd()
{
return $this->only(['name']);
}
/**
* @notes 编辑场景
* @return WarehouseValidate
* @author admin
* @date 2024/07/31 16:10
*/
public function sceneEdit()
{
return $this->only(['id','name']);
}
/**
* @notes 删除场景
* @return WarehouseValidate
* @author admin
* @date 2024/07/31 16:10
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return WarehouseValidate
* @author admin
* @date 2024/07/31 16:10
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,98 @@
<?php
namespace app\admin\validate\warehouse_product;
use app\common\validate\BaseValidate;
/**
* 商品仓储信息验证器
* Class WarehouseProductValidate
* @package app\admin\validate\warehouse_product
*/
class WarehouseProductValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'warehouse_id' => 'require',
'product_id' => 'require',
'financial_pm' => 'require',
'batch' => 'require',
'nums' => 'require',
'price' => 'require',
'total_price' => 'require',
'status' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'warehouse_id' => '仓库ID',
'product_id' => '商品ID',
'financial_pm' => '0 = 出库 1 = 获得',
'batch' => '批次',
'nums' => '数量',
'price' => '价格',
'total_price' => '总价',
'status' => '状态',
];
/**
* @notes 添加场景
* @return WarehouseProductValidate
* @author admin
* @date 2024/07/31 16:55
*/
public function sceneAdd()
{
return $this->only(['warehouse_id','product_id','financial_pm','batch','nums','price','total_price','status']);
}
/**
* @notes 编辑场景
* @return WarehouseProductValidate
* @author admin
* @date 2024/07/31 16:55
*/
public function sceneEdit()
{
return $this->only(['id','warehouse_id','product_id','financial_pm','batch','nums','price','total_price','status']);
}
/**
* @notes 删除场景
* @return WarehouseProductValidate
* @author admin
* @date 2024/07/31 16:55
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return WarehouseProductValidate
* @author admin
* @date 2024/07/31 16:55
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace app\common\model\warehouse;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 仓库信息模型
* Class Warehouse
* @package app\common\model\warehouse
*/
class Warehouse extends BaseModel
{
use SoftDelete;
protected $name = 'warehouse';
protected $deleteTime = 'delete_time';
}

View File

@ -0,0 +1,22 @@
<?php
namespace app\common\model\warehouse_product;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 商品仓储信息模型
* Class WarehouseProduct
* @package app\common\model\warehouse_product
*/
class WarehouseProduct extends BaseModel
{
use SoftDelete;
protected $name = 'warehouse_product';
protected $deleteTime = 'delete_time';
}