feat(admin): 添加 demo4 接口并实现价格同步功能
- 在 IndexController 中添加 demo4 方法,用于处理价格同步请求 - 在 DemoLogic 中实现 syncPrice 方法,完成价格同步逻辑 - 支持根据是否为 VIP 用户更新商品价格 - 更新订单总价和商品小计价格 - 如果存在出库单,同步更新仓库商品价格
This commit is contained in:
parent
a6c386a298
commit
82c1eb1ce6
@ -37,4 +37,12 @@ class IndexController extends BaseAdminController
|
|||||||
$res=DemoLogic::test3($id,$warehouse_id);
|
$res=DemoLogic::test3($id,$warehouse_id);
|
||||||
return $this->success('成功');
|
return $this->success('成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function demo4()
|
||||||
|
{
|
||||||
|
$params=$this->request->get();
|
||||||
|
$is_vip=$this->request->get('is_vip',0);
|
||||||
|
$res=DemoLogic::syncPrice($params,$is_vip);
|
||||||
|
return $this->success('成功');
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,6 +3,8 @@
|
|||||||
namespace app\api\logic;
|
namespace app\api\logic;
|
||||||
|
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
|
use app\common\model\beforehand_order\BeforehandOrder;
|
||||||
|
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\store_product_group_price\StoreProductGroupPrice;
|
use app\common\model\store_product_group_price\StoreProductGroupPrice;
|
||||||
@ -111,4 +113,49 @@ class DemoLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function syncPrice($params,$is_vip=0)
|
||||||
|
{
|
||||||
|
$outbound_id=BeforehandOrder::where('id', $params['id'])->value('outbound_id');
|
||||||
|
|
||||||
|
$cartInfo = BeforehandOrderCartInfo::where('bhoid', $params['id'])->select()->toArray();
|
||||||
|
$productIds = array_column($cartInfo, 'product_id');
|
||||||
|
$products = StoreProduct::whereIn('id', $productIds)->select()->toArray();
|
||||||
|
$products = reset_index($products, 'id');
|
||||||
|
$update = [];
|
||||||
|
foreach ($cartInfo as $v) {
|
||||||
|
$product = $products[$v['product_id']];
|
||||||
|
if (empty($product)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($is_vip == 1) {
|
||||||
|
$price = $product['vip_price'];
|
||||||
|
} else {
|
||||||
|
$price = $product['price'];
|
||||||
|
}
|
||||||
|
$update[] = [
|
||||||
|
'id' => $v['id'],
|
||||||
|
'price' => $price,
|
||||||
|
'total_price' => $price * $v['cart_num'],
|
||||||
|
'pay_price' => $price * $v['cart_num'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
(new BeforehandOrderCartInfo())->saveAll($update);
|
||||||
|
$totalPrice = array_sum(array_column($update, 'total_price'));
|
||||||
|
BeforehandOrder::where('id', $params['id'])->update(['total_price' => $totalPrice,'pay_price' => $totalPrice]);
|
||||||
|
if($outbound_id){
|
||||||
|
WarehouseProduct::where('oid', $outbound_id)->select()->each(function ($item) use($is_vip) {
|
||||||
|
if($is_vip==0){
|
||||||
|
$find = StoreProduct::where('id', $item['product_id'])->withTrashed()->field('purchase,vip_price,price')->find();
|
||||||
|
$item->save(['price' => $find['price'], 'purchase' => $find['purchase'], 'vip_price' => $find['vip_price'],'total_price' => $find['price'] * $item['nums']]);
|
||||||
|
}else{
|
||||||
|
$find = StoreProduct::where('id', $item['product_id'])->withTrashed()->field('purchase,vip_price,price')->find();
|
||||||
|
$item->save(['price' => $find['vip_price'], 'purchase' => $find['purchase'], 'vip_price' => $find['vip_price'],'total_price' => $find['vip_price'] * $item['nums']]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$total_price=WarehouseProduct::where('oid', $outbound_id)->sum('total_price');
|
||||||
|
BeforehandOrder::where('id', $params['id'])->update(['total_price' => $total_price]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user