feat(PurchaseOrderInfoLists): 添加StoreBranchProduct模型使用及库存查询功能
This commit is contained in:
parent
9e0e1524f2
commit
610514e8d6
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\purchase_order_info;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\logic\purchase_order_info\PurchaseOrderInfoLogic;
|
||||
|
||||
/**
|
||||
* 采购订单详情控制器
|
||||
* Class PurchaseOrderInfoController
|
||||
* @package app\admin\controller\purchase_order_info
|
||||
*/
|
||||
class PurchaseOrderInfoController extends BaseAdminController
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 编辑采购供应链商品
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/14 15:06
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
switch ($params['type']) {
|
||||
case 'buyer':
|
||||
PurchaseOrderInfoLogic::buyer($params);
|
||||
break;
|
||||
default:
|
||||
return $this->fail('参数错误');
|
||||
break;
|
||||
}
|
||||
if (PurchaseOrderInfoLogic::hasError()) {
|
||||
return $this->fail(PurchaseOrderInfoLogic::getError());
|
||||
}
|
||||
return $this->success('设置成功', [], 1, 1);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ namespace app\admin\lists\purchase_order_info;
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\purchase_order_info\PurchaseOrderInfo;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
@ -48,13 +49,22 @@ class PurchaseOrderInfoLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
$find=StoreProduct::where('id',$item->product_id)->field('store_info,unit,store_name,image')->find();
|
||||
$find=StoreBranchProduct::where('product_id',$item->product_id)->where('store_id',$item->store_id)->field('store_info,stock,unit,store_name,image')->find();
|
||||
if($find){
|
||||
$item->store_name=$find->store_name;
|
||||
$item->unit_name=StoreProductUnit::where('id',$find->unit)->value('name');
|
||||
$item->unit=$find->unit;
|
||||
$item->stock=$find->stock;
|
||||
$item->store_info=$find->store_info;
|
||||
$item->image=$find->image;
|
||||
}
|
||||
if($item->is_buyer==1){
|
||||
$item->is_buyer_name='需采购';
|
||||
}elseif($item->is_buyer==-1){
|
||||
$item->is_buyer_name='不采购';
|
||||
}else{
|
||||
$item->is_buyer_name='未知';
|
||||
}
|
||||
switch ($item->storage) {
|
||||
case 0:
|
||||
$item->storage_name = '未入库';
|
||||
|
@ -112,18 +112,18 @@ class PurchaseOrderLogic extends BaseLogic
|
||||
$purchase_order_info_two[] = $arr;
|
||||
}
|
||||
$purchaseOrderInfo->saveAll($purchase_order_info_two);
|
||||
$productOffer = [];
|
||||
foreach ($info as $item) {
|
||||
$arr['order_id'] = $res['id'];
|
||||
$arr['product_id'] = $item['product_id'];
|
||||
$arr['price'] = $item['price'];
|
||||
$arr['total_price'] = $item['total_price'];
|
||||
$arr['need_num'] = $item['cart_num'];
|
||||
$arr['unit'] = StoreProduct::where('id', $item['product_id'])->value('unit');
|
||||
$productOffer[] = $arr;
|
||||
}
|
||||
$purchaseProductOffer = new PurchaseProductOffer();
|
||||
$purchaseProductOffer->saveAll($productOffer);
|
||||
// $productOffer = [];
|
||||
// foreach ($info as $item) {
|
||||
// $arr['order_id'] = $res['id'];
|
||||
// $arr['product_id'] = $item['product_id'];
|
||||
// $arr['price'] = $item['price'];
|
||||
// $arr['total_price'] = $item['total_price'];
|
||||
// $arr['need_num'] = $item['cart_num'];
|
||||
// $arr['unit'] = StoreProduct::where('id', $item['product_id'])->value('unit');
|
||||
// $productOffer[] = $arr;
|
||||
// }
|
||||
// $purchaseProductOffer = new PurchaseProductOffer();
|
||||
// $purchaseProductOffer->saveAll($productOffer);
|
||||
// StoreOrder::whereIn('id', $oid_arr)->update(['is_merge' => 1]);
|
||||
// Db::commit();
|
||||
// return true;
|
||||
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\purchase_order_info;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\purchase_order_info\PurchaseOrderInfo;
|
||||
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use think\facade\Db;
|
||||
|
||||
class PurchaseOrderInfoLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* 是否需采购
|
||||
*/
|
||||
public static function buyer($params)
|
||||
{
|
||||
$data['is_buyer'] = $params['is_buyer'];
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($params['is_buyer'] == 1&& $params['poid']>0) {
|
||||
$data['buyer_nums'] = $params['buyer_nums'];
|
||||
$find = PurchaseProductOffer::where('order_id', $params['poid'])->where('product_id', $params['product_id'])->find();
|
||||
if ($find) {
|
||||
PurchaseProductOffer::where('id', $find['id'])->inc('buyer_nums', $params['buyer_nums'])->update();
|
||||
} else {
|
||||
$arr['order_id'] = $params['poid'];
|
||||
$arr['product_id'] = $params['product_id'];
|
||||
$arr['need_num'] = $params['cart_num'];
|
||||
$arr['buyer_nums'] = $params['buyer_nums'];
|
||||
$arr['unit'] = StoreProduct::where('id', $params['product_id'])->value('unit');
|
||||
PurchaseProductOffer::create($arr);
|
||||
}
|
||||
}
|
||||
PurchaseOrderInfo::where('id', $params['id'])->update($data);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user