| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\controllers\v1;
- use app\modules\client\controllers\BaseController;
- use app\models\SaasUserInvoiceConf;
- use app\models\OrderInvoice;
- use app\models\Order;
- use app\modules\admin\models\InvoiceForm;
- class InvoiceController extends BaseController
- {
- public function actionSearchInvoiceNo() {
- $keyword = input_params('keyword');
- $ApiSearchInvoiceNo = InvoiceForm::ApiSearchInvoiceNo(get_store_id(), $keyword);
- return $this->asJson($ApiSearchInvoiceNo);
- }
- public function actionInvoiceConf() {
- $invoiceConf = [];
- $invoice_is_open = InvoiceForm::is_open(get_store_id(), $invoiceConf);
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'invoice_is_open' => $invoice_is_open,
- 'invoiceConf' => $invoiceConf,
- ],
- ]);
- }
- public function actionSaasUserConfList() {
- $list = SaasUserInvoiceConf::find()->where(['saas_id' => get_saas_user_id(), 'is_delete' => 0])->orderBy('updated_at DESC')->all();
- return $this->asJson([
- 'code' => 0,
- 'data' => $list,
- ]);
- }
- public function actionSaasUserConfDel() {
- $ids = input_params('ids');
- $del = SaasUserInvoiceConf::updateAll(['is_delete' => 1], ['saas_id' => get_saas_user_id(), 'is_delete' => 0, 'id' => explode(',', $ids)]);
- return $this->asJson([
- 'code' => $del ? 0 : 1,
- 'msg' => '删除数据:' . $del . '条',
- ]);
- }
- public function actionSaasUserConfSave() {
- try{
- $saas_id = get_saas_user_id();
- $params = all_params();
- if($params['id']){
- $conf = SaasUserInvoiceConf::findOne(['id' => $params['id'], 'saas_id' => $saas_id, 'is_delete' => 0]);
- }else{
- $conf = new SaasUserInvoiceConf();
- $conf->saas_id = $saas_id;
- }
- $conf->title = $params['title'];
- $conf->type = $params['type'];
- $conf->code = $params['code'];
- $conf->email = $params['email'];
- $conf->desc_type = $params['desc_type'];
- $conf->ext = is_array($params['ext']) ? json_encode($params['ext']) : $params['ext'];
- if(!$conf->save()){
- throw new \Exception(array_shift($conf->getFirstErrors()));
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功!'
- ]);
- } catch (Exception $e) {
- \Yii::error($e);
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- public function actionUserInvoiceSave() {
- try{
- $order_id = input_params('order_id');
- $invoiceConf = input_params('invoiceConf');
- if(empty($order_id) || empty($invoiceConf)){
- throw new \Exception('缺少参数');
- }
- $save = InvoiceForm::orderInvoiceSave($order_id, $invoiceConf);
- if($save['code'] != 0){
- return $save;
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功!'
- ]);
- } catch (Exception $e) {
- \Yii::error($e);
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- public function actionUserInvoiceApply() {
- try{
- $id = input_params('id') ? explode(',', input_params('id')) : null;
- $order_id = input_params('order_id') ? explode(',', input_params('order_id')) : null;
- if(empty($id) && empty($order_id)){
- throw new \Exception('缺少参数');
- }
- $query = OrderInvoice::find()
- ->where(['user_id' => get_user_id(), 'is_delete' => 0, 'has_apply' => 0]);
- if($id){
- $query->andWhere(['id' => $id]);
- }
- if($order_id){
- $query->andWhere(['order_id' => $order_id]);
- }
- $list = $query->all();
- if(!$list){
- throw new \Exception('未找到数据');
- }
- foreach($list as $invoice){
- InvoiceForm::orderInvoiceApply($invoice);
- if(!$invoice->save()){
- throw new \Exception(array_shift($invoice->getFirstErrors()));
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功!'
- ]);
- } catch (Exception $e) {
- \Yii::error($e);
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- public function actionUserInvoiceList() {
- $id = input_params('id');
- $order_id = input_params('order_id');
- $has_apply = input_params('has_apply', 1);
- $query = OrderInvoice::find()->alias('oi')
- ->leftJoin(['o' => Order::tableName()], 'o.id = oi.order_id')
- ->where(['oi.user_id' => get_user_id(), 'oi.is_delete' => 0, 'oi.has_apply' => $has_apply])
- ->andWhere(['o.is_pay' => 1])
- ->andWhere(['!=', 'o.trade_status', 1]);
- if(!$has_apply){
- $invoiceConf = [];
- $invoice_is_open = InvoiceForm::is_open(get_store_id(), $invoiceConf);
- if(!$invoice_is_open){
- $query->andWhere(['oi.id' => null]);
- }
- $query->andWhere(['>', 'o.pay_time', time() - 86400 * $invoiceConf['conf']['timeout']]);
- }
- if($id){
- $query->andWhere(['oi.id' => $id]);
- }
- if($order_id){
- $query->andWhere(['oi.order_id' => $order_id]);
- }
- $query->orderBy('oi.id DESC');
- $query->select(['oi.*', 'o.order_no', 'o.trade_status']);
- $list = pagination_make($query);
- return $this->asJson([
- 'q' => $query->createCommand()->getRawSql(),
- 'code' => 0,
- 'data' => $list,
- ]);
- }
- }
|