SystemStoreStaff.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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\store;
  12. use app\model\user\User;
  13. use app\model\work\WorkMember;
  14. use crmeb\basic\BaseModel;
  15. use crmeb\traits\ModelTrait;
  16. use think\Model;
  17. /**
  18. * 店员模型
  19. * Class SystemStoreStaff
  20. * @package app\model\store
  21. */
  22. class SystemStoreStaff extends BaseModel
  23. {
  24. use ModelTrait;
  25. /**
  26. * 数据表主键
  27. * @var string
  28. */
  29. protected $pk = 'id';
  30. /**
  31. * 模型名称
  32. * @var string
  33. */
  34. protected $name = 'system_store_staff';
  35. /**
  36. * @var string[]
  37. */
  38. protected $hidden = [
  39. 'last_ip'
  40. ];
  41. /**
  42. * @return \think\model\relation\HasOne
  43. */
  44. public function workMember()
  45. {
  46. return $this->hasOne(WorkMember::class, 'uid', 'uid');
  47. }
  48. /**
  49. * 规则修改器
  50. * @param $value
  51. * @return string
  52. */
  53. public function setRolesAttr($value)
  54. {
  55. if ($value) {
  56. return is_array($value) ? implode(',', $value) : $value;
  57. }
  58. return '';
  59. }
  60. /**
  61. * @param $value
  62. * @return array|false|string[]
  63. */
  64. public function getRolesAttr($value)
  65. {
  66. if ($value) {
  67. return is_string($value) ? explode(',', $value) : $value;
  68. }
  69. return [];
  70. }
  71. /**
  72. * user用户表一对一关联
  73. * @return \think\model\relation\HasOne
  74. */
  75. public function user()
  76. {
  77. return $this->hasOne(User::class, 'uid', 'uid', false)->field(['uid', 'nickname', 'delete_time'])->bind([
  78. 'nickname' => 'nickname',
  79. 'delete_time' => 'delete_time',
  80. ]);
  81. }
  82. /**
  83. * 门店表一对一关联
  84. * @return \think\model\relation\HasOne
  85. */
  86. public function store()
  87. {
  88. return $this->hasOne(SystemStore::class, 'id', 'store_id')->field(['id', 'name'])->bind([
  89. 'name' => 'name'
  90. ]);
  91. }
  92. /**
  93. * 时间戳获取器转日期
  94. * @param $value
  95. * @return false|string
  96. */
  97. public static function getAddTimeAttr($value)
  98. {
  99. return date('Y-m-d H:i:s', $value);
  100. }
  101. public function searchAccountAttr($query, $value)
  102. {
  103. if ($value) $query->where('account', $value);
  104. }
  105. public function searchPhoneAttr($query, $value)
  106. {
  107. if ($value) $query->where('phone', $value);
  108. }
  109. /**
  110. * 权限规格状态搜索器
  111. * @param Model $query
  112. * @param $value
  113. */
  114. public function searchStatusAttr($query, $value)
  115. {
  116. if ($value != '') {
  117. $query->where('status', $value);
  118. }
  119. }
  120. /**
  121. * 权限等级搜索器
  122. * @param Model $query
  123. * @param $value
  124. */
  125. public function searchLevelAttr($query, $value)
  126. {
  127. if (is_array($value)) {
  128. $query->where('level', $value[0], $value[1]);
  129. } else {
  130. $query->where('level', $value);
  131. }
  132. }
  133. /**
  134. * 是否有核销权限搜索器
  135. * @param Model $query
  136. * @param $value 用户uid
  137. */
  138. public function searchIsStatusAttr($query, $value)
  139. {
  140. $query->where(['uid' => $value, 'status' => 1, 'verify_status' => 1]);
  141. }
  142. /**
  143. * uid搜索器
  144. * @param Model $query
  145. * @param $value
  146. */
  147. public function searchUidAttr($query, $value)
  148. {
  149. $query->where('uid', $value);
  150. }
  151. /**
  152. * 门店id搜索器
  153. * @param Model $query
  154. * @param $value
  155. */
  156. public function searchStoreIdAttr($query, $value)
  157. {
  158. if ($value !== '') {
  159. $query->where('store_id', $value);
  160. }
  161. }
  162. /**
  163. * 角色
  164. * @param $query
  165. * @param $value
  166. */
  167. public function searchRolesAttr($query, $value)
  168. {
  169. if ($value) {
  170. $query->where('find_in_set(' . $value . ',`roles`)');
  171. }
  172. }
  173. /**
  174. * 是否是管理员
  175. * @param $query
  176. * @param $value
  177. */
  178. public function searchIsAdminAttr($query, $value)
  179. {
  180. if ($value !== '') {
  181. $query->where('is_admin', $value);
  182. }
  183. }
  184. /**
  185. * 是否是店员
  186. * @param $query
  187. * @param $value
  188. */
  189. public function searchIsStoreAttr($query, $value)
  190. {
  191. if ($value !== '') {
  192. $query->where('is_store', $value);
  193. }
  194. }
  195. /**
  196. * 是否删除
  197. * @param $query
  198. * @param $value
  199. */
  200. public function searchIsDelAttr($query, $value)
  201. {
  202. if ($value !== '') {
  203. $query->where('is_del', $value);
  204. }
  205. }
  206. /**
  207. * 是否接收通知
  208. * @param $query
  209. * @param $value
  210. */
  211. public function searchNotifyAttr($query, $value)
  212. {
  213. if ($value !== '') {
  214. $query->where('notify', $value);
  215. }
  216. }
  217. }