<?php
namespace app\store\model\dealer;
use app\common\model\dealer\Apply as ApplyModel;
use app\common\service\Message as MessageService;
use app\common\enum\dealer\ApplyStatus as ApplyStatusEnum;
class Apply extends ApplyModel
{
public function getList($search = '')
{
$this->alias('apply')
->field('apply.*, user.nickName, user.avatarUrl')
->with(['referee'])
->join('user', 'user.user_id = apply.user_id')
->order(['apply.create_time' => 'desc']);
!empty($search) && $this->where('user.nickName|apply.real_name|apply.mobile', 'like', "%$search%");
return $this->paginate(15, false, [
'query' => \request()->request()
]);
}
public function submit($data)
{
if ($data['apply_status'] == ApplyStatusEnum::AUDIT_REJECT && empty($data['reject_reason'])) {
$this->error = '请填写驳回原因';
return false;
}
$this->transaction(function () use ($data) {
if ($data['apply_status'] == ApplyStatusEnum::AUDIT_PASS) {
User::add($this['user_id'], [
'real_name' => $this['real_name'],
'mobile' => $this['mobile'],
'referee_id' => $this['referee_id'],
]);
}
$data['audit_time'] = time();
$this->allowField(true)->save($data);
MessageService::send('dealer.apply', [
'apply' => $this, 'user' => $this['user'], ]);
});
return true;
}
}