|
@@ -138,7 +138,7 @@ class Orders extends Api{
|
|
|
// 判断库存,如果库存不足,只赠送最后的库存
|
|
|
if( $productList[$value['product_id']]['stock'] <= $value['buy_num'] ) $value['buy_num'] = $productList[$value['product_id']]['stock'];
|
|
|
// 库存扣减
|
|
|
- $productList[$value['product_id']]['stock'] = $productList[$value['product_id']]['stock'] - $value['buy_num'];
|
|
|
+ $productList[$value['product_id']]['decr'] = empty($productList[$value['product_id']]['decr']) ? $value['buy_num'] : $productList[$value['product_id']]['decr'] + $value['buy_num'];
|
|
|
// 追加到订单表
|
|
|
$order['product_list'][] = ['is_rebate'=>1,'custom_uid'=>$uid,'business_id'=>$value['business_id'],'product_id'=>$value['product_id'],'buy_num'=>$value['buy_num'],'price_total'=>$value['price_total'],'pay_total'=>$value['pay_total'],'coupon_total'=>$value['coupon_total'],'product_name'=>$value['product_name'],'sku_attr_names'=>$value['sku_attr_names'],'product_thumb'=>$value['product_thumb']];
|
|
|
}
|
|
@@ -200,7 +200,7 @@ class Orders extends Api{
|
|
|
// 循环订单数据
|
|
|
foreach ($orderProduct as $order) {
|
|
|
// 先获取产品列表,并去除key
|
|
|
- $productList = array_values($order['product_list']);
|
|
|
+ $productItem = array_values($order['product_list']);
|
|
|
// 删除非必要数据
|
|
|
unset($order['product_list']);
|
|
|
// 创建总订单
|
|
@@ -213,23 +213,23 @@ class Orders extends Api{
|
|
|
return json_send(['code'=>'error','msg'=>'下单失败','data'=>['error'=>'订单创建失败']]);
|
|
|
}
|
|
|
// 创建子订单
|
|
|
- foreach ($productList as $key=>$value) {
|
|
|
+ foreach ($productItem as $key=>$value) {
|
|
|
// 增加订单ID
|
|
|
$value['order_id'] = $orderId;
|
|
|
// 增加订单ID
|
|
|
$value['insert_time']= $time;
|
|
|
$value['update_time']= $time;
|
|
|
// 结果
|
|
|
- $productList[$key] = $value;
|
|
|
+ $productItem[$key] = $value;
|
|
|
}
|
|
|
// 写入子表
|
|
|
- $result = $OrdersProduct->query()->insert($productList);
|
|
|
+ $result = $OrdersProduct->query()->insert($productItem);
|
|
|
// 如果扣减失败
|
|
|
if( !$result ) {
|
|
|
// 回退数据
|
|
|
DB::rollBack();
|
|
|
// 提示信息
|
|
|
- return json_send(['code'=>'error','msg'=>'下单失败','data'=>['error'=>'子订单创建失败']]);
|
|
|
+ return json_send(['code'=>'error','msg'=>'子订单创建失败','data'=>['error'=>'子订单创建失败']]);
|
|
|
}
|
|
|
// 写入订单地址表
|
|
|
$addr['order_id'] = $orderId;
|
|
@@ -240,7 +240,7 @@ class Orders extends Api{
|
|
|
// 回退数据
|
|
|
DB::rollBack();
|
|
|
// 提示信息
|
|
|
- return json_send(['code'=>'error','msg'=>'下单失败','data'=>['error'=>'地址写入失败']]);
|
|
|
+ return json_send(['code'=>'error','msg'=>'地址写入失败','data'=>['error'=>'地址写入失败']]);
|
|
|
}
|
|
|
// 赠送积分
|
|
|
if( $order['order_score'] > 0 ) $CustomScore->trade($order['custom_uid'],$orderId,$order['order_score'],5,1);
|
|
@@ -262,7 +262,7 @@ class Orders extends Api{
|
|
|
// 判断结果,如果库存扣减失败的话
|
|
|
if( stripos($th->getMessage(),'UNSIGNED') ) return json_send(['code'=>'error','msg'=>'库存不足','data'=>['error'=>'产品库存扣减失败']]);
|
|
|
// 下单失败提示
|
|
|
- return json_send(['code'=>'error','msg'=>'下单失败','data'=>['error'=>$th->getMessage().$th->getLine()]]);
|
|
|
+ return json_send(['code'=>'error','msg'=>'系统异常,请稍后再试','data'=>['error'=>$th->getMessage().$th->getLine()]]);
|
|
|
}
|
|
|
}
|
|
|
|