FaceSheetSenderValidate.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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\express_assistant;
  20. use app\common\model\FaceSheetSender;
  21. use app\common\model\Region;
  22. use app\common\validate\BaseValidate;
  23. /**
  24. * 发件人验证器
  25. */
  26. class FaceSheetSenderValidate extends BaseValidate
  27. {
  28. protected $rule = [
  29. 'id' => 'require|checkSender',
  30. 'name' => 'require|checkName',
  31. 'mobile' => 'require|mobile',
  32. 'province_id' => 'require|verifyLegitimacy',
  33. 'city_id' => 'require|verifyLegitimacy',
  34. 'district_id' => 'require|verifyLegitimacy',
  35. 'address' => 'require',
  36. ];
  37. protected $message = [
  38. 'id.require' => '参数缺失',
  39. 'name.require' => '请输入发件人名称',
  40. 'mobile.require' => '请输入发件人手机',
  41. 'mobile.mobile' => '手机号码格式不正确',
  42. 'province_id.require' => '请选择发件省份',
  43. 'city_id.require' => '请选择发件城市',
  44. 'district_id.require' => '请选择发件地区',
  45. 'address.require' => '请输入详细地址',
  46. ];
  47. public function sceneAdd()
  48. {
  49. return $this->only(['name', 'mobile', 'province_id', 'city_id', 'district_id', 'address']);
  50. }
  51. public function sceneDetail()
  52. {
  53. return $this->only(['id']);
  54. }
  55. public function sceneEdit()
  56. {
  57. return $this->only(['id', 'name', 'mobile', 'province_id', 'city_id', 'district_id', 'address']);
  58. }
  59. public function sceneDelete()
  60. {
  61. return $this->only(['id']);
  62. }
  63. /**
  64. * @notes 校验发件人名称
  65. * @param $name
  66. * @param $rule
  67. * @param $data
  68. * @return bool|string
  69. * @author Tab
  70. * @date 2021/11/22 15:56
  71. */
  72. public function checkName($name, $rule, $data)
  73. {
  74. $where = [['name', '=', $name]];
  75. if (isset($data['id'])) {
  76. $where[] = ['id', '<>', $data['id']];
  77. }
  78. $template = FaceSheetSender::where($where)->findOrEmpty();
  79. if ($template->isEmpty()) {
  80. return true;
  81. }
  82. return '该发件人名称已被使用,请重新输入';
  83. }
  84. /**
  85. * @notes 校验地区编码合法性
  86. * @param $value
  87. * @author Tab
  88. * @date 2021/11/22 16:03
  89. */
  90. public function verifyLegitimacy($value)
  91. {
  92. $region = Region::findOrEmpty($value);
  93. if ($region->isEmpty()) {
  94. return '地区编码有误';
  95. }
  96. return true;
  97. }
  98. /**
  99. * @notes 校验发件人模板
  100. * @param $senderId
  101. * @author Tab
  102. * @date 2021/11/22 16:09
  103. */
  104. public function checkSender($senderId)
  105. {
  106. $sender = FaceSheetSender::findOrEmpty($senderId);
  107. if ($sender->isEmpty()) {
  108. return '发件人模板不存在';
  109. }
  110. return true;
  111. }
  112. }