IntegralOrderValidate.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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\adminapi\validate\integral;
  20. use app\common\enum\IntegralGoodsEnum;
  21. use app\common\enum\IntegralOrderEnum;
  22. use app\common\model\IntegralOrder;
  23. use app\common\validate\BaseValidate;
  24. class IntegralOrderValidate extends BaseValidate
  25. {
  26. protected $rule = [
  27. 'id' => 'require',
  28. 'send_type' => 'require|in:1,2',
  29. 'express_id' => 'requireIf:send_type,1',
  30. 'invoice_no' => 'requireIf:send_type,1|alphaNum'
  31. ];
  32. protected $message = [
  33. 'id.require' => '参数缺失',
  34. 'express_id.requireIf' => '物流公司不能为空',
  35. 'invoice_no.requireIf' => '快递单号不能为空',
  36. 'invoice_no.alphaNum' => '快递单号只能是字母和数字',
  37. ];
  38. public function sceneDetail()
  39. {
  40. return $this->only(['id']);
  41. }
  42. public function sceneDelivery()
  43. {
  44. return $this->only(['id','send_type','express_id','invoice_no'])
  45. ->append('id','checkDelivery');
  46. }
  47. public function sceneDeliveryInfo()
  48. {
  49. return $this->only(['id']);
  50. }
  51. public function sceneConfirm()
  52. {
  53. return $this->only(['id'])
  54. ->append('id','checkConfirm');
  55. }
  56. public function sceneLogistics()
  57. {
  58. return $this->only(['id'])
  59. ->append('id','checkLogistics');
  60. }
  61. public function sceneCancel()
  62. {
  63. return $this->only(['id'])
  64. ->append('id','checkCancel');
  65. }
  66. /**
  67. * @notes 检验订单能否发货
  68. * @param $value
  69. * @param $rule
  70. * @param $data
  71. * @return bool|string
  72. * @author ljj
  73. * @date 2022/3/31 12:09 下午
  74. */
  75. public function checkDelivery($value,$rule,$data)
  76. {
  77. $result = IntegralOrder::findOrEmpty($value);
  78. if ($result->isEmpty()) {
  79. return '订单不存在';
  80. }
  81. if ($result['delivery_way'] == 0) {
  82. return '订单无需快递';
  83. }
  84. if ($result['express_status'] == 1) {
  85. return '订单已发货';
  86. }
  87. if ($result['order_status'] != IntegralOrderEnum::ORDER_STATUS_DELIVERY) {
  88. return '订单状态不正确,无法发货';
  89. }
  90. return true;
  91. }
  92. /**
  93. * @notes 检验订单是否可以确认收货
  94. * @param $value
  95. * @param $rule
  96. * @param $data
  97. * @return bool|string
  98. * @author ljj
  99. * @date 2022/3/31 4:04 下午
  100. */
  101. public function checkConfirm($value,$rule,$data)
  102. {
  103. $result = IntegralOrder::findOrEmpty($value);
  104. if ($result->isEmpty()) {
  105. return '订单不存在';
  106. }
  107. if ($result['order_status'] != IntegralOrderEnum::ORDER_STATUS_GOODS) {
  108. return '订单不允许确认收货';
  109. }
  110. return true;
  111. }
  112. /**
  113. * @notes 检查订单是否已发货
  114. * @param $value
  115. * @param $rule
  116. * @param $data
  117. * @return bool|string
  118. * @author 段誉
  119. * @date 2022/4/1 15:00
  120. */
  121. public function checkLogistics($value,$rule,$data)
  122. {
  123. $order = IntegralOrder::findOrEmpty($value);
  124. if ($order['express_status'] == IntegralOrderEnum::SHIPPING_NO) {
  125. return '订单未发货,暂无物流信息';
  126. }
  127. return true;
  128. }
  129. /**
  130. * @notes 校验取消
  131. * @param $value
  132. * @param $rule
  133. * @param $data
  134. * @return bool|string
  135. * @author 段誉
  136. * @date 2022/4/1 15:37
  137. */
  138. public function checkCancel($value, $rule, $data)
  139. {
  140. $order = IntegralOrder::findOrEmpty($value);
  141. if ($order->isEmpty()) {
  142. return '订单不存在';
  143. }
  144. // 商品类型为红包的不可取消
  145. if ($order['goods_snap']['type'] == IntegralGoodsEnum::TYPE_BALANCE) {
  146. return '类型为红包的订单不可取消';
  147. }
  148. if ($order['order_status'] >= IntegralOrderEnum::ORDER_STATUS_GOODS) {
  149. return '已发货订单不可取消';
  150. }
  151. return true;
  152. }
  153. }