VerificationValidate.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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\selffetch_shop;
  20. use app\common\enum\AfterSaleEnum;
  21. use app\common\enum\DeliveryEnum;
  22. use app\common\enum\OrderEnum;
  23. use app\common\enum\PayEnum;
  24. use app\common\enum\TeamEnum;
  25. use app\common\model\AfterSale;
  26. use app\common\model\Order;
  27. use app\common\model\OrderGoods;
  28. use app\common\validate\BaseValidate;
  29. class VerificationValidate extends BaseValidate
  30. {
  31. protected $rule = [
  32. 'id' => 'require|checkId',
  33. 'confirm' => 'require|in:0,1'
  34. ];
  35. protected $message = [
  36. 'id.require' => '参数缺失',
  37. 'confirm.require' => '参数缺失',
  38. 'confirm.in' => '参数错误',
  39. ];
  40. public function sceneVerification()
  41. {
  42. return $this->only(['id','confirm'])
  43. ->append('id','checkVerification');
  44. }
  45. public function sceneVerificationQuery()
  46. {
  47. return $this->only(['id'])
  48. ->append('id','checkVerificationQuery');
  49. }
  50. public function sceneVerificationDetail()
  51. {
  52. return $this->only(['id'])
  53. ->append('id','checkVerificationDetail');
  54. }
  55. /**
  56. * @notes 检查订单ID是否存在
  57. * @param $value
  58. * @param $rule
  59. * @param $data
  60. * @return bool|string
  61. * @author ljj
  62. * @date 2021/8/12 11:44 上午
  63. */
  64. public function checkId($value,$rule,$data)
  65. {
  66. $result = Order::where('id', $value)->findOrEmpty();
  67. if ($result->isEmpty()) {
  68. return '订单不存在';
  69. }
  70. return true;
  71. }
  72. /**
  73. * @notes 检查订单是否可以提货核销
  74. * @param $value
  75. * @param $rule
  76. * @param $data
  77. * @return bool|string
  78. * @author ljj
  79. * @date 2021/8/12 11:47 上午
  80. */
  81. public function checkVerification($value,$rule,$data)
  82. {
  83. $result = Order::where('id', $value)->findOrEmpty();
  84. if ($result['pay_status'] != PayEnum::ISPAID) {
  85. return '订单未支付,不允许核销';
  86. }
  87. if ($result['delivery_type'] != DeliveryEnum::SELF_DELIVERY) {
  88. return '非自提订单,不允许核销';
  89. }
  90. if ($result['order_status'] == OrderEnum::STATUS_CLOSE) {
  91. return '订单已关闭';
  92. }
  93. if (! in_array($result['order_status'], [ OrderEnum::STATUS_WAIT_RECEIVE,OrderEnum::STATUS_WAIT_DELIVERY ])) {
  94. return '订单不允许核销';
  95. }
  96. if ($result['verification_status'] == OrderEnum::WRITTEN_OFF) {
  97. return '订单已核销';
  98. }
  99. if ($result['order_type'] == OrderEnum::TEAM_ORDER){
  100. if ($result['is_team_success'] != TeamEnum::TEAM_FOUND_SUCCESS){
  101. return '拼团成功后才能核销';
  102. }
  103. }
  104. $order_goods = OrderGoods::where(['order_id'=>$result['id']])->select()->toArray();
  105. foreach ($order_goods as $goods) {
  106. $after_sale = AfterSale::where(['order_goods_id' => $goods['id'], 'order_id' => $goods['order_id']])->findOrEmpty();
  107. if (!$after_sale->isEmpty() && $after_sale->status == AfterSaleEnum::STATUS_ING) {
  108. return '订单商品:'.$goods['goods_name'].' 处于售后中,无法发货';
  109. }
  110. }
  111. return true;
  112. }
  113. /**
  114. * @notes 检查订单是否已核销
  115. * @param $value
  116. * @param $rule
  117. * @param $data
  118. * @return bool|string
  119. * @author ljj
  120. * @date 2021/8/26 6:40 下午
  121. */
  122. public function checkVerificationQuery($value,$rule,$data)
  123. {
  124. $result = Order::where('id', $value)->findOrEmpty();
  125. if ($result['verification_status'] == OrderEnum::NOT_WRITTEN_OFF) {
  126. return '订单未核销,无法查询';
  127. }
  128. return true;
  129. }
  130. /**
  131. * @notes 检测是否为自提订单
  132. * @param $value
  133. * @param $rule
  134. * @param $data
  135. * @return bool|string
  136. * @author ljj
  137. * @date 2021/8/27 10:49 上午
  138. */
  139. public function checkVerificationDetail($value,$rule,$data)
  140. {
  141. $result = Order::where('id', $value)->findOrEmpty();
  142. if ($result['delivery_type'] != DeliveryEnum::SELF_DELIVERY) {
  143. return '非自提订单,不允许核销';
  144. }
  145. return true;
  146. }
  147. }