|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use EasyWeChat\Factory;
|
|
|
|
|
|
|
|
|
|
class Visit extends SoftDeletesModel
|
|
|
|
|
{
|
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
|
|
|
|
|
|
protected $appends = ['type_text', 'audit_status_text', 'file_detail'];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'follw_people' => 'json',
|
|
|
|
|
'cars' => 'json',
|
|
|
|
|
'file' => 'json',
|
|
|
|
|
'person_no' => 'json',
|
|
|
|
|
'car_no' => 'json'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function getFileDetailAttribute()
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->file)) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
return Upload::whereIn('id', $this->file)->get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getTypeTextAttribute()
|
|
|
|
|
{
|
|
|
|
|
$array = [1 => '普通访客', 2 => '施工访客', 3 => '物流访客', 4 => 'VIP访客'];
|
|
|
|
|
return $array[$this->type] ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAuditStatusTextAttribute()
|
|
|
|
|
{
|
|
|
|
|
$array = ['-1' => '待学习', '0' => '待审核', '1' => '通过', '2' => '驳回', '3' => '已进厂', '4' => '已离厂', '5' => '已取消'];
|
|
|
|
|
return $array[$this->audit_status] ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function visitTime()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(VisitTime::class, 'id', 'visit_time_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function admin()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(Admin::class, 'id', 'admin_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function accompany()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(Admin::class, 'id', 'accompany_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function acceptAdmin()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(Admin::class, 'id', 'accept_admin_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function acceptGoodsAdmin()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(Admin::class, 'id', 'accept_goods_admin_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function acceptAdminSignFile()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(Upload::class, 'id', 'accept_admin_sign');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function visitArea()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(VisitArea::class, 'id', 'visit_area_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function audit()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(VisitAudit::class, 'visit_id', 'id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function logs()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(VisitLog::class, 'visit_id', 'id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function gateLogs()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(GateLog::class, 'code', 'code');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 小程序订阅消息
|
|
|
|
|
public static function subMsg($template_id, $openid, $data,$id)
|
|
|
|
|
{
|
|
|
|
|
$config = [
|
|
|
|
|
'app_id' => \config('app.wechat_appid'),
|
|
|
|
|
'secret' => \config('app.wechat_appsecret')
|
|
|
|
|
];
|
|
|
|
|
$app = Factory::miniProgram($config);
|
|
|
|
|
$data = [
|
|
|
|
|
'template_id' => $template_id,
|
|
|
|
|
'touser' => $openid,
|
|
|
|
|
'page' => 'pages/visit/detail?id=' . $id,
|
|
|
|
|
'data' => $data
|
|
|
|
|
];
|
|
|
|
|
return $app->subscribe_message->send($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|