| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\db\ActiveRecord;
- use yii\behaviors\TimestampBehavior;
- /**
- * This is the model class for table "{{%saas_user_invoice_conf}}".
- *
- */
- class SaasUserInvoiceConf extends \yii\db\ActiveRecord
- {
- const TYPE_DEFAULT = 1;//普通发票
- const TYPE_SPECIAL = 2;//专用发票
-
- const DESC_TYPE_GOODS = 1;//商品明细
- const DESC_TYPE_CAT = 2;//商品类别
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%saas_user_invoice_conf}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- ]
- ];
- }
- public static function saveOrderInvoiceConf($orderInvoice)
- {
- try{
- $user = User::findOne($orderInvoice->user_id);
- $saasUser = SaasUser::findOne(['mobile' => $user['binding'], 'is_delete' => 0]);
- if(!$saasUser){
- \Yii::error([__METHOD__, $orderInvoice->user_id, $user['binding']]);
- return;
- }
- $invoice_conf = json_decode($orderInvoice->invoice_conf, true);
- $conf = SaasUserInvoiceConf::findOne(['title' => $invoice_conf['title'], 'saas_id' => $saasUser['id'], 'is_delete' => 0]);
- if(!$conf){
- $conf = new SaasUserInvoiceConf();
- $conf->saas_id = $saasUser['id'];
- $conf->title = $invoice_conf['title'];
- }
- $conf->type = $invoice_conf['type'];
- $conf->code = $invoice_conf['code'];
- $conf->email = $invoice_conf['email'];
- $conf->desc_type = $invoice_conf['desc_type'];
- $conf->ext = is_array($invoice_conf['ext']) ? json_encode($invoice_conf['ext']) : $invoice_conf['ext'];
- if(!$conf->save()){
- throw new \Exception(array_shift($conf->getFirstErrors()));
- }
- return [
- 'code' => 0,
- 'msg' => '操作成功!'
- ];
- } catch (Exception $e) {
- \Yii::error($e);
- return [
- 'code' => 1,
- 'msg' => '开发票出错,' . $e->getMessage()
- ];
- }
- }
- }
|