AreaValidate.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. 'free_shipping_money'=> 'checkFreeShipFee'
  29. ];
  30. protected $message = [
  31. 'name.require' => '地区名称不能为空',
  32. 'is_show.in' => '是否显示类型错误',
  33. ];
  34. /**
  35. * @notes 添加地区
  36. * @return AreaValidate
  37. * @author Tab
  38. * @date 2021/7/22 17:06
  39. */
  40. public function sceneAdd()
  41. {
  42. return $this->remove('id', 'require');
  43. }
  44. /**
  45. * @notes 获取地区场景
  46. * @return AreaValidate
  47. * @author Tab
  48. * @date 2021/7/22 17:06
  49. */
  50. public function sceneDetail()
  51. {
  52. return $this->only(['id']);
  53. }
  54. /**
  55. * @notes 删除地区
  56. * @return AreaValidate
  57. * @author Tab
  58. * @date 2021/7/22 17:06
  59. */
  60. public function sceneDelete()
  61. {
  62. return $this->only(['id']);
  63. }
  64. /**
  65. * @notes 显示或隐藏场景
  66. * @return AreaValidate
  67. * @author Tab
  68. * @date 2021/7/22 17:07
  69. */
  70. public function sceneShow()
  71. {
  72. return $this->only(['id']);
  73. }
  74. /**
  75. * @notes 校验地区名称
  76. * @param $value
  77. * @return bool|string
  78. * @author Tab
  79. * @date 2021/7/22 17:08
  80. */
  81. public function checkName($value,$rule,$data)
  82. {
  83. $where[]=['name','=',$value];
  84. if(isset($data['id'])){
  85. $where[]=['id','<>',$data['id']];
  86. $areas = SpecialArea::findOrEmpty($data['id']);
  87. if($areas->isEmpty()){
  88. return '传入的信息有误!';
  89. }
  90. }
  91. $area = SpecialArea::where($where)->findOrEmpty();
  92. if(!$area->isEmpty()) {
  93. return '地区名称已存在';
  94. }
  95. return true;
  96. }
  97. //free_shipping_money reduce_shipping_money
  98. public function checkFreeShipFee($value,$rule,$data){
  99. if(isset($data['reduce_shipping_money'])){
  100. if($value < $data['reduce_shipping_money']){
  101. return '包邮门槛和减免运费门槛规则错误!';
  102. }
  103. }
  104. return true;
  105. }
  106. }