refactor(psi): 重构采购模块

- 移除了供应链相关代码,包括 SupplierController、SupplierLists 和 SupplierLogic
- 更新了 PurchaseOrderController 和 PurchaseProductController,调整了相关逻辑
- 修改了 PurchaseProductLists 中的供应商名称获取方式
- 优化了 PurchaseOrderLogic 中的订单编辑逻辑
- 更新了 Supplier 模型的表名
This commit is contained in:
mkm 2025-03-04 16:18:22 +08:00
parent 4bc701a546
commit 6757d05842
9 changed files with 455 additions and 113 deletions

View File

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

View File

@ -62,69 +62,6 @@ class PurchaseOrderController extends BaseAdminController
return $this->success('添加成功', [], 1, 1);
}
}
/**
* @notes 添加出库单
* @return \think\response\Json
* @author admin
* @date 2024/08/20 10:50
*/
public function outbound()
{
$product_arr = $this->request->post('product_arr');
$warehouse_id = $this->request->post('warehouse_id');
$delivery_time = $this->request->post('delivery_time');
$mark = $this->request->post('mark');
$type = $this->request->post('order_type', 1);
Db::startTrans();
try {
if($type==1){
$code=getNewOrderId('TGY');
}else{
$code=getNewOrderId('BS');
}
$arr = [
'warehouse_id' => $warehouse_id,
'store_id' => 0,
'supplier_id' => 0,
'code' => $code,
'admin_id' => $this->adminId,
'financial_pm' => 0,
'batch' => 0,
'mark' => $mark ?? "",
];
$arr['delivery_time'] = strtotime($delivery_time);
$res = WarehouseOrder::create($arr);
foreach ($product_arr as $key => $arr) {
$data = [
'warehouse_id' => $warehouse_id,
'product_id' => $arr['id'],
'store_id' => 0,
'financial_pm' => 0,
'batch' => 1,
'nums' => $arr['stock'],
'status' => 1,
'admin_id' => $this->adminId,
'type' => $type,
'order_type' => 0,
];
$storeProduct = StoreProduct::where('id', $arr['id'])->find();
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
$data['purchase'] = $storeProduct['purchase'];
$data['oid'] = $res['id'];
$data['financial_pm'] = 0;
$data['price'] = $storeProduct['price'];
WarehouseProductLogic::setOutbound($data,1,$this->adminId);
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
}
Db::commit();
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
return $this->success('出库成功', [], 1, 1);
}
/**
* @notes 编辑仓储商品单
@ -136,7 +73,7 @@ class PurchaseOrderController extends BaseAdminController
{
$params = $this->request->post();
$params['admin_id'] = $this->adminId;
$result = WarehouseOrderLogic::edit($params);
$result = PurchaseOrderLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}

View File

@ -7,6 +7,7 @@ use app\admin\controller\BaseAdminController;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\admin\validate\warehouse_product\WarehouseProductValidate;
use app\psi\lists\purchase_product\PurchaseProductLists;
use app\psi\logic\purchase_product\PurchaseProductLogic;
/**
* 商品仓储信息控制器
@ -51,7 +52,7 @@ class PurchaseProductController extends BaseAdminController
{
$params = $this->request->post();
$params['admin_id'] = $this->adminId;
$result = WarehouseProductLogic::edit($params,$this->adminId);
$result = PurchaseProductLogic::edit($params, $this->adminId);
return $this->success('编辑成功', [], 1, 1);
}
@ -64,10 +65,9 @@ class PurchaseProductController extends BaseAdminController
*/
public function delete()
{
$params = (new WarehouseProductValidate())->post()->goCheck('delete');
WarehouseProductLogic::delete($params,$this->adminId);
$params = $this->request->post();
PurchaseProductLogic::delete($params, $this->adminId);
return $this->success('删除成功', [], 1, 1);
}
@ -79,22 +79,10 @@ class PurchaseProductController extends BaseAdminController
*/
public function detail()
{
$params = (new WarehouseProductValidate())->goCheck('detail');
$result = WarehouseProductLogic::detail($params);
$params = $this->request->post();
$result = PurchaseProductLogic::detail($params);
return $this->data($result);
}
/**
* @notes 结算
* @return \think\response\Json
* @author admin
* @date 2024/07/31 16:55
*/
public function settlement(){
$id=$this->request->post('id');
$result = WarehouseProductLogic::settlement($id);
return $this->success('结算成功', [], 1, 1);
}
/**
* 确认操作
*/
@ -109,13 +97,34 @@ class PurchaseProductController extends BaseAdminController
return $this->success('');
}
/**
/**
* 仓库重置出入库数量
*/
public function set_nums()
{
$params=$this->request->post();
$result = WarehouseProductLogic::settNums($params,$this->adminId);
$params = $this->request->post();
$result = PurchaseProductLogic::settNums($params, $this->adminId);
return $this->success('');
}
/**
* 分拣
*/
public function warehouse()
{
$params = $this->request->post();
$result = PurchaseProductLogic::warehouse($params);
return $this->success('');
}
/**
* 追加商品
*/
public function add_arr()
{
$params = $this->request->post();
$params['admin_id'] = $this->adminId;
$result = PurchaseProductLogic::addArr($params);
return $this->success('');
}
}

View File

@ -1,12 +1,11 @@
<?php
namespace app\admin\controller\supplier;
namespace app\psi\controller\supplier;
use app\admin\controller\BaseAdminController;
use app\admin\lists\supplier\SupplierLists;
use app\admin\logic\supplier\SupplierLogic;
use app\admin\validate\supplier\SupplierValidate;
use app\psi\lists\supplier\SupplierLists;
use app\psi\logic\supplier\SupplierLogic;
/**
@ -38,7 +37,7 @@ class SupplierController extends BaseAdminController
*/
public function add()
{
$params = (new SupplierValidate())->post()->goCheck('add');
$params = $this->request->post();
$result = SupplierLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
@ -55,7 +54,7 @@ class SupplierController extends BaseAdminController
*/
public function edit()
{
$params = (new SupplierValidate())->post()->goCheck('edit');
$params = $this->request->post();
$result = SupplierLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
@ -72,7 +71,7 @@ class SupplierController extends BaseAdminController
*/
public function delete()
{
$params = (new SupplierValidate())->post()->goCheck('delete');
$params = $this->request->post();
SupplierLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
@ -86,7 +85,7 @@ class SupplierController extends BaseAdminController
*/
public function detail()
{
$params = (new SupplierValidate())->goCheck('detail');
$params = $this->request->post();
$result = SupplierLogic::detail($params);
return $this->data($result);
}

View File

@ -76,7 +76,7 @@ class PurchaseProductLists extends BaseAdminDataLists implements ListsSearchInte
if (isset($this->params['is_group']) && $this->params['is_group'] == 1) {
$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 {
$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']);
$query->field(['id', 'code','oid','admin_id','supplier_id', 'warehouse_id', 'product_id','is_warehouse', 'nums', 'price', 'total_price', 'manufacture', 'expiration_date', 'mark', 'create_time', 'order_type']);
}
return $query
->limit($this->limitOffset, $this->limitLength)
@ -112,7 +112,7 @@ class PurchaseProductLists extends BaseAdminDataLists implements ListsSearchInte
$item->warehouse_name = '';
}
if ($item->supplier_id) {
$item->supplier_name = Supplier::where('id', $item->supplier_id)->value('mer_name');
$item->supplier_name = Supplier::where('id', $item->supplier_id)->value('name');
}else{
$item->supplier_name = '';
}

View File

@ -1,12 +1,11 @@
<?php
namespace app\admin\lists\supplier;
namespace app\psi\lists\supplier;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\supplier\Supplier;
use app\common\lists\ListsSearchInterface;
use app\common\model\warehouse_product\WarehouseProduct;
/**
* 供应链列表
@ -44,7 +43,7 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array
{
return Supplier::where($this->searchWhere)
->field(['id', 'category_id', 'name', 'phone', 'settle_cycle', 'address', 'mark'])
->field(['id', 'name', 'phone', 'settle_cycle', 'address', 'mark'])
->limit($this->limitOffset, 100)
->order(['id' => 'desc'])
->select()

View File

@ -9,6 +9,7 @@ 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\psi\logic\purchase_product\PurchaseProductLogic;
use Exception;
use support\exception\BusinessException;
use think\facade\Db;
@ -85,15 +86,14 @@ class PurchaseOrderLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
$find = WarehouseOrder::where('id', $params['id'])->find();
$find = PurchaseOrder::where('id', $params['id'])->find();
if (!$find) {
throw new BusinessException('订单不存在');
throw new Exception('订单不存在');
}
$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['order_type'] = $find['order_type'];
$data['supplier_id'] = $v['supplier_id']??0;
$data['pay_type'] = $v['pay_type']??0;
$data['admin_id'] = $params['admin_id'];
@ -103,7 +103,7 @@ class PurchaseOrderLogic extends BaseLogic
$data['code'] = $find['code'];
$data['product_id'] = $v['id'];
$data['nums'] = $v['nums'];
$data['purchase'] = $v['purchase'];
$data['price'] = $v['price'];
$data['total_price'] = $v['total_price'];
$data['financial_pm'] = $find['financial_pm'];
if (!empty($v['manufacture'])) {
@ -112,15 +112,11 @@ class PurchaseOrderLogic extends BaseLogic
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']);
PurchaseProductLogic::add($data,1,$params['admin_id']);
}
$find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
$find = PurchaseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
if ($find) {
WarehouseOrder::where('id', $params['id'])->update([
PurchaseOrder::where('id', $params['id'])->update([
'nums' => $find['nums'],
'total_price' => $find['total_price']
]);

View File

@ -0,0 +1,402 @@
<?php
namespace app\psi\logic\purchase_product;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\logic\BaseLogic;
use app\common\model\psi\purchase_order\PurchaseOrder;
use app\common\model\psi\purchase_product\PurchaseProduct;
use app\common\model\psi\warehouse_storege\WarehouseStorege;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct;
use app\common\model\system_store_storage\SystemStoreStorage;
use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use Exception;
use think\facade\Db;
use support\exception\BusinessException;
/**
* 商品仓储信息逻辑
* Class PurchaseProductLogic
* @package app\admin\logic\warehouse_product
*/
class PurchaseProductLogic extends BaseLogic
{
/**
* @notes 添加商品仓储信息
* @param array $params
* @return bool
* @author admin
* @date 2024/07/31 16:55
*/
public static function add(array $params, $type = 1, $admin_id = 0)
{
// Db::startTrans();
try {
$after_nums = 0;
if (!in_array($params['order_type'], [6, 9])) {
$storege = WarehouseStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
if ($storege) {
$after_nums = $storege['nums'] + $params['nums'];
if ($type == 1) {
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
if (!$storeProduct) {
throw new Exception('商品不存在');
}
if ($storeProduct['purchase'] <= 0) {
$total_price = 0;
} else {
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
}
WarehouseStorege::update(['nums' => $after_nums, 'total_price' => $total_price], ['id' => $storege['id']]);
// SqlChannelLog('WarehouseProductStorege', $storege['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 Exception('商品不存在');
}
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
];
if ($params['financial_pm'] == 0) {
$data['nums'] = -$params['nums'];
}
$storege = WarehouseStorege::create($data);
// SqlChannelLog('WarehouseProductStorege', $storege['id'], -$params['nums'], 1, Request()->url(),$admin_id);
}
}
// $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'] ?? 0,
'oid' => $params['oid'] ?? 0,
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'price' => $params['price'] ?? 0,
'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 = PurchaseProduct::create($data);
// SqlChannelLog('WarehouseProduct', $res['id'], $params['nums'], $params['financial_pm'] == 1 ? 1 : -1, Request()->url(),$admin_id);
return $res;
} catch (\Throwable $e) {
throw new Exception($e->getMessage());
}
}
/**
* @notes 编辑商品仓储信息
* @param array $params
* @return bool
* @author admin
* @date 2024/07/31 16:55
*/
public static function edit(array $params, $admin_id = 0)
{
Db::startTrans();
try {
$find = PurchaseOrder::where('id', $params['oid'])->find();
if ($find) {
$res = PurchaseProduct::where('id', $params['id'])->find();
if ($res['is_warehouse'] == 1) {
WarehouseStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->update([
'nums' => bcsub($res['nums'], $params['nums'], 2)
]);
}
PurchaseProduct::where('id', $params['id'])->update([
'supplier_id' => $params['supplier_id'],
'nums' => $params['nums'],
'price' => $params['price'],
'total_price' => $params['total_price'],
'mark' => $params['mark'] ?? '',
]);
}
Db::commit();
return $res;
} catch (\Exception $e) {
Db::rollback();
throw new Exception($e->getMessage());
}
}
/**
* @notes 删除商品仓储信息
* @param array $params
* @return bool
* @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::decProductIncStorege($res, $res['nums'], $admin_id);
} elseif ($res['financial_pm'] == 0) {
self::incProductDecStorege($res, $res['nums'], $admin_id);
}
$res->delete();
Db::commit();
return true;
} catch (\Throwable $th) {
Db::rollback();
throw new BusinessException($th->getMessage());
}
}
throw new BusinessException('没有查到出入库信息');
}
/**
* * @notes 仓库重置出入库数量
* @param $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::incProductDecStorege($res, $nums, $admin_id);
} else {
$nums = bcsub($res['nums'], $params['nums'], 2);
self::decProductIncStorege($res, $nums, $admin_id);
}
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 2024/07/31 16:55
*/
public static function detail($params): array
{
$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)
{
$warehouseProductStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])
->where('product_id', $warehouseProduct['product_id'])->find();
$warehouseProductStorage->nums = bcadd($warehouseProductStorage->nums, $nums, 2);
$warehouseProductStorage->save();
SqlChannelLog('WarehouseProductStorege', $warehouseProductStorage['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)
{
$warehouseProductStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])
->where('product_id', $warehouseProduct['product_id'])->find();
$warehouseProductStorage->nums = bcsub($warehouseProductStorage->nums, $nums, 2);
$warehouseProductStorage->save();
SqlChannelLog('WarehouseProductStorege', $warehouseProductStorage['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();
}
}
}
/**
* 分拣
*/
public static function warehouse($params)
{
Db::startTrans();
try {
$find = PurchaseProduct::where('id', $params['id'])->find();
if ($find) {
$data = ['is_warehouse' => 1, 'nums' => $params['nums'], 'price' => bcdiv($find['total_price'], $params['nums'], 2)];
PurchaseProduct::where('id', $params['id'])->update($data);
$res = WarehouseStorege::where('warehouse_id', $find['warehouse_id'])->where('product_id', $find['product_id'])->find();
$total_price=PurchaseProduct::where('oid',$find['oid'])->sum('total_price');
PurchaseOrder::where('id',$find['oid'])->update(['total_price'=>$total_price]);
if ($res) {
$res->nums = bcadd($res->nums, $params['nums'], 2);
$res->save();
}else{
$data = [
'warehouse_id' => $find['warehouse_id'],
'product_id' => $find['product_id'],
'nums' => $params['nums'],
'price' => bcdiv($find['total_price'], $params['nums'], 2)
];
WarehouseStorege::create($data);
}
}
Db::commit();
}catch (\Throwable $e) {
Db::rollback();
throw new Exception($e->getMessage());
}
}
public static function addArr($params){
Db::startTrans();
try {
$order=PurchaseOrder::where('id',$params['oid'])->find();
if(!$order){
throw new Exception('订单不存在');
}
$oid=$order['id'];
$code=$order['code'];
$order_type=$order['order_type'];
$product_arr=[];
foreach ($params['product_arr'] as $k => $v) {
if($v['id']<=0){
continue ;
}
$data['admin_id'] = $params['admin_id'];
$data['order_type'] = $order_type;
$data['store_id'] = 0;
$data['oid'] = $oid;
$data['supplier_id'] = 0;
$data['warehouse_id'] = 0;
$data['code'] = $code;
$data['product_id'] = $v['id'];
$data['need_nums'] = $v['nums'];
$data['nums'] = $v['nums'];
$data['price'] = $v['price'];
$data['total_price'] = $v['total_price'];
$product_arr[]=$data;
}
(new PurchaseProduct())->saveAll($product_arr);
Db::commit();
}catch (\Throwable $e) {
Db::rollback();
throw new Exception($e->getMessage());
}
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace app\admin\logic\supplier;
namespace app\psi\logic\supplier;
use app\common\model\supplier\Supplier;
@ -30,7 +30,7 @@ class SupplierLogic extends BaseLogic
Db::startTrans();
try {
Supplier::create([
'mer_name' => $params['mer_name'],
'name' => $params['name'],
'phone' => $params['phone'],
'settle_cycle' => $params['settle_cycle'],
'address' => $params['address'],