StoreUser.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 门店用户
  18. * Class StoreUser
  19. * @package app\model\store
  20. */
  21. class StoreUser extends BaseModel
  22. {
  23. use ModelTrait;
  24. /**
  25. * 数据表主键
  26. * @var string
  27. */
  28. protected $pk = 'id';
  29. /**
  30. * 模型名称
  31. * @var string
  32. */
  33. protected $name = 'store_user';
  34. /**
  35. * user用户表一对一关联
  36. * @return \think\model\relation\HasOne
  37. */
  38. public function user()
  39. {
  40. return $this->hasOne(User::class, 'uid', 'uid');
  41. }
  42. /**
  43. * 门店id搜索器
  44. * @param $query
  45. * @param $value
  46. */
  47. public function searchStoreIdAttr($query, $value)
  48. {
  49. if ($value && $value != -1) {
  50. $query->where('store_id', $value);
  51. }
  52. }
  53. /**
  54. * 关联标签修改器
  55. * @param $value
  56. * @return false|string
  57. */
  58. protected function setLabelIdAttr($value)
  59. {
  60. if ($value) {
  61. return is_array($value) ? implode(',', $value) : $value;
  62. }
  63. return '';
  64. }
  65. /**
  66. * 关联标签获取器
  67. * @param $value
  68. * @param $data
  69. * @return mixed
  70. */
  71. protected function getLabelIdAttr($value)
  72. {
  73. if ($value) {
  74. return is_string($value) ? explode(',', $value) : $value;
  75. }
  76. return [];
  77. }
  78. /**
  79. * uid搜索器
  80. * @param Model $query
  81. * @param $value
  82. */
  83. public function searchUidAttr($query, $value)
  84. {
  85. if (is_array($value)) {
  86. $query->whereIn('uid', $value);
  87. } else {
  88. if ($value) {
  89. $query->where('uid', $value);
  90. }
  91. }
  92. }
  93. }