SelffetchShopValidate.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\validate\selffetch_shop;
  20. use app\common\model\SelffetchShop;
  21. use app\common\model\SelffetchVerifier;
  22. use app\common\validate\BaseValidate;
  23. class SelffetchShopValidate extends BaseValidate
  24. {
  25. protected $rule = [
  26. 'id' => 'require|checkId',
  27. 'name' => 'require|checkName',
  28. 'image' => 'require',
  29. 'contact' => 'require',
  30. 'mobile' => 'require',
  31. 'province' => 'require|number',
  32. 'city' => 'number',
  33. 'district' => 'number',
  34. 'address' => 'require',
  35. 'longitude' => 'require',
  36. 'latitude' => 'require',
  37. 'business_start_time' => 'require',
  38. 'business_end_time' => 'require',
  39. 'weekdays' => 'require',
  40. 'status' => 'require|in:0,1',
  41. 'keyword' => 'require',
  42. 'boundary' => 'require',
  43. 'key' => 'require',
  44. ];
  45. protected $message = [
  46. 'name.require' => '门店名称不能为空',
  47. 'image.require' => '门店LOGO不能为空',
  48. 'contact.require' => '联系人不能为空',
  49. 'mobile.require' => '联系电话不能为空',
  50. 'mobile.mobile' => '不是有效的手机号码',
  51. 'province.require' => '门店地区不能为空',
  52. 'address.require' => '详细地址不能为空',
  53. 'longitude.require' => '经度不能为空',
  54. 'latitude.require' => '纬度不能为空',
  55. 'business_start_time.require' => '营业开始时间不能为空',
  56. 'business_end_time.require' => '营业结束时间不能为空',
  57. 'weekdays.require' => '营业周天不能为空',
  58. 'status.require' => '门店状态不能为空',
  59. 'status.in' => '门店状态取值范围[0,1]',
  60. 'keyword.require' => '搜索关键字不能为空',
  61. 'boundary.require' => '搜索区域不能为空',
  62. 'key.require' => '腾讯地图开发密钥不能为空',
  63. ];
  64. public function sceneAdd()
  65. {
  66. return $this->only(['name','image','contact','mobile','province','city','district','address','longitude','latitude','business_start_time','business_end_time','weekdays','status']);
  67. }
  68. public function sceneEdit()
  69. {
  70. return $this->only(['id','name','image','contact','mobile','province','city','district','address','longitude','latitude','business_start_time','business_end_time','weekdays','status']);
  71. }
  72. public function sceneDetail()
  73. {
  74. return $this->only(['id']);
  75. }
  76. public function sceneStatus()
  77. {
  78. return $this->only(['id','status']);
  79. }
  80. public function sceneDel()
  81. {
  82. return $this->only(['id'])
  83. ->append('id','checkDel');
  84. }
  85. public function sceneRegionSearch()
  86. {
  87. return $this->only(['keyword','boundary','key']);
  88. }
  89. /**
  90. * @notes 检查门店名称是否已存在
  91. * @param $value
  92. * @param $rule
  93. * @param $data
  94. * @return bool|string
  95. * @author ljj
  96. * @date 2021/8/11 2:46 下午
  97. */
  98. public function checkName($value,$rule,$data)
  99. {
  100. $where[] = ['name', '=', $value];
  101. //编辑的情况,要排除自身ID
  102. if (isset($data['id'])) {
  103. $where[] = ['id', '<>', $data['id']];
  104. }
  105. $result = SelffetchShop::where($where)->findOrEmpty();
  106. if (!$result->isEmpty()) {
  107. return '门店名称已存在';
  108. }
  109. return true;
  110. }
  111. /**
  112. * @notes 检查门店ID是否存在
  113. * @param $value
  114. * @param $rule
  115. * @param $data
  116. * @return bool|string
  117. * @author ljj
  118. * @date 2021/8/11 3:25 下午
  119. */
  120. public function checkId($value,$rule,$data)
  121. {
  122. $result = SelffetchShop::where('id', $value)->findOrEmpty();
  123. if ($result->isEmpty()) {
  124. return '自提门店不存在';
  125. }
  126. return true;
  127. }
  128. /**
  129. * @notes 检查门店是否可以删除
  130. * @param $value
  131. * @param $rule
  132. * @param $data
  133. * @return bool|string
  134. * @throws \think\db\exception\DataNotFoundException
  135. * @throws \think\db\exception\DbException
  136. * @throws \think\db\exception\ModelNotFoundException
  137. * @author ljj
  138. * @date 2021/8/11 5:06 下午
  139. */
  140. public function checkDel($value,$rule,$data)
  141. {
  142. $result = SelffetchVerifier::where('selffetch_shop_id', $value)->select()->toArray();
  143. if (!empty($result)) {
  144. return '门店正在使用中,无法删除';
  145. }
  146. return true;
  147. }
  148. }