Merge branch 'updateOrder' into dev
# Conflicts: # app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php
This commit is contained in:
commit
f38f1e98a1
@ -6,8 +6,10 @@ namespace app\admin\controller\beforehand_order_cart_info;
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\beforehand_order_cart_info\BeforehandOrderCartInfoLists;
|
||||
use app\admin\logic\beforehand_order_cart_info\BeforehandOrderCartInfoLogic;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
|
||||
/**
|
||||
* 预订单购物详情表控制器
|
||||
@ -65,11 +67,34 @@ class BeforehandOrderCartInfoController extends BaseAdminController
|
||||
|
||||
$res=BeforehandOrderCartInfo::where('id',$id)->find();
|
||||
$find=PurchaseProductOffer::where(['product_id'=>$res['product_id'],'order_id'=>$res['bhoid']])->find();
|
||||
if (empty($find)) {
|
||||
$rawSql = "JSON_CONTAINS(source_order_info, '{\"source_order_id\": {$res['bhoid']}}')";
|
||||
$find = PurchaseProductOffer::where(['product_id' => $res['product_id']])->whereRaw($rawSql)->find();
|
||||
}
|
||||
if($find){
|
||||
if($find['buyer_confirm']==1){
|
||||
return $this->fail('该商品已采购完成,无法更改状态');
|
||||
}else{
|
||||
PurchaseProductOffer::where('id',$find['id'])->update(['delete_time'=>time()]);
|
||||
if (!empty($find['source_order_info'])) {
|
||||
$json = $find['source_order_info'];
|
||||
foreach ($json as $key => $value) {
|
||||
if ($value['source_order_id'] == $res['bhoid']) {
|
||||
$find->need_num = $find->need_num - $value['need_num'];
|
||||
unset($json[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$find->source_order_info = array_values($json);
|
||||
$productPrice = StoreProduct::where('id',$res['product_id'])->value('price');
|
||||
$procurementOrder = BeforehandOrder::where('id', $find['order_id'])->find();
|
||||
$procurementOrder->total_price = bcsub($procurementOrder->total_price, bcmul($productPrice, $res['cart_num'], 2), 2);
|
||||
$procurementOrder->pay_price = $procurementOrder->total_price;
|
||||
$procurementOrder->save();
|
||||
}
|
||||
if ($find->need_num <= 0) {
|
||||
$find->delete_time = time();
|
||||
}
|
||||
$find->save();
|
||||
}
|
||||
}
|
||||
$res->save(['is_buyer'=>-1]);
|
||||
|
@ -41,26 +41,64 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$procurementOrder = BeforehandOrder::where('order_type', 7)->where('is_buying', 0)->where('create_time', '>=', strtotime('-3 days'))->find();
|
||||
if (empty($procurementOrder)) {
|
||||
$beforeOrder = BeforehandOrder::where('id', $params['order_id'])->findOrEmpty()->toArray();
|
||||
unset($beforeOrder['id'], $beforeOrder['create_time'], $beforeOrder['update_time']);
|
||||
$procurementOrder = new BeforehandOrder();
|
||||
$procurementOrder->setAttrs($beforeOrder);
|
||||
$procurementOrder->order_id = getNewOrderId('CG');
|
||||
$procurementOrder->order_type = 7;
|
||||
$procurementOrder->total_price = 0;
|
||||
$procurementOrder->pay_price = 0;
|
||||
$procurementOrder->save();
|
||||
}
|
||||
$mark = $params['mark'] ?? '';
|
||||
if ($mark == '') {
|
||||
$mark = BeforehandOrderCartInfo::where('bhoid', $params['order_id'])->where('product_id', $params['product_id'])->value('mark');
|
||||
}
|
||||
$find=StoreProduct::where('id',$params['product_id'])->find();
|
||||
PurchaseProductOffer::create([
|
||||
'order_id' => $params['order_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'unit' => $params['unit'],
|
||||
'is_buyer' => $params['is_buyer'],
|
||||
'need_num' => $params['need_num'],
|
||||
'mark' => $mark,
|
||||
'buyer_id' => $params['buyer_id'],
|
||||
'package' => $find['package'],
|
||||
'store_info' => $find['store_info'],
|
||||
'marques' => $find['marques'],
|
||||
'after_sales' => $find['after_sales'],
|
||||
'status' => 0,
|
||||
|
||||
]);
|
||||
$purchaseProductOffer = PurchaseProductOffer::where(['order_id' => $procurementOrder['id'], 'product_id' => $params['product_id']])->find();
|
||||
$procurementOrder->total_price = bcadd($procurementOrder->total_price, bcmul($find['price'], $params['need_num'], 2), 2);
|
||||
$procurementOrder->pay_price = $procurementOrder->total_price;
|
||||
$procurementOrder->save();
|
||||
if ($purchaseProductOffer) {
|
||||
$purchaseProductOffer->need_num = $purchaseProductOffer['need_num'] + $params['need_num'];
|
||||
if (!empty($purchaseProductOffer['source_order_info'])) {
|
||||
$sourceOrderInfo = $purchaseProductOffer['source_order_info'];
|
||||
$sourceOrderInfo[] = [
|
||||
'source_order_id' => $params['order_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'need_num' => $params['need_num'],
|
||||
'mark' => $mark,
|
||||
];
|
||||
$purchaseProductOffer->source_order_info = $sourceOrderInfo;
|
||||
}
|
||||
$purchaseProductOffer->save();
|
||||
} else {
|
||||
PurchaseProductOffer::create([
|
||||
'order_id' => $procurementOrder['id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'unit' => $params['unit'],
|
||||
'is_buyer' => $params['is_buyer'],
|
||||
'need_num' => $params['need_num'],
|
||||
'mark' => $mark,
|
||||
'buyer_id' => $params['buyer_id'],
|
||||
'package' => $find['package'],
|
||||
'store_info' => $find['store_info'],
|
||||
'marques' => $find['marques'],
|
||||
'after_sales' => $find['after_sales'],
|
||||
'status' => 0,
|
||||
'source_order_info' => [
|
||||
[
|
||||
'source_order_id' => $params['order_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'need_num' => $params['need_num'],
|
||||
'mark' => $mark,
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
BeforehandOrderCartInfo::where(['bhoid' => $params['order_id'], 'product_id' => $params['product_id']])->update(['is_buyer' => 1]);
|
||||
Db::commit();
|
||||
return true;
|
||||
|
@ -18,5 +18,7 @@ class PurchaseProductOffer extends BaseModel
|
||||
protected $name = 'purchase_product_offer';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
protected $json = ['source_order_info'];
|
||||
protected $jsonAssoc = true;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user