切换导航条
此项目
正在载入...
登录
景龙
/
feifangu
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
jinglong
5 years ago
提交
7aea90be0c22cce2d7faf8b35a5f25269e47cbc0
1 个父辈
2d40bbb5
1 个管道 的构建
通过
耗费 4 秒
修改支付检测库存
变更
3
构建
1
隐藏空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
172 行增加
和
10 行删除
application/api/controller/Common.php
application/api/controller/Pay.php
public/api.html
application/api/controller/Common.php
查看文件 @
7aea90b
...
...
@@ -592,6 +592,7 @@ class Common
$s_index
=
array_search
(
$value
[
'style'
],
self
::
salePrice
(
$g_value
[
'g_style'
]));
$stock
=
self
::
salePrice
(
$g_value
[
'stock'
])[
$s_index
]
-
1
;
$arr_stock
[
$s_index
]
=
$stock
;
//更新库存
$goodsModel
->
where
([
'id'
=>
$value
[
'g_id'
]])
->
update
(
'stock'
,
implode
(
'|'
,
$arr_stock
));
}
}
...
...
@@ -602,4 +603,33 @@ class Common
self
::
deleteCar
([
'uid'
=>
$res
[
'uid'
],
'g_id'
=>
[
'in'
,
$g_ids
]]);
}
}
/**
* 支付检测库存
* @ApiInternal
*/
public
static
function
checkPayStock
(
$order_goods
,
$goods_id
=
''
){
//检查库存
if
(
empty
(
$goods_id
)){
$goods_id_s
=
array_column
(
$order_goods
,
'goods_id'
);
//查询商品
$res
=
self
::
selectSoftWhereData
(
'goods'
,[
'id'
=>
[
'in'
,
$goods_id_s
]],
'id,name,stock,style g_style'
);
}
else
{
//查询商品
$res
=
self
::
selectSoftWhereData
(
'goods'
,[
'id'
=>
[
'in'
,
$goods_id
]],
'id,name,stock,style g_style'
);
}
foreach
(
$order_goods
as
$g_value
){
foreach
(
$res
as
$value
){
if
(
$value
[
'id'
]
==
$g_value
[
'goods_id'
]){
//检测库存
$check_stock
=
self
::
checkStock
(
$g_value
[
'style'
],
$g_value
[
'goods_number'
],
$value
[
'g_style'
],
$value
[
'stock'
]);
if
(
!
$check_stock
){
return
'商品名称:'
.
$value
[
'name'
]
.
',规格:'
.
$g_value
[
'style'
]
.
'库存不足'
;
}
}
}
}
return
true
;
}
}
...
...
application/api/controller/Pay.php
查看文件 @
7aea90b
...
...
@@ -33,18 +33,29 @@ class Pay extends Api
* @ApiParams (name="openid", type="string", required=true, description="小程序openid")
* @ApiParams (name="order_sn", type="inter", required=true, description="订单号")
*
* @ApiParams (name="receive_name", type="string", required=false, description="收货人")
* @ApiParams (name="receive_mobile", type="string", required=false, description="联系方式")
* @ApiParams (name="receive_address", type="string", required=false, description="收货地址")
* @ApiParams (name="leave_message", type="string", required=false, description="留言")
* @ApiParams (name="coupon_id", type="inter", required=false, description="优惠券id")
*
* @ApiParams (name="discount_price", type="inter", required=false, description="优惠金额")
* @ApiParams (name="total_price", type="inter", required=false, description="实付总金额")
*
*
*/
public
function
pay
(){
if
(
$this
->
request
->
isPost
()){
$openid
=
$this
->
request
->
post
(
'openid'
);
$order_sn
=
$this
->
request
->
post
(
'order_sn'
);
$data
=
$this
->
request
->
post
();
$rule
=
config
(
'verify.pay'
);
$validate
=
new
Validate
(
$rule
[
'rule'
],
$rule
[
'msg'
]);
if
(
!
$validate
->
check
(
[
'openid'
=>
$openid
,
'order_sn'
=>
$order_sn
]
))
{
if
(
!
$validate
->
check
(
$data
))
{
$this
->
error
(
$validate
->
getError
());
}
$order_sn
=
$data
[
'order_sn'
];
$openid
=
$data
[
'openid'
];
$ffg_host
=
config
(
'verify.ffg_host'
);
$status
=
$this
->
order_status
;
//支付订单
...
...
@@ -53,6 +64,13 @@ class Pay extends Api
$this
->
error
(
'无效的订单'
);
}
//检测库存
$order_goods
=
Common
::
selectSoftWhereData
(
'ogoods'
,[
'o_id'
=>
$res
[
'id'
]],
'id,g_id goods_id,style,goods_number'
);
$check_stock
=
Common
::
checkPayStock
(
$order_goods
);
if
(
!
$check_stock
){
$this
->
error
(
$check_stock
);
}
//创建支付对象
$config
=
config
(
'verify.wx_pay'
);
$pay_order_sn
=
Common
::
genPayOrderSn
(
'pay'
);
//支付订单号
...
...
@@ -79,7 +97,38 @@ class Pay extends Api
//更新订单的支付订单号
$orderModel
=
new
Order
();
$res1
=
$orderModel
->
where
([
'order_sn'
=>
$order_sn
,
'uid'
=>
$this
->
uid
])
->
update
([
'pay_order_sn'
=>
$pay_order_sn
]);
$arr
=
[];
$arr
[
'pay_order_sn'
]
=
$pay_order_sn
;
if
(
isset
(
$data
[
'receive_name'
])
&&
!
empty
(
$data
[
'receive_name'
])){
//收货人
$arr
[
'receive_name'
]
=
$data
[
'receive_name'
];
}
if
(
isset
(
$data
[
'receive_mobile'
])
&&
!
empty
(
$data
[
'receive_mobile'
])){
//收货电话
$arr
[
'receive_mobile'
]
=
$data
[
'receive_mobile'
];
}
if
(
isset
(
$data
[
'receive_address'
])
&&
!
empty
(
$data
[
'receive_address'
])){
//收货地址
$arr
[
'receive_address'
]
=
$data
[
'receive_address'
];
}
if
(
isset
(
$data
[
'leave_message'
])
&&
!
empty
(
$data
[
'leave_message'
])){
//留言
$arr
[
'leave_message'
]
=
$data
[
'leave_message'
];
}
if
(
isset
(
$data
[
'coupon_id'
])
&&
!
empty
(
$data
[
'coupon_id'
])){
//优惠券id
$arr
[
'coupon_id'
]
=
$data
[
'coupon_id'
];
}
if
(
isset
(
$data
[
'discount_price'
])
&&
!
empty
(
$data
[
'discount_price'
])){
//优惠价格
$arr
[
'discount_price'
]
=
$data
[
'discount_price'
];
}
if
(
isset
(
$data
[
'total_price'
])
&&
!
empty
(
$data
[
'total_price'
])){
//支付总金额
$arr
[
'total_price'
]
=
$data
[
'total_price'
];
}
$res1
=
$orderModel
->
where
([
'order_sn'
=>
$order_sn
,
'uid'
=>
$this
->
uid
])
->
update
(
$arr
);
if
(
$res1
){
$res2
=
Common
::
findSoftWhereData
(
'order'
,[
'order_sn'
=>
$order_sn
,
'uid'
=>
$this
->
uid
],
'id order_id'
);
$this
->
success
(
'成功'
,[
'data'
=>
$params
,
'order_id'
=>
$res2
[
'order_id'
]]);
...
...
@@ -139,7 +188,7 @@ class Pay extends Api
* @ApiParams (name="total_goods_price", type="inter", required=true, description="商品总金额")
* @ApiParams (name="discount_price", type="inter", required=true, description="优惠金额")
* @ApiParams (name="total_expense_price", type="inter", required=true, description="运费总金额")
* @ApiParams (name="total_price", type="inter", required=true, description="
运费
总金额")
* @ApiParams (name="total_price", type="inter", required=true, description="
实付
总金额")
*/
public
function
purchase
(){
if
(
$this
->
request
->
isPost
()){
...
...
@@ -151,12 +200,25 @@ class Pay extends Api
$this
->
error
(
$validate
->
getError
());
}
//检测库存
$goods_id_s
=
explode
(
','
,
$data
[
'goods_id'
]);
$price_s
=
explode
(
','
,
$data
[
'price'
]);
$goods_number_s
=
explode
(
','
,
$data
[
'goods_number'
]);
$style_s
=
explode
(
','
,
$data
[
'style'
]);
//合并数组
$key
=
[
'goods_id'
,
'price'
,
'goods_number'
,
'style'
];
$res_goods
=
Common
::
array_merge_more
(
$key
,
$goods_id_s
,
$price_s
,
$goods_number_s
,
$style_s
);
$check_stock
=
Common
::
checkPayStock
(
$res_goods
,
$goods_id_s
);
if
(
!
$check_stock
){
$this
->
error
(
$check_stock
);
}
//创建支付对象
$config
=
config
(
'verify.wx_pay'
);
$app
=
Factory
::
payment
(
$config
);
$pay_order_sn
=
Common
::
genPayOrderSn
(
'pay'
);
//支付订单号
//暂时没有真正支付
$ffg_host
=
config
(
'verify.ffg_host'
);
$result
=
$app
->
order
->
unify
([
'body'
=>
'佛山市理想中网络科技有限公司'
,
...
...
public/api.html
查看文件 @
7aea90b
...
...
@@ -5613,6 +5613,48 @@
<td>
是
</td>
<td>
订单号
</td>
</tr>
<tr>
<td>
receive_name
</td>
<td>
string
</td>
<td>
否
</td>
<td>
收货人
</td>
</tr>
<tr>
<td>
receive_mobile
</td>
<td>
string
</td>
<td>
否
</td>
<td>
联系方式
</td>
</tr>
<tr>
<td>
receive_address
</td>
<td>
string
</td>
<td>
否
</td>
<td>
收货地址
</td>
</tr>
<tr>
<td>
leave_message
</td>
<td>
string
</td>
<td>
否
</td>
<td>
留言
</td>
</tr>
<tr>
<td>
coupon_id
</td>
<td>
inter
</td>
<td>
否
</td>
<td>
优惠券id
</td>
</tr>
<tr>
<td>
discount_price
</td>
<td>
inter
</td>
<td>
否
</td>
<td>
优惠金额
</td>
</tr>
<tr>
<td>
total_price
</td>
<td>
inter
</td>
<td>
否
</td>
<td>
实付总金额
</td>
</tr>
</tbody>
</table>
</div>
...
...
@@ -5651,6 +5693,34 @@
<input
type=
"inter"
class=
"form-control input-sm"
id=
"order_sn"
required
placeholder=
"订单号"
name=
"order_sn"
>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label"
for=
"receive_name"
>
receive_name
</label>
<input
type=
"string"
class=
"form-control input-sm"
id=
"receive_name"
placeholder=
"收货人"
name=
"receive_name"
>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label"
for=
"receive_mobile"
>
receive_mobile
</label>
<input
type=
"string"
class=
"form-control input-sm"
id=
"receive_mobile"
placeholder=
"联系方式"
name=
"receive_mobile"
>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label"
for=
"receive_address"
>
receive_address
</label>
<input
type=
"string"
class=
"form-control input-sm"
id=
"receive_address"
placeholder=
"收货地址"
name=
"receive_address"
>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label"
for=
"leave_message"
>
leave_message
</label>
<input
type=
"string"
class=
"form-control input-sm"
id=
"leave_message"
placeholder=
"留言"
name=
"leave_message"
>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label"
for=
"coupon_id"
>
coupon_id
</label>
<input
type=
"inter"
class=
"form-control input-sm"
id=
"coupon_id"
placeholder=
"优惠券id"
name=
"coupon_id"
>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label"
for=
"discount_price"
>
discount_price
</label>
<input
type=
"inter"
class=
"form-control input-sm"
id=
"discount_price"
placeholder=
"优惠金额"
name=
"discount_price"
>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label"
for=
"total_price"
>
total_price
</label>
<input
type=
"inter"
class=
"form-control input-sm"
id=
"total_price"
placeholder=
"实付总金额"
name=
"total_price"
>
</div>
<div
class=
"form-group"
>
<button
type=
"submit"
class=
"btn btn-success send"
rel=
"35"
>
提交
</button>
<button
type=
"reset"
class=
"btn btn-info"
rel=
"35"
>
重置
</button>
</div>
...
...
@@ -5831,7 +5901,7 @@
<td>
total_price
</td>
<td>
inter
</td>
<td>
是
</td>
<td>
运费
总金额
</td>
<td>
实付
总金额
</td>
</tr>
</tbody>
</table>
...
...
@@ -5916,7 +5986,7 @@
</div>
<div
class=
"form-group"
>
<label
class=
"control-label"
for=
"total_price"
>
total_price
</label>
<input
type=
"inter"
class=
"form-control input-sm"
id=
"total_price"
required
placeholder=
"
运费
总金额"
name=
"total_price"
>
<input
type=
"inter"
class=
"form-control input-sm"
id=
"total_price"
required
placeholder=
"
实付
总金额"
name=
"total_price"
>
</div>
<div
class=
"form-group"
>
<button
type=
"submit"
class=
"btn btn-success send"
rel=
"36"
>
提交
</button>
...
...
@@ -7406,7 +7476,7 @@
<div
class=
"row mt0 footer"
>
<div
class=
"col-md-6"
align=
"left"
>
Generated on 2019-12-09 1
4:16:46
</div>
Generated on 2019-12-09 1
9:35:05
</div>
<div
class=
"col-md-6"
align=
"right"
>
<a
href=
"https://www.fastadmin.net"
target=
"_blank"
>
FastAdmin
</a>
</div>
...
...
请
注册
或
登录
后发表评论