<?php
|
|
namespace app\api\model\plus\vip;
|
|
use app\common\model\plus\vip\Cash as CashModel;
|
use app\common\exception\BaseException;
|
|
|
/**
|
* VIP专区提现API模型
|
*/
|
class Cash extends CashModel
|
{
|
/**
|
* 隐藏属性
|
* @var array
|
*/
|
protected $hidden = [
|
'app_id',
|
'update_time'
|
];
|
|
/**
|
* 提交提现申请
|
* @param $vipUser
|
* @param $data
|
* @return bool
|
* @throws BaseException
|
*/
|
public function submit($vipUser, $data)
|
{
|
// 设置验证
|
$setting = \app\common\model\plus\vip\Setting::getItem('settlement', $vipUser['app_id']);
|
|
// 验证最低提现金额
|
if ($data['money'] <= 0) {
|
$this->error = '提现金额必须大于0';
|
return false;
|
}
|
|
if ($data['money'] < $setting['min_money']) {
|
$this->error = '最低提现金额为' . $setting['min_money'] . '元';
|
return false;
|
}
|
|
if ($data['money'] > $vipUser['money']) {
|
$this->error = '提现金额不能超过可提现佣金';
|
return false;
|
}
|
// 生成提现单号
|
$data['cash_no'] = 'V' . date('YmdHis') . mt_rand(1000, 9999);
|
$data['user_id'] = $vipUser['user_id'];
|
$data['apply_status'] = 10;
|
$data['app_id'] = $vipUser['app_id'];
|
|
// 计算手续费
|
$fee_rate = $setting['fee_rate'] ?? 0;
|
$data['fee_rate'] = $fee_rate;
|
$data['fee_money'] = $data['money'] * ($fee_rate * 0.01);
|
$data['real_money'] = $data['money'] - $data['fee_money'];
|
|
// 开启事务
|
$this->startTrans();
|
try {
|
// 保存提现申请
|
$this->save($data);
|
|
// 冻结VIP用户资金
|
User::freezeMoney($vipUser['user_id'], $data['money']);
|
|
$this->commit();
|
return true;
|
} catch (\Exception $e) {
|
$this->rollback();
|
$this->error = $e->getMessage();
|
return false;
|
}
|
}
|
|
/**
|
* 获取提现明细列表
|
* @param $user_id
|
* @param int $status
|
* @param array $query
|
* @return \think\Paginator
|
* @throws \think\exception\DbException
|
*/
|
public function getList($user_id, $status = -1, $query = [])
|
{
|
$model = $this->where('user_id', '=', $user_id);
|
|
if ($status > -1) {
|
$model = $model->where('apply_status', '=', $status);
|
}
|
|
return $model->with(['user'])
|
->order(['create_time' => 'desc'])
|
->paginate($query, false, [
|
'query' => \request()->request()
|
]);
|
}
|
}
|