|
- <?php
-
- namespace backend\modules\hotel\controllers;
-
- use backend\modules\api\models\BaseUser;
- use backend\modules\hotel\models\InvoiceLog;
- use common\components\zOfficeWechat;
- use common\models\BaseSupplier;
- use backend\modules\hotel\models\OrderInvoiceInfo;
- use backend\modules\hotel\models\search\searchInvoice;
- use yii\web\NotFoundHttpException;
- use Yii;
- use yii\data\ActiveDataProvider;
-
- class InvoiceController extends BaseController
- {
- public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
-
- public $enableCsrfValidation = false;
-
- /**
- * Author:Steven
- * Desc:发票列表
- * @return string
- */
- public function actionIndex()
- {
- $searchModel = new searchInvoice();
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
- $channel = BaseSupplier::find()
- ->select(['DISTINCT(a.ID)', 'a.SUPPLIER_NAME'])
- ->joinWith('baseSupplierSale as b', false)
- ->from('base_supplier as a')
- ->where(['and',
- ['=', 'b.PARENT_TYPE', 25],
- ['=', 'a.SUPPLIER_TYPE', 301],
- ['=', 'a.cancel_flag', 0],
- ['=', 'a.IS_DISABLED', 0],
- ['=', 'b.cancel_flag', 0],
- ['or', ['=', 'main_corp_id', Yii::$app->user->identity->MAIN_CORP_ID], ['=', 'main_corp_id', 0],
- ],
- ])
- ->asArray()->all();
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- 'channel' => $channel
- ]);
- }
-
- /**
- * Author:Steven
- * Desc:发票详情
- * @param $id
- * @return string
- */
- public function actionDetail($id)
- {
- $query = InvoiceLog::find()
- ->joinWith('orderInvoiceInfo')
- ->joinWith('baseUser')
- ->where(['order_invoice_info.ID' => $id])->orderBy('CreateTime');
-
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- 'sort' => false,
- 'pagination' => [
- 'pageSize' => 20,
- ]
- ]);
-
- $InvoiceInfo = OrderInvoiceInfo::find()
- -> select(['order_main.*', 'a.*'])
- -> joinWith('orderMain')
- -> joinWith('orderMain.operaHotel')
- -> joinWith('orderMain.operaHotelRoom')
- -> joinWith('orderMain.baseChannel')
- -> joinWith('orderMain.statusLabel d1')
- -> joinWith('orderMain.channelStatusLabel d2')
- -> from('order_invoice_info a')
- -> where(['a.ID' => $id])
- -> one();
-
- $scenario = $InvoiceInfo ->InvoiceType == 1 ? 'showInvoice' : 'exclusive';
- $InvoiceInfo -> scenario = $scenario;
- return $this->render('detail', ['InvoiceInfo' => $InvoiceInfo, 'logProvider' => $dataProvider]);
- }
-
- /**
- * Author:Steven
- * Desc:开设发票
- * @param $id
- * @param $status
- * @param $msg
- * @return string
- */
- public function actionMakeInvoice($id, $status, $msg)
- {
- $invoice = $this->findModel($id);
- if ($invoice->Status != $status) {
- return \GuzzleHttp\json_encode(['code' => 2, 'msg' => '发票状态已经发生变化,请刷新后再操作']);
- }
- $invoice->InvoiceNum = $msg;
- $invoice->OpenTicketTime = date('Y-m-d H:i:s');
- $invoice->OpenTicketUserId = Yii::$app->user->id;
- $invoice->Status = OrderInvoiceInfo::ORDER_TICKET_OPENED;
- if ($invoice->validate()) {
- if (!$invoice->makeInvoice()) {
- return \GuzzleHttp\json_encode(['code' => 1, 'msg' => '开票信息保存失败']);
- }
- return \GuzzleHttp\json_encode(['code' => 0]);
- } else {
- return \GuzzleHttp\json_encode(['code' => 1, 'msg' => $invoice->getErrors()]);
- }
-
- }
-
- /**
- * Author:Steven
- * Desc:邮寄发票信息填写
- * @param $id
- * @param $status
- * @param $msg
- * @return string
- * @throws NotFoundHttpException
- * @throws \yii\db\Exception
- */
- public function actionPostInvoice($id, $status, $msg)
- {
- $invoice = $this->findModel($id);
- if ($invoice->Status != $status) {
- return \GuzzleHttp\json_encode(['code' => 2, 'msg' => '发票状态已经发生变化,请刷新后再操作']);
- }
- $invoice->PostTime = date('Y-m-d H:i:s');
- $invoice->PostUserId = Yii::$app->user->id;
- $invoice->Status = OrderInvoiceInfo::ORDER_POSTED;
- $invoice_info = explode("||", $msg);
- $invoice->PostCompany = $invoice_info[0];
- $invoice->CourierNum = $invoice_info[1];
- if ($invoice->validate()) {
- if (!$invoice->postInvoice()) {
- return \GuzzleHttp\json_encode(['code' => 1, 'msg' => '邮寄信息保存失败']);
- }
- return \GuzzleHttp\json_encode(['code' => 0]);
- } else {
- return \GuzzleHttp\json_encode(['code' => 1, 'msg' => $invoice->getErrors()]);
- }
- }
-
- /**
- * Author:Steven
- * Desc:驳回申请
- * @param $id
- * @param $status
- * @param $msg
- * @return string
- * @throws NotFoundHttpException
- * @throws \yii\db\Exception
- */
- public function actionRefuse($id, $status, $msg)
- {
- $invoice = $this->findModel($id);
- if ($invoice->Status != $status) {
- return \GuzzleHttp\json_encode(['code' => 2, 'msg' => '发票状态已经发生变化,请刷新后再操作']);
- }
- $invoice->RejectReason = $msg;
- $invoice->Status = OrderInvoiceInfo::ORDER_REFUSE;
- if ($invoice->validate()) {
- if (!$invoice->refuse()) {
- return \GuzzleHttp\json_encode(['code' => 1, 'msg' => '驳回失败']);
- }
- $user = BaseUser::findOne(['CANCEL_FLAG' => 0, 'ID' => Yii::$app -> user -> id]);
- $appyUser = BaseUser::findOne(['CANCEL_FLAG' => 0, 'ID' => $invoice -> ApplyUser]);
- zOfficeWechat::sendMsg([
- 'agentid' => zOfficeWechat::SEND_HOTEL,
- "title" => '【发票通知】发票驳回:',
- "msg" => '关联订单号:'.$id . "\n" .'操作人:'. $user -> TRUE_NAME . "\n驳回原因:" .$msg,
- "touser" => $appyUser -> USER_NAME.'|panlj',]
- );
- return \GuzzleHttp\json_encode(['code' => 0]);
- } else {
- return \GuzzleHttp\json_encode(['code' => 1, 'msg' => $invoice->getErrors()]);
- }
- }
-
- /**
- * @Author wanglg
- * @Desc 将发票详情导出
- */
- public function actionExport()
- {
- $id = Yii::$app -> request -> get('id');
- $model = new OrderInvoiceInfo();
- $InvoiceInfo = OrderInvoiceInfo::find()
- -> select(['order_main.*', 'a.*'])
- -> joinWith('orderMain')
- -> joinWith('orderMain.operaHotel')
- -> joinWith('orderMain.operaHotelRoom')
- -> joinWith('orderMain.baseChannel')
- -> joinWith('orderMain.statusLabel d1')
- -> joinWith('orderMain.channelStatusLabel d2')
- -> from('order_invoice_info a')
- -> where(['a.ID' => $id])
- -> one();
-
- $invoiceType = $InvoiceInfo -> InvoiceType;
- $str = $InvoiceInfo -> orderMain -> ORDER_DESCRIPTION;
- $arr = explode('|', trim($str, '|'));
- $order_description = '';
- foreach ($arr as $v) {
- $fdc = explode(',', $v);
- if (count($fdc) >= 3)
- $order_description .= $fdc[1] . '*' . $fdc[2] . '间' . ' ';
- }
-
- $html = '<!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>发票详情</title>
- <style>
- td, th {
- padding: 4px; height: 33px;
- font-size: 15px;
- font-family: "宋体";
- }
- table
- {
- border-width: 0px;
- }
- .second
- {
- width: 190px;
- }
- </style>
- </head>
- <body style="margin: 0 auto; width: 800px; font-size: 15px; font-family: 宋体">
- <table border="2" cellpadding="0" cellspacing="0" style="border-color: #a9c6c9; border-collapse: collapse;">
- <tr>
- <td style="width: 20%">订单号</td>
- <td style="width: 35%">'.$InvoiceInfo -> orderMain -> ORDER_ID .'</td>
- <td style="width: 20%">渠道名称</td>
- <td style="width: 25%">'. $InvoiceInfo -> orderMain -> baseChannel -> SUPPLIER_NAME .'</td>
- </tr>
- <tr>
- <td>渠道单号</td>
- <td>'.$InvoiceInfo -> orderMain -> OUTSIDE_ORDER_NO .'</td>
- <td>订单状态</td>
- <td>'.$InvoiceInfo -> orderMain -> statusLabel -> TYPE_NAME .'</td>
- </tr>
- <tr>
- <td>预定时间</td>
- <td>'.$InvoiceInfo -> orderMain -> CREATE_TIME .'</td>
- <td>订单金额</td>
- <td>'.$InvoiceInfo -> orderMain -> ORDER_PRICE .'</td>
- </tr>
- <tr>
- <td>客人姓名</td>
- <td>'.$InvoiceInfo -> orderMain -> CUSTOMER_NAME .'</td>
- <td>客人电话</td>
- <td>'.$InvoiceInfo -> orderMain -> CUSTOMER_MOBILE .'</td>
- </tr>
- <tr>
- <td>酒店名称</td>
- <td colspan="3">'. $InvoiceInfo -> orderMain -> operaHotel -> HOTEL_NAME .'</td>
- </tr>
- <tr>
- <td>子房型名称</td>
- <td colspan="3">'.$InvoiceInfo -> orderMain -> operaHotelRoom -> ROOM_NAME . ' ' .$InvoiceInfo -> orderMain -> operaHotelRoom -> INNER_IDENTIFY .'</td>
- </tr>
- <tr>
- <td>入住信息</td>
- <td colspan="3">'. $order_description .'</td>
- </tr>
- </table>
- <br/>
- <br/>
- <table border="2" cellpadding="0" cellspacing="0" style="width: 100%;height: 100%; text-align: left; line-height: 100% border-color: #a9c6c9;border-collapse: collapse;">
- <tr>
- <td class="second">发票类型:</td>
- <td><input type="radio" id="ordinary" '. ($invoiceType == 1 ? 'checked' : "") .' name="type"> <label for="ordinary">普通发票</label>
- <input type="radio" id="exclusive" '. ($invoiceType == 2 ? 'checked' : "") .' name="type"><label for="exclusive">专用发票</label></td>
- </tr>
- <tr>
- <td class="second">发票抬头:</td>
- <td>'. $InvoiceInfo -> InvoiceTitle .'</td>
- </tr>
- <tr>
- <td class="second">纳税人识别号:</td>
- <td>'. $InvoiceInfo -> CompanyTax .'</td>
- </tr>
- <tr>
- <td class="second">地址、电话</td>
- <td>'. $InvoiceInfo -> RegisterAddress .' <br>'. $InvoiceInfo -> CompanyTel .' </td>
- </tr>
- <tr>
- <td class="second">开户行及账号:</td>
- <td>'. $InvoiceInfo -> Bank .' <br> '. $InvoiceInfo -> BankAccount .'</td>
- </tr>
- <tr>
- <td class="second">开票金额(含税):</td>
- <td> '.$InvoiceInfo -> InvoiceMoney .' </td>
- </tr>
- <tr>
- <td class="second"> 开票内容 </td>
- <td>'.$InvoiceInfo -> Comment .'</td>
- </tr>
-
- <tr>
- <td class="second">收件人姓名、地址、电话:</td>
- <td> '.$InvoiceInfo -> ReceiverName .' <br> '.$InvoiceInfo -> ReceiverAddress .' <br> '.$InvoiceInfo -> ReceiverMobile .' </td>
- </tr>
- <tr>
- <td class="second">申请人:</td>
- <td>'.$InvoiceInfo -> baseUser -> TRUE_NAME .'</td>
- </tr>
-
- <tr>
- <td class="second">CS 订单号:</td>
- <td> '.$InvoiceInfo -> OrderID .' </td>
- </tr>
- <tr>
- <td class="second">发票备注:</td>
- <td> '.$InvoiceInfo -> Remark .' </td>
- </tr>
- </table>
- </body>
- </html>';
- $model -> startWord();
- $wordname = '【'.$InvoiceInfo -> OrderID.'】 '. $InvoiceInfo -> ReceiverName . date('Y-m-d') . '发票详情.doc';
- echo $html;
- header('Content-type: application/word');
- header("Content-Disposition: attachment; filename='{$wordname}'");
- ob_flush();
- flush();
- exit();
- }
-
-
- /**
- * Finds the OrderMain model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return OrderInvoiceInfo the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = OrderInvoiceInfo::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|