<?php
|
|
namespace app\api\model\plus\operations;
|
|
use app\common\exception\BaseException;
|
use app\common\model\plus\operations\Cash as CashModel;
|
use app\api\model\user\UserAuth;
|
|
/**
|
* 队长提现明细模型
|
*/
|
class Cash extends CashModel
|
{
|
/**
|
* 隐藏字段
|
*/
|
protected $hidden = [
|
'update_time',
|
];
|
|
/**
|
* 获取队长提现明细
|
*/
|
public function getList($user_id, $apply_status = -1,$limit=15)
|
{
|
$model = $this;
|
$apply_status > -1 && $model = $model->where('apply_status', '=', $apply_status);
|
return $model->where('user_id', '=', $user_id)->order(['create_time' => 'desc'])
|
->paginate($limit);
|
}
|
|
/**
|
* 提交申请
|
*/
|
public function submit($shareholder, $data)
|
{
|
// 数据验证
|
$this->validation($shareholder, $data);
|
// 新增申请记录
|
$this->save(array_merge($data, [
|
'user_id' => $shareholder['user_id'],
|
'apply_status' => 10,
|
'app_id' => self::$app_id,
|
]));
|
// 冻结用户资金
|
$shareholder->freezeMoney($data['money']);
|
return true;
|
}
|
|
/**
|
* 数据验证
|
*/
|
private function validation($shareholder, &$data)
|
{
|
// 结算设置
|
$settlement = Setting::getItem('settlement');
|
// 最低提现佣金
|
if ($data['money'] <= 0) {
|
throw new BaseException(['msg' => '提现金额不正确']);
|
}
|
if ($shareholder['money'] <= 0) {
|
throw new BaseException(['msg' => '当前用户没有可提现佣金']);
|
}
|
if ($data['money'] > $shareholder['money']) {
|
throw new BaseException(['msg' => '提现金额不能大于可提现佣金']);
|
}
|
if ($data['money'] < $settlement['min_money']) {
|
throw new BaseException(['msg' => '最低提现金额为' . $settlement['min_money']]);
|
}
|
if (!in_array($data['pay_type'], $settlement['pay_type'])) {
|
throw new BaseException(['msg' => '提现方式不正确']);
|
}
|
if ($data['pay_type'] == '20') {
|
if (empty($data['alipay_name']) || empty($data['alipay_account'])) {
|
throw new BaseException(['msg' => '请补全提现信息']);
|
}
|
} elseif ($data['pay_type'] == '30') {
|
if (empty($data['bank_name']) || empty($data['bank_account']) || empty($data['bank_card'])) {
|
throw new BaseException(['msg' => '请补全提现信息']);
|
}
|
} elseif ($data['pay_type'] == '10') {
|
//微信支付需要实名认证
|
$auth = UserAuth::detail($shareholder['user_id']);
|
if(empty($auth)){
|
throw new BaseException(['msg' => '请先到个人中心->设置->实名认证']);
|
}elseif(!empty($auth) && $auth["auth_status"] != 1){
|
throw new BaseException(['msg' => '您的实名认证还未审核通过']);
|
}
|
}
|
// 处理手续费
|
$data['fee_rate'] = $settlement['fee_rate'];
|
if ($settlement['fee_rate']) {
|
$data['fee_money'] = round($data['money'] * $settlement['fee_rate'] / 100, 2);
|
$data['real_money'] = $data['money'] - $data['fee_money'];
|
} else {
|
$data['real_money'] = $data['money'];
|
}
|
}
|
|
}
|