commit
ad47b44c78
@ -37,4 +37,12 @@ class IndexController extends BaseAdminController
|
||||
$res=DemoLogic::test3($id,$warehouse_id);
|
||||
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,9 +3,12 @@
|
||||
namespace app\api\logic;
|
||||
|
||||
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_product\StoreProduct;
|
||||
use app\common\model\store_product_group_price\StoreProductGroupPrice;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use think\facade\Db;
|
||||
@ -111,4 +114,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');
|
||||
WarehouseOrder::where('id', $outbound_id)->update(['total_price' => $total_price]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user