WorkMomentSendResult.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\model\work;
  3. use crmeb\basic\BaseModel;
  4. use crmeb\traits\ModelTrait;
  5. /**
  6. * Class WorkMomentSendResult
  7. * @package app\model\work
  8. */
  9. class WorkMomentSendResult extends BaseModel
  10. {
  11. use ModelTrait;
  12. /**
  13. * @var string
  14. */
  15. protected $name = 'work_moment_send_result';
  16. /**
  17. * @var string
  18. */
  19. protected $pk = 'id';
  20. /**
  21. * @var bool
  22. */
  23. protected $autoWriteTimestamp = false;
  24. /**
  25. * @return \think\model\relation\HasOne
  26. */
  27. public function member()
  28. {
  29. return $this->hasOne(WorkMember::class, 'userid', 'user_id')->field(['userid', 'name'])->bind(['name' => 'name']);
  30. }
  31. /**
  32. * @param $query
  33. * @param $value
  34. */
  35. public function searchMomentIdAttr($query, $value)
  36. {
  37. $query->where('moment_id', $value);
  38. }
  39. /**
  40. * @param $query
  41. * @param $value
  42. */
  43. public function searchUserIdAttr($query, $value)
  44. {
  45. if (!empty($value)) {
  46. if (is_array($value)) {
  47. $query->whereIn('user_id', $value);
  48. } else {
  49. $query->where('user_id', $value);
  50. }
  51. }
  52. }
  53. public function searchStatusAttr($query, $value)
  54. {
  55. if ('' !== $value) {
  56. $query->where('status', $value);
  57. }
  58. }
  59. /**
  60. * @param $value
  61. * @return false|string
  62. */
  63. public function setExternalUseridAttr($value)
  64. {
  65. return is_array($value) ? json_encode($value, true) : $value;
  66. }
  67. /**
  68. * @param $value
  69. * @return array|mixed
  70. */
  71. public function getExternalUseridAttr($value)
  72. {
  73. return $value ? json_decode($value, true) : [];
  74. }
  75. }