refactor(psi): 删除进销存相关无用代码

- 移除 PsiOrder、PsiProduct、Warehouse 等模型类
- 删除 PsiOrderController、PsiProductController 控制器
- 移除 PsiOrderLists 列表类
- 清理 StoreProductLists 中的冗余代码
- 更新 Warehouse 和 WarehouseStorege 模型的表名
This commit is contained in:
mkm 2025-03-01 17:11:56 +08:00
parent 627ee8dfbd
commit cda9d2404e
14 changed files with 284 additions and 265 deletions

View File

@ -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);
}
}

View 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','type'],
];
}
/**
* @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();
}
}

View File

@ -16,6 +16,7 @@ use app\common\model\system_store\SystemStore;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\model\warehouse_product_storege\WarehouseProductStorege; use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use app\common\lists\ListsExcelInterface; use app\common\lists\ListsExcelInterface;
use app\common\model\psi\warehouse_storege\WarehouseStorege;
/** /**
* 商品列表列表 * 商品列表列表
@ -54,49 +55,17 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
*/ */
public function lists(): array public function lists(): array
{ {
$class_all = $this->request->get('class_all');
if ($class_all) {
//查3级别的
$arr = Cate::where('pid', $class_all)->column('id');
if ($arr) {
$arr2 = Cate::where('pid', 'in', $arr)->column('id');
$this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
} else {
$this->searchWhere[] = ['cate_id', '=', $class_all];
}
}
$is_warehouse = $this->request->get('is_warehouse', 0); $is_warehouse = $this->request->get('is_warehouse', 0);
$order_type = $this->request->get('order_type', 0); $order_type = $this->request->get('order_type', 0);
$userShip = 0;
if (!empty($this->params['user_id'])) {
$userShip = User::where('id', $this->params['user_id'])->value('user_ship');
}
$query = StoreProduct::where($this->searchWhere); $query = StoreProduct::where($this->searchWhere);
if (isset($this->params['type_filter'])) {
$query->where('product_type', '<>', 5);
if ($this->params['type_filter'] == 0) {
$query->where(function ($query) {
$query->where('product_type', 6)->whereOr('is_show', 0);
});
} else {
$query->where('is_show', 1);
}
}
if (!empty($this->params['activity_zone_form_id'])) {
$exceptIds = ActivityZone::where('form_id', $this->params['activity_zone_form_id'])->column('product_id');
$query->where('is_show', 1)->where('product_type', '<>', 5)->whereNotIn('id', $exceptIds);
}
$storeId = $this->params['store_id'] ?? 0;
$is_true = true; $is_true = true;
if ($storeId > 0) {
$is_true = SystemStore::isSelfOperate($storeId);
}
if (!empty($this->params['product_status'])) {
$query->onlyTrashed();
}
$list = $query->limit($this->limitOffset, $this->limitLength) $list = $query->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function ($item) use ($is_warehouse, $userShip, $order_type, $is_true) { ->select()->each(function ($item) use ($is_warehouse,$order_type, $is_true) {
$item['product_id'] = $item['id']; $item['product_id'] = $item['id'];
$item['bar_code_two'] = ''; $item['bar_code_two'] = '';
if (in_array($item['unit'], [2, 21])) { if (in_array($item['unit'], [2, 21])) {
@ -134,38 +103,16 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
$item['product_type_name'] = '普通商品'; $item['product_type_name'] = '普通商品';
} }
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
$stock = StoreBranchProduct::where('store_id', '<>', '4')->where('product_id', $item['id'])->sum('stock');
$category = StoreCategory::where('id', 'in', [$item['top_cate_id'], $item['two_cate_id'], $item['cate_id']])->column('name'); $category = StoreCategory::where('id', 'in', [$item['top_cate_id'], $item['two_cate_id'], $item['cate_id']])->column('name');
$item['cate_name'] = implode('/', $category); $item['cate_name'] = implode('/', $category);
if ($is_warehouse == 1) { $item['stock'] = WarehouseStorege::where('product_id', $item['id'])->sum('nums');
$item['stock'] = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
} else {
$nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
$item['stock'] = bcadd($nums, $stock);
}
if ($userShip == 4) {
$item['price'] = $item['cost'];
}
if ($item['is_show'] == 1) { if ($item['is_show'] == 1) {
$item['status_msg'] = '上架|常用'; $item['status_msg'] = '上架|常用';
} else { } else {
$item['status_msg'] = '下架|不常用|是否有替换'; $item['status_msg'] = '下架|不常用|是否有替换';
} }
if ($order_type == 2) {
$price = StoreProductGroupPrice::where('group_id', 42)->where('product_id', $item['product_id'])->value('price');
if ($price > 0) {
$item['price'] = $price;
$item['store_name'] = $item['store_name'] . '|活动价';
}
}elseif($is_true == true && $userShip>0){
$item['price'] = $item['vip_price'];
$item['store_name'] = $item['store_name'] . '|会员价';
}
return $item; return $item;
})?->toArray(); })?->toArray();
// if ($userShip > 0 && $userShip != 4) {
// $list = StoreProductGroupPrice::resetStoreProductsPrice($list, $userShip, $this->params['store_id'] ?? 0);
// }
return $list; return $list;
} }
@ -178,33 +125,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
*/ */
public function count(): int public function count(): int
{ {
$export = $this->request->get('export');
if ($export == 1) {
$class_all = $this->request->get('class_all');
if ($class_all) {
//查3级别的
$arr = Cate::where('pid', $class_all)->column('id');
if ($arr) {
$arr2 = Cate::where('pid', 'in', $arr)->column('id');
$this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
} else {
$this->searchWhere[] = ['cate_id', '=', $class_all];
}
}
}
$query = StoreProduct::where($this->searchWhere); $query = StoreProduct::where($this->searchWhere);
if (isset($this->params['type_filter'])) {
if ($this->params['type_filter'] == 0) {
$query->where(function ($query) {
$query->where('product_type', 6)->whereOr('is_show', 0);
});
} else {
$query->where('is_show', 1);
}
}
if (!empty($this->params['product_status'])) {
$query->onlyTrashed();
}
return $query->count(); return $query->count();
} }
@ -239,7 +160,6 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
'purchase' => '采购价', 'purchase' => '采购价',
'cost' => '商户', 'cost' => '商户',
'price' => '零售', 'price' => '零售',
'rose' => '毛利率',
'bar_code' => '条码', 'bar_code' => '条码',
]; ];
return $data; return $data;

View File

@ -44,7 +44,7 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array public function lists(): array
{ {
return Supplier::where($this->searchWhere) return Supplier::where($this->searchWhere)
->field(['id', 'category_id', 'mer_name', 'phone', 'settle_cycle', 'address', 'mark']) ->field(['id', 'category_id', 'name', 'phone', 'settle_cycle', 'address', 'mark'])
->limit($this->limitOffset, 100) ->limit($this->limitOffset, 100)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function ($item) { ->select()->each(function ($item) {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace app\common\model\psi\psi_order; namespace app\common\model\delivery_service;
use app\common\model\BaseModel; use app\common\model\BaseModel;
@ -8,14 +8,14 @@ use think\model\concern\SoftDelete;
/** /**
* 进销订单模型 * 配送员模型
* Class PsiOrder * Class DeliveryService
* @package app\common\model\psi\PsiOrder * @package app\common\model\delivery_service
*/ */
class PsiOrder extends BaseModel class DeliveryService extends BaseModel
{ {
use SoftDelete; use SoftDelete;
protected $name = 'psi_order'; protected $name = 'delivery_service';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
// 不生成该表的日志 // 不生成该表的日志
public $doNotRecordLog = true; public $doNotRecordLog = true;

View File

@ -0,0 +1,23 @@
<?php
namespace app\common\model\psi\purchase_order;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 入库订单模型
* Class PurchaseOrder
* @package app\common\model\psi\purchase_order
*/
class PurchaseOrder extends BaseModel
{
use SoftDelete;
protected $name = 'psi_purchase_order';
protected $deleteTime = 'delete_time';
// 不生成该表的日志
public $doNotRecordLog = true;
}

View File

@ -1,21 +1,20 @@
<?php <?php
namespace app\common\model\psi\psi_product; namespace app\common\model\psi\purchase_product;
use app\common\model\BaseModel; use app\common\model\BaseModel;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
use Throwable;
/** /**
* 商品仓储信息模型 * 入库商品信息模型
* Class WarehouseProduct * Class PurchaseProduct
* @package app\common\model\psi\psi_product * @package app\common\model\psi\purchase_product
*/ */
class PsiProduct extends BaseModel class PurchaseProduct extends BaseModel
{ {
use SoftDelete; use SoftDelete;
protected $name = 'psi_product'; protected $name = 'psi_purchase_product';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
public $ignoreLogFields = [ public $ignoreLogFields = [
'price', 'price',

View File

@ -15,7 +15,7 @@ use think\model\concern\SoftDelete;
class Warehouse extends BaseModel class Warehouse extends BaseModel
{ {
use SoftDelete; use SoftDelete;
protected $name = 'warehouse'; protected $name = 'psi_warehouse';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
// 不生成该表的日志 // 不生成该表的日志
public $doNotRecordLog = true; public $doNotRecordLog = true;

View File

@ -14,7 +14,7 @@ use think\model\concern\SoftDelete;
class WarehouseStorege extends BaseModel class WarehouseStorege extends BaseModel
{ {
use SoftDelete; use SoftDelete;
protected $name = 'warehouse_storege'; protected $name = 'psi_warehouse_storege';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
public $ignoreLogFields = [ public $ignoreLogFields = [
'price', 'price',

View File

@ -1,11 +1,10 @@
<?php <?php
namespace app\psi\controller\psi_order; namespace app\psi\controller\purchase_order;
use app\admin\controller\BaseAdminController; use app\admin\controller\BaseAdminController;
use app\admin\lists\warehouse_order\WarehouseOrderLists; use app\psi\logic\purchase_order\PurchaseOrderLogic;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\logic\warehouse_order\WarehouseOrderLogic; use app\admin\logic\warehouse_order\WarehouseOrderLogic;
use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\admin\validate\warehouse_order\WarehouseOrderValidate; use app\admin\validate\warehouse_order\WarehouseOrderValidate;
@ -17,21 +16,20 @@ use app\common\model\supplier\Supplier;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product\WarehouseProduct;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use app\common\service\xlsx\Beforehand; use app\common\service\xlsx\Beforehand;
use app\common\service\xlsx\OrderDetail; use app\common\service\xlsx\OrderDetail;
use app\common\service\xlsx\WarehouseOrdeRentry; use app\common\service\xlsx\WarehouseOrdeRentry;
use app\psi\lists\psi_order\PsiOrderLists; use app\psi\lists\purchase_order\PurchaseOrderLists;
use support\exception\BusinessException; use support\exception\BusinessException;
use support\Log; use support\Log;
use think\facade\Db; use think\facade\Db;
/** /**
* 进销订单控制器 * 进销订单控制器
* Class PsiOrderController * Class PurchaseOrderController
* @package app\admin\controller\warehouse_order * @package app\admin\controller\warehouse_order
*/ */
class PsiOrderController extends BaseAdminController class PurchaseOrderController extends BaseAdminController
{ {
@ -44,7 +42,7 @@ class PsiOrderController extends BaseAdminController
public function lists() public function lists()
{ {
return $this->dataLists(new PsiOrderLists()); return $this->dataLists(new PurchaseOrderLists());
} }
@ -58,7 +56,8 @@ class PsiOrderController extends BaseAdminController
{ {
$params = $this->request->post(); $params = $this->request->post();
$params['admin_id'] = $this->adminId; $params['admin_id'] = $this->adminId;
$result = WarehouseOrderLogic::add($params); $params['warehouse_id']=1;
$result = PurchaseOrderLogic::add($params);
if (true === $result) { if (true === $result) {
return $this->success('添加成功', [], 1, 1); return $this->success('添加成功', [], 1, 1);
} }

View File

@ -1,19 +1,19 @@
<?php <?php
namespace app\psi\controller\psi_product; namespace app\psi\controller\purchase_product;
use app\admin\controller\BaseAdminController; use app\admin\controller\BaseAdminController;
use app\admin\lists\psi_product\PsiProductLists;
use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\admin\validate\warehouse_product\WarehouseProductValidate; use app\admin\validate\warehouse_product\WarehouseProductValidate;
use app\psi\lists\purchase_product\PurchaseProductLists;
/** /**
* 商品仓储信息控制器 * 商品仓储信息控制器
* Class PsiProductController * Class PurchaseProductController
* @package app\admin\controller\warehouse_product * @package app\admin\controller\warehouse_product
*/ */
class PsiProductController extends BaseAdminController class PurchaseProductController extends BaseAdminController
{ {
@ -25,7 +25,7 @@ class PsiProductController extends BaseAdminController
*/ */
public function lists() public function lists()
{ {
return $this->dataLists(new PsiProductLists()); return $this->dataLists(new PurchaseProductLists());
} }

View File

@ -1,23 +1,22 @@
<?php <?php
namespace app\psi\lists\psi_order; namespace app\psi\lists\purchase_order;
use app\admin\lists\BaseAdminDataLists; use app\admin\lists\BaseAdminDataLists;
use app\common\model\beforehand_order\BeforehandOrder;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\auth\Admin; use app\common\model\auth\Admin;
use app\common\model\supplier\Supplier; use app\common\model\supplier\Supplier;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\lists\ListsExcelInterface; use app\common\lists\ListsExcelInterface;
use app\common\model\psi\psi_order\PsiOrder; use app\common\model\psi\purchase_order\PurchaseOrder;
use app\common\model\psi\warehouse\Warehouse; use app\common\model\psi\warehouse\Warehouse;
/** /**
* 进销存单列表 * 进销存单列表
* Class PsiOrderLists * Class PurchaseOrderLists
* @package app\admin\listswarehouse_order * @package app\admin\listswarehouse_order
*/ */
class PsiOrderLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface class PurchaseOrderLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
{ {
@ -30,7 +29,7 @@ class PsiOrderLists extends BaseAdminDataLists implements ListsSearchInterface,
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['financial_pm', 'supplier_id', 'warehouse_id', 'store_id','id'], '=' => ['warehouse_id', 'id'],
'%like' => ['code'], '%like' => ['code'],
'between_time' => 'create_time' 'between_time' => 'create_time'
]; ];
@ -48,23 +47,12 @@ class PsiOrderLists extends BaseAdminDataLists implements ListsSearchInterface,
*/ */
public function lists(): array public function lists(): array
{ {
return PsiOrder::where($this->searchWhere) return PurchaseOrder::where($this->searchWhere)
->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'code', 'financial_pm', 'admin_id', 'batch', 'mark', 'purchase', 'total_price', 'status', 'create_time','oid', 'order_type']) ->field(['id', 'code', 'admin_id', 'batch', 'mark', 'total_price', 'status', 'create_time', 'oid', 'order_type'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function ($item) { ->select()->each(function ($item) {
if ($item->financial_pm == 0) {
$item->financial_pm_name = '出库';
} else {
$item->financial_pm_name = '入库';
}
if ($item->financial_pm == 0) {
if ($item->store_id) {
$item->system_store = SystemStore::where('id', $item->store_id)->value('name');
} else {
$item->system_store = '';
}
}
if ($item->admin_id) { if ($item->admin_id) {
$item->admin_name = Admin::where('id', $item->admin_id)->value('name'); $item->admin_name = Admin::where('id', $item->admin_id)->value('name');
} else { } else {
@ -75,11 +63,6 @@ class PsiOrderLists extends BaseAdminDataLists implements ListsSearchInterface,
} else { } else {
$item->warehouse_name = ''; $item->warehouse_name = '';
} }
if ($item->supplier_id) {
$item->supplier_name = Supplier::where('id', $item->supplier_id)->value('mer_name');
}else{
$item->supplier_name = '';
}
if (!empty($item['order_type'])) { if (!empty($item['order_type'])) {
$item->order_type_name = getOrderTypeName($item->order_type); $item->order_type_name = getOrderTypeName($item->order_type);
} }
@ -96,7 +79,7 @@ class PsiOrderLists extends BaseAdminDataLists implements ListsSearchInterface,
*/ */
public function count(): int public function count(): int
{ {
return PsiOrder::where($this->searchWhere)->count(); return PurchaseOrder::where($this->searchWhere)->count();
} }
/** /**
* @notes 导出文件名 * @notes 导出文件名
@ -121,32 +104,15 @@ class PsiOrderLists extends BaseAdminDataLists implements ListsSearchInterface,
*/ */
public function setExcelFields(): array public function setExcelFields(): array
{ {
$financial_pm = $this->request->get('financial_pm');
if ($financial_pm == 1) {
$data = [ $data = [
'create_time' => '操作时间', 'create_time' => '操作时间',
'warehouse_name' => '仓库', 'warehouse_name' => '仓库',
'supplier_name' => '供应商',
'code' => '单号', 'code' => '单号',
'financial_pm_name' => '状态',
'admin_name' => '填写人员',
'completed_amount' => '已结金额',
'outstanding_amount' => '未结金额',
'total_price' => '总金额',
'mark' => '备注',
];
} else {
$data = [
'create_time' => '操作时间',
'warehouse_name' => '仓库',
'supplier_name' => '供应商',
'code' => '单号',
'financial_pm_name' => '状态',
'admin_name' => '填写人员', 'admin_name' => '填写人员',
'total_price' => '总金额', 'total_price' => '总金额',
'mark' => '备注', 'mark' => '备注',
]; ];
}
return $data; return $data;
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace app\psi\lists\psi_product; namespace app\psi\lists\purchase_product;
use app\admin\lists\BaseAdminDataLists; use app\admin\lists\BaseAdminDataLists;
@ -9,7 +9,7 @@ use app\common\model\auth\Admin;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\lists\ListsExcelInterface; use app\common\lists\ListsExcelInterface;
use app\common\model\psi\psi_product\PsiProduct; use app\common\model\psi\purchase_product\PurchaseProduct;
use app\common\model\psi\warehouse\Warehouse; use app\common\model\psi\warehouse\Warehouse;
use app\common\model\store_category\StoreCategory; use app\common\model\store_category\StoreCategory;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
@ -17,10 +17,10 @@ use app\common\model\supplier\Supplier;
/** /**
* 进销存订单信息列表 * 进销存订单信息列表
* Class PsiProductLists * Class PurchaseProductLists
* @package app\admin\listswarehouse_product * @package app\admin\PurchaseProductLists
*/ */
class PsiProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface class PurchaseProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
{ {
public $ids; public $ids;
@ -35,7 +35,7 @@ class PsiProductLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['warehouse_id', 'financial_pm', 'product_id','store_id','oid','supplier_id','is_pay','code'], '=' => ['warehouse_id', 'product_id','oid','supplier_id','code'],
'between_time' => 'create_time' 'between_time' => 'create_time'
]; ];
} }
@ -72,11 +72,11 @@ class PsiProductLists extends BaseAdminDataLists implements ListsSearchInterface
return []; return [];
} }
} }
$query = PsiProduct::where($this->searchWhere); $query = PurchaseProduct::where($this->searchWhere);
if (isset($this->params['is_group']) && $this->params['is_group'] == 1) { if (isset($this->params['is_group']) && $this->params['is_group'] == 1) {
$query->group('product_id')->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'sum(nums) nums', 'price', 'purchase', 'cost', 'sum(total_price) total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay', 'order_type','vip_price']); $query->group('product_id')->field(['id', 'code','oid','admin_id','supplier_id', 'warehouse_id', 'product_id', 'sum(nums) nums', 'price', 'sum(total_price) total_price', 'manufacture', 'expiration_date', 'mark', 'create_time', 'order_type']);
} else { } else {
$query->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay', 'order_type','vip_price']); $query->field(['id', 'code','oid','admin_id','supplier_id', 'warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'manufacture', 'expiration_date', 'mark', 'create_time', 'order_type']);
} }
return $query return $query
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
@ -86,27 +86,11 @@ class PsiProductLists extends BaseAdminDataLists implements ListsSearchInterface
$item->store_name = ''; $item->store_name = '';
$item->image = ''; $item->image = '';
$item->price = $item['price']??0; $item->price = $item['price']??0;
$item->purchase = $item['purchase']??0;
$item->unit_name = ''; $item->unit_name = '';
$item->store_info = ''; $item->store_info = '';
$item->top_cate_name = ''; $item->top_cate_name = '';
if ($item->financial_pm == 0) {
$item->financial_pm_name = '出库';
} else {
$item->financial_pm_name = '入库'; $item->financial_pm_name = '入库';
}
if ($item->store_id > 0) {
$item->system_store_name = SystemStore::where('id', $item->store_id)->value('name');
} else {
$item->system_store_name = '';
}
if ($item->status == 0) {
$item->status_name = '未确认';
} elseif ($item->status == 1) {
$item->status_name = '已确认';
} else {
$item->status_name = '库存不足';
}
if ($item->admin_id) { if ($item->admin_id) {
$item->admin_name = Admin::where('id', $item->admin_id)->value('name'); $item->admin_name = Admin::where('id', $item->admin_id)->value('name');
} else { } else {
@ -132,15 +116,10 @@ class PsiProductLists extends BaseAdminDataLists implements ListsSearchInterface
}else{ }else{
$item->supplier_name = ''; $item->supplier_name = '';
} }
$item->expiration_date = $item->expiration_date ? date('Y-m-d', $item->expiration_date) : '';
$item->manufacture = $item->manufacture ? date('Y-m-d', $item->manufacture) : '';
if (!empty($item['order_type'])) { if (!empty($item['order_type'])) {
$item->order_type_name = getOrderTypeName($item->order_type); $item->order_type_name = getOrderTypeName($item->order_type);
} }
if ($item->order_type == 5) {
$item->outbound = '无须出库';
}
}) })
->toArray(); ->toArray();
} }
@ -155,9 +134,9 @@ class PsiProductLists extends BaseAdminDataLists implements ListsSearchInterface
public function count(): int public function count(): int
{ {
if ($this->ids) { if ($this->ids) {
return PsiProduct::whereIn('id', $this->ids)->where($this->searchWhere)->count(); return PurchaseProduct::whereIn('id', $this->ids)->where($this->searchWhere)->count();
} else { } else {
return PsiProduct::where($this->searchWhere)->count(); return PurchaseProduct::where($this->searchWhere)->count();
} }
} }
/** /**
@ -168,11 +147,9 @@ class PsiProductLists extends BaseAdminDataLists implements ListsSearchInterface
*/ */
public function setFileName(): string public function setFileName(): string
{ {
$financial_pm = $this->request->get('financial_pm');
if ($financial_pm == 1) {
return '入库列表'; return '入库列表';
}
return '出库列表';
} }
@ -184,45 +161,22 @@ class PsiProductLists extends BaseAdminDataLists implements ListsSearchInterface
*/ */
public function setExcelFields(): array public function setExcelFields(): array
{ {
$financial_pm = $this->request->get('financial_pm');
if ($financial_pm == 1) {
$data = [ $data = [
'admin_name' => '操作人员', 'admin_name' => '操作人员',
'warehouse_name' => '仓库', 'warehouse_name' => '仓库',
'supplier_name' => '供应商', 'supplier_name' => '供应商',
'store_name' => '商品名称', 'store_name' => '商品名称',
'financial_pm_name' => '出入库', 'financial_pm_name' => '出入库',
'code' => '入库单', 'code' => '入库单',
'batch' => '批次', 'batch' => '批次',
'nums' => '数量', 'nums' => '数量',
'manufacture' => '生产日期', 'manufacture' => '生产日期',
'expiration_date' => '保质期', 'expiration_date' => '保质期',
'purchase' => '采购价', 'price' => '采购价',
'price' => '零售',
'total_price' => '总价', 'total_price' => '总价',
'create_time' => '操作时间', 'create_time' => '操作时间',
]; ];
} else {
$data = [
'id' => 'id',
'admin_name' => '操作人员',
'warehouse_name' => '仓库',
'store_name' => '商品名称',
'top_cate_name' => '分类',
'store_info' => '规格',
'unit_name' => '单位',
'financial_pm_name' => '出入库',
'code' => '出库单',
'system_store_name' => '门店',
'nums' => '数量',
'purchase' => '供货价',
'vip_price' => '会员价',
'price' => '零售价',
'total_price' => '供货总价',
'create_time' => '操作时间',
];
}
return $data; return $data;
} }
} }

View File

@ -1,21 +1,24 @@
<?php <?php
namespace app\admin\logic\warehouse_order; namespace app\psi\logic\purchase_order;
use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_order\WarehouseOrder;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\beforehand_order\BeforehandOrder; use app\common\model\beforehand_order\BeforehandOrder;
use app\common\model\psi\purchase_order\PurchaseOrder;
use app\common\model\psi\purchase_product\PurchaseProduct;
use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product\WarehouseProduct;
use Exception;
use support\exception\BusinessException; use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
/** /**
* 进销订单逻辑 * 进销订单逻辑
* Class PsiOrderLogic * Class PurchaseOrderLogic
* @package app\admin\logic\warehouse_order * @package app\psi\logic\purchase_order
*/ */
class PsiOrderLogic extends BaseLogic class PurchaseOrderLogic extends BaseLogic
{ {
@ -30,50 +33,45 @@ class PsiOrderLogic extends BaseLogic
{ {
Db::startTrans(); Db::startTrans();
try { try {
$code = getNewOrderId('RK');
$arr = [ $arr = [
'warehouse_id' => $params['warehouse_id'], 'warehouse_id' => $params['warehouse_id'],
'supplier_id' => $params['supplier_id'], 'order_type' => $params['order_type']??0,
'code' => $params['code'], 'oid' => 0,
'admin_id' => $params['admin_id'], 'admin_id' => $params['admin_id'],
'financial_pm' => 1,
'batch' => 0, 'batch' => 0,
'mark' => $params['remark'], 'code' => $code,
'total_price' => $params['remark'], 'mark' => $params['remark'] ?? '',
'completed_amount' => $params['completed_amount']??0, 'total_price' => 0
'outstanding_amount' => $params['outstanding_amount']??0,
]; ];
$res = PurchaseOrder::create($arr);
$total_price = 0; $product_arr=[];
foreach ($params['product_arr'] as $k => $v) { foreach ($params['product_arr'] as $k => $v) {
$total_price += $v['total_price']; if($v['product_id']<=0){
continue ;
} }
$arr['total_price'] = $total_price;
$res = WarehouseOrder::create($arr);
foreach ($params['product_arr'] as $k => $v) {
$data['admin_id'] = $params['admin_id']; $data['admin_id'] = $params['admin_id'];
$data['order_type'] = $params['order_type'];
$data['store_id'] = 0; $data['store_id'] = 0;
$data['oid'] = $res['id']; $data['oid'] = $res['id'];
$data['supplier_id'] = $params['supplier_id']; $data['supplier_id'] = 0;
$data['warehouse_id'] = $params['warehouse_id']; $data['warehouse_id'] = $params['warehouse_id'];
$data['code'] = $params['code']; $data['code'] = $code;
$data['product_id'] = $v['product_id']; $data['product_id'] = $v['product_id'];
$data['need_nums'] = $v['nums'];
$data['nums'] = $v['nums']; $data['nums'] = $v['nums'];
$data['purchase'] = $v['purchase']; $data['price'] = $v['price'];
$data['total_price'] = $v['total_price']; $data['total_price'] = $v['total_price'];
$data['financial_pm'] = 1; $product_arr[]=$data;
if (!empty($v['manufacture'])) {
$data['manufacture'] = $v['manufacture'];
}
if (!empty($v['expiration_date'])) {
$data['expiration_date'] = $v['expiration_date'];
}
WarehouseProductLogic::add($data,1,$params['admin_id']);
} }
(new PurchaseProduct())->saveAll($product_arr);
$total_price=PurchaseProduct::where('oid', $res['id'])->sum('total_price');
PurchaseOrder::where('id', $res['id'])->update(['total_price' => $total_price]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Throwable $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
throw new BusinessException($e->getMessage()); throw new Exception($e->getMessage());
} }
} }