Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
semour
/
semour_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
81a6c72b
authored
Nov 16, 2022
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
订单添加
parent
dc2d4310
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
23 deletions
app/Http/Controllers/Api/OrderApiController.php
app/Http/Services/OrderService.php
app/Http/Controllers/Api/OrderApiController.php
View file @
81a6c72b
...
...
@@ -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
);
...
...
app/Http/Services/OrderService.php
View file @
81a6c72b
...
...
@@ -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
(
$user
Address
,
"address_type"
,
0
),
"order_address_type"
=>
\Arr
::
get
(
$userAddress
,
"order_address_type"
,
1
),
"consignee"
=>
\Arr
::
get
(
$user
Address
,
"consignee"
,
""
),
"company_name"
=>
\Arr
::
get
(
$user
Address
,
"company_name"
,
""
),
"email"
=>
\Arr
::
get
(
$user
Address
,
"email"
,
""
),
"post_code"
=>
\Arr
::
get
(
$user
Address
,
"post_code"
,
""
),
"phone"
=>
\Arr
::
get
(
$user
Address
,
"phone"
,
""
),
"country_name"
=>
\Arr
::
get
(
$user
Address
,
"country_name"
,
""
)
,
"country"
=>
\Arr
::
get
(
$user
Address
,
"country"
,
""
),
"province"
=>
\Arr
::
get
(
$user
Address
,
"province"
,
""
),
"city"
=>
\Arr
::
get
(
$user
Address
,
"city"
,
""
),
"detail_address"
=>
\Arr
::
get
(
$user
Address
,
"detail_address"
,
""
),
"address_type"
=>
\Arr
::
get
(
$shipping
Address
,
"address_type"
,
0
),
"order_address_type"
=>
1
,
//收货信息
"consignee"
=>
\Arr
::
get
(
$shipping
Address
,
"consignee"
,
""
),
"company_name"
=>
\Arr
::
get
(
$shipping
Address
,
"company_name"
,
""
),
"email"
=>
\Arr
::
get
(
$shipping
Address
,
"email"
,
""
),
"post_code"
=>
\Arr
::
get
(
$shipping
Address
,
"post_code"
,
""
),
"phone"
=>
\Arr
::
get
(
$shipping
Address
,
"phone"
,
""
),
"country_name"
=>
\Arr
::
get
(
$shipping
Address
,
"country_name"
,
""
)
,
"country"
=>
\Arr
::
get
(
$shipping
Address
,
"country"
,
""
),
"province"
=>
\Arr
::
get
(
$shipping
Address
,
"province"
,
""
),
"city"
=>
\Arr
::
get
(
$shipping
Address
,
"city"
,
""
),
"detail_address"
=>
\Arr
::
get
(
$shipping
Address
,
"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
::
insert
GetId
(
$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
addres
s"
);
$
itemFlag
=
OrderItemsModel
::
insert
(
$orderItems
);
if
(
!
$
itemFlag
){
throw
new
InvalidRequestException
(
"error:order
item
s"
);
}
#插入收款信息
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment