|
|
@@ -26,6 +26,7 @@ use app\common\model\RechargeOrder;
|
|
|
use app\common\model\RechargeTemplate;
|
|
|
use app\common\model\User;
|
|
|
use app\common\service\ConfigService;
|
|
|
+use think\facade\Db;
|
|
|
use think\response\Json;
|
|
|
|
|
|
/**
|
|
|
@@ -165,41 +166,53 @@ class RechargeLogic extends BaseLogic
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- public static function exchange($params){
|
|
|
+ public static function exchange($params)
|
|
|
+ {
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $gift_card_info = GiftCardInfo::where(['card_pass' => $params['pass']])->findOrEmpty();
|
|
|
+ if ($gift_card_info->isEmpty()) {
|
|
|
+ throw new \think\Exception('卡密有误,请检查!');
|
|
|
+ }
|
|
|
|
|
|
- $gift_card_info = GiftCardInfo::where(['card_pass'=>$params['pass']])->findOrEmpty();
|
|
|
- if($gift_card_info->isEmpty()){
|
|
|
- throw new \think\Exception('卡密有误,请检查!');
|
|
|
+ $data = [
|
|
|
+ 'sn' => generate_sn((new RechargeOrder()), 'sn'),
|
|
|
+ 'terminal' => 0,
|
|
|
+ 'user_id' => $params['user_id'],
|
|
|
+ 'pay_status' => PayEnum::ISPAID,
|
|
|
+ 'pay_time' => time(),
|
|
|
+ 'pay_way' => 7,
|
|
|
+ 'order_amount' => $gift_card_info['card_money'],
|
|
|
+ 'template_id' => 0,
|
|
|
+ 'award' => 0
|
|
|
+ ];
|
|
|
+
|
|
|
+ $order = RechargeOrder::create($data);
|
|
|
+ if(!$order){
|
|
|
+ Db::rollback();
|
|
|
+ throw new \think\Exception('充值订单表插入失败!');
|
|
|
+ }
|
|
|
+ $user_info = User::find($params['user_id']);
|
|
|
+ $user_info->user_money = $user_info->user_money + $gift_card_info['card_money'];
|
|
|
+ $user_info->save();
|
|
|
+
|
|
|
+ $gift_card_info->is_used = 1;
|
|
|
+ $gift_card_info->user_id = $params['user_id'];
|
|
|
+ $gift_card_info->used_time = time();
|
|
|
+ $gift_card_info->save();
|
|
|
+
|
|
|
+
|
|
|
+ // 记录账户流水
|
|
|
+ AccountLogLogic::add($params['user_id'], AccountLogEnum::EXCHANGE_INC_RECHARGE, AccountLogEnum::INC, $gift_card_info['card_money'], $order->sn, '用户礼品卡兑换金额');
|
|
|
+
|
|
|
+ // 提交事务
|
|
|
+ Db::commit();
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ Db::rollback();
|
|
|
+ return $e->getMessage();
|
|
|
}
|
|
|
|
|
|
- $data = [
|
|
|
- 'sn' => generate_sn((new RechargeOrder()),'sn'),
|
|
|
- 'terminal' => 0,
|
|
|
- 'user_id' => $params['user_id'],
|
|
|
- 'pay_status' => PayEnum::ISPAID,
|
|
|
- 'pay_time' => time(),
|
|
|
- 'pay_way' => 7,
|
|
|
- 'order_amount' => $gift_card_info['card_money'],
|
|
|
- 'template_id' => 0,
|
|
|
- 'award' => 0
|
|
|
- ];
|
|
|
-
|
|
|
- $order = RechargeOrder::create($data);
|
|
|
-
|
|
|
- $user_info = User::find($params['user_id']);
|
|
|
- $user_info->user_money = $user_info->user_money + $gift_card_info['card_money'];
|
|
|
- $user_info->save();
|
|
|
-
|
|
|
- $gift_card_info->is_used = 1;
|
|
|
- $gift_card_info->user_id = $params['user_id'];
|
|
|
- $gift_card_info->used_time = time();
|
|
|
- $gift_card_info->save();
|
|
|
-
|
|
|
-
|
|
|
- // 记录账户流水
|
|
|
- AccountLogLogic::add($params['user_id'], AccountLogEnum::EXCHANGE_INC_RECHARGE, AccountLogEnum::INC,$gift_card_info['card_money'], $order->sn, '用户礼品卡兑换金额');
|
|
|
-
|
|
|
-
|
|
|
- return true;
|
|
|
}
|
|
|
}
|