WorkGroupTemplate.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\work;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. /**
  15. * 企业群发模板
  16. * Class WorkGroupTemplate
  17. * @package app\model\work
  18. */
  19. class WorkGroupTemplate extends BaseModel
  20. {
  21. use ModelTrait;
  22. /**
  23. * @var string
  24. */
  25. protected $name = 'work_group_template';
  26. /**
  27. * @var string
  28. */
  29. protected $key = 'id';
  30. /**
  31. * @var string
  32. */
  33. protected $autoWriteTimestamp = 'int';
  34. /**
  35. * @var string
  36. */
  37. protected $timeKey = 'create_time';
  38. /**
  39. * @return \think\model\relation\HasMany
  40. */
  41. public function msgIds()
  42. {
  43. return $this->hasMany(WorkGroupMsgRelation::class, 'template_id', 'id');
  44. }
  45. /**
  46. * @param $value
  47. * @return false|string
  48. */
  49. public function setWhereExternalUseridsAttr($value)
  50. {
  51. return json_encode($value);
  52. }
  53. /**
  54. * @param $value
  55. * @return array|mixed
  56. */
  57. public function getWhereExternalUseridsAttr($value)
  58. {
  59. return $value ? json_decode($value, true) : [];
  60. }
  61. /**
  62. * @param $value
  63. * @return false|string
  64. */
  65. public function setUseridsAttr($value)
  66. {
  67. return is_array($value) ? json_encode($value) : $value;
  68. }
  69. /**
  70. * @param $value
  71. * @return mixed
  72. */
  73. public function getUseridsAttr($value)
  74. {
  75. return $value ? json_decode($value, true) : [];
  76. }
  77. /**
  78. * @param $value
  79. * @return false|string
  80. */
  81. public function getWhereLabelAttr($value)
  82. {
  83. return json_decode($value, true);
  84. }
  85. /**
  86. * @param $value
  87. * @return array|mixed
  88. */
  89. public function setWhereLabelAttr($value)
  90. {
  91. return json_encode($value);
  92. }
  93. /**
  94. * @param $value
  95. * @return false|string
  96. */
  97. public function setWelcomeWordsAttr($value)
  98. {
  99. return json_encode($value);
  100. }
  101. /**
  102. * @param $value
  103. * @return array|mixed
  104. */
  105. public function getWelcomeWordsAttr($value)
  106. {
  107. return $value ? json_decode($value, true) : [];
  108. }
  109. /**
  110. * @param $query
  111. * @param $value
  112. */
  113. public function searchSendTimeAttr($query, $value)
  114. {
  115. $query->where('send_time', $value);
  116. }
  117. /**
  118. * @param $query
  119. * @param $value
  120. */
  121. public function searchSendTypeAttr($query, $value)
  122. {
  123. if (is_array($value)) {
  124. $query->whereIn('send_type', $value);
  125. } else {
  126. $query->where('send_type', $value);
  127. }
  128. }
  129. /**
  130. * @param $query
  131. * @param $value
  132. */
  133. public function searchNameAttr($query, $value)
  134. {
  135. if ('' !== $value) {
  136. $query->whereLike('name', '%' . $value . '%');
  137. }
  138. }
  139. /**
  140. * @param $query
  141. * @param $value
  142. */
  143. public function searchClientTypeAttr($query, $value)
  144. {
  145. if ('' !== $value) {
  146. $query->where('client_type', $value);
  147. }
  148. }
  149. /**
  150. * @param $query
  151. * @param $value
  152. */
  153. public function searchUpdateTimeAttr($query, $value)
  154. {
  155. $this->searchTimeAttr($query, $value, ['timeKey' => 'update_time']);
  156. }
  157. }