截流自动化的商城平台
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.

OrderInvoiceValidate.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace app\api\validate;
  3. use app\common\basics\Validate;
  4. use app\common\enum\OrderEnum;
  5. use app\common\enum\OrderInvoiceEnum;
  6. use app\common\model\order\Order;
  7. use app\common\model\order\OrderInvoice;
  8. /**
  9. * 订单发票验证
  10. * Class OrderInvoiceValidate
  11. * @package app\api\validate
  12. */
  13. class OrderInvoiceValidate extends Validate
  14. {
  15. protected $rule = [
  16. 'id' => 'require|checkInvoice', // 发票id
  17. 'shop_id' => 'require', // 门店id
  18. 'order_id' => 'require|checkOrder', // 订单id
  19. 'type' => 'require', // 发票类型
  20. 'header_type' => 'require|checkHeaderType',// 抬头类型
  21. 'name' => 'require',// 抬头名称
  22. 'email' => 'require',// 邮箱
  23. 'duty_number' => 'requireIf:header_type,' . OrderInvoiceEnum::HEADER_TYPE_COMPANY,// 税号 (企业类型必填)
  24. 'address' => 'requireIf:type,' . OrderInvoiceEnum::TYPE_SPEC,// 企业地址(专票类型必填)
  25. 'mobile' => 'requireIf:type,' . OrderInvoiceEnum::TYPE_SPEC,// 企业电话(专票类型必填)
  26. 'bank' => 'requireIf:type,' . OrderInvoiceEnum::TYPE_SPEC,// 快狐银行(专票类型必填)
  27. 'bank_account' => 'requireIf:type,' . OrderInvoiceEnum::TYPE_SPEC,// 银行账号(专票类型必填)
  28. ];
  29. protected $message = [
  30. 'id.require' => '参数缺失',
  31. 'shop_id.require' => '参数缺失',
  32. 'order_id.require' => '订单参数缺失',
  33. 'type.require' => '请选择发票类型',
  34. 'header_type.require' => '请选择抬头类型',
  35. 'name.require' => '请填写抬头名称',
  36. 'email.require' => '请填写邮箱',
  37. 'duty_number.requireIf' => '请填写税号',
  38. 'address.requireIf' => '请填写企业地址',
  39. 'mobile.requireIf' => '请填写企业电话',
  40. 'bank.requireIf' => '请填写开户银行',
  41. 'bank_account.requireIf' => '请填写银行账号',
  42. ];
  43. public function sceneAdd()
  44. {
  45. return $this->remove('id', true)
  46. ->remove('shop_id', true);
  47. }
  48. public function sceneEdit()
  49. {
  50. return $this->remove('order_id', true)
  51. ->remove('shop_id', true)
  52. ->append('id', 'checkAbleEdit');
  53. }
  54. public function sceneDetail()
  55. {
  56. return $this->only(['id']);
  57. }
  58. public function sceneSetting()
  59. {
  60. return $this->only(['shop_id']);
  61. }
  62. /**
  63. * @notes 校验发票
  64. * @param $value
  65. * @param $rule
  66. * @param $data
  67. * @return bool|string
  68. * @author 段誉
  69. * @date 2022/4/12 12:09
  70. */
  71. protected function checkInvoice($value, $rule, $data)
  72. {
  73. $invoice = OrderInvoice::findOrEmpty($value);
  74. if ($invoice->isEmpty()) {
  75. return '发票信息不存在';
  76. }
  77. return true;
  78. }
  79. /**
  80. * @notes 校验订单是否可添加发票
  81. * @param $value
  82. * @param $rule
  83. * @param $data
  84. * @return bool|string
  85. * @author 段誉
  86. * @date 2022/4/12 10:01
  87. */
  88. protected function checkOrder($value, $rule, $data)
  89. {
  90. $order = Order::with(['invoice'])->findOrEmpty($value);
  91. if ($order->isEmpty()) {
  92. return '订单不存在';
  93. }
  94. if ($order['del'] == 1 || $order['order_status'] == OrderEnum::ORDER_STATUS_DOWN) {
  95. return '此订单已不可申请发票';
  96. }
  97. if (!empty($order['invoice'])) {
  98. return '此订单已有发票信息';
  99. }
  100. return true;
  101. }
  102. /**
  103. * @notes 校验抬头类型
  104. * @param $value
  105. * @param $rule
  106. * @param $data
  107. * @return bool|string
  108. * @author 段誉
  109. * @date 2022/4/11 17:17
  110. */
  111. protected function checkHeaderType($value, $rule, $data)
  112. {
  113. if ($value == OrderInvoiceEnum::HEADER_TYPE_PERSONAL && $data['type'] == OrderInvoiceEnum::TYPE_SPEC) {
  114. return '专用发票抬头类型仅支持企业';
  115. }
  116. return true;
  117. }
  118. /**
  119. * @notes 校验能否编辑
  120. * @param $value
  121. * @param $rule
  122. * @param $data
  123. * @return bool|string
  124. * @author 段誉
  125. * @date 2022/4/12 14:56
  126. */
  127. protected function checkAbleEdit($value, $rule, $data)
  128. {
  129. $invoice = OrderInvoice::findOrEmpty($value);
  130. if ($invoice['status'] == OrderInvoiceEnum::STATUS_YES) {
  131. return '此发票已开票,无法编辑';
  132. }
  133. return true;
  134. }
  135. }