订单添加

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