切换导航条
此项目
正在载入...
登录
李忠强
/
temporaryfood
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
何书鹏
3 years ago
提交
c96d919f3d33878130901ba4064d2319a814bcb0
1 个父辈
0565b170
优惠券使用逻辑修改
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
49 行增加
和
28 行删除
application/api/controller/Order.php
application/api/controller/Order.php
查看文件 @
c96d919
...
...
@@ -502,7 +502,8 @@ class Order extends Api
'discount_price'
=>
$couponprice
,
// 优惠价格
'pay_price'
=>
bcadd
(
$sum_price
,
$couponprice
,
2
),
// 支付总价
'express_price'
=>
$distance_price
,
// 骑手费用
'user_id'
=>
$user_id
'user_id'
=>
$user_id
,
'user_coupon_id'
=>
$coupon_id
>
0
?
$coupon_id
:
0
];
// 添加订单
...
...
@@ -530,6 +531,8 @@ class Order extends Api
->
whereIn
(
'sku_id'
,
$skuids
)
->
where
(
'user_id'
,
$this
->
auth
->
id
)
->
delete
();
// 如果使用了优惠券,就把优惠券状态变为已使用
UserCoupon
::
where
(
'id'
,
$coupon_id
)
->
update
([
'status'
=>
'1'
]);
Db
::
commit
();
}
catch
(
PDOException
$e
){
Db
::
rollback
();
...
...
@@ -653,37 +656,55 @@ class Order extends Api
if
(
$order
[
'freight_status'
]
==
20
)
$this
->
error
(
'订单已发货无法取消'
);
$goodsmodel
=
new
\app\api\model\OrderGoods
();
$skumodel
=
new
\app\api\model\GoodsSpec
();
// 增加库存
$list
=
$goodsmodel
->
where
(
'order_id'
,
$order
[
'id'
])
->
select
();
foreach
(
$list
as
$key
=>
$value
){
if
(
$value
[
'deduct_stock_type'
]
==
10
){
$skumodel
->
where
(
'goods_spec_id'
,
$value
[
'goods_spec_id'
])
->
setInc
(
'stock_num'
,
$value
[
'total_num'
]);
Db
::
startTrans
();
try
{
// 增加库存
$list
=
$goodsmodel
->
where
(
'order_id'
,
$order
[
'id'
])
->
select
();
foreach
(
$list
as
$key
=>
$value
){
if
(
$value
[
'deduct_stock_type'
]
==
10
){
$skumodel
->
where
(
'goods_spec_id'
,
$value
[
'goods_spec_id'
])
->
setInc
(
'stock_num'
,
$value
[
'total_num'
]);
}
}
}
// 已支付就退款
if
(
$order
[
'pay_status'
]
==
'20'
){
$config
=
Service
::
getConfig
(
'wechat'
);
$config
[
'app_id'
]
=
$config
[
'miniapp_id'
];
$config
[
'notify_url'
]
=
$this
->
request
->
domain
()
.
'api/notify/refund/type/wechat'
;
$config
[
'return_url'
]
=
''
;
$wechat
=
Pay
::
wechat
(
$config
);
$refund_no
=
'LQ-'
.
time
()
.
mt_rand
(
10000
,
99999
);
$param
=
[
// 已支付就退款
if
(
$order
[
'pay_status'
]
==
'20'
){
$config
=
Service
::
getConfig
(
'wechat'
);
$config
[
'app_id'
]
=
$config
[
'miniapp_id'
];
$config
[
'notify_url'
]
=
$this
->
request
->
domain
()
.
'api/notify/refund/type/wechat'
;
$config
[
'return_url'
]
=
''
;
$wechat
=
Pay
::
wechat
(
$config
);
$refund_no
=
'LQ-'
.
time
()
.
mt_rand
(
10000
,
99999
);
$param
=
[
// 'total_fee' => $order['pay_price'],
// 'refund_fee' => $order['pay_price'],
'total_fee'
=>
1
,
'refund_fee'
=>
1
,
'out_trade_no'
=>
$order
[
'order_no'
],
'out_refund_no'
=>
$refund_no
];
$wechat
->
refund
(
$param
);
$order
->
refund_no
=
$refund_no
;
$order
->
refund_time
=
time
();
'total_fee'
=>
1
,
'refund_fee'
=>
1
,
'out_trade_no'
=>
$order
[
'order_no'
],
'out_refund_no'
=>
$refund_no
];
$wechat
->
refund
(
$param
);
$order
->
refund_no
=
$refund_no
;
$order
->
refund_time
=
time
();
}
// 状态变为已取消
$order
->
order_status
=
'20'
;
$order
->
status
=
'hidden'
;
$order
->
isUpdate
(
true
)
->
save
();
// 如果使用了优惠券,就把优惠券状态变为待使用或者已过期
if
(
$order
[
'user_coupon_id'
]
>
0
){
$user_coupon
=
UserCoupon
::
get
(
$order
[
'user_coupon_id'
]);
if
(
$user_coupon
){
$status
=
$user_coupon
[
'endtime'
]
>
time
()
?
'0'
:
'2'
;
$user_coupon
->
save
([
'status'
=>
$status
]);
}
}
Db
::
commit
();
}
catch
(
PDOException
$e
){
Db
::
rollback
();
$this
->
error
(
$e
->
getMessage
());
}
// 状态变为已取消
$order
->
order_status
=
'20'
;
$order
->
status
=
'hidden'
;
$order
->
isUpdate
(
true
)
->
save
();
$this
->
success
(
'取消成功'
);
}
...
...
请
注册
或
登录
后发表评论