Browse Source

消费返点

master
wanghongjun 2 years ago
parent
commit
dba5598398
  1. 3
      app/controller/AdminAgentTeam.php
  2. 3
      app/controller/AdminUserTeam.php
  3. 9
      app/controller/AgentTeam.php
  4. 2
      app/model/RechargeRecords.php
  5. 25
      app/model/User.php

3
app/controller/AdminAgentTeam.php

@ -104,6 +104,9 @@ class AdminAgentTeam extends BaseController
# 代理充值记录
RechargeRecords::createRecords($aid,$quota,$agentBalance,1,2,$adminUser['id']);
# 消费返点
User::addRebateRatioAmount($aid,$quota);
$connection->commit();
return $this->renderSuccess('上分成功');
} catch (ValidateException $e) {

3
app/controller/AdminUserTeam.php

@ -178,6 +178,9 @@ class AdminUserTeam extends BaseController
# 用户充值记录-上分
RechargeRecords::createRecords($user_id,$quota,$userBalance,1,2,$adminUser['id']);
# 消费返点
User::addRebateRatioAmount($user_id,$quota);
$connection->commit();
return $this->renderSuccess('上分成功');
} catch (ValidateException $e) {

9
app/controller/AgentTeam.php

@ -94,7 +94,7 @@ class AgentTeam extends BaseController
$RechargeRecords = new RechargeRecords();
$list = Db::name('recharge_records')
->where('user_id',$userData['id'])
->field('recharge_amount,residue_amount,trade_type,recharge_time')
->field('recharge_amount,residue_amount,trade_type,trade_id,recharge_time')
->order('id' ,'desc')
->paginate($limit);
@ -102,8 +102,10 @@ class AgentTeam extends BaseController
foreach ($listArr as &$item) {
give_symbol($item['recharge_amount']);
$item['trade_type'] = $RechargeRecords->tradeType[$item['trade_type']];
$str = $item['trade_type'] == 4 ? 'ID:' . $item['trade_id'] . ' ' : '';
$item['trade_type'] = $str . $RechargeRecords->tradeType[$item['trade_type']];
$item['recharge_time'] = date("m月d日 H:i",strtotime($item['recharge_time']));
unset($item['trade_id']);
}
return $this->renderSuccess('数据获取成功',[
@ -150,6 +152,9 @@ class AgentTeam extends BaseController
# 用户充值记录-上分
RechargeRecords::createRecords($user_id,$quota,$userBalance,1,1,$agentUser['id']);
# 消费返点
User::addRebateRatioAmount($user_id,$quota);
$connection->commit();
return $this->renderSuccess('上分成功');
} catch (ValidateException $e) {

2
app/model/RechargeRecords.php

@ -11,7 +11,7 @@ use think\Model;
class RechargeRecords extends Model
{
public $tradeType = [1 => '代理上分', 2 => '管理员上分', 3 => '支付宝'];
public $tradeType = [1 => '代理上分', 2 => '管理员上分', 3 => '支付宝', 4 => '消费返点'];
/**
* 创建充值记录
* @param $user_id

25
app/model/User.php

@ -330,6 +330,31 @@ class User extends Model
$userRes->save();
}
/**
* 添加消费返点
* @param $user_id // 充值用户
* @param $amount // 充值金额
* @return false|void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function addRebateRatioAmount($user_id,$amount)
{
$aid = User::where('id',$user_id)->value('aid');
if (empty($aid)) return false;
$rebate_ratio = AgentInfo::where('aid',$aid)->value('rebate_ratio');
if (!$rebate_ratio || !($rebate_ratio * 1)) return false;
$rebateRatioAmount = bcmul($amount,$rebate_ratio,2);
$residue_amount = self::incrBalance($aid,$rebateRatioAmount);
# 代理充值返点金额
RechargeRecords::createRecords($aid,$rebateRatioAmount,$residue_amount,1,4,$user_id);
}
/**
* 生成盐值
* @return string

Loading…
Cancel
Save