- 在多个控制器和逻辑类中,为相关函数增加了admin_id参数 - 更新了WarehouseProductLogic中的多个方法,使其支持记录管理员ID - 修改了ChangeLogLogic和SqlChannelLog函数,增加了admin_id字段
191 lines
6.4 KiB
PHP
191 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic\warehouse_order;
|
|
|
|
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
|
use app\common\model\warehouse_order\WarehouseOrder;
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\beforehand_order\BeforehandOrder;
|
|
use app\common\model\warehouse_product\WarehouseProduct;
|
|
use support\exception\BusinessException;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 仓储商品单逻辑
|
|
* Class WarehouseOrderLogic
|
|
* @package app\admin\logic\warehouse_order
|
|
*/
|
|
class WarehouseOrderLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 添加仓储商品单
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/08/20 10:50
|
|
*/
|
|
public static function add(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
$arr = [
|
|
'warehouse_id' => $params['warehouse_id'],
|
|
'supplier_id' => $params['supplier_id'],
|
|
'code' => $params['code'],
|
|
'admin_id' => $params['admin_id'],
|
|
'financial_pm' => 1,
|
|
'batch' => 0,
|
|
'mark' => $params['remark'],
|
|
'total_price' => $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'];
|
|
}
|
|
$arr['total_price'] = $total_price;
|
|
$res = WarehouseOrder::create($arr);
|
|
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['financial_pm'] = 1;
|
|
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 BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 编辑仓储商品单
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/08/20 10:50
|
|
*/
|
|
public static function edit(array $params): bool
|
|
{
|
|
$find = WarehouseOrder::where('id', $params['id'])->find();
|
|
if (!$find) {
|
|
throw new BusinessException('订单不存在');
|
|
}
|
|
$order_type=BeforehandOrder::where('warehousing_id|outbound_id',$find['id'])->value('order_type')??0;
|
|
Db::startTrans();
|
|
try {
|
|
foreach ($params['product_arr'] as $k => $v) {
|
|
$data['order_type'] = $order_type;
|
|
$data['supplier_id'] = $v['supplier_id']??0;
|
|
$data['pay_type'] = $v['pay_type']??0;
|
|
$data['admin_id'] = $params['admin_id'];
|
|
$data['store_id'] = $find['store_id'];
|
|
$data['oid'] = $find['id'];
|
|
$data['warehouse_id'] = $find['warehouse_id'];
|
|
$data['code'] = $find['code'];
|
|
$data['product_id'] = $v['id'];
|
|
$data['nums'] = $v['nums'];
|
|
$data['purchase'] = $v['purchase'];
|
|
$data['total_price'] = $v['total_price'];
|
|
$data['financial_pm'] = $find['financial_pm'];
|
|
if (!empty($v['manufacture'])) {
|
|
$data['manufacture'] = $v['manufacture'];
|
|
}
|
|
if (!empty($v['expiration_date'])) {
|
|
$data['expiration_date'] = $v['expiration_date'];
|
|
}
|
|
if($find['financial_pm']==0){
|
|
$data['purchase'] = $v['prices'];
|
|
$data['total_price'] = bcmul($v['prices'], $v['nums'], 2);
|
|
}
|
|
WarehouseProductLogic::add($data,1,$params['admin_id']);
|
|
}
|
|
$find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
|
if ($find) {
|
|
WarehouseOrder::where('id', $params['id'])->update([
|
|
'nums' => $find['nums'],
|
|
'total_price' => $find['total_price']
|
|
]);
|
|
}
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Throwable $e) {
|
|
Db::rollback();
|
|
throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 删除仓储商品单
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/08/20 10:50
|
|
*/
|
|
public static function delete(array $params): bool
|
|
{
|
|
$count = WarehouseProduct::where('oid', $params['id'])->count();
|
|
if ($count >= 1) {
|
|
throw new BusinessException('该订单下还有商品没有删除,请先删除商品');
|
|
}
|
|
WarehouseOrder::destroy($params['id']);
|
|
$find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
|
if ($find) {
|
|
WarehouseOrder::where('id', $params['id'])->update([
|
|
'nums' => $find['nums'],
|
|
'total_price' => $find['total_price']
|
|
]);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @notes 编辑仓储商品单
|
|
* @param $data
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/08/20 10:50
|
|
*/
|
|
public static function update_edit($data){
|
|
$res=WarehouseOrder::update($data);
|
|
if($res){
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @notes 获取仓储商品单详情
|
|
* @param $params
|
|
* @return array
|
|
* @author admin
|
|
* @date 2024/08/20 10:50
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
return WarehouseOrder::findOrEmpty($params['id'])->toArray();
|
|
}
|
|
}
|