123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace App\Repositories\Models\Info;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Models\Base\Admin;
- use App\Repositories\Models\Base\Department;
- use App\Repositories\Models\Base\Resource;
- use App\Repositories\Models\Base\User;
- use App\Repositories\Models\Manage\Message;
- use App\Repositories\Models\Model;
- class Complaint extends Model
- {
- /**
- * @var string
- */
- protected $table = 'info_complaint';
- protected $guarded = [];
- protected $casts = [
- 'relevant_documents' => 'array'
- ];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [];
- public function messages()
- {
- return $this->hasMany(ComplaintMessage::class)->select(['id', 'complaint_status', 'deal_department_id', 'content', 'created_at']);
- }
- public function dealDepartment()
- {
- return $this->belongsTo(Department::class)->select(['id', 'name']);
- }
- public function dealAdmin()
- {
- return $this->belongsTo(Admin::class)->select(['id', 'name']);
- }
- public function getRelevantDocumentUrlsAttribute()
- {
- if (array_key_exists('relevant_documents', $this->attributes)) {
- $ids = json_decode($this->attributes['relevant_documents']);
- $data = [];
- foreach ($ids as $id) {
- $resource = Resource::query()->where('id', $id)->first();
- if ($resource == null) return $data;
- //判断图片还是视频,供前端判断
- $type = 0;
- $img_type = config('site.img_type');
- $video_type = config('site.video_type');
- $arr = explode('.', $resource->path);
- if (strpos($img_type, $arr[1]) !== false) $type = 1;
- if (strpos($video_type, $arr[1]) !== false) $type = 2;
- $data[] = [
- 'path' => $resource->path,
- 'url' => $resource->url,
- 'type' => $type
- ];
- }
- return $data;
- }
- return [];
- }
- public function user()
- {
- return $this->belongsTo(User::class)->select(['id', 'name']);
- }
- public static function byManageMessagesIdGet($manage_messages_id)
- {
- return Message::query()->select(['id', 'deal_time', 'deal_limit_day', 'assign_admin_id', 'created_at', 'updated_at'])
- ->where('id', $manage_messages_id)->where('status', ModelStatusEnum::OK)->with('assign_admin')->first();
- }
- public static function getExtra($manage_messages_id)
- {
- $message = Message::query()->select(['extra'])->where('id', $manage_messages_id)->where('status', ModelStatusEnum::OK)->first();
- if ($message == null || $message['extra'] == null || $message['extra']['multiData'] == null) return null;
- $data_extra = [];
- foreach ($message['extra']['multiData'] as $data) {
- if ($data['department_id'] == null) {
- $data_extra[] = [
- 'body' => $data['body'],
- // 'claim' => $data['claim'],
- 'limit_day' => $data['limit_day'],
- 'department_id' => $data['department_id'],
- 'deal_idea' => '',
- 'deal_department_name' => '',
- ];
- continue;
- }
- $deal_idea = Message::query()->where('more_pid', $manage_messages_id)
- ->where('deal_department_id', $data['department_id'])
- ->where('status', ModelStatusEnum::OK)->value('deal_idea');
- $deal_department_name = Department::query()->where('id', $data['department_id'])->value('name');
- $data_extra[] = [
- 'body' => $data['body'],
- // 'claim' => $data['claim'],
- 'limit_day' => $data['limit_day'],
- 'department_id' => $data['department_id'],
- 'deal_idea' => $deal_idea,
- 'deal_department_name' => $deal_department_name,
- ];
- }
- return $data_extra;
- }
- }
|