ExpressValidate.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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\settings\delivery;
  20. use app\common\model\Express;
  21. use app\common\validate\BaseValidate;
  22. class ExpressValidate extends BaseValidate
  23. {
  24. protected $rule = [
  25. 'id' => 'require|checkId',
  26. 'name' => 'require|checkName',
  27. 'sort' => 'number|max:5',
  28. ];
  29. protected $message = [
  30. 'name.require' => '快递公司名称不能为空',
  31. 'sort.number' => '排序只能是纯数字',
  32. 'sort.max' => '排序最大不能超过五位数',
  33. ];
  34. public function sceneAdd()
  35. {
  36. return $this->only(['name','sort']);
  37. }
  38. public function sceneEdit()
  39. {
  40. return $this->only(['id','name','sort']);
  41. }
  42. public function sceneDel()
  43. {
  44. return $this->only(['id']);
  45. }
  46. public function sceneDetail()
  47. {
  48. return $this->only(['id']);
  49. }
  50. /**
  51. * @notes 检查快递公司名称是否已存在
  52. * @param $value
  53. * @param $rule
  54. * @param $data
  55. * @return bool|string
  56. * @author ljj
  57. * @date 2021/7/29 4:29 下午
  58. */
  59. public function checkName($value,$rule,$data)
  60. {
  61. $where[] = ['name', '=', $value];
  62. // 编辑的情况,要排除自身ID
  63. if (isset($data['id'])) {
  64. $where[] = ['id', '<>', $data['id']];
  65. }
  66. $result = Express::where($where)->findOrEmpty();
  67. if (!$result->isEmpty()) {
  68. return '快递公司名称已存在';
  69. }
  70. return true;
  71. }
  72. /**
  73. * @notes 检查ID是否存在
  74. * @param $value
  75. * @param $rule
  76. * @param $data
  77. * @return bool|string
  78. * @author ljj
  79. * @date 2021/7/29 5:17 下午
  80. */
  81. public function checkId($value,$rule,$data)
  82. {
  83. $result = Express::where('id',$value)->findOrEmpty();
  84. if ($result->isEmpty()) {
  85. return '快递公司不存在';
  86. }
  87. return true;
  88. }
  89. }