SpecialistInfo.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\Log;
  4. class SpecialistInfo extends SoftBaseModel
  5. {
  6. /**
  7. * 类别 1:文字
  8. * @var integer
  9. */
  10. const TYPE_1 = 1;
  11. /**
  12. * 类别 2:图片
  13. * @var integer
  14. */
  15. const TYPE_2 = 2;
  16. /**
  17. * 类别 3:视频
  18. * @var integer
  19. */
  20. const TYPE_3 = 3;
  21. static public $typeMap = [
  22. self::TYPE_1 => '文字',
  23. self::TYPE_2 => '图片',
  24. self::TYPE_3 => '视频',
  25. ];
  26. public $category_id = 0;
  27. public $thumb = '';
  28. protected $casts = ['cover'=>'array','comment_tag'=>'array'];
  29. protected $appends = ['category_id', 'thumb'];
  30. public function getCategoryIdAttribute()
  31. {
  32. return $this->attributes['second_id'] ? $this->attributes['second_id'] : $this->attributes['first_id'];
  33. }
  34. public function getThumbAttribute()
  35. {
  36. return $this->cover ? asset('storage/'.$this->cover[0]) : '';
  37. }
  38. public function firstCloumn(){
  39. return $this->belongsTo(SpecialistCloumn::class, 'first_id', 'id');
  40. }
  41. public function secondCloumn(){
  42. return $this->belongsTo(SpecialistCloumn::class, 'second_id', 'id');
  43. }
  44. public function leaveMessage(){
  45. return $this->hasMany(SpecialistInfoLeaveMessage::class, 'specialist_infos_id', 'id')
  46. ->with(
  47. ["user"=>function($with){
  48. $with->select(['id','wx_nickname','wx_headimgurl','third_up_nickname','third_up_headimg']);
  49. }
  50. ]
  51. );
  52. }
  53. protected static function booted()
  54. {
  55. //回调删除操作
  56. static::deleting(function ($model) {
  57. BrowseRecord::query()->where(
  58. array(
  59. "column"=>BrowseRecord::COLUMN_3,
  60. "object_id"=>$model->id
  61. )
  62. )->delete();
  63. SpecialistInfosAssociation::query()->where(
  64. array(
  65. "association_id"=>$model->id,
  66. )
  67. )->delete();
  68. });
  69. }
  70. }