SystemStore.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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\other\Category;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 门店列表
  18. * Class SystemStore
  19. * @package app\model\store
  20. */
  21. class SystemStore 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 = 'system_store';
  34. /**
  35. * @return \think\model\relation\HasOne
  36. */
  37. public function categoryName()
  38. {
  39. return $this->hasOne(Category::class, 'id', 'cate_id')->where('group', 5)->field('id,pid,name')->bind([
  40. 'cate_name' => 'name'
  41. ]);
  42. }
  43. /**
  44. * @return \think\model\relation\HasOne
  45. */
  46. public function category()
  47. {
  48. return $this->hasOne(Category::class, 'id', 'cate_id')->where('group', 5);
  49. }
  50. /**
  51. * 经纬度获取器
  52. * @param $value
  53. * @param $data
  54. * @return string
  55. */
  56. public static function getLatlngAttr($value, $data)
  57. {
  58. return $data['latitude'] . ',' . $data['longitude'];
  59. }
  60. /**
  61. * id
  62. * @param Model $query
  63. * @param $value
  64. */
  65. public function searchIdAttr($query, $value)
  66. {
  67. if ($value) {
  68. if (is_array($value))
  69. $query->whereIn('id', $value);
  70. else
  71. $query->where('id', $value);
  72. }
  73. }
  74. /**
  75. * cate_id
  76. * @param Model $query
  77. * @param $value
  78. */
  79. public function searchCateIdAttr($query, $value)
  80. {
  81. if ($value) {
  82. if (is_array($value))
  83. $query->whereIn('cate_id', $value);
  84. else
  85. $query->where('cate_id', $value);
  86. }
  87. }
  88. /**
  89. * 店铺类型搜索器
  90. * @param Model $query
  91. * @param $value
  92. */
  93. public function searchTypeAttr($query, $value)
  94. {
  95. if ($value !== '') {
  96. switch ((int)$value) {
  97. case 1://营业中
  98. case 0://休息中
  99. $query->where(['is_del' => 0, 'is_show' => 1]);
  100. break;
  101. case -1://已停业
  102. $query->where(['is_del' => 0, 'is_show' => 0]);
  103. break;
  104. default:
  105. $query->where(['is_del' => 0]);
  106. break;
  107. }
  108. }
  109. }
  110. /**
  111. * is_show搜索器
  112. * @param $query
  113. * @param $value
  114. */
  115. public function searchIsShowAttr($query, $value)
  116. {
  117. if ($value !== '') $query->where('is_show', $value);
  118. }
  119. /**
  120. * is_del搜索器
  121. * @param $query
  122. * @param $value
  123. */
  124. public function searchIsDelAttr($query, $value)
  125. {
  126. if ($value !== '') $query->where('is_del', $value);
  127. }
  128. /**
  129. * is_store搜索器
  130. * @param $query
  131. * @param $value
  132. */
  133. public function searchIsStoreAttr($query, $value)
  134. {
  135. if ($value !== '') $query->where('is_store', $value);
  136. }
  137. /**
  138. * 手机号,id,昵称搜索器
  139. * @param Model $query
  140. * @param $value
  141. */
  142. public function searchKeywordsAttr($query, $value)
  143. {
  144. if ($value != '') {
  145. $query->where('id|name|introduction|phone|detailed_address|address', 'LIKE', "%$value%");
  146. }
  147. }
  148. }