VerificationValidate.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\validate;
  20. use app\common\enum\AfterSaleEnum;
  21. use app\common\enum\DeliveryEnum;
  22. use app\common\enum\OrderEnum;
  23. use app\common\enum\TeamEnum;
  24. use app\common\model\AfterSale;
  25. use app\common\model\Order;
  26. use app\common\model\OrderGoods;
  27. use app\common\model\SelffetchVerifier;
  28. use app\common\validate\BaseValidate;
  29. class VerificationValidate extends BaseValidate
  30. {
  31. protected $rule = [
  32. 'id' => 'require|checkId',
  33. 'pickup_code' => 'require|checkPickupCode',
  34. 'confirm' => 'require|in:0,1'
  35. ];
  36. protected $message = [
  37. 'pickup_code.require' => '参数缺失',
  38. 'confirm.require' => '参数缺失',
  39. 'confirm.in' => '参数错误',
  40. ];
  41. public function sceneVerification()
  42. {
  43. return $this->only(['pickup_code','confirm']);
  44. }
  45. public function sceneVerificationConfirm()
  46. {
  47. return $this->only(['id']);
  48. }
  49. /**
  50. * @notes 检测订单是否可以核销
  51. * @param $value
  52. * @param $rule
  53. * @param $data
  54. * @return bool|string
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\DbException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. * @author ljj
  59. * @date 2021/8/27 5:19 下午
  60. */
  61. public function checkPickupCode($value,$rule,$data)
  62. {
  63. $result = Order::where(['pickup_code'=>$value])->find();
  64. if (empty($result)) {
  65. return '提货码不正确';
  66. }
  67. if ($result['order_status'] == OrderEnum::STATUS_CLOSE) {
  68. return '订单已关闭';
  69. }
  70. if (! in_array($result['order_status'], [ OrderEnum::STATUS_WAIT_DELIVERY, OrderEnum::STATUS_WAIT_RECEIVE ])) {
  71. return '订单已不允许核销';
  72. }
  73. if ($result['delivery_type'] != DeliveryEnum::SELF_DELIVERY) {
  74. return '不是自提订单,不允许核销';
  75. }
  76. if ($result['verification_status'] == OrderEnum::WRITTEN_OFF) {
  77. return '订单已核销';
  78. }
  79. if ($result['order_type'] == OrderEnum::TEAM_ORDER){
  80. if ($result['is_team_success'] != TeamEnum::TEAM_FOUND_SUCCESS){
  81. return '拼团成功后才能核销';
  82. }
  83. }
  84. $verifier = SelffetchVerifier::where(['selffetch_shop_id'=>$result['selffetch_shop_id'],'user_id'=>$data['user_id'],'status'=>1])->find();
  85. if (empty($verifier)) {
  86. return '非门店核销员,无法核销订单';
  87. }
  88. $order_goods = OrderGoods::where(['order_id'=>$result['id']])->select()->toArray();
  89. foreach ($order_goods as $goods) {
  90. $after_sale = AfterSale::where(['order_goods_id' => $goods['id'], 'order_id' => $goods['order_id']])->findOrEmpty();
  91. if (!$after_sale->isEmpty() && $after_sale->status == AfterSaleEnum::STATUS_ING) {
  92. return '订单商品:'.$goods['goods_name'].' 处于售后中,无法核销';
  93. }
  94. }
  95. return true;
  96. }
  97. /**
  98. * @notes 检查订单是否可以提货
  99. * @param $value
  100. * @param $rule
  101. * @param $data
  102. * @return bool|string
  103. * @throws \think\db\exception\DataNotFoundException
  104. * @throws \think\db\exception\DbException
  105. * @throws \think\db\exception\ModelNotFoundException
  106. * @author ljj
  107. * @date 2021/8/27 5:46 下午
  108. */
  109. public function checkId($value,$rule,$data)
  110. {
  111. $result = Order::findOrEmpty($value);
  112. if ($result->isEmpty()) {
  113. return '订单不存在';
  114. }
  115. if (! in_array($result['order_status'], [ OrderEnum::STATUS_WAIT_DELIVERY, OrderEnum::STATUS_WAIT_RECEIVE ])) {
  116. return '订单已不允许核销';
  117. }
  118. if ($result['delivery_type'] != DeliveryEnum::SELF_DELIVERY) {
  119. return '不是自提订单,不允许提货';
  120. }
  121. if ($result['verification_status'] == OrderEnum::WRITTEN_OFF) {
  122. return '订单已核销';
  123. }
  124. if ($result['order_type'] == OrderEnum::TEAM_ORDER){
  125. if ($result['is_team_success'] != TeamEnum::TEAM_FOUND_SUCCESS){
  126. return '拼团成功后才能提货';
  127. }
  128. }
  129. $verifier = SelffetchVerifier::where(['selffetch_shop_id'=>$result['selffetch_shop_id'],'user_id'=>$data['user_id'],'status'=>1])->find();
  130. if (empty($verifier)) {
  131. return '非门店核销员,无法核销订单';
  132. }
  133. return true;
  134. }
  135. }