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
3b56a1ac
authored
Nov 10, 2022
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
购物
parent
13fea70d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
306 additions
and
30 deletions
app/Http/Services/CartService.php
app/Http/Services/OrderService.php
app/Models/CartModel.php
app/Models/OrderModel.php
app/Http/Services/CartService.php
View file @
3b56a1ac
...
...
@@ -67,14 +67,14 @@ class CartService
if
(
$checkHas
){
//存在累计库存
$temp
[
"buy_number"
]
=
$skuInfo
[
"stock"
]
>
(
$v
[
'buy_number'
]
+
$checkHas
[
"buy_number"
])
?
$v
[
'buy_number'
]
+
$checkHas
[
"buy_number"
]
:
$skuInfo
[
"stock"
];
$temp
[
"update_time"
]
=
time
();
$temp
[
"status"
]
=
$v
[
"buy_number"
]
>
0
?
CartModel
::
STATUS_YES
:
CartModel
::
STATUS_NO
;
$temp
[
"status"
]
=
$v
[
"buy_number"
]
>
0
?
CartModel
::
status_yes
:
CartModel
::
status_no
;
$flag
=
CartModel
::
where
([
"cart_id"
=>
$checkHas
[
"cart_id"
]])
->
update
(
$temp
);
if
(
!
$flag
){
return
false
;
}
}
else
{
//不存在插入购物车
$temp
[
"buy_number"
]
=
$skuInfo
[
"stock"
]
>
$v
[
'buy_number'
]
?
$v
[
'buy_number'
]
:
$skuInfo
[
"stock"
];
$temp
[
"status"
]
=
$v
[
"buy_number"
]
>
0
?
CartModel
::
STATUS_YES
:
CartModel
::
STATUS_NO
;
$temp
[
"status"
]
=
$v
[
"buy_number"
]
>
0
?
CartModel
::
status_yes
:
CartModel
::
status_no
;
$temp
[
"create_time"
]
=
time
();
$temp
[
"update_time"
]
=
time
();
...
...
app/Http/Services/OrderService.php
0 → 100644
View file @
3b56a1ac
<?php
namespace
App\Http\Services
;
use
App\Exceptions\InvalidRequestException
;
use
App\Http\Models\Order\OrderModel
;
use
App\Models\Inquiry
;
use
App\Models\InquiryItems
;
use
App\Models\InquiryItemsModel
;
use
App\Models\InquiryModel
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Redis
;
use
App\Models\CartModel
;
//订单服务层
class
OrderService
{
//新增订单
public
static
function
addOrder
(
$data
,
$user_id
)
{
$vs
=
json_decode
(
\Arr
::
get
(
$data
,
'items'
,
[]),
true
);
try
{
$con
=
DB
::
connection
();
$redis
=
Redis
::
connection
();
$con
->
beginTransaction
();
#订单主表
$mainData
=
[
"order_sn"
=>
11
,
""
=>
""
,
];
$order_id
=
OrderModel
::
insertGetId
(
$mainData
);
if
(
!
$order_id
){
return
false
;
}
#订单明细
$goodsInfoArr
=
ThirdService
::
getGoodsInfo
(
array_column
(
$vs
,
"goods_id"
));
foreach
(
$vs
as
$v
)
{
$goods_id
=
$v
[
'goods_id'
];
$temp
=
[
'user_id'
=>
$user_id
,
'goods_id'
=>
$v
[
'goods_id'
],
];
$skuInfo
=
$goodsInfoArr
[
$goods_id
];
//sku库存
$digikeyInfo
=
$redis
->
hget
(
"sku_raw_map"
,
$goods_id
);
//digikey 编码
if
(
$digikeyInfo
){
$digikeyArr
=
json_decode
(
$digikeyInfo
,
true
);
$temp
[
"raw_goods_sn"
]
=
$digikeyArr
[
"raw_goods_id"
];
$temp
[
"raw_goods_packing"
]
=
$digikeyArr
[
"pack"
];
$temp
[
"raw_brand_name"
]
=
$digikeyArr
[
"raw_brand_name"
];
}
//购买时价格
$buy_price
=
0
;
$ladder_price
=
data_get
(
$skuInfo
,
"ladder_price"
);
if
(
$ladder_price
){
//购买价格
foreach
(
$ladder_price
as
$a
=>
$b
){
if
(
$v
[
"buy_number"
]
>=
$b
[
"purchases"
]){
$buy_price
=
$b
[
"price_us"
];
}
else
{
break
;
}
}
}
$temp
[
"buy_price"
]
=
$buy_price
;
$checkHas
=
CartModel
::
where
([
"user_id"
=>
$user_id
,
"goods_id"
=>
$goods_id
,
"status"
=>
1
])
->
first
();
$temp
[
"buy_number"
]
=
$skuInfo
[
"stock"
]
>
$v
[
'buy_number'
]
?
$v
[
'buy_number'
]
:
$skuInfo
[
"stock"
];
$temp
[
"status"
]
=
$v
[
"buy_number"
]
>
0
?
CartModel
::
status_yes
:
CartModel
::
status_no
;
$temp
[
"create_time"
]
=
time
();
$temp
[
"update_time"
]
=
time
();
$flag
=
CartModel
::
insertGetId
(
$temp
);
if
(
!
$flag
){
return
false
;
}
}
#收款信息 1货款
$con
->
commit
();
return
true
;
}
catch
(
\Exception
$e
){
$con
->
rollback
();
throw
new
InvalidRequestException
(
$e
->
getMessage
()
.
$e
->
getLine
());
}
}
//刷新购物车并且返回列表
public
static
function
orderLists
(
$user_id
){
//当前用户所有可用的购物车数据
$query
=
CartModel
::
where
([
'user_id'
=>
$user_id
,
"status"
=>
1
])
->
orderBy
(
'cart_id'
,
'desc'
);
$result
=
$query
->
get
()
->
toArray
();
if
(
!
$result
){
return
false
;
}
try
{
$con
=
DB
::
connection
();
$con
->
beginTransaction
();
$redis
=
Redis
::
connection
();
$goodsInfoArr
=
ThirdService
::
getGoodsInfo
(
array_column
(
$result
,
"goods_id"
));
$cartList
=
[];
foreach
(
$result
as
$v
)
{
$goods_id
=
$v
[
'goods_id'
];
$temp
=
[
'user_id'
=>
$user_id
,
'goods_id'
=>
$v
[
'goods_id'
],
];
$skuInfo
=
$goodsInfoArr
[
$goods_id
];
//sku库存
$digikeyInfo
=
$redis
->
hget
(
"sku_raw_map"
,
$goods_id
);
//digikey 编码
if
(
$digikeyInfo
){
$digikeyArr
=
json_decode
(
$digikeyInfo
,
true
);
$temp
[
"raw_goods_sn"
]
=
$digikeyArr
[
"raw_goods_id"
];
$temp
[
"raw_goods_packing"
]
=
$digikeyArr
[
"pack"
];
$temp
[
"raw_brand_name"
]
=
$digikeyArr
[
"raw_brand_name"
];
}
$temp
[
"buy_number"
]
=
$skuInfo
[
"stock"
]
>
$v
[
'buy_number'
]
?
$v
[
'buy_number'
]
:
$skuInfo
[
"stock"
];
//购买数量
$buy_price
=
0
;
$ladder_price
=
\Arr
::
get
(
$skuInfo
,
"ladder_price"
);
if
(
$ladder_price
){
//购买价格
foreach
(
$ladder_price
as
$a
=>
$b
){
if
(
$temp
[
"buy_number"
]
>=
$b
[
"purchases"
]){
$buy_price
=
$b
[
"price_us"
];
}
else
{
break
;
}
}
}
$temp
[
"status"
]
=
$temp
[
"buy_number"
]
>
0
?
CartModel
::
STATUS_YES
:
CartModel
::
STATUS_NO
;
$temp
[
"buy_price"
]
=
$buy_price
;
$temp
[
"update_time"
]
=
time
();
$temp
[
"update_time"
]
=
time
();
$flag
=
CartModel
::
where
([
"cart_id"
=>
$v
[
"cart_id"
]])
->
update
(
$temp
);
if
(
!
$flag
){
continue
;
}
//格式化数据
$skuInfo
=
self
::
dullDataInfo
(
$skuInfo
);
$cartList
[]
=
[
"goods_id"
=>
$skuInfo
[
"goods_id"
],
//sku_id
"goods_name"
=>
$skuInfo
[
"goods_name"
],
//型号名称
"supplier_id"
=>
$skuInfo
[
"supplier_id"
],
//供应商id
"supplier_name"
=>
$skuInfo
[
"supplier_name"
],
//供应商id
"buy_number"
=>
$temp
[
"buy_number"
],
//购买数量
"encap"
=>
$skuInfo
[
"encap"
],
//标准包装数
"pdf"
=>
$skuInfo
[
"pdf"
],
//型号pdf
"brand_id"
=>
$skuInfo
[
"brand_id"
],
//品牌id
"brand_name"
=>
$skuInfo
[
"brand_name"
],
//品牌名称
"stock"
=>
$skuInfo
[
"stock"
],
//库存
"stock_format"
=>
numberToHtml
(
$skuInfo
[
"stock"
]),
//库存加密
"max_buy_stock"
=>
$skuInfo
[
"max_buy_stock"
],
//最大可购买数量
"moq"
=>
numberToHtml
(
$skuInfo
[
"moq"
]),
//最少起订量
"mpq"
=>
numberToHtml
(
$skuInfo
[
"mpq"
]),
//标准包装量
"mult"
=>
numberToHtml
(
$skuInfo
[
"multiple"
]),
//递增量
"hk_delivery_time"
=>
$skuInfo
[
"hk_delivery_time"
],
//香港交期
"ladder_price"
=>
$skuInfo
[
"ladder_price"
],
//价格阶梯
"is_buy"
=>
$skuInfo
[
"is_buy"
],
//是否能购买
];
}
$con
->
commit
();
return
$cartList
;
}
catch
(
\Exception
$e
){
$con
->
rollback
();
throw
new
InvalidRequestException
(
$e
->
getMessage
()
.
$e
->
getLine
());
return
false
;
}
}
/**
*格式化商品服务数据
*/
public
static
function
dullDataInfo
(
$info
,
$keyword
=
""
){
$redis
=
Redis
::
connection
();
$info
[
'pdf'
]
=
empty
(
$info
[
'pdf'
])
?
''
:
$info
[
'pdf'
];
$info
[
'encap'
]
=
empty
(
$info
[
'encap'
])
?
''
:
$info
[
'encap'
];
$info
[
'spu_brief'
]
=
empty
(
$info
[
'spu_brief'
])
?
''
:
$info
[
'spu_brief'
];
$info
[
'mpq'
]
=
$info
[
'mpq'
]
>
0
?
$info
[
'mpq'
]
:
1
;
$info
[
'goods_name'
]
=
empty
(
$info
[
'goods_name'
])
?
$info
[
'spu_name'
]
:
$info
[
'goods_name'
];
if
(
!
empty
(
$keyword
)){
$info
[
'goods_name_temp'
]
=
str_ireplace
(
$keyword
,
"<b class='f-red'>"
.
strtoupper
(
$keyword
)
.
"</b>"
,
$info
[
'goods_name'
]);
}
else
{
$info
[
'goods_name_temp'
]
=
$info
[
'goods_name'
];
}
$info
[
'multiple'
]
=
$info
[
'mpq'
]
>
$info
[
'moq'
]
?
$info
[
'moq'
]
:
$info
[
'mpq'
];
//那个小用那个
//todo 2022.9.27 计算最大购买数量
$info
[
"max_buy_stock"
]
=
getMaxBuyStock
(
$info
[
"stock"
],
$info
[
"multiple"
],
$info
[
"ladder_price"
]);
$info
[
'page_flag'
]
=
2
;
//猎芯联营采购员 ,添加供应商采购员渠道不得为空
$info
[
'purchase_name'
]
=
''
;
if
(
$info
[
'canal'
]
!=
""
){
$pur_name
=
$redis
->
hget
(
'search_supplier_canaltopurchase'
,
$info
[
'canal'
]);
$info
[
'purchase_name'
]
=
$pur_name
;
}
//货区去掉工作日
$info
[
'hk_delivery_time_origin'
]
=
$info
[
'hk_delivery_time'
];
$info
[
'cn_delivery_time'
]
=
str_replace
(
"工作日"
,
""
,
$info
[
'cn_delivery_time'
]);
$info
[
'cn_delivery_time'
]
=
str_replace
(
"个"
,
""
,
$info
[
'cn_delivery_time'
]);
$info
[
'hk_delivery_time'
]
=
str_replace
(
"工作日"
,
""
,
$info
[
'hk_delivery_time'
]);
$info
[
'hk_delivery_time'
]
=
str_replace
(
"个"
,
""
,
$info
[
'hk_delivery_time'
]);
#查询英文品牌缩写
$standard_brand_id
=
$info
[
"standard_brand"
][
"standard_brand_id"
];
$standardBrandInfo
=
$redis
->
hget
(
"standard_brand"
,
$standard_brand_id
);
if
(
$standardBrandInfo
){
$standardBrandInfoArr
=
json_decode
(
$standardBrandInfo
,
true
);
#深贸商城的品牌字段需展示该SKU对应基石标准品牌列表的英文简称,无则取英文名称、都无则取品牌名称
$brandName
=
$info
[
"brand_name"
];
if
(
$standardBrandInfoArr
[
"brand_short_name_en"
]){
$brandName
=
$standardBrandInfoArr
[
"brand_short_name_en"
];
}
else
if
(
$standardBrandInfoArr
[
"brand_name_en"
]){
$brandName
=
$standardBrandInfoArr
[
"brand_name_en"
];
}
$info
[
"brand_name"
]
=
$brandName
;
}
$original_price
=
$info
[
"original_price"
];
#梯度价转换
foreach
(
$original_price
as
$e
=>&
$f
){
$f
[
"purchases_format"
]
=
numberToHtml
(
$f
[
"purchases"
]);
}
usort
(
$original_price
,
function
(
$current
,
$next
)
{
//原始价格倒叙
return
$current
[
'purchases'
]
<
$next
[
'purchases'
];
});
$info
[
"ladder_price"
]
=
$original_price
;
#工作日转换
foreach
(
self
::
$day_filter
as
$d
){
if
(
strpos
(
$info
[
"hk_delivery_time_origin"
],
$d
)
!==
false
){
$info
[
"hk_delivery_time"
]
=
$info
[
"hk_delivery_time"
]
.
" workdays"
;
break
;
}
}
#周转换
foreach
(
self
::
$week_filter
as
$d
){
if
(
strpos
(
$info
[
"hk_delivery_time_origin"
],
$d
)
!==
false
){
$info
[
"hk_delivery_time"
]
=
$info
[
"hk_delivery_time"
]
.
" weeks"
;
break
;
}
}
return
$info
;
}
}
app/Models/CartModel.php
View file @
3b56a1ac
...
...
@@ -10,18 +10,8 @@ class CartModel extends Model
protected
$table
=
'cart'
;
public
$timestamps
=
false
;
const
STATUS_NO
=
-
1
;
//状态禁用
const
STATUS_YES
=
1
;
//状态启动
//查询购物车数据
public
static
function
getCartInfo
(
$user_id
)
{
$map
=
[
"user_id"
=>
$user_id
];
$res
=
self
::
where
(
$map
)
->
first
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
const
status_no
=
-
1
;
//状态禁用
const
status_yes
=
1
;
//状态启动
}
app/Models/OrderModel.php
View file @
3b56a1ac
...
...
@@ -10,21 +10,35 @@ class OrderModel extends Model
protected
$primaryKey
=
'order_id'
;
public
$timestamps
=
false
;
//添加购物车
public
static
function
addCart
()
{
}
//查询购物车数据
public
static
function
getOrderInfoByrderSn
(
$order_sn
)
{
$map
=
[
"order_sn"
=>
$order_sn
];
$res
=
self
::
where
(
$map
)
->
first
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
//已取消 -1 Cancelled
//待审核 1 Waiting for approval
//待付款 2 Waiting for payment
//待付尾款 3
//待发货 4 Waiting for dispatch
//部分发货 7
//待收货 8 Waiting for delivery
//已完成 10 Transaction Complete
const
status_cancel
=
-
1
;
const
status_waiting_approval
=
1
;
const
status_waiting_pay
=
2
;
const
status_waiting_end_pay
=
3
;
const
status_waiting_send
=
4
;
const
status_waiting_half_send
=
7
;
const
status_waiting_delivery
=
8
;
const
status_complete
=
10
;
static
$status
=
[
self
::
status_cancel
=>
"Cancelled"
,
self
::
status_waiting_approval
=>
"Waiting for approval"
,
self
::
status_waiting_pay
=>
"Waiting for payment"
,
self
::
status_waiting_end_pay
=>
""
,
self
::
status_waiting_send
=>
" Waiting for dispatch"
,
self
::
status_waiting_half_send
=>
""
,
self
::
status_waiting_delivery
=>
"Waiting for delivery"
,
self
::
status_complete
=>
"Transaction Complete"
,
];
}
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