You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.6 KiB

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