WorkMoment.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\model\work;
  3. use crmeb\basic\BaseModel;
  4. use crmeb\traits\ModelTrait;
  5. /**
  6. * 朋友圈
  7. * Class WorkMoment
  8. * @package app\model\work
  9. */
  10. class WorkMoment extends BaseModel
  11. {
  12. use ModelTrait;
  13. /**
  14. * @var string
  15. */
  16. protected $name = 'work_moment';
  17. /**
  18. * @var string
  19. */
  20. protected $pk = 'id';
  21. /**
  22. * @var string
  23. */
  24. protected $autoWriteTimestamp = 'int';
  25. /**
  26. * @var string
  27. */
  28. protected $timeKey = 'create_time';
  29. /**
  30. * @return \think\model\relation\HasMany
  31. */
  32. public function sendResult()
  33. {
  34. return $this->hasMany(WorkMomentSendResult::class, 'moment_id', 'moment_id');
  35. }
  36. /**
  37. * @param $value
  38. * @return array|mixed
  39. */
  40. public function getWelcomeWordsAttr($value)
  41. {
  42. return $value ? json_decode($value, true) : [];
  43. }
  44. /**
  45. * @param $value
  46. * @return false|string
  47. */
  48. public function setWelcomeWordsAttr($value)
  49. {
  50. return json_encode($value);
  51. }
  52. /**
  53. * @param $value
  54. * @return array|mixed
  55. */
  56. public function getClientTagListAttr($value)
  57. {
  58. return $value ? json_decode($value, true) : [];
  59. }
  60. /**
  61. * @param $value
  62. * @return array|mixed
  63. */
  64. public function getUserIdsAttr($value)
  65. {
  66. return $value ? json_decode($value, true) : [];
  67. }
  68. /**
  69. * @param $value
  70. * @return false|string
  71. */
  72. public function setClientTagListAttr($value)
  73. {
  74. return json_encode($value);
  75. }
  76. /**
  77. * @param $value
  78. * @return false|string
  79. */
  80. public function setUserIdsAttr($value)
  81. {
  82. return json_encode($value);
  83. }
  84. /**
  85. * @param $query
  86. * @param $value
  87. */
  88. public function searchSendTimeAttr($query, $value)
  89. {
  90. $query->where('send_time', $value);
  91. }
  92. /**
  93. * @param $query
  94. * @param $value
  95. */
  96. public function searchJobidNullAttr($query, $value)
  97. {
  98. $query->whereNull('jobid');
  99. }
  100. /**
  101. * @param $query
  102. * @param $value
  103. */
  104. public function searchNameLikeAttr($query, $value)
  105. {
  106. if ('' !== $value) {
  107. $query->whereLike('name', '%' . $value . '%');
  108. }
  109. }
  110. }