订单添加

parent dc2d4310
...@@ -25,7 +25,8 @@ class OrderApiController extends Controller ...@@ -25,7 +25,8 @@ class OrderApiController extends Controller
public function addOrder(Request $request) public function addOrder(Request $request)
{ {
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'address_id' => 'required|string', 'billing_address_id' => 'required|string',
'shipping_address_id' => 'required|string',
'items' => 'required|string', 'items' => 'required|string',
], [ ], [
'items.min' => 'items must be at least 1 characters long.' 'items.min' => 'items must be at least 1 characters long.'
...@@ -36,7 +37,8 @@ class OrderApiController extends Controller ...@@ -36,7 +37,8 @@ class OrderApiController extends Controller
} }
$data = $request->only([ $data = $request->only([
'items', 'items',
'address_id', 'billing_address_id',
'shipping_address_id',
]); ]);
$result = OrderService::addOrder($data, $request->user->id); $result = OrderService::addOrder($data, $request->user->id);
......
...@@ -29,7 +29,8 @@ class OrderService ...@@ -29,7 +29,8 @@ class OrderService
*/ */
public static function addOrder($data, $user_id) public static function addOrder($data, $user_id)
{ {
$address_id = $data["address_id"]; $shipping_address_id = $data["shipping_address_id"]; //收货地址
$billing_address_id = $data["billing_address_id"]; //账单地址
$items = json_decode(\Arr::get($data, 'items', []),true); $items = json_decode(\Arr::get($data, 'items', []),true);
//查询用户详情 //查询用户详情
$userInfo = UserModel::getUserInfo($user_id); $userInfo = UserModel::getUserInfo($user_id);
...@@ -45,6 +46,7 @@ class OrderService ...@@ -45,6 +46,7 @@ class OrderService
$mainData =[ $mainData =[
"order_sn"=>$order_sn, "order_sn"=>$order_sn,
"user_id"=>$user_id, "user_id"=>$user_id,
"creator_uid"=>$user_id,
"company_name"=>$userInfo["company_name"], "company_name"=>$userInfo["company_name"],
"exchange_rate"=>getRate(), "exchange_rate"=>getRate(),
"currency"=>2, "currency"=>2,
...@@ -58,28 +60,48 @@ class OrderService ...@@ -58,28 +60,48 @@ class OrderService
} }
#订单地址 #订单地址
$userAddress = UserAddressModel::where("address_id",$address_id)->first(); $shippingAddress = UserAddressModel::where("address_id",$shipping_address_id)->first();
$addressData =[ $billingAddress = UserAddressModel::where("address_id",$billing_address_id)->first();
"address_id"=>$address_id, $addressData =[[
"user_id"=>$user_id, "address_id"=>$shipping_address_id,
"order_id"=>$order_id, "user_id"=>$user_id,
"address_type"=>\Arr::get($userAddress,"address_type",0), "order_id"=>$order_id,
"order_address_type"=>\Arr::get($userAddress,"order_address_type",1), "address_type"=>\Arr::get($shippingAddress,"address_type",0),
"consignee"=>\Arr::get($userAddress,"consignee",""), "order_address_type"=>1, //收货信息
"company_name"=>\Arr::get($userAddress,"company_name",""), "consignee"=>\Arr::get($shippingAddress,"consignee",""),
"email"=>\Arr::get($userAddress,"email",""), "company_name"=>\Arr::get($shippingAddress,"company_name",""),
"post_code"=>\Arr::get($userAddress,"post_code",""), "email"=>\Arr::get($shippingAddress,"email",""),
"phone"=>\Arr::get($userAddress,"phone",""), "post_code"=>\Arr::get($shippingAddress,"post_code",""),
"country_name"=>\Arr::get($userAddress,"country_name","") , "phone"=>\Arr::get($shippingAddress,"phone",""),
"country"=>\Arr::get($userAddress,"country",""), "country_name"=>\Arr::get($shippingAddress,"country_name","") ,
"province"=>\Arr::get($userAddress,"province",""), "country"=>\Arr::get($shippingAddress,"country",""),
"city"=>\Arr::get($userAddress,"city",""), "province"=>\Arr::get($shippingAddress,"province",""),
"detail_address"=>\Arr::get($userAddress,"detail_address",""), "city"=>\Arr::get($shippingAddress,"city",""),
"create_time"=>time(), "detail_address"=>\Arr::get($shippingAddress,"detail_address",""),
"update_time"=>time(), "create_time"=>time(),
]; "update_time"=>time(),
],[
"address_id"=>$shipping_address_id,
"user_id"=>$user_id,
"order_id"=>$order_id,
"address_type"=>\Arr::get($billingAddress,"address_type",0),
"order_address_type"=>2, //账单邮寄信息
"consignee"=>\Arr::get($billingAddress,"consignee",""),
"company_name"=>\Arr::get($billingAddress,"company_name",""),
"email"=>\Arr::get($billingAddress,"email",""),
"post_code"=>\Arr::get($billingAddress,"post_code",""),
"phone"=>\Arr::get($billingAddress,"phone",""),
"country_name"=>\Arr::get($billingAddress,"country_name","") ,
"country"=>\Arr::get($billingAddress,"country",""),
"province"=>\Arr::get($shippingAddress,"province",""),
"city"=>\Arr::get($shippingAddress,"city",""),
"detail_address"=>\Arr::get($shippingAddress,"detail_address",""),
"create_time"=>time(),
"update_time"=>time(),
]
];
$order_address_id = OrderAddressModel::insertGetId($addressData); $order_address_id = OrderAddressModel::insert($addressData);
if (!$order_address_id){ if (!$order_address_id){
throw new InvalidRequestException("error:order address"); throw new InvalidRequestException("error:order address");
} }
...@@ -97,7 +119,6 @@ class OrderService ...@@ -97,7 +119,6 @@ class OrderService
$orderAmount += round($buy_number*$buy_price,2); $orderAmount += round($buy_number*$buy_price,2);
$standard_brand = data_get($skuInfo,"standard_brand"); $standard_brand = data_get($skuInfo,"standard_brand");
//订单明细 //订单明细
$orderItems[] = [ $orderItems[] = [
"order_id"=>$order_id, //订单ID "order_id"=>$order_id, //订单ID
...@@ -143,9 +164,9 @@ class OrderService ...@@ -143,9 +164,9 @@ class OrderService
} }
} }
$order_address_id = OrderItemsModel::insert($orderItems); $itemFlag = OrderItemsModel::insert($orderItems);
if (!$order_address_id){ if (!$itemFlag){
throw new InvalidRequestException("error:order address"); throw new InvalidRequestException("error:order items");
} }
#插入收款信息 #插入收款信息
......
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