刮刮后端接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.0 KiB

<?php
declare (strict_types = 1);
namespace app\model;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @mixin \think\Model
*/
class AgentInfo extends Model
{
//
use SoftDelete;
protected $deleteTime = 'delete_time';
/**
* 升级为代理
* @param $aid
* @param $rebate_ratio
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function createInfo($aid,$rebate_ratio = 0)
{
$invite_code = self::returnInviteCode();
$model = new AgentInfo();
$save = [
'aid' => $aid,
'invite_code' => $invite_code,
'create_time' => date("Y-m-d H:i:s",time())
];
if (!empty($rebate_ratio)) {
$save['rebate_ratio'] = $rebate_ratio / 100;
}
$model->save($save);
}
/**
* 递归获取验证码(不重复)
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function returnInviteCode()
{
$invite_code = generate_random_str(6);
$query = AgentInfo::withTrashed()->where('invite_code',$invite_code)->field('id')->find();
if ($query) {
return self::returnInviteCode();
}
return $invite_code;
}
/**
* 修改返点占比
* @param $aid
* @param $rebate_ratio
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function updateRebateRatio($aid,$rebate_ratio)
{
$AgentInfo = new AgentInfo();
$AgentInfoRes = $AgentInfo->where('aid',$aid)->find();
$AgentInfoRes->rebate_ratio = $rebate_ratio / 100;
$AgentInfoRes->update_time = date("Y-m-d H:i:s",time());
$AgentInfoRes->save();
}
}