<?php
|
|
namespace app\api\model\plus\vip;
|
|
use app\api\model\plus\vip\User as VipUserModel;
|
use app\common\model\plus\vip\Apply as ApplyModel;
|
use app\common\exception\BaseException;
|
|
|
/**
|
* VIP专区申请模型
|
*/
|
class Apply extends ApplyModel
|
{
|
/**
|
* 隐藏属性
|
* @var array
|
*/
|
protected $hidden = [
|
'app_id',
|
'update_time'
|
];
|
|
/**
|
* 提交申请
|
* @param $user
|
* @param $data
|
* @return bool|false
|
* @throws BaseException
|
*/
|
public function submit($user, $data)
|
{
|
// 是否已提交申请
|
if ($this->checkExist($user['user_id'])) {
|
throw new BaseException(['msg' => '该用户已提交过申请,请勿重复提交']);
|
}
|
|
// 表单数据
|
$data['user_id'] = $user['user_id'];
|
$data['apply_status'] = 10;
|
$data['app_id'] = $user['app_id'];
|
|
// 开启事务
|
$this->startTrans();
|
try {
|
// 保存申请信息
|
$this->save($data);
|
|
// 新增VIP专区用户
|
VipUserModel::add($user['user_id'], [
|
'real_name' => $data['real_name'],
|
'mobile' => $data['mobile'],
|
'referee_id' => $user['referee_id'] ?? 0,
|
]);
|
|
$this->commit();
|
return true;
|
} catch (\Exception $e) {
|
$this->rollback();
|
throw new BaseException(['msg' => $e->getMessage()]);
|
}
|
}
|
|
/**
|
* 检查是否已提交申请
|
* @param $user_id
|
* @return bool
|
*/
|
private function checkExist($user_id)
|
{
|
return (new self)->where('user_id', '=', $user_id)
|
->where('apply_status', '<>', 30)
|
->count() > 0;
|
}
|
|
/**
|
* 获取申请列表
|
* @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()
|
]);
|
}
|
}
|