Complaint.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace App\Repositories\Models\Info;
  3. use App\Repositories\Enums\ModelStatusEnum;
  4. use App\Repositories\Models\Base\Admin;
  5. use App\Repositories\Models\Base\Department;
  6. use App\Repositories\Models\Base\Resource;
  7. use App\Repositories\Models\Base\User;
  8. use App\Repositories\Models\Manage\Message;
  9. use App\Repositories\Models\Model;
  10. class Complaint extends Model
  11. {
  12. /**
  13. * @var string
  14. */
  15. protected $table = 'info_complaint';
  16. protected $guarded = [];
  17. protected $casts = [
  18. 'relevant_documents' => 'array'
  19. ];
  20. /**
  21. * The attributes excluded from the model's JSON form.
  22. *
  23. * @var array
  24. */
  25. protected $hidden = [];
  26. public function messages()
  27. {
  28. return $this->hasMany(ComplaintMessage::class)->select(['id', 'complaint_status', 'deal_department_id', 'content', 'created_at']);
  29. }
  30. public function dealDepartment()
  31. {
  32. return $this->belongsTo(Department::class)->select(['id', 'name']);
  33. }
  34. public function dealAdmin()
  35. {
  36. return $this->belongsTo(Admin::class)->select(['id', 'name']);
  37. }
  38. public function getRelevantDocumentUrlsAttribute()
  39. {
  40. if (array_key_exists('relevant_documents', $this->attributes)) {
  41. $ids = json_decode($this->attributes['relevant_documents']);
  42. $data = [];
  43. foreach ($ids as $id) {
  44. $resource = Resource::query()->where('id', $id)->first();
  45. if ($resource == null) return $data;
  46. //判断图片还是视频,供前端判断
  47. $type = 0;
  48. $img_type = config('site.img_type');
  49. $video_type = config('site.video_type');
  50. $arr = explode('.', $resource->path);
  51. if (strpos($img_type, $arr[1]) !== false) $type = 1;
  52. if (strpos($video_type, $arr[1]) !== false) $type = 2;
  53. $data[] = [
  54. 'path' => $resource->path,
  55. 'url' => $resource->url,
  56. 'type' => $type
  57. ];
  58. }
  59. return $data;
  60. }
  61. return [];
  62. }
  63. public function user()
  64. {
  65. return $this->belongsTo(User::class)->select(['id', 'name']);
  66. }
  67. public static function byManageMessagesIdGet($manage_messages_id)
  68. {
  69. return Message::query()->select(['id', 'deal_time', 'deal_limit_day', 'assign_admin_id', 'created_at', 'updated_at'])
  70. ->where('id', $manage_messages_id)->where('status', ModelStatusEnum::OK)->with('assign_admin')->first();
  71. }
  72. public static function getExtra($manage_messages_id)
  73. {
  74. $message = Message::query()->select(['extra'])->where('id', $manage_messages_id)->where('status', ModelStatusEnum::OK)->first();
  75. if ($message == null || $message['extra'] == null || $message['extra']['multiData'] == null) return null;
  76. $data_extra = [];
  77. foreach ($message['extra']['multiData'] as $data) {
  78. if ($data['department_id'] == null) {
  79. $data_extra[] = [
  80. 'body' => $data['body'],
  81. // 'claim' => $data['claim'],
  82. 'limit_day' => $data['limit_day'],
  83. 'department_id' => $data['department_id'],
  84. 'deal_idea' => '',
  85. 'deal_department_name' => '',
  86. ];
  87. continue;
  88. }
  89. $deal_idea = Message::query()->where('more_pid', $manage_messages_id)
  90. ->where('deal_department_id', $data['department_id'])
  91. ->where('status', ModelStatusEnum::OK)->value('deal_idea');
  92. $deal_department_name = Department::query()->where('id', $data['department_id'])->value('name');
  93. $data_extra[] = [
  94. 'body' => $data['body'],
  95. // 'claim' => $data['claim'],
  96. 'limit_day' => $data['limit_day'],
  97. 'department_id' => $data['department_id'],
  98. 'deal_idea' => $deal_idea,
  99. 'deal_department_name' => $deal_department_name,
  100. ];
  101. }
  102. return $data_extra;
  103. }
  104. }