截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FaceSheetOrderValidate.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\shop\validate\express_assistant;
  3. use app\common\basics\Validate;
  4. use app\common\enum\OrderEnum;
  5. use app\common\enum\PayEnum;
  6. use app\common\enum\TeamEnum;
  7. use app\common\model\Express;
  8. use app\common\model\face_sheet\FaceSheetSender;
  9. use app\common\model\face_sheet\FaceSheetTemplate;
  10. use app\common\model\order\Order;
  11. use app\common\model\team\TeamJoin;
  12. /**
  13. * 电子面单打印
  14. * Class FaceSheetOrderValidate
  15. * @package app\shop\validate\kefu
  16. */
  17. class FaceSheetOrderValidate extends Validate
  18. {
  19. protected $rule = [
  20. 'order_id' => 'require|checkOrder',
  21. 'template_id' => 'require|checkTemplate',
  22. 'sender_id' => 'require|checkSender',
  23. ];
  24. protected $message = [
  25. 'order_ids.require' => '请选择要打印的订单',
  26. 'order_ids.array' => '订单参数须为数组格式',
  27. 'template_id.require' => '请选择电子模板',
  28. 'sender_id.require' => '请选择发件人',
  29. ];
  30. /**
  31. * @notes 校验订单是否可打印
  32. * @param $value
  33. * @param $rrule
  34. * @param $data
  35. * @return bool|string
  36. * @author 段誉
  37. * @date 2023/2/14 9:49
  38. */
  39. public function checkOrder($value, $rrule, $data)
  40. {
  41. $order = Order::where(['shop_id' => $data['shop_id'], 'id' => $value])->findOrEmpty()->toArray();
  42. if (empty($order)) {
  43. return '不存在id为' . $value . '的订单';
  44. }
  45. if ($order['order_status'] != OrderEnum::ORDER_STATUS_DELIVERY) {
  46. return '订单' . $order['order_sn'] . '不是待发货状态';
  47. }
  48. if ($order['pay_status'] == PayEnum::UNPAID) {
  49. return '订单' . $order['order_sn'] . '未支付';
  50. }
  51. if ($order['delivery_type'] != OrderEnum::DELIVERY_TYPE_EXPRESS) {
  52. return '订单' . $order['order_sn'] . '配送方式不是快递发货';
  53. }
  54. if ($order['refund_status'] > OrderEnum::REFUND_STATUS_NO_REFUND) {
  55. return '订单' . $order['order_sn'] . '已发生退款';
  56. }
  57. if ($order['order_type'] == OrderEnum::TEAM_ORDER && !$this->checkTeamJoinOrder($order['id'])) {
  58. return '拼团订单:' . $order['order_sn'] . '需要拼团成功后才能打印';
  59. }
  60. return true;
  61. }
  62. /**
  63. * @notes 校验面单模板
  64. * @param $templateId
  65. * @return bool|string
  66. * @author 段誉
  67. * @date 2023/2/13 18:15
  68. */
  69. public function checkTemplate($templateId, $rule, $data)
  70. {
  71. $template = FaceSheetTemplate::where(['shop_id' => $data['shop_id'], 'id' => $templateId])->findOrEmpty($templateId);
  72. if ($template->isEmpty()) {
  73. return '电子面单模板不存在';
  74. }
  75. if (Express::findOrEmpty($template['express_id'])->isEmpty()) {
  76. return '电子面单模板中的快递公司不存在';
  77. }
  78. return true;
  79. }
  80. /**
  81. * @notes 校验发件人模板
  82. * @param $senderId
  83. * @return bool|string
  84. * @author 段誉
  85. * @date 2023/2/13 18:16
  86. */
  87. public function checkSender($senderId, $rule, $data)
  88. {
  89. $sender = FaceSheetSender::where(['shop_id' => $data['shop_id'], 'id' => $senderId])->findOrEmpty();
  90. if ($sender->isEmpty()) {
  91. return '发件人模板不存在';
  92. }
  93. return true;
  94. }
  95. /**
  96. * @notes 校验拼团订单
  97. * @param $orderId
  98. * @return bool
  99. * @author 段誉
  100. * @date 2023/2/13 18:11
  101. */
  102. public function checkTeamJoinOrder($orderId)
  103. {
  104. $teamJoin = TeamJoin::where(['order_id' => $orderId])->findOrEmpty();
  105. if (!$teamJoin->isEmpty() && $teamJoin['status'] == TeamEnum::TEAM_STATUS_SUCCESS) {
  106. // 拼团成功
  107. return true;
  108. }
  109. return false;
  110. }
  111. }