FaceSheetOrderValidate.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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\enum\DeliveryEnum;
  21. use app\common\enum\OrderEnum;
  22. use app\common\enum\TeamEnum;
  23. use app\common\enum\YesNoEnum;
  24. use app\common\model\Express;
  25. use app\common\model\FaceSheetSender;
  26. use app\common\model\FaceSheetTemplate;
  27. use app\common\model\Order;
  28. use app\common\model\TeamFound;
  29. use app\common\validate\BaseValidate;
  30. /**
  31. * 打印电子面单验证器
  32. */
  33. class FaceSheetOrderValidate extends BaseValidate
  34. {
  35. protected $rule = [
  36. 'order_ids' => 'require|array|checkOrder',
  37. 'template_id' => 'require|checkTemplate',
  38. 'sender_id' => 'require|checkSender',
  39. ];
  40. protected $message = [
  41. 'order_ids.require' => '请选择要打印的订单',
  42. 'order_ids.array' => '订单参数须为数组格式',
  43. 'template_id.require' => '请选择电子模板',
  44. 'sender_id.require' => '请选择发件人',
  45. ];
  46. /**
  47. * @notes 校验订单
  48. * @param $orderIds
  49. * @author Tab
  50. * @date 2021/11/22 16:45
  51. */
  52. public function checkOrder($orderIds)
  53. {
  54. foreach($orderIds as $orderId) {
  55. $order = Order::findOrEmpty($orderId);
  56. if ($order->isEmpty()) {
  57. return '不存在id为' . $orderId . '的订单';
  58. }
  59. $order = $order->toArray();
  60. if ($order['order_status'] != OrderEnum::STATUS_WAIT_DELIVERY) {
  61. return '订单' . $order['sn'] . '不是待发货状态';
  62. }
  63. if ($order['pay_status'] == YesNoEnum::NO) {
  64. return '订单' . $order['sn'] . '未支付';
  65. }
  66. if ($order['delivery_type'] != DeliveryEnum::EXPRESS_DELIVERY) {
  67. return '订单' . $order['sn'] . '配送方式不是快递发货';
  68. }
  69. if ($order['order_type'] == OrderEnum::TEAM_ORDER && !$this->checkTeamFoundOrder($order['team_found_id'])) {
  70. return '拼团订单:' . $order['sn'] . '需要拼团成功后才能打印';
  71. }
  72. }
  73. return true;
  74. }
  75. /**
  76. * @notes 校验模板
  77. * @param $templateId
  78. * @author Tab
  79. * @date 2021/11/22 16:45
  80. */
  81. public function checkTemplate($templateId)
  82. {
  83. $template = FaceSheetTemplate::findOrEmpty($templateId);
  84. if ($template->isEmpty()) {
  85. return '模板不存在';
  86. }
  87. if (!$this->checkExpress($template['express_id'])) {
  88. return '模板中的快递公司不存在';
  89. }
  90. return true;
  91. }
  92. /**
  93. * @notes 校验发件人
  94. * @param $senderId
  95. * @author Tab
  96. * @date 2021/11/22 16:46
  97. */
  98. public function checkSender($senderId)
  99. {
  100. $sender = FaceSheetSender::findOrEmpty($senderId);
  101. if ($sender->isEmpty()) {
  102. return '发件人不存在';
  103. }
  104. return true;
  105. }
  106. /**
  107. * @notes 校验拼团订单
  108. * @param $id
  109. * @return bool
  110. * @author Tab
  111. * @date 2021/11/22 16:59
  112. */
  113. public function checkTeamFoundOrder($id)
  114. {
  115. $teamFound = TeamFound::findOrEmpty($id);
  116. if (!$teamFound->isEmpty() && $teamFound->status == TeamEnum::TEAM_FOUND_SUCCESS) {
  117. // 拼团成功
  118. return true;
  119. }
  120. return false;
  121. }
  122. /**
  123. * @notes 校验快递公司
  124. * @param $id
  125. * @return bool
  126. * @author Tab
  127. * @date 2021/11/22 17:15
  128. */
  129. public function checkExpress($id)
  130. {
  131. $express = Express::findOrEmpty($id);
  132. if ($express->isEmpty()) {
  133. return false;
  134. }
  135. return true;
  136. }
  137. }