| | |
| | | use app\common\enum\user\grade\ChangeTypeEnum; |
| | | use app\common\enum\user\balanceLog\BalanceLogSceneEnum as SceneEnum; |
| | | use app\shop\model\user\PointsLog as PointsLogModel; |
| | | use app\shop\model\user\ConsumptionLog as ConsumptionLogModel; |
| | | use app\shop\model\plus\agent\User as AgentUserModel; |
| | | /** |
| | | * 用户模型 |
| | |
| | | return $this->rechargeToBalance($storeUserName, $data['balance']); |
| | | } elseif ($source == 1) { |
| | | return $this->rechargeToPoints($storeUserName, $data['points']); |
| | | } elseif ($source == 2) { |
| | | return $this->rechargeToconCumption($storeUserName, $data['consumption']); |
| | | } |
| | | return false; |
| | | } |
| | |
| | | event('UserGrade', $this['user_id']); |
| | | return true; |
| | | } |
| | | /** |
| | | * 用户充值:消费券 |
| | | */ |
| | | private function rechargeToconCumption($storeUserName, $data) |
| | | { |
| | | if (!isset($data['value']) || $data['value'] === '' || $data['value'] < 0) { |
| | | $this->error = '请输入正确的消费券数量'; |
| | | return false; |
| | | } |
| | | $consumer_coupon = 0; |
| | | // 判断充值方式,计算最终消费券 |
| | | if ($data['mode'] === 'inc') { |
| | | $diffMoney = $this['consumer_coupon'] + $data['value']; |
| | | $consumer_coupon = $data['value']; |
| | | } elseif ($data['mode'] === 'dec') { |
| | | $diffMoney = $this['consumer_coupon'] - $data['value'] <= 0 ? 0 : $this['consumer_coupon'] - $data['value']; |
| | | $consumer_coupon = -$data['value']; |
| | | } else { |
| | | $diffMoney = $data['value']; |
| | | $consumer_coupon= $data['value'] - $this['consumer_coupon']; |
| | | } |
| | | // 更新记录 |
| | | $this->transaction(function () use ($storeUserName, $data, $diffMoney, $consumer_coupon) { |
| | | $total_expend_money = $this['total_expend_money'] + $consumer_coupon <= 0? 0 : $this['total_expend_money'] + $consumer_coupon; |
| | | // 更新账户消费券 |
| | | $this->where('user_id', '=', $this['user_id'])->update([ |
| | | 'consumer_coupon' => $diffMoney, |
| | | 'total_expend_money' => $total_expend_money |
| | | ]); |
| | | // 新增消费券变动记录 |
| | | ConsumptionLogModel::add([ |
| | | 'user_id' => $this['user_id'], |
| | | 'value' => $consumer_coupon, |
| | | 'describe' => "后台管理员 [{$storeUserName}] 操作", |
| | | 'remark' => $data['remark'], |
| | | ]); |
| | | }); |
| | | event('UserGrade', $this['user_id']); |
| | | return true; |
| | | } |
| | | |
| | | |
| | | /** |