AreaValidate.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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;
  20. use app\common\model\SpecialArea;
  21. use app\common\validate\BaseValidate;
  22. class AreaValidate extends BaseValidate
  23. {
  24. protected $rule = [
  25. 'id' => 'require',
  26. 'name' => 'require|checkName',
  27. 'is_show' => 'in:0,1',
  28. ];
  29. protected $message = [
  30. 'name.require' => '地区名称不能为空',
  31. 'is_show.in' => '是否显示类型错误',
  32. ];
  33. /**
  34. * @notes 添加地区
  35. * @return AreaValidate
  36. * @author Tab
  37. * @date 2021/7/22 17:06
  38. */
  39. public function sceneAdd()
  40. {
  41. return $this->remove('id', 'require');
  42. }
  43. /**
  44. * @notes 获取地区场景
  45. * @return AreaValidate
  46. * @author Tab
  47. * @date 2021/7/22 17:06
  48. */
  49. public function sceneDetail()
  50. {
  51. return $this->only(['id']);
  52. }
  53. /**
  54. * @notes 删除地区
  55. * @return AreaValidate
  56. * @author Tab
  57. * @date 2021/7/22 17:06
  58. */
  59. public function sceneDelete()
  60. {
  61. return $this->only(['id']);
  62. }
  63. /**
  64. * @notes 显示或隐藏场景
  65. * @return AreaValidate
  66. * @author Tab
  67. * @date 2021/7/22 17:07
  68. */
  69. public function sceneShow()
  70. {
  71. return $this->only(['id']);
  72. }
  73. /**
  74. * @notes 校验地区名称
  75. * @param $value
  76. * @return bool|string
  77. * @author Tab
  78. * @date 2021/7/22 17:08
  79. */
  80. public function checkName($value,$rule,$data)
  81. {
  82. $where[]=['name','=',$value];
  83. if(isset($data['id'])){
  84. $where[]=['id','<>',$data['id']];
  85. }
  86. $area = SpecialArea::where($where)->findOrEmpty();
  87. if(!$area->isEmpty()) {
  88. return '地区名称已存在';
  89. }
  90. return true;
  91. }
  92. }