66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
|
|
class Audit extends Model
|
|
{
|
|
protected $table = 'audit';
|
|
|
|
const TYPE_INDUSTRY_SUB = 'industry_sub';//职位
|
|
const TYPE_USER_AVATAR = 'user_avatar';//头像
|
|
const TYPE_MARRIAGE_APPROVE = 'marriage_approve';//介绍人认证
|
|
|
|
public function user(): HasOne
|
|
{
|
|
return $this->hasOne(User::class, 'id', 'user_id')
|
|
->selectRaw('id,nickname,photo,app_avatar,circle_avatar,type,sex,is_photo_audited,belief');
|
|
}
|
|
|
|
public function operator(): HasOne
|
|
{
|
|
return $this->hasOne(User::class, 'id', 'operator_id')
|
|
->selectRaw('id,nickname,photo,app_avatar,circle_avatar,type,sex,is_photo_audited');
|
|
}
|
|
|
|
public function getCheckDataAttribute($value)
|
|
{
|
|
return json_decode($value, true);
|
|
}
|
|
|
|
/**
|
|
* 检查是否有待审核的数据
|
|
* @param $user_id
|
|
* @param $type
|
|
* @return mixed
|
|
*/
|
|
public function checkHasAudit($user_id, $type)
|
|
{
|
|
$where = [
|
|
'user_id' => $user_id,
|
|
'type' => $type,
|
|
'status' => 0
|
|
];
|
|
return $this->where($where)->first();
|
|
}
|
|
|
|
/**
|
|
* 创建审核数据
|
|
* @param $user_id
|
|
* @param $type
|
|
* @param $check_data
|
|
*/
|
|
public function createAuditData($user_id, $type, $check_data)
|
|
{
|
|
$check = $this->checkHasAudit($user_id, $type);
|
|
if ($check) {
|
|
return;
|
|
}
|
|
$this->user_id = $user_id;
|
|
$this->type = $type;
|
|
$this->check_data = json_encode($check_data,JSON_UNESCAPED_UNICODE);
|
|
$this->save();
|
|
}
|
|
} |