调整入库单和入库商品
This commit is contained in:
parent
6a4f087bc0
commit
2b815064b4
@ -25,7 +25,7 @@ class ExceptionHandler extends Handler
|
||||
return json(['code' => 0, 'msg' => $exception->getMessage(),'show'=>1]);
|
||||
}
|
||||
return response($exception->getMessage());
|
||||
} elseif ($exception instanceof \Error || $exception instanceof \ErrorException) {
|
||||
} elseif ($exception instanceof \Exception) {
|
||||
$isDebug = config('app.debug');
|
||||
$error = [
|
||||
'show' => 1,
|
||||
|
@ -44,9 +44,7 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
public function lists(): array
|
||||
{
|
||||
return SystemStore::where($this->searchWhere)
|
||||
->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show','day_start','day_end'
|
||||
,'bank','bank_code','bank_address','realname,paid_deposit,security_deposit'
|
||||
])
|
||||
->field(['id', 'name', 'abbreviation', 'introduction'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
|
@ -241,4 +241,21 @@ class OrderEnum
|
||||
}
|
||||
return $data[$value] ?? '';
|
||||
}
|
||||
|
||||
public static function getOrderTypeName($type)
|
||||
{
|
||||
$typeMap = [
|
||||
1 => '铺货订单',
|
||||
2 => '商贩订单',
|
||||
3 => '一条龙订单',
|
||||
4 => '线上订单',
|
||||
5 => '仓库补货',
|
||||
6 => '往期补单-出库',
|
||||
7 => '采购订单',
|
||||
8 => '其他订单',
|
||||
9 => '往期补单-入库',
|
||||
];
|
||||
return $typeMap[$type] ?? '';
|
||||
}
|
||||
|
||||
}
|
||||
|
26
app/common/logic/ChangeLogLogic.php
Normal file
26
app/common/logic/ChangeLogLogic.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\model\change_log\ChangeLog;
|
||||
|
||||
class ChangeLogLogic extends BaseLogic
|
||||
{
|
||||
|
||||
public function insert($model='',$link_id=0,$nums=0,$pm=0,$url='',$admin_id=0, $remark = ''):void
|
||||
{
|
||||
$info=\Chance\Log\facades\OperationLog::getLog();
|
||||
ChangeLog::create([
|
||||
'model' => $model,
|
||||
'link_id' => $link_id,
|
||||
'nums' => $nums,
|
||||
'pm' => $pm,
|
||||
'mark' => $info,
|
||||
'remark' => $remark,
|
||||
'url' => $url,
|
||||
'admin_id' => $admin_id,
|
||||
'create_time' => time()
|
||||
]);
|
||||
\Chance\Log\facades\OperationLog::clearLog();
|
||||
}
|
||||
}
|
19
app/common/model/change_log/ChangeLog.php
Normal file
19
app/common/model/change_log/ChangeLog.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\change_log;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 数据变更记录模型
|
||||
* Class ChangeLog
|
||||
* @package app\common\model\change_log
|
||||
*/
|
||||
class ChangeLog extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
|
||||
protected $deleteTime = 'delete_time';
|
||||
}
|
65
app/common/model/store/StoreBranchProduct.php
Normal file
65
app/common/model/store/StoreBranchProduct.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\store;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* 门店商品属性值辅助表模型
|
||||
* Class StoreBranchProduct
|
||||
* @package app\common\model\store_branch_product
|
||||
*/
|
||||
class StoreBranchProduct extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
|
||||
protected $name = 'store_branch_product';
|
||||
protected $deleteTime = 'delete_time';
|
||||
public $ignoreLogFields = [
|
||||
'top_cate_id',
|
||||
'two_cate_id',
|
||||
'cate_id',
|
||||
'store_name',
|
||||
'image',
|
||||
'price',
|
||||
'vip_price',
|
||||
'cost',
|
||||
'purchase',
|
||||
'total_price',
|
||||
'store_info',
|
||||
'keyword',
|
||||
'bar_code',
|
||||
'rose',
|
||||
'status',
|
||||
'product_type',
|
||||
'unit',
|
||||
'batch',
|
||||
'store_batch',
|
||||
'sort',
|
||||
'label_id',
|
||||
'is_lack',
|
||||
'manufacturer_information',
|
||||
'status',
|
||||
'create_time',
|
||||
'update_time',
|
||||
];
|
||||
|
||||
public function unitName()
|
||||
{
|
||||
return $this->hasOne(StoreProductUnit::class, 'id', 'unit')->bind(['unit_name' => 'name', 'is_bulk']);
|
||||
}
|
||||
|
||||
public function className()
|
||||
{
|
||||
return $this->hasOne(StoreCategory::class, 'id', 'cate_id')->bind(['class_name' => 'name']);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
return $this->hasOne(StoreProduct::class, 'id', 'product_id');
|
||||
}
|
||||
}
|
@ -519,4 +519,17 @@ function group_by($array, $key): array
|
||||
$result[$item[$key]][] = $item;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 日志记录
|
||||
* @param string $model 模型
|
||||
* @param int $id 更新的模型组件id
|
||||
* @param int $nums 更新的数量
|
||||
* @param int $pm 1:增加 -1:减少
|
||||
* @param string $url 请求地址
|
||||
*/
|
||||
function SqlChannelLog($model='', $id=0, $nums=0,$pm=0,$url='',$admin_id=0, $remark = ''):void
|
||||
{
|
||||
// (new \app\common\logic\ChangeLogLogic())->insert($model, $id, $nums, $pm, $url,$admin_id, $remark);
|
||||
}
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace app\psi\controller;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\common\model\WarehouseOrder;
|
||||
use app\psi\lists\WarehouseOrderLists;
|
||||
use app\psi\logic\WarehouseOrderLogic;
|
||||
use app\psi\validate\WarehouseOrderValidate;
|
||||
@ -20,7 +20,6 @@ class WarehouseOrderController extends BaseAdminController
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
*/
|
||||
@ -32,13 +31,13 @@ class WarehouseOrderController extends BaseAdminController
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new WarehouseOrderValidate())->post()->goCheck('add');
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$result = WarehouseOrderLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
@ -49,7 +48,6 @@ class WarehouseOrderController extends BaseAdminController
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
*/
|
||||
@ -63,10 +61,18 @@ class WarehouseOrderController extends BaseAdminController
|
||||
return $this->fail(WarehouseOrderLogic::getError());
|
||||
}
|
||||
|
||||
public function updateAmount()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$res = WarehouseOrder::update($params);
|
||||
if ($res) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail('编辑失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
*/
|
||||
@ -80,7 +86,6 @@ class WarehouseOrderController extends BaseAdminController
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
*/
|
||||
|
@ -20,7 +20,6 @@ class WarehouseProductController extends BaseAdminController
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
*/
|
||||
@ -32,7 +31,6 @@ class WarehouseProductController extends BaseAdminController
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
*/
|
||||
@ -49,15 +47,14 @@ class WarehouseProductController extends BaseAdminController
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new WarehouseProductValidate())->post()->goCheck('edit');
|
||||
$result = WarehouseProductLogic::edit($params);
|
||||
if (true === $result) {
|
||||
$params = $this->request->post();
|
||||
$result = WarehouseProductLogic::edit($params, $this->adminId);
|
||||
if ($result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(WarehouseProductLogic::getError());
|
||||
@ -66,7 +63,6 @@ class WarehouseProductController extends BaseAdminController
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
*/
|
||||
@ -80,7 +76,6 @@ class WarehouseProductController extends BaseAdminController
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
*/
|
||||
|
@ -2,12 +2,15 @@
|
||||
|
||||
namespace app\psi\lists;
|
||||
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\lists\BaseDataLists;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\psi\warehouse\Warehouse;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\WarehouseOrder;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* PsiWarehouseOrder列表
|
||||
* Class WarehouseOrderLists
|
||||
@ -26,12 +29,12 @@ class WarehouseOrderLists extends BaseDataLists implements ListsSearchInterface
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['warehouse_id', 'store_id', 'oid', 'order_type', 'code', 'status', 'create_time'],
|
||||
|
||||
'=' => ['supplier_id', 'warehouse_id', 'store_id', 'id', 'oid', 'order_type'],
|
||||
'%like' => ['code'],
|
||||
'between_time' => 'create_time'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
@ -44,14 +47,39 @@ class WarehouseOrderLists extends BaseDataLists implements ListsSearchInterface
|
||||
public function lists(): array
|
||||
{
|
||||
return WarehouseOrder::where($this->searchWhere)
|
||||
->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'oid', 'order_type', 'code', 'mark', 'nums', 'purchase', 'total_price', 'completed_amount', 'outstanding_amount', 'status'])
|
||||
->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'code', 'admin_id', 'batch', 'mark', 'nums', 'purchase', 'total_price', 'status', 'create_time', 'completed_amount', 'outstanding_amount', 'oid', 'order_type'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->select()->each(function ($item) {
|
||||
if ($item->store_id) {
|
||||
$item->system_store = SystemStore::where('id', $item->store_id)->value('name');
|
||||
} else {
|
||||
$item->system_store = '';
|
||||
}
|
||||
if ($item->admin_id) {
|
||||
$item->admin_name = Admin::where('id', $item->admin_id)->value('name');
|
||||
} else {
|
||||
$item->admin_name = '';
|
||||
}
|
||||
if ($item->warehouse_id) {
|
||||
$item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name');
|
||||
} else {
|
||||
$item->warehouse_name = '';
|
||||
}
|
||||
if ($item->supplier_id) {
|
||||
$item->supplier_name = Supplier::where('id', $item->supplier_id)->value('name');
|
||||
}else{
|
||||
$item->supplier_name = '';
|
||||
}
|
||||
if (!empty($item['order_type'])) {
|
||||
$item->order_type_name = OrderEnum::getOrderTypeName($item->order_type);
|
||||
} else {
|
||||
$item->order_type_name = '';
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
|
@ -2,11 +2,19 @@
|
||||
|
||||
namespace app\psi\lists;
|
||||
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\lists\BaseDataLists;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\psi\warehouse\Warehouse;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\WarehouseOrder;
|
||||
use app\common\model\WarehouseProduct;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Enum;
|
||||
|
||||
/**
|
||||
* PsiWarehouseProduct列表
|
||||
@ -16,6 +24,7 @@ use app\common\lists\ListsSearchInterface;
|
||||
class WarehouseProductLists extends BaseDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
public $ids;
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
@ -26,8 +35,8 @@ class WarehouseProductLists extends BaseDataLists implements ListsSearchInterfac
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['warehouse_id', 'supplier_id', 'store_id', 'order_type', 'product_id', 'oid', 'code', 'pay_type', 'status'],
|
||||
|
||||
'=' => ['warehouse_id', 'product_id','store_id','oid','supplier_id','is_pay','code'],
|
||||
'between_time' => 'create_time'
|
||||
];
|
||||
}
|
||||
|
||||
@ -43,11 +52,96 @@ class WarehouseProductLists extends BaseDataLists implements ListsSearchInterfac
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return WarehouseProduct::where($this->searchWhere)
|
||||
->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'order_type', 'product_id', 'unit', 'oid', 'code', 'nums', 'refund_nums', 'before_nums', 'after_nums', 'mark', 'total_price', 'purchase', 'pay_type', 'status'])
|
||||
if ($this->request->get('product_name')) {
|
||||
$product_name = $this->request->get('product_name');
|
||||
$ids = StoreProduct::where('store_name', 'like', '%' . $product_name . '%')->withTrashed()->column('id');
|
||||
if ($ids) {
|
||||
$this->searchWhere[] = ['product_id', 'in', $ids];
|
||||
$this->ids = $ids;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
if ($this->request->get('bar_code')) {
|
||||
$bar_code = $this->request->get('bar_code');
|
||||
$ids = StoreProduct::where('bar_code', 'like', '%' . $bar_code . '%')->withTrashed()->column('id');
|
||||
if ($ids) {
|
||||
$this->searchWhere[] = ['product_id', 'in', $ids];
|
||||
$this->ids = $ids;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
$query = WarehouseProduct::where($this->searchWhere);
|
||||
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', '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']);
|
||||
} else {
|
||||
$query->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay', 'order_type','vip_price']);
|
||||
}
|
||||
return $query
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->select()->each(function ($item) {
|
||||
$item->store_name = '';
|
||||
$item->image = '';
|
||||
$item->price = $item['price']??0;
|
||||
$item->purchase = $item['purchase']??0;
|
||||
$item->unit_name = '';
|
||||
$item->store_info = '';
|
||||
$item->top_cate_name = '';
|
||||
$item->order_type_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) {
|
||||
$item->admin_name = Admin::where('id', $item->admin_id)->value('name');
|
||||
} else {
|
||||
$item->admin_name = '';
|
||||
}
|
||||
if ($item->product_id) {
|
||||
$find = StoreProduct::where('id', $item->product_id)->field('price,purchase,image,store_name,unit,store_info,top_cate_id')->withTrashed()->find();
|
||||
if($find){
|
||||
$item->store_name = $find->store_name . '|' . $item->product_id;
|
||||
$item->image = $find->image;
|
||||
$item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name');
|
||||
$item->store_info =$find->store_info;
|
||||
$item->top_cate_name =StoreCategory::where('id', $find->top_cate_id)->value('name');
|
||||
}
|
||||
}
|
||||
if ($item->warehouse_id) {
|
||||
$item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name');
|
||||
} else {
|
||||
$item->warehouse_name = '';
|
||||
}
|
||||
if ($item->supplier_id) {
|
||||
$item->supplier_name = Supplier::where('id', $item->supplier_id)->value('name');
|
||||
}else{
|
||||
$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'])) {
|
||||
$item->order_type_name = OrderEnum::getOrderTypeName($item->order_type);
|
||||
} else {
|
||||
$beforehandOrderId = WarehouseOrder::where('id', $item['oid'])->value('oid');
|
||||
if ($beforehandOrderId) {
|
||||
$item->order_type_name = '';
|
||||
}
|
||||
}
|
||||
if ($item->order_type == 5) {
|
||||
$item->outbound = '无须出库';
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,16 @@ namespace app\psi\logic;
|
||||
|
||||
use app\common\model\OutboundProduct;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\psi\warehouse_storage\WarehouseStorage;
|
||||
use app\common\model\store\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\WarehouseOrder;
|
||||
use app\common\model\WarehouseProduct;
|
||||
use Exception;
|
||||
use support\exception\BusinessException;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -19,127 +28,417 @@ class OutboundProductLogic extends BaseLogic
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @notes 添加商品仓储信息
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
public static function add(array $params, $type = 1, $admin_id = 0)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
OutboundProduct::create([
|
||||
if (!in_array($params['order_type'], [6, 9])) {
|
||||
$storage = WarehouseStorage::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storage) {
|
||||
$after_nums = $storage['nums'] + $params['nums'];
|
||||
if ($type == 1) {
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
|
||||
if (!$storeProduct) {
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
if ($storeProduct['purchase'] <= 0) {
|
||||
$total_price = 0;
|
||||
} else {
|
||||
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
||||
}
|
||||
WarehouseStorage::update(['nums' => $after_nums, 'total_price' => $total_price], ['id' => $storage['id']]);
|
||||
SqlChannelLog('WarehouseStorage', $storage['id'], $after_nums, 1, Request()->url(), $admin_id);
|
||||
}
|
||||
} else {
|
||||
$after_nums = $params['nums'];
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
|
||||
if (!$storeProduct) {
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
if ($storeProduct['purchase'] <= 0) {
|
||||
$total_price = 0;
|
||||
} else {
|
||||
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
||||
}
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'nums' => $params['nums'],
|
||||
'total_price' => $total_price
|
||||
];
|
||||
$storage = WarehouseStorage::create($data);
|
||||
SqlChannelLog('WarehouseStorage', $storage['id'], -$params['nums'], 1, Request()->url(), $admin_id);
|
||||
}
|
||||
}
|
||||
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'store_id' => $params['store_id']])->count();
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'supplier_id' => $params['supplier_id'],
|
||||
'store_id' => $params['store_id'],
|
||||
'order_type' => $params['order_type'],
|
||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||
'oid' => $params['oid'] ?? 0,
|
||||
'store_id' => $params['store_id'] ?? 0,
|
||||
'product_id' => $params['product_id'],
|
||||
'unit' => $params['unit'],
|
||||
'oid' => $params['oid'],
|
||||
'code' => $params['code'],
|
||||
'manufacture' => $params['manufacture'],
|
||||
'expiration_date' => $params['expiration_date'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'enter_admin_id' => $params['enter_admin_id'],
|
||||
'staff_id' => $params['staff_id'],
|
||||
'batch' => $params['batch'],
|
||||
'batch' => $batch_count + 1,
|
||||
'nums' => $params['nums'],
|
||||
'refund_nums' => $params['refund_nums'],
|
||||
'before_nums' => $params['before_nums'],
|
||||
'after_nums' => $params['after_nums'],
|
||||
'mark' => $params['mark'],
|
||||
'price' => $params['price'],
|
||||
'total_price' => $params['total_price'],
|
||||
'purchase' => $params['purchase'],
|
||||
'cost' => $params['cost'],
|
||||
'vip_price' => $params['vip_price'],
|
||||
'is_pay' => $params['is_pay'],
|
||||
'pay_type' => $params['pay_type'],
|
||||
'status' => $params['status'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
'before_nums' => 0,
|
||||
'after_nums' => 0,
|
||||
'price' => $params['price'] ?? '',
|
||||
'purchase' => $params['purchase'] ?? '',
|
||||
'total_price' => $params['total_price'] ?? '',
|
||||
'admin_id' => $params['admin_id'],
|
||||
'code' => $params['code'] ?? '',
|
||||
'status' => 1,
|
||||
'pay_type' => $params['pay_type'] ?? 0,
|
||||
'mark' => $params['mark'] ?? '',
|
||||
];
|
||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||
$data['manufacture'] = strtotime($params['manufacture']);
|
||||
}
|
||||
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
||||
$data['expiration_date'] = strtotime($params['expiration_date']);
|
||||
}
|
||||
$res = WarehouseProduct::create($data);
|
||||
SqlChannelLog('WarehouseProduct', $res['id'], $params['nums'], 1, Request()->url(), $admin_id);
|
||||
return $res;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
* 设置出库商品
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
public static function setOutbound(array $params, $type = 1, $admin_id = 0)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
OutboundProduct::where('id', $params['id'])->update([
|
||||
$after_nums = 0;
|
||||
if ($params['order_type'] != 6) {
|
||||
$storage = WarehouseStorage::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storage) {
|
||||
$after_nums = bcsub($storage['nums'], $params['nums']);
|
||||
$total_price = bcmul($after_nums, $params['purchase'], 2);
|
||||
WarehouseStorage::update(['nums' => bcsub($storage['nums'], $params['nums']), 'total_price' => $total_price], ['id' => $storage['id']]);
|
||||
SqlChannelLog('WarehouseStorage', $storage['id'], bcsub($storage['nums'], $params['nums']), -1, Request()->url(), $admin_id);
|
||||
} else {
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'nums' => -$params['nums'],
|
||||
'total_price' => 0
|
||||
];
|
||||
$storage = WarehouseStorage::create($data);
|
||||
SqlChannelLog('WarehouseStorage', $storage->id, -$params['nums'], -1, Request()->url(), $admin_id);
|
||||
}
|
||||
} else {
|
||||
$storage['nums'] = 0;
|
||||
}
|
||||
|
||||
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count();
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'supplier_id' => $params['supplier_id'],
|
||||
'store_id' => $params['store_id'],
|
||||
'order_type' => $params['order_type'],
|
||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||
'oid' => $params['oid'] ?? 0,
|
||||
'store_id' => $params['store_id'] ?? 0,
|
||||
'product_id' => $params['product_id'],
|
||||
'unit' => $params['unit'],
|
||||
'oid' => $params['oid'],
|
||||
'code' => $params['code'],
|
||||
'manufacture' => $params['manufacture'],
|
||||
'expiration_date' => $params['expiration_date'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'enter_admin_id' => $params['enter_admin_id'],
|
||||
'staff_id' => $params['staff_id'],
|
||||
'batch' => $params['batch'],
|
||||
'financial_pm' => $params['financial_pm'],
|
||||
'batch' => $batch_count + 1,
|
||||
'nums' => $params['nums'],
|
||||
'refund_nums' => $params['refund_nums'],
|
||||
'before_nums' => $params['before_nums'],
|
||||
'after_nums' => $params['after_nums'],
|
||||
'mark' => $params['mark'],
|
||||
'price' => $params['price'],
|
||||
'total_price' => $params['total_price'],
|
||||
'purchase' => $params['purchase'],
|
||||
'cost' => $params['cost'],
|
||||
'vip_price' => $params['vip_price'],
|
||||
'is_pay' => $params['is_pay'],
|
||||
'pay_type' => $params['pay_type'],
|
||||
'status' => $params['status'],
|
||||
]);
|
||||
'before_nums' => $storage['nums'],
|
||||
'after_nums' => $after_nums,
|
||||
'price' => $params['price'] ?? 0,
|
||||
'purchase' => $params['purchase'] ?? 0,
|
||||
'vip_price' => $params['vip_price'] ?? 0,
|
||||
'total_price' => $params['total_price'] ?? 0,
|
||||
'admin_id' => $params['admin_id'],
|
||||
'code' => $params['code'] ?? '',
|
||||
'unit' => $params['unit'] ?? 0,
|
||||
'status' => 0,
|
||||
'mark' => $params['mark'] ?? '',
|
||||
'order_type' => $params['order_type'] ?? '',
|
||||
];
|
||||
$res = WarehouseProduct::create($data);
|
||||
SqlChannelLog('WarehouseProduct', $res->id, $params['nums'], $params['financial_pm'] == 1 ? 1 : -1, Request()->url(), $admin_id);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
return $res;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @notes 编辑商品仓储信息
|
||||
* @param array $params
|
||||
* @param int $admin_id
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
public static function edit(array $params, $admin_id = 0)
|
||||
{
|
||||
return OutboundProduct::destroy($params['id']);
|
||||
Db::startTrans();
|
||||
try {
|
||||
$find = WarehouseOrder::where('id', $params['oid'])->find();
|
||||
if ($find) {
|
||||
$res = WarehouseProduct::where('id', $params['id'])->withTrashed()->find();
|
||||
if ($params['nums'] > $res['nums']) {
|
||||
$nums = bcsub($params['nums'], $res['nums'], 2);
|
||||
if ($res['financial_pm'] == 0) {
|
||||
self::decWarehouseProduct($res, $nums);
|
||||
} else {
|
||||
self::incWarehouseProduct($res, $nums);
|
||||
}
|
||||
} else {
|
||||
if ($params['nums'] == 0) {
|
||||
self::decWarehouseProduct($res, $res['nums']);
|
||||
} else {
|
||||
$nums = bcsub($res['nums'], $params['nums'], 2);
|
||||
if ($res['financial_pm'] == 0) {
|
||||
self::incWarehouseProduct($res, $nums);
|
||||
} else {
|
||||
self::decWarehouseProduct($res, $nums);
|
||||
}
|
||||
}
|
||||
}
|
||||
$datas = [
|
||||
'total_price' => $params['total_price'],
|
||||
];
|
||||
if ($find['financial_pm'] == 1) {
|
||||
$datas['supplier_id'] = $params['supplier_id'];
|
||||
$datas['pay_type'] = $params['pay_type'];
|
||||
$datas['purchase'] = $params['purchase'];
|
||||
} else {
|
||||
$datas['price'] = $params['price'];
|
||||
}
|
||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||
$datas['manufacture'] = strtotime($params['manufacture']);
|
||||
}
|
||||
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
||||
$datas['expiration_date'] = strtotime($params['expiration_date']);
|
||||
}
|
||||
$res->save($datas);
|
||||
}
|
||||
Db::commit();
|
||||
return $res;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除商品仓储信息
|
||||
* @param array $params
|
||||
* @param int $admin_id
|
||||
* @return bool
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function delete(array $params, $admin_id = 0): bool
|
||||
{
|
||||
$res = WarehouseProduct::where('id', $params['id'])->find();
|
||||
if ($res) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($res['financial_pm'] == 1) {
|
||||
self::decWarehouseProduct($res, $res['nums']);
|
||||
} else {
|
||||
self::incWarehouseProduct($res, $res['nums']);
|
||||
}
|
||||
$res->delete();
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($th->getMessage());
|
||||
}
|
||||
}
|
||||
throw new BusinessException('没有查到出入库信息');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @notes 结算
|
||||
* @param $id
|
||||
* @return void
|
||||
*/
|
||||
public static function settlement($id)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$find = WarehouseProduct::where(['id' => $id, 'financial_pm' => 1, 'is_pay' => 0])->find();
|
||||
if ($find) {
|
||||
$find->is_pay = 1;
|
||||
$find->save();
|
||||
} else {
|
||||
throw new BusinessException('没有查到出入库信息');
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 仓库重置出入库数量
|
||||
* @param $params
|
||||
* @param int $admin_id
|
||||
* @return void
|
||||
*/
|
||||
public static function settNums($params, $admin_id = 0)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$res = WarehouseProduct::where('id', $params['id'])->find();
|
||||
if ($res) {
|
||||
if ($params['nums'] > $res['nums']) {
|
||||
$nums = bcsub($params['nums'], $res['nums'], 2);
|
||||
self::incWarehouseProduct($res, $nums);
|
||||
} else {
|
||||
$nums = bcsub($res['nums'], $params['nums'], 2);
|
||||
self::decWarehouseProduct($res, $nums);
|
||||
}
|
||||
if ($res['financial_pm'] == 1) {
|
||||
$datas = [
|
||||
'nums' => $params['nums'],
|
||||
'total_price' => bcmul($params['nums'], $res['purchase'], 2),
|
||||
];
|
||||
} else {
|
||||
$datas = [
|
||||
'nums' => $params['nums'],
|
||||
'total_price' => bcmul($params['nums'], $res['price'], 2),
|
||||
];
|
||||
}
|
||||
|
||||
$res->save($datas);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取商品仓储信息详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return OutboundProduct::findOrEmpty($params['id'])->toArray();
|
||||
$data = WarehouseProduct::findOrEmpty($params['id'])->toArray();
|
||||
if ($data) {
|
||||
$data['manufacture'] = date('Y-m-d', $data['manufacture']);
|
||||
$data['expiration_date'] = date('Y-m-d', $data['expiration_date']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加商品入库数量
|
||||
* @param $warehouseProduct
|
||||
* @param $nums
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function incWarehouseProduct($warehouseProduct, $nums)
|
||||
{
|
||||
$warehouseStorage = WarehouseStorage::where('warehouse_id', $warehouseProduct['warehouse_id'])
|
||||
->where('product_id', $warehouseProduct['product_id'])->find();
|
||||
$warehouseStorage->nums = bcadd($warehouseStorage->nums, $nums, 2);
|
||||
$warehouseStorage->save();
|
||||
SqlChannelLog('WarehouseStorage', $warehouseStorage['id'], $nums, 1, Request()->url());
|
||||
|
||||
$update = [
|
||||
'nums' => bcadd($warehouseProduct['nums'], $nums, 2),
|
||||
'total_price' => bcadd($warehouseProduct['total_price'], bcmul($nums, $warehouseProduct['price'], 2), 2),
|
||||
];
|
||||
WarehouseProduct::where('id', $warehouseProduct['id'])->update($update);
|
||||
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $nums, 1, Request()->url());
|
||||
|
||||
$find = WarehouseProduct::where('oid', $warehouseProduct['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $warehouseProduct['oid'])->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
self::updateStoreStorage2($warehouseProduct, $nums);
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少商品入库数量
|
||||
* @param $warehouseProduct
|
||||
* @param $nums
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function decWarehouseProduct($warehouseProduct, $nums)
|
||||
{
|
||||
$warehouseStorage = WarehouseStorage::where('warehouse_id', $warehouseProduct['warehouse_id'])
|
||||
->where('product_id', $warehouseProduct['product_id'])->find();
|
||||
$warehouseStorage->nums = bcsub($warehouseStorage->nums, $nums, 2);
|
||||
$warehouseStorage->save();
|
||||
SqlChannelLog('WarehouseStorage', $warehouseStorage['id'], $nums, -1, Request()->url());
|
||||
|
||||
$update = [
|
||||
'nums' => bcsub($warehouseProduct['nums'], $nums, 2),
|
||||
'total_price' => bcsub($warehouseProduct['total_price'], bcmul($nums, $warehouseProduct['price'], 2), 2),
|
||||
];
|
||||
WarehouseProduct::where('id', $warehouseProduct['id'])->update($update);
|
||||
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $nums, -1, Request()->url());
|
||||
|
||||
$find = WarehouseProduct::where('oid', $warehouseProduct['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $warehouseProduct['oid'])->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
self::updateStoreStorage2($warehouseProduct, $nums);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改门店商品库存
|
||||
* @param $warehouseProduct
|
||||
* @param $nums
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function updateStoreStorage2($warehouseProduct, $nums)
|
||||
{
|
||||
if ($warehouseProduct['financial_pm'] == 0 && $warehouseProduct['status'] == 1) {
|
||||
// 出库单已确认,增加门店库存
|
||||
$storeBranchProduct = StoreBranchProduct::where('store_id', $warehouseProduct->store_id)
|
||||
->where('product_id', $warehouseProduct->product_id)->find();
|
||||
if (!empty($storeBranchProduct)) {
|
||||
$storeBranchProduct->stock = $storeBranchProduct->stock + $nums;
|
||||
$storeBranchProduct->save();
|
||||
}
|
||||
} elseif ($warehouseProduct['store_id'] == 1 && $warehouseProduct['financial_pm'] == 1 && $warehouseProduct['status'] == 1) {
|
||||
// 入库单已确认,减少门店库存
|
||||
$storeBranchProduct = StoreBranchProduct::where('store_id', $warehouseProduct->store_id)
|
||||
->where('product_id', $warehouseProduct->product_id)->find();
|
||||
if (!empty($storeBranchProduct)) {
|
||||
$storeBranchProduct->stock = $storeBranchProduct->stock - $nums;
|
||||
$storeBranchProduct->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ namespace app\psi\logic;
|
||||
use app\common\model\WarehouseOrder;
|
||||
use app\common\logic\BaseLogic;
|
||||
use Exception;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -29,29 +30,48 @@ class WarehouseOrderLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
WarehouseOrder::create([
|
||||
$warehouseOrderAttr = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'supplier_id' => $params['supplier_id'],
|
||||
'store_id' => $params['store_id'],
|
||||
'oid' => $params['oid'],
|
||||
'order_type' => $params['order_type'],
|
||||
'code' => $params['code'],
|
||||
'order_type' => $params['order_type'] ?? 7,
|
||||
'admin_id' => $params['admin_id'],
|
||||
'batch' => $params['batch'],
|
||||
'mark' => $params['mark'],
|
||||
'nums' => $params['nums'],
|
||||
'purchase' => $params['purchase'],
|
||||
'total_price' => $params['total_price'],
|
||||
'completed_amount' => $params['completed_amount'],
|
||||
'outstanding_amount' => $params['outstanding_amount'],
|
||||
'status' => $params['status'],
|
||||
]);
|
||||
|
||||
'batch' => 0,
|
||||
'code' => getNewOrderId('RK'),
|
||||
'mark' => $params['remark'],
|
||||
'completed_amount' => $params['completed_amount'] ?? 0,
|
||||
'outstanding_amount' => $params['outstanding_amount'] ?? 0,
|
||||
];
|
||||
$total_price = 0;
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$total_price += $v['total_price'];
|
||||
}
|
||||
$warehouseOrderAttr['total_price'] = $total_price;
|
||||
$res = WarehouseOrder::create($warehouseOrderAttr);
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$data['admin_id'] = $params['admin_id'];
|
||||
$data['store_id'] = 0;
|
||||
$data['oid'] = $res['id'];
|
||||
$data['supplier_id'] = $params['supplier_id'];
|
||||
$data['warehouse_id'] = $params['warehouse_id'];
|
||||
$data['code'] = $params['code'];
|
||||
$data['product_id'] = $v['product_id'];
|
||||
$data['nums'] = $v['nums'];
|
||||
$data['purchase'] = $v['purchase'];
|
||||
$data['total_price'] = $v['total_price'];
|
||||
$data['order_type'] = $warehouseOrderAttr['order_type'];
|
||||
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']);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,18 @@
|
||||
namespace app\psi\logic;
|
||||
|
||||
|
||||
use app\common\model\psi\warehouse_storage\WarehouseStorage;
|
||||
use app\common\model\store\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\WarehouseOrder;
|
||||
use app\common\model\WarehouseProduct;
|
||||
use app\common\logic\BaseLogic;
|
||||
use Exception;
|
||||
use support\exception\BusinessException;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* PsiWarehouseProduct逻辑
|
||||
* Class WarehouseProductLogic
|
||||
@ -17,129 +23,403 @@ use think\facade\Db;
|
||||
class WarehouseProductLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @notes 添加商品仓储信息
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
public static function add(array $params, $type = 1, $admin_id = 0)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
WarehouseProduct::create([
|
||||
if (!in_array($params['order_type'], [6, 9])) {
|
||||
$storage = WarehouseStorage::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storage) {
|
||||
$after_nums = $storage['nums'] + $params['nums'];
|
||||
if ($type == 1) {
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
|
||||
if (!$storeProduct) {
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
if ($storeProduct['purchase'] <= 0) {
|
||||
$total_price = 0;
|
||||
} else {
|
||||
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
||||
}
|
||||
WarehouseStorage::update(['nums' => $after_nums, 'total_price' => $total_price], ['id' => $storage['id']]);
|
||||
SqlChannelLog('WarehouseStorage', $storage['id'], $after_nums, 1, Request()->url(), $admin_id);
|
||||
}
|
||||
} else {
|
||||
$after_nums = $params['nums'];
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
|
||||
if (!$storeProduct) {
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
if ($storeProduct['purchase'] <= 0) {
|
||||
$total_price = 0;
|
||||
} else {
|
||||
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
||||
}
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'nums' => $params['nums'],
|
||||
'total_price' => $total_price
|
||||
];
|
||||
$storage = WarehouseStorage::create($data);
|
||||
SqlChannelLog('WarehouseStorage', $storage['id'], -$params['nums'], 1, Request()->url(), $admin_id);
|
||||
}
|
||||
}
|
||||
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'store_id' => $params['store_id']])->count();
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'supplier_id' => $params['supplier_id'],
|
||||
'store_id' => $params['store_id'],
|
||||
'order_type' => $params['order_type'],
|
||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||
'oid' => $params['oid'] ?? 0,
|
||||
'store_id' => $params['store_id'] ?? 0,
|
||||
'product_id' => $params['product_id'],
|
||||
'unit' => $params['unit'],
|
||||
'oid' => $params['oid'],
|
||||
'code' => $params['code'],
|
||||
'manufacture' => $params['manufacture'],
|
||||
'expiration_date' => $params['expiration_date'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'enter_admin_id' => $params['enter_admin_id'],
|
||||
'staff_id' => $params['staff_id'],
|
||||
'batch' => $params['batch'],
|
||||
'batch' => $batch_count + 1,
|
||||
'nums' => $params['nums'],
|
||||
'refund_nums' => $params['refund_nums'],
|
||||
'before_nums' => $params['before_nums'],
|
||||
'after_nums' => $params['after_nums'],
|
||||
'mark' => $params['mark'],
|
||||
'price' => $params['price'],
|
||||
'total_price' => $params['total_price'],
|
||||
'purchase' => $params['purchase'],
|
||||
'cost' => $params['cost'],
|
||||
'vip_price' => $params['vip_price'],
|
||||
'is_pay' => $params['is_pay'],
|
||||
'pay_type' => $params['pay_type'],
|
||||
'status' => $params['status'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
'before_nums' => 0,
|
||||
'after_nums' => 0,
|
||||
'price' => $params['price'] ?? '',
|
||||
'purchase' => $params['purchase'] ?? '',
|
||||
'total_price' => $params['total_price'] ?? '',
|
||||
'admin_id' => $params['admin_id'],
|
||||
'code' => $params['code'] ?? '',
|
||||
'status' => 1,
|
||||
'pay_type' => $params['pay_type'] ?? 0,
|
||||
'mark' => $params['mark'] ?? '',
|
||||
];
|
||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||
$data['manufacture'] = strtotime($params['manufacture']);
|
||||
}
|
||||
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
||||
$data['expiration_date'] = strtotime($params['expiration_date']);
|
||||
}
|
||||
$res = WarehouseProduct::create($data);
|
||||
SqlChannelLog('WarehouseProduct', $res['id'], $params['nums'], 1, Request()->url(), $admin_id);
|
||||
return $res;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
* 设置出库商品
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
public static function setOutbound(array $params, $type = 1, $admin_id = 0)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
WarehouseProduct::where('id', $params['id'])->update([
|
||||
$after_nums = 0;
|
||||
if ($params['order_type'] != 6) {
|
||||
$storage = WarehouseStorage::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storage) {
|
||||
$after_nums = bcsub($storage['nums'], $params['nums']);
|
||||
$total_price = bcmul($after_nums, $params['purchase'], 2);
|
||||
WarehouseStorage::update(['nums' => bcsub($storage['nums'], $params['nums']), 'total_price' => $total_price], ['id' => $storage['id']]);
|
||||
SqlChannelLog('WarehouseStorage', $storage['id'], bcsub($storage['nums'], $params['nums']), -1, Request()->url(), $admin_id);
|
||||
} else {
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'nums' => -$params['nums'],
|
||||
'total_price' => 0
|
||||
];
|
||||
$storage = WarehouseStorage::create($data);
|
||||
SqlChannelLog('WarehouseStorage', $storage->id, -$params['nums'], -1, Request()->url(), $admin_id);
|
||||
}
|
||||
} else {
|
||||
$storage['nums'] = 0;
|
||||
}
|
||||
|
||||
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count();
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'supplier_id' => $params['supplier_id'],
|
||||
'store_id' => $params['store_id'],
|
||||
'order_type' => $params['order_type'],
|
||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||
'oid' => $params['oid'] ?? 0,
|
||||
'store_id' => $params['store_id'] ?? 0,
|
||||
'product_id' => $params['product_id'],
|
||||
'unit' => $params['unit'],
|
||||
'oid' => $params['oid'],
|
||||
'code' => $params['code'],
|
||||
'manufacture' => $params['manufacture'],
|
||||
'expiration_date' => $params['expiration_date'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'enter_admin_id' => $params['enter_admin_id'],
|
||||
'staff_id' => $params['staff_id'],
|
||||
'batch' => $params['batch'],
|
||||
'financial_pm' => $params['financial_pm'],
|
||||
'batch' => $batch_count + 1,
|
||||
'nums' => $params['nums'],
|
||||
'refund_nums' => $params['refund_nums'],
|
||||
'before_nums' => $params['before_nums'],
|
||||
'after_nums' => $params['after_nums'],
|
||||
'mark' => $params['mark'],
|
||||
'price' => $params['price'],
|
||||
'total_price' => $params['total_price'],
|
||||
'purchase' => $params['purchase'],
|
||||
'cost' => $params['cost'],
|
||||
'vip_price' => $params['vip_price'],
|
||||
'is_pay' => $params['is_pay'],
|
||||
'pay_type' => $params['pay_type'],
|
||||
'status' => $params['status'],
|
||||
]);
|
||||
'before_nums' => $storage['nums'],
|
||||
'after_nums' => $after_nums,
|
||||
'price' => $params['price'] ?? 0,
|
||||
'purchase' => $params['purchase'] ?? 0,
|
||||
'vip_price' => $params['vip_price'] ?? 0,
|
||||
'total_price' => $params['total_price'] ?? 0,
|
||||
'admin_id' => $params['admin_id'],
|
||||
'code' => $params['code'] ?? '',
|
||||
'unit' => $params['unit'] ?? 0,
|
||||
'status' => 0,
|
||||
'mark' => $params['mark'] ?? '',
|
||||
'order_type' => $params['order_type'] ?? '',
|
||||
];
|
||||
$res = WarehouseProduct::create($data);
|
||||
SqlChannelLog('WarehouseProduct', $res->id, $params['nums'], $params['financial_pm'] == 1 ? 1 : -1, Request()->url(), $admin_id);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
return $res;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @notes 编辑商品仓储信息
|
||||
* @param array $params
|
||||
* @param int $admin_id
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
public static function edit(array $params, $admin_id = 0)
|
||||
{
|
||||
return WarehouseProduct::destroy($params['id']);
|
||||
Db::startTrans();
|
||||
try {
|
||||
$find = WarehouseOrder::where('id', $params['oid'])->find();
|
||||
if ($find) {
|
||||
$res = WarehouseProduct::where('id', $params['id'])->withTrashed()->find();
|
||||
if ($params['nums'] > $res['nums']) {
|
||||
$nums = bcsub($params['nums'], $res['nums'], 2);
|
||||
self::incWarehouseProduct($res, $nums);
|
||||
} else {
|
||||
if ($params['nums'] == 0) {
|
||||
self::decWarehouseProduct($res, $res['nums']);
|
||||
} else {
|
||||
$nums = bcsub($res['nums'], $params['nums'], 2);
|
||||
self::decWarehouseProduct($res, $nums);
|
||||
}
|
||||
}
|
||||
$datas = [
|
||||
'total_price' => $params['total_price'],
|
||||
];
|
||||
if ($find['financial_pm'] == 1) {
|
||||
$datas['supplier_id'] = $params['supplier_id'];
|
||||
$datas['pay_type'] = $params['pay_type'];
|
||||
$datas['purchase'] = $params['purchase'];
|
||||
} else {
|
||||
$datas['price'] = $params['price'];
|
||||
}
|
||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||
$datas['manufacture'] = strtotime($params['manufacture']);
|
||||
}
|
||||
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
||||
$datas['expiration_date'] = strtotime($params['expiration_date']);
|
||||
}
|
||||
$res->save($datas);
|
||||
}
|
||||
Db::commit();
|
||||
return $res;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除商品仓储信息
|
||||
* @param array $params
|
||||
* @param int $admin_id
|
||||
* @return bool
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function delete(array $params, $admin_id = 0): bool
|
||||
{
|
||||
$res = WarehouseProduct::where('id', $params['id'])->find();
|
||||
if ($res) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($res['financial_pm'] == 1) {
|
||||
self::decWarehouseProduct($res, $res['nums']);
|
||||
} else {
|
||||
self::incWarehouseProduct($res, $res['nums']);
|
||||
}
|
||||
$res->delete();
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($th->getMessage());
|
||||
}
|
||||
}
|
||||
throw new BusinessException('没有查到出入库信息');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @notes 结算
|
||||
* @param $id
|
||||
* @return void
|
||||
*/
|
||||
public static function settlement($id)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$find = WarehouseProduct::where(['id' => $id, 'financial_pm' => 1, 'is_pay' => 0])->find();
|
||||
if ($find) {
|
||||
$find->is_pay = 1;
|
||||
$find->save();
|
||||
} else {
|
||||
throw new BusinessException('没有查到出入库信息');
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 仓库重置出入库数量
|
||||
* @param $params
|
||||
* @param int $admin_id
|
||||
* @return void
|
||||
*/
|
||||
public static function settNums($params, $admin_id = 0)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$res = WarehouseProduct::where('id', $params['id'])->find();
|
||||
if ($res) {
|
||||
if ($params['nums'] > $res['nums']) {
|
||||
$nums = bcsub($params['nums'], $res['nums'], 2);
|
||||
self::incWarehouseProduct($res, $nums);
|
||||
} else {
|
||||
$nums = bcsub($res['nums'], $params['nums'], 2);
|
||||
self::decWarehouseProduct($res, $nums);
|
||||
}
|
||||
if ($res['financial_pm'] == 1) {
|
||||
$datas = [
|
||||
'nums' => $params['nums'],
|
||||
'total_price' => bcmul($params['nums'], $res['purchase'], 2),
|
||||
];
|
||||
} else {
|
||||
$datas = [
|
||||
'nums' => $params['nums'],
|
||||
'total_price' => bcmul($params['nums'], $res['price'], 2),
|
||||
];
|
||||
}
|
||||
|
||||
$res->save($datas);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取商品仓储信息详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2025/03/10 11:08
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return WarehouseProduct::findOrEmpty($params['id'])->toArray();
|
||||
$data = WarehouseProduct::findOrEmpty($params['id'])->toArray();
|
||||
if ($data) {
|
||||
$data['manufacture'] = date('Y-m-d', $data['manufacture']);
|
||||
$data['expiration_date'] = date('Y-m-d', $data['expiration_date']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加商品入库数量
|
||||
* @param $warehouseProduct
|
||||
* @param $nums
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function incWarehouseProduct($warehouseProduct, $nums)
|
||||
{
|
||||
$warehouseStorage = WarehouseStorage::where('warehouse_id', $warehouseProduct['warehouse_id'])
|
||||
->where('product_id', $warehouseProduct['product_id'])->find();
|
||||
$warehouseStorage->nums = bcadd($warehouseStorage->nums, $nums, 2);
|
||||
$warehouseStorage->save();
|
||||
SqlChannelLog('WarehouseStorage', $warehouseStorage['id'], $nums, 1, Request()->url());
|
||||
|
||||
$update = [
|
||||
'nums' => bcadd($warehouseProduct['nums'], $nums, 2),
|
||||
'total_price' => bcadd($warehouseProduct['total_price'], bcmul($nums, $warehouseProduct['price'], 2), 2),
|
||||
];
|
||||
WarehouseProduct::where('id', $warehouseProduct['id'])->update($update);
|
||||
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $nums, 1, Request()->url());
|
||||
|
||||
$find = WarehouseProduct::where('oid', $warehouseProduct['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $warehouseProduct['oid'])->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
self::updateStoreStorage($warehouseProduct, $nums);
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少商品入库数量
|
||||
* @param $warehouseProduct
|
||||
* @param $nums
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function decWarehouseProduct($warehouseProduct, $nums)
|
||||
{
|
||||
$warehouseStorage = WarehouseStorage::where('warehouse_id', $warehouseProduct['warehouse_id'])
|
||||
->where('product_id', $warehouseProduct['product_id'])->find();
|
||||
$warehouseStorage->nums = bcsub($warehouseStorage->nums, $nums, 2);
|
||||
$warehouseStorage->save();
|
||||
SqlChannelLog('WarehouseStorage', $warehouseStorage['id'], $nums, -1, Request()->url());
|
||||
|
||||
$update = [
|
||||
'nums' => bcsub($warehouseProduct['nums'], $nums, 2),
|
||||
'total_price' => bcsub($warehouseProduct['total_price'], bcmul($nums, $warehouseProduct['price'], 2), 2),
|
||||
];
|
||||
WarehouseProduct::where('id', $warehouseProduct['id'])->update($update);
|
||||
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $nums, -1, Request()->url());
|
||||
|
||||
$find = WarehouseProduct::where('oid', $warehouseProduct['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $warehouseProduct['oid'])->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
self::updateStoreStorage($warehouseProduct, $nums);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改门店商品库存
|
||||
* @param $warehouseProduct
|
||||
* @param $nums
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function updateStoreStorage($warehouseProduct, $nums)
|
||||
{
|
||||
if ($warehouseProduct['store_id'] == 1 && $warehouseProduct['status'] == 1) {
|
||||
// 入库单已确认,减少门店库存
|
||||
$storeBranchProduct = StoreBranchProduct::where('store_id', $warehouseProduct->store_id)
|
||||
->where('product_id', $warehouseProduct->product_id)->find();
|
||||
if (!empty($storeBranchProduct)) {
|
||||
$storeBranchProduct->stock = $storeBranchProduct->stock - $nums;
|
||||
$storeBranchProduct->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -20,10 +20,7 @@ class WarehouseOrderValidate extends BaseValidate
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'batch' => 'require',
|
||||
'total_price' => 'require',
|
||||
'status' => 'require',
|
||||
|
||||
];
|
||||
|
||||
|
||||
@ -33,10 +30,7 @@ class WarehouseOrderValidate extends BaseValidate
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'batch' => '批次',
|
||||
'total_price' => '总价格',
|
||||
'status' => '状态',
|
||||
|
||||
];
|
||||
|
||||
|
||||
@ -48,7 +42,7 @@ class WarehouseOrderValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['batch','total_price','status']);
|
||||
return $this->only(['total_price']);
|
||||
}
|
||||
|
||||
|
||||
@ -60,7 +54,7 @@ class WarehouseOrderValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','batch','total_price','status']);
|
||||
return $this->only(['id','total_price']);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user