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
75e480d6
authored
Nov 30, 2022
by
肖康
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'dev/ver/1.0.0' of
http://git.ichunt.net/semour/semour_web
into dev/ver/1.0.0
parents
5a56ae7e
3ae16414
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
16 deletions
app/Http/Controllers/Api/OrderApiController.php
app/Http/Services/OrderService.php
app/Models/OrderPriceModel.php
app/Http/Controllers/Api/OrderApiController.php
View file @
75e480d6
...
...
@@ -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'
);
}
//订单列表
...
...
app/Http/Services/OrderService.php
View file @
75e480d6
...
...
@@ -127,11 +127,26 @@ 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
);
$standard_brand
=
data_get
(
$skuInfo
,
"standard_brand"
);
#查询英文品牌缩写
$brandName
=
$skuInfo
[
"brand_name"
];
$standard_brand_id
=
\Arr
::
get
(
$standard_brand
,
"standard_brand_id"
,
0
);
$standardBrandInfo
=
$redis
->
hget
(
"standard_brand"
,
$standard_brand_id
);
if
(
$standardBrandInfo
){
$standardBrandInfoArr
=
json_decode
(
$standardBrandInfo
,
true
);
#深贸商城的品牌字段需展示该SKU对应基石标准品牌列表的英文简称,无则取英文名称、都无则取品牌名称
if
(
$standardBrandInfoArr
[
"brand_short_name_en"
]){
$brandName
=
$standardBrandInfoArr
[
"brand_short_name_en"
];
}
else
if
(
$standardBrandInfoArr
[
"brand_name_en"
]){
$brandName
=
$standardBrandInfoArr
[
"brand_name_en"
];
}
}
//订单明细
$orderItems
[]
=
[
"order_id"
=>
$order_id
,
//订单ID
...
...
@@ -139,17 +154,17 @@ class OrderService
"goods_id"
=>
$goods_id
,
//商品ID
"supplier_id"
=>
\Arr
::
get
(
$skuInfo
,
"supplier_id"
,
0
),
//供应商ID(=company_id)
"brand_id"
=>
$skuInfo
[
"brand_id"
],
//品牌ID
"standard_brand_id"
=>
\Arr
::
get
(
$standard_brand
,
"standard_brand_id"
,
0
)
,
//标准品牌ID
"standard_brand_id"
=>
$standard_brand_id
,
//标准品牌ID
"goods_name"
=>
\Arr
::
get
(
$skuInfo
,
"goods_name"
,
0
),
//型号
"class_id2"
=>
\Arr
::
get
(
$skuInfo
,
"class_id2"
,
0
),
//商品二级分类id
"batch"
=>
\Arr
::
get
(
$skuInfo
,
"batch_sn"
,
0
),
//批次
"class_id2_name"
=>
""
,
//商品二级分类名称
"supplier_name"
=>
\Arr
::
get
(
$skuInfo
,
"supplier_name"
,
0
),
//供应商名(=company_name)
"brand_name"
=>
\Arr
::
get
(
$skuInfo
,
"brand_name"
,
0
)
,
//品牌名
"brand_name"
=>
$brandName
,
//品牌名
"standard_brand_name"
=>
\Arr
::
get
(
$standard_brand
,
"brand_name"
,
""
),
//标准品牌
"goods_type"
=>
2
,
//商品类型 联营:1专卖 2联营 自营 :3自营 4寄售 5第三方仓库
"goods_number"
=>
$buy_number
,
//购买数量
"goods_price"
=>
\Arr
::
get
(
$skuInfo
,
"buy_price"
,
0
)
,
//商品单价
"goods_price"
=>
$buy_price
,
//商品单价
"goods_unit"
=>
"pcs"
,
//商品单位
"delivery_time"
=>
\Arr
::
get
(
$skuInfo
,
"hk_delivery_time"
,
""
),
//交货时间
"canal"
=>
\Arr
::
get
(
$skuInfo
,
"canal"
,
""
),
//渠道标签
...
...
@@ -166,14 +181,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 +219,7 @@ class OrderService
$con
->
commit
();
return
true
;
return
$order_id
;
}
catch
(
\Exception
$e
){
$con
->
rollback
();
throw
new
InvalidRequestException
(
$e
->
getMessage
()
.
$e
->
getFile
()
.
$e
->
getLine
());
...
...
@@ -299,7 +315,7 @@ class OrderService
"shipping"
=>
\Arr
::
get
(
$priceArr
,
3
,
0
),
//运费
"payment_surcharge"
=>
\Arr
::
get
(
$priceArr
,
5
,
0
),
//支付手续费
"merchandise_total"
=>
$merchandise_total
,
//商品总额
"sub_total"
=>
$v
[
"order_amount"
]
,
//小计
"sub_total"
=>
OrderPriceModel
::
getOrderSubTotal
(
$order_id
)
,
//小计
"create_time"
=>
date
(
'Y-m-d H:i:s'
,
$v
[
'create_time'
]),
//下单时间
"over_time"
=>
$v
[
"status"
]
==
OrderModel
::
status_waiting_pay
?
date
(
'Y-m-d H:i:s'
,
$v
[
'create_time'
]
+
48
*
3600
)
:
""
,
//截止时间
];
...
...
@@ -398,7 +414,7 @@ class OrderService
"order_id"
=>
$order_id
,
"order_sn"
=>
$orderInfo
[
"order_sn"
],
"order_amount"
=>
$orderInfo
[
"order_amount"
],
"sub_total"
=>
$orderInfo
[
"order_amount"
]
,
//小计
"sub_total"
=>
OrderPriceModel
::
getOrderSubTotal
(
$order_id
)
,
//小计
"created_time"
=>
timeToDate
(
$orderInfo
[
"create_time"
]),
//创建时间
"reviewed_time"
=>
timeToDate
(
$orderInfo
[
"confirm_time"
]),
//审核时间
"paid_time"
=>
timeToDate
(
$orderInfo
[
"pay_time"
]),
//支付时间
...
...
app/Models/OrderPriceModel.php
View file @
75e480d6
...
...
@@ -17,5 +17,12 @@ class OrderPriceModel extends Model
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
//计算订单总金额
public
static
function
getOrderSubTotal
(
$order_id
)
{
return
self
::
where
(
"order_id"
,
$order_id
)
->
wherein
(
"price_type"
,[
1
,
3
,
5
])
->
sum
(
"price"
);
}
}
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