截流自动化的商城平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AfterSaleValidate.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace app\api\validate;
  3. use app\common\basics\Validate;
  4. use app\common\server\ConfigServer;
  5. use think\facade\Db;
  6. use app\common\model\after_sale\AfterSale;
  7. use app\common\enum\OrderEnum;
  8. class AfterSaleValidate extends Validate
  9. {
  10. protected $rule = [
  11. 'id' => 'require',
  12. 'order_id' => 'require|checkSettle|checkRefundAddress|checkAfterSale|checkAbleApply',
  13. 'reason' => 'require',
  14. 'item_id' => 'require',
  15. 'refund_type' => 'require',
  16. 'express_name' => 'require',
  17. 'invoice_no' => 'require|alphaNum',
  18. ];
  19. protected $message = [
  20. 'id.require' => '参数错误',
  21. 'reason.require' => '请选择退款原因',
  22. 'order_id.require' => '参数错误',
  23. 'order_id.checkSettle' => '该订单无法申请售后',
  24. 'order_id.checkRefundAddress' => '该商家未设置售后地址',
  25. 'item_id.require' => '参数错误',
  26. 'refund_type.require' => '参数错误',
  27. 'express_name.require' => '请填写物流公司名称',
  28. 'invoice_no.require' => '请填写快递单号',
  29. 'invoice_no.alphaNum' => '请填写正确的快递单号',
  30. ];
  31. protected $scene = [
  32. 'add' => ['item_id', 'order_id', 'reason', 'refund_type'],
  33. 'sceneInfo' => ['order_id', 'item_id'],
  34. 'goodsInfo' => ['item_id'],
  35. 'express' => ['id', 'express_name', 'invoice_no'],
  36. 'cancel' => ['id'],
  37. 'detail' => ['id'],
  38. 'again' => ['id', 'reason', 'refund_type'],
  39. ];
  40. /**
  41. * @notes 验证该订单是否已经申请售后
  42. * @param $value
  43. * @param $rule
  44. * @param $data
  45. * @author suny
  46. * @date 2021/7/29 4:43 下午
  47. */
  48. public function checkAfterSale($value, $rule, $data)
  49. {
  50. $condition = [
  51. 'order_id' => $value,
  52. 'item_id' => $data['item_id'],
  53. 'del' => 0
  54. ];
  55. $after_sale = AfterSale::where($condition)->find();
  56. if (!$after_sale) {
  57. return true;
  58. } else {
  59. return '该订单已申请过售后,请勿重复申请';
  60. }
  61. }
  62. /**
  63. * @notes 判断该订单是否已经结算
  64. * @param $value
  65. * @param $rule
  66. * @param $data
  67. * @return bool
  68. * @author suny
  69. * @date 2021/7/13 6:26 下午
  70. */
  71. public function checkSettle($value, $rule, $data)
  72. {
  73. $settle_id = Db::name('order')->where('id', $value)->value('settle_id');
  74. if ($settle_id == 1) {
  75. return false;
  76. } else {
  77. return true;
  78. }
  79. }
  80. /**
  81. * @notes 验证退货地址
  82. * @param $value
  83. * @param $rule
  84. * @param $data
  85. * @return bool
  86. * @author suny
  87. * @date 2021/7/13 6:27 下午
  88. */
  89. public function checkRefundAddress($value, $rule, $data)
  90. {
  91. if ($data['refund_type'] == 1) {
  92. $shop_id = Db::name('order')->where('id', $value)->value('shop_id');
  93. $refund_address = Db::name('shop')->where('id', $shop_id)->value('refund_address');
  94. if (empty($refund_address) || $refund_address == '') {
  95. return false;
  96. } else {
  97. return true;
  98. }
  99. } else {
  100. return true;
  101. }
  102. }
  103. //验证订单是否在售后时间内
  104. protected function checkAbleApply($value, $rule, $data)
  105. {
  106. $now = time();
  107. $where = [];
  108. $where[] = ['o.id', '=', $value];
  109. $where[] = ['g.item_id', '=', $data['item_id']];
  110. $where[] = ['o.order_status', 'in', [OrderEnum::ORDER_STATUS_GOODS, OrderEnum::ORDER_STATUS_COMPLETE]];
  111. $order = Db::name('order')->alias('o')
  112. ->field('o.order_status,o.confirm_take_time,g.refund_status')
  113. ->join('order_goods g', 'o.id = g.order_id')
  114. ->where($where)
  115. ->find();
  116. $refund_days = ConfigServer::get('transaction', 'order_after_sale_days', 7);
  117. if ($refund_days == 0) {
  118. return true;
  119. }
  120. if ($order['order_status'] == OrderEnum::ORDER_STATUS_COMPLETE) {
  121. $check_time = intval($order['confirm_take_time'] + ($refund_days * 24 * 60 * 60));
  122. if ($now > $check_time) {
  123. return '不在售后时间内';
  124. }
  125. }
  126. return true;
  127. }
  128. }