PreOrderInvoice.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/9/24
  6. * Time: 17:12
  7. */
  8. namespace app\frontend\modules\order\models;
  9. use app\common\models\Goods;
  10. use app\common\models\order\OrderInvoice;
  11. class PreOrderInvoice extends OrderInvoice
  12. {
  13. protected $order;
  14. protected function _initAttributes()
  15. {
  16. $get = \Setting::get('plugin.invoice');
  17. $data = $this->order->getRequest()->input('invoice');
  18. $is_open = false;
  19. if (app('plugins')->isEnabled('invoice') && $get['is_open']) {
  20. $is_open = true;
  21. }
  22. $content = ['商品明细', '商品类别', '不开发票'];
  23. $attributes = [
  24. 'uid' => \YunShop::app()->getMemberId(),
  25. 'invoice_type' => $data['invoice_type'] ?:0,//发票类型
  26. 'email' => $data['email'] ?: '',//电子邮箱
  27. 'rise_type' => isset($data['rise_type'])? $data['rise_type']:1,//收件人或单位
  28. 'collect_name' => $data['collect_name'] ?: '',//抬头或单位名称
  29. 'uniacid' => \Yunshop::app()->uniacid,
  30. 'enterprise_id' => empty($get['enterprise_name']) ? '' : $get['enterprise_name'],// 企业唯一标识
  31. 'invoice_sn' => empty($get['appid']) ? '' : $get['appid'] . $this->createInvitecode(),// 发票请求流水号 (全局唯一)
  32. 'equipment_number' => empty($get['enterprise_equipment']) ? '' : $get['enterprise_equipment'], // 税控设备号
  33. 'xsf_name' => empty($get['enterprise_name']) ? '' : $get['enterprise_name'],// 销售方名称
  34. 'xsf_taxpayer' => empty($get['taxpayer_number']) ? '' : $get['taxpayer_number'], // 销售方纳税人识别号,
  35. 'xsf_address' => empty($get['taxpayer_number']) ? '' : $get['address'], // 销售方地址
  36. 'xsf_mobile' => empty($get['mobile']) ? '' : $get['mobile'], // 销售方电话
  37. 'xsf_bank_admin' => empty($get['bank_admin']) ? '' : $get['bank_admin'], // 销售方开户银行
  38. 'content' => $is_open&&$data['content'] ? $content[$data['content']] : '', // 发票内容
  39. 'drawer' => empty($get['invoice_drawer']) ? '' : $get['invoice_drawer'], // 开票人
  40. 'payee' => empty($get['billing_payee']) ? '' : $get['billing_payee'], // 收款人
  41. 'reviewer' => empty($get['invoice_reviewer']) ? '' : $get['invoice_reviewer'], // 收款人
  42. 'bill_type' => !empty($data['bill_type']) ? $data['bill_type'] : 0, // 开票类型:0-蓝字发票;1-红字发票
  43. 'special_type' => !empty($data['special_type']) ? $data['special_type'] : 0, // 特殊票种:0-不是;1-农产品销售;2-农产品收购(收购票)
  44. 'collection' => !empty($data['collection']) ? $data['collection'] : 0, // 征收方式:0- 专普票;1-减按计增;2-差额征收
  45. 'list_identification'=> !empty($data['list_identification']) ? $data['list_identification'] : 0,// 清单标识:0- 非清单;1- 清单
  46. 'gmf_taxpayer' => !empty($data['gmf_taxpayer']) ? $data['gmf_taxpayer']: '',// 购买方纳税人识别号
  47. 'gmf_address' => !empty($data['gmf_address']) ? $data['gmf_address'] : '', // 注册地址
  48. 'gmf_bank' => !empty($data['gmf_bank']) ? $data['gmf_bank'] : '', // 开户银行
  49. 'gmf_bank_admin' => !empty($data['gmf_bank_admin']) ? $data['gmf_bank_admin'] : '',// 购买方银行账户
  50. 'gmf_mobile' => !empty($data['gmf_mobile']) ? $data['gmf_mobile'] : '', // 注册手机号码
  51. 'remarks' => !empty($data['remarks']) ? $data['remarks'] : '', // 备注
  52. 'notice_no' => !empty($data['notice_no']) ? $data['notice_no'] : '',// 通知单编号
  53. 'applicant' => !empty($data['applicant']) ? $data['applicant'] : '',// 申请人
  54. 'is_audit' => !empty($data['is_audit']) ? $data['is_audit'] : 0, // 是否自动审核:0-非自动审核;1-自动审核
  55. 'tax_rate' => !empty($data['tax_rate']) ? $data['tax_rate'] : 0, // 税率
  56. 'zero_tax_rate' => !empty($data['zero_tax_rate']) ? $data['zero_tax_rate'] : 0, // 零税率标识:0-正常税率;1-免税;2-不征税;3-普通零税率
  57. 'invoice_no' => !empty($data['invoice_no']) ? $data['invoice_no'] : '', // 发票编号
  58. 'invoice_nature' => !empty($data['invoice_nature']) ? $data['invoice_nature'] : 0, // 发票行性质: 0-正常行;1-折扣行 (折扣票金额正);2-被折扣行'(折扣票金额负)
  59. 'status' => !empty($data['status']) ? $data['status'] : 0,// 开票状态 0-未开票,1-开票成功,2-开票中
  60. 'apply' => !empty($data['apply']) ? $data['apply'] : 0,
  61. 'col_address' => !empty($data['col_address']) ? $data['col_address'] : '', // 收票地址
  62. 'col_name' => !empty($data['col_name']) ? $data['col_name'] : '', //收票人
  63. 'col_mobile' => !empty($data['col_mobile']) ? $data['col_mobile'] : '', //收票人手机号码
  64. 'detail_param' => !empty($data['detail_param']) ? $data['detail_param'] : '',
  65. 'invoice_time' => time()
  66. ];
  67. /* $attributes = [
  68. 'invoice_type' => $this->order->getRequest()->input('invoice_type', null),//发票类型
  69. 'email' => $this->order->getRequest()->input('email'),//电子邮箱
  70. // 'rise_type' => $this->order->getRequest()->input('rise_type', null),//收件人或单位
  71. 'collect_name' => $this->order->getRequest()->input('call', ''),//抬头或单位名称
  72. // 'company_number' => $this->order->getRequest()->input('company_number', ''),//单位识别号
  73. 'uniacid' => \Yunshop::app()->uniacid
  74. ];
  75. if ($this->order->getRequest()->input('invoice_type')){
  76. $attributes['invoice_type'] = $this->order->getRequest()->input('invoice_type');
  77. }
  78. if ($this->order->getRequest()->input('rise_type')){
  79. $attributes['rise_type'] = $this->order->getRequest()->input('rise_type');
  80. }
  81. $this->dataOrder();
  82. */
  83. $attributes = array_merge($this->getAttributes(), $attributes);
  84. $this->setRawAttributes($attributes);
  85. }
  86. /**
  87. * @param PreOrder $order
  88. */
  89. public function setOrder(PreOrder $order)
  90. {
  91. $this->order = $order;
  92. $this->_initAttributes();
  93. $this->order->setRelation('orderInvoice', $this);
  94. }
  95. public function createInvitecode()
  96. {
  97. $length = 8;
  98. $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  99. $str = '';
  100. for($i = 0; $i < $length; $i++) {
  101. $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
  102. }
  103. return $str;
  104. }
  105. }