深茂订单详情

parent 415d30a3
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Api;
use App\Http\ApiHelper\ApiCode;
use App\Http\Requests\UserRegister;
use App\Http\Services\CartService;
use App\Http\Services\InquiryService;
......@@ -41,8 +42,8 @@ class OrderApiController extends Controller
'shipping_address_id',
]);
$result = OrderService::addOrder($data, $request->user->id);
return !$result ? $this->setError('Add order failed , please contact administrator'):$this->setSuccess('Add order success');
$order_id = OrderService::addOrder($data, $request->user->id);
return !$order_id ? $this->setError('Add order failed , please contact administrator'):$this->setSuccessData($order_id,0,ApiCode::API_CODE_SUCCESS,'Add order success');
}
//订单列表
......
......@@ -127,6 +127,7 @@ class OrderService
$goods_id = $v['goods_id'];
$skuInfo = $goodsInfoArr[$goods_id]; //sku详情
$cartInfo = CartModel::where(["user_id"=>$user_id,"goods_id"=>(string)$goods_id,"status"=>1])->first();
$buy_number = $v["buy_number"];
$buy_price = $v["buy_price"];
$orderAmount += round($buy_number*$buy_price,2);
......@@ -166,14 +167,15 @@ class OrderService
"remarks"=>$v["remark"], //客户备注
];
#扣减购物车库存
$temp["status"] = $v["buy_number"] > 0 ? CartModel::status_yes:CartModel::status_no;
$temp["create_time"] = time();
$temp["update_time"] = time();
$cartUpdate = CartModel::where("cart_id",$cartInfo["cart_id"])->update($temp);
if (!$cartUpdate){
throw new InvalidRequestException("error:update cart");
if ($cartInfo){
#扣减购物车库存
$temp["status"] = $v["buy_number"] > 0 ? CartModel::status_yes:CartModel::status_no;
$temp["create_time"] = time();
$temp["update_time"] = time();
$cartUpdate = CartModel::where("cart_id",$cartInfo["cart_id"])->update($temp);
if (!$cartUpdate){
throw new InvalidRequestException("error:update cart");
}
}
}
......@@ -203,7 +205,7 @@ class OrderService
$con->commit();
return true;
return $order_id;
}catch (\Exception $e){
$con->rollback();
throw new InvalidRequestException($e->getMessage().$e->getFile().$e->getLine());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment