zhangdehua 1 рік тому
батько
коміт
eb2cdd1e3a
2 змінених файлів з 7 додано та 7 видалено
  1. 6 4
      app/api/service/order/PaySuccess.php
  2. 1 3
      app/common/model/User.php

+ 6 - 4
app/api/service/order/PaySuccess.php

@@ -104,16 +104,18 @@ class PaySuccess extends BaseService
 
         //积分不足
         if ($payType == OrderPayTypeEnum::EXCHANGE) {
-            if ($this->user['accumulate_points'] < $this->model['total_price']) {
+            $rate = SettingModel::getItem('points_rate')['points_2_money'];
+
+            $points = bcmul($this->model['total_price'],$rate,0);
+
+            if ($this->user['accumulate_points'] < $points) {
                 $this->error = '用户积分不足,无法兑换成功';
                 return false;
             }
-            $this->model->transaction(function () use ($payType, $payData) {
+            $this->model->transaction(function () use ($payType, $payData, $points) {
                 // 更新订单状态
                 $this->updateOrderInfo($payType, $payData);
                 //扣除用户积分
-                $rate = SettingModel::getItem('points_rate')['points_2_money'];
-                $points = bcmul($this->model['total_price'],$rate,0);
                 UserModel::setDecAccumulatePoints($this->user['user_id'], $points,AccumulatePointsScene::CONSUME,'兑换商品');
                 // 记录订单支付信息
                 $this->updatePayInfo($payType);

+ 1 - 3
app/common/model/User.php

@@ -317,10 +317,8 @@ class User extends BaseModel
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public static function setDecAccumulatePoints(int $userId, string $payMoney, int $scene = AccumulatePointsScene::RECHARGE, string $describe = '')
+    public static function setDecAccumulatePoints(int $userId, string $points, int $scene = AccumulatePointsScene::RECHARGE, string $describe = '')
     {
-        $rate = SettingModel::getItem('points_rate')['points_rate'];
-        $points = bcmul(strval($payMoney),$rate,0);
         // 新增积分变动明细
         AccumulatePointsLog::add([
             'user_id' => $userId,