|
|
@@ -412,9 +412,39 @@ class OrderController extends BaseController
|
|
|
$modifyPrice = bcadd($modifyPrice, $sendCost, 2);
|
|
|
}
|
|
|
|
|
|
+ //红包使用
|
|
|
+ $hbId = $post['hbId'] ?? 0;
|
|
|
+ $hb = null;
|
|
|
+ if ($hbId > 0) { // 不使用 $hbId =! 0,因为要用负数来表示红包已取消
|
|
|
+ $hb = HbClass::getById($hbId, true);
|
|
|
+ if (!empty($hb)) {
|
|
|
+ if ($hb->amount != $post['hbAmount']) {
|
|
|
+ util::fail('红包金额不相等'); //红包数据可能被串改
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($hb->status == 1 || $hb->status == -1) {
|
|
|
+ util::fail($hb->status == 1 ? '红包已使用' : '红包已作废');
|
|
|
+ }
|
|
|
+ if ($hb->endTime < time()) {
|
|
|
+ util::fail('红包已过期');
|
|
|
+ }
|
|
|
+ $modifyPrice = bcsub($modifyPrice, $hb->amount, 2);//扣减红包
|
|
|
+ }else{
|
|
|
+ Yii::error('没有找到红包,hbId', $hbId . ' ' . __METHOD__);
|
|
|
+ util::fail('没有找到红包,hbId: ' . $hbId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$post['modifyPrice'] = $modifyPrice;
|
|
|
//多处调用这个方法,注意同步修改,搜索关键词 createHdNewOrder
|
|
|
$return = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
|
|
|
+
|
|
|
+ if($hb != null){
|
|
|
+ $hb->status = 1;
|
|
|
+ $hb->orderId = $return->id;
|
|
|
+ $hb->save();
|
|
|
+ }
|
|
|
+
|
|
|
if (isset($return->shopId)) {
|
|
|
if ($return->shopId == 7610) {
|
|
|
if ($return->actPrice < 200) {
|
|
|
@@ -430,22 +460,7 @@ class OrderController extends BaseController
|
|
|
util::fail('本店暂不能使用跑腿呢');
|
|
|
}
|
|
|
}
|
|
|
- //红包使用
|
|
|
- $hbId = $post['hbId'] ?? 0;
|
|
|
- if ($hbId > 0) { // 不使用 $hbId =! 0,因为要用负数来表示红包已取消
|
|
|
- $hb = HbClass::getById($hbId, true);
|
|
|
- if (!empty($hb)) {
|
|
|
- if ($hb->status == 1 || $hb->status == -1) {
|
|
|
- util::fail($hb->status == 1 ? '红包已使用' : '红包已作废');
|
|
|
- }
|
|
|
- $hb->status = 1;
|
|
|
- $hb->orderId = $return->id;
|
|
|
- $hb->save();
|
|
|
- }else{
|
|
|
- Yii::error('没有找到红包,hbId', $hbId . ' ' . __METHOD__);
|
|
|
- util::fail('没有找到红包,hbId: ' . $hbId);
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
$transaction->commit();
|
|
|
|
|
|
$orderSn = $return->orderSn ?? '';
|