WorkChannelCode.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 app\model\other\Category;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\model\concern\SoftDelete;
  16. use think\model\relation\HasMany;
  17. use think\model\relation\HasOne;
  18. /**
  19. * 企业微信渠道码
  20. * Class WorkChannelCode
  21. * @package app\model\work
  22. */
  23. class WorkChannelCode extends BaseModel
  24. {
  25. use ModelTrait, SoftDelete;
  26. /**
  27. * @var string
  28. */
  29. protected $name = 'work_channel_code';
  30. /**
  31. * @var string
  32. */
  33. protected $key = 'id';
  34. /**
  35. * @var string
  36. */
  37. protected $autoWriteTimestamp = 'int';
  38. /**
  39. * @return HasMany
  40. */
  41. public function cycle()
  42. {
  43. return $this->hasMany(WorkChannelCycle::class, 'channel_id', 'id');
  44. }
  45. /**
  46. * @return HasMany
  47. */
  48. public function useridLimit()
  49. {
  50. return $this->hasMany(WorkChannelLimit::class, 'channel_id', 'id');
  51. }
  52. /**
  53. * @return HasOne
  54. */
  55. public function category()
  56. {
  57. return $this->hasOne(Category::class, 'id', 'cate_id');
  58. }
  59. /**
  60. * @param $value
  61. * @return false|string
  62. */
  63. public function setReserveUseridAttr($value)
  64. {
  65. return json_encode($value);
  66. }
  67. /**
  68. * @param $value
  69. * @return mixed
  70. */
  71. public function getReserveUseridAttr($value)
  72. {
  73. return json_decode($value, true);
  74. }
  75. /**
  76. * @param $value
  77. * @return false|string
  78. */
  79. public function setUseridsAttr($value)
  80. {
  81. return json_encode($value);
  82. }
  83. /**
  84. * @param $value
  85. * @return mixed
  86. */
  87. public function getuseridsAttr($value)
  88. {
  89. return json_decode($value, true);
  90. }
  91. /**
  92. * @param $value
  93. * @return false|string
  94. */
  95. public function setWelcomeWordsAttr($value)
  96. {
  97. return json_encode($value);
  98. }
  99. /**
  100. * @param $value
  101. * @return mixed
  102. */
  103. public function getWelcomeWordsAttr($value)
  104. {
  105. return json_decode($value, true);
  106. }
  107. /**
  108. * @param $value
  109. * @return false|string
  110. */
  111. public function setLabelIdAttr($value)
  112. {
  113. return json_encode($value);
  114. }
  115. /**
  116. * @param $value
  117. * @return mixed
  118. */
  119. public function getLabelIdAttr($value)
  120. {
  121. return json_decode($value, true);
  122. }
  123. /**
  124. * @param $query
  125. * @param $value
  126. */
  127. public function searchNameAttr($query, $value)
  128. {
  129. $query->where('name', 'like', '%' . $value . '%');
  130. }
  131. /**
  132. * @param $query
  133. * @param $value
  134. */
  135. public function searchTypeAttr($query, $value)
  136. {
  137. if ('' !== $value) {
  138. $query->where('type', $value);
  139. }
  140. }
  141. /**
  142. * @param $query
  143. * @param $value
  144. */
  145. public function searchIdAttr($query, $value)
  146. {
  147. if (is_array($value)) {
  148. $query->where('id', 'in', $value);
  149. } else {
  150. $query->where('id', $value);
  151. }
  152. }
  153. /**
  154. * 分类搜索
  155. * @param $query
  156. * @param $value
  157. */
  158. public function searchCateIdAttr($query, $value)
  159. {
  160. if ('' !== $value) {
  161. $query->where('cate_id', $value);
  162. }
  163. }
  164. }