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.
 
 
 
 
 
 

357 lines
12 KiB

  1. <?php
  2. namespace backend\modules\hotel\controllers;
  3. use backend\modules\api\models\BaseUser;
  4. use backend\modules\hotel\models\InvoiceLog;
  5. use common\components\zOfficeWechat;
  6. use common\models\BaseSupplier;
  7. use backend\modules\hotel\models\OrderInvoiceInfo;
  8. use backend\modules\hotel\models\search\searchInvoice;
  9. use yii\web\NotFoundHttpException;
  10. use Yii;
  11. use yii\data\ActiveDataProvider;
  12. class InvoiceController extends BaseController
  13. {
  14. public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
  15. public $enableCsrfValidation = false;
  16. /**
  17. * Author:Steven
  18. * Desc:发票列表
  19. * @return string
  20. */
  21. public function actionIndex()
  22. {
  23. $searchModel = new searchInvoice();
  24. $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  25. $channel = BaseSupplier::find()
  26. ->select(['DISTINCT(a.ID)', 'a.SUPPLIER_NAME'])
  27. ->joinWith('baseSupplierSale as b', false)
  28. ->from('base_supplier as a')
  29. ->where(['and',
  30. ['=', 'b.PARENT_TYPE', 25],
  31. ['=', 'a.SUPPLIER_TYPE', 301],
  32. ['=', 'a.cancel_flag', 0],
  33. ['=', 'a.IS_DISABLED', 0],
  34. ['=', 'b.cancel_flag', 0],
  35. ['or', ['=', 'main_corp_id', Yii::$app->user->identity->MAIN_CORP_ID], ['=', 'main_corp_id', 0],
  36. ],
  37. ])
  38. ->asArray()->all();
  39. return $this->render('index', [
  40. 'searchModel' => $searchModel,
  41. 'dataProvider' => $dataProvider,
  42. 'channel' => $channel
  43. ]);
  44. }
  45. /**
  46. * Author:Steven
  47. * Desc:发票详情
  48. * @param $id
  49. * @return string
  50. */
  51. public function actionDetail($id)
  52. {
  53. $query = InvoiceLog::find()
  54. ->joinWith('orderInvoiceInfo')
  55. ->joinWith('baseUser')
  56. ->where(['order_invoice_info.ID' => $id])->orderBy('CreateTime');
  57. $dataProvider = new ActiveDataProvider([
  58. 'query' => $query,
  59. 'sort' => false,
  60. 'pagination' => [
  61. 'pageSize' => 20,
  62. ]
  63. ]);
  64. $InvoiceInfo = OrderInvoiceInfo::find()
  65. -> select(['order_main.*', 'a.*'])
  66. -> joinWith('orderMain')
  67. -> joinWith('orderMain.operaHotel')
  68. -> joinWith('orderMain.operaHotelRoom')
  69. -> joinWith('orderMain.baseChannel')
  70. -> joinWith('orderMain.statusLabel d1')
  71. -> joinWith('orderMain.channelStatusLabel d2')
  72. -> from('order_invoice_info a')
  73. -> where(['a.ID' => $id])
  74. -> one();
  75. $scenario = $InvoiceInfo ->InvoiceType == 1 ? 'showInvoice' : 'exclusive';
  76. $InvoiceInfo -> scenario = $scenario;
  77. return $this->render('detail', ['InvoiceInfo' => $InvoiceInfo, 'logProvider' => $dataProvider]);
  78. }
  79. /**
  80. * Author:Steven
  81. * Desc:开设发票
  82. * @param $id
  83. * @param $status
  84. * @param $msg
  85. * @return string
  86. */
  87. public function actionMakeInvoice($id, $status, $msg)
  88. {
  89. $invoice = $this->findModel($id);
  90. if ($invoice->Status != $status) {
  91. return \GuzzleHttp\json_encode(['code' => 2, 'msg' => '发票状态已经发生变化,请刷新后再操作']);
  92. }
  93. $invoice->InvoiceNum = $msg;
  94. $invoice->OpenTicketTime = date('Y-m-d H:i:s');
  95. $invoice->OpenTicketUserId = Yii::$app->user->id;
  96. $invoice->Status = OrderInvoiceInfo::ORDER_TICKET_OPENED;
  97. if ($invoice->validate()) {
  98. if (!$invoice->makeInvoice()) {
  99. return \GuzzleHttp\json_encode(['code' => 1, 'msg' => '开票信息保存失败']);
  100. }
  101. return \GuzzleHttp\json_encode(['code' => 0]);
  102. } else {
  103. return \GuzzleHttp\json_encode(['code' => 1, 'msg' => $invoice->getErrors()]);
  104. }
  105. }
  106. /**
  107. * Author:Steven
  108. * Desc:邮寄发票信息填写
  109. * @param $id
  110. * @param $status
  111. * @param $msg
  112. * @return string
  113. * @throws NotFoundHttpException
  114. * @throws \yii\db\Exception
  115. */
  116. public function actionPostInvoice($id, $status, $msg)
  117. {
  118. $invoice = $this->findModel($id);
  119. if ($invoice->Status != $status) {
  120. return \GuzzleHttp\json_encode(['code' => 2, 'msg' => '发票状态已经发生变化,请刷新后再操作']);
  121. }
  122. $invoice->PostTime = date('Y-m-d H:i:s');
  123. $invoice->PostUserId = Yii::$app->user->id;
  124. $invoice->Status = OrderInvoiceInfo::ORDER_POSTED;
  125. $invoice_info = explode("||", $msg);
  126. $invoice->PostCompany = $invoice_info[0];
  127. $invoice->CourierNum = $invoice_info[1];
  128. if ($invoice->validate()) {
  129. if (!$invoice->postInvoice()) {
  130. return \GuzzleHttp\json_encode(['code' => 1, 'msg' => '邮寄信息保存失败']);
  131. }
  132. return \GuzzleHttp\json_encode(['code' => 0]);
  133. } else {
  134. return \GuzzleHttp\json_encode(['code' => 1, 'msg' => $invoice->getErrors()]);
  135. }
  136. }
  137. /**
  138. * Author:Steven
  139. * Desc:驳回申请
  140. * @param $id
  141. * @param $status
  142. * @param $msg
  143. * @return string
  144. * @throws NotFoundHttpException
  145. * @throws \yii\db\Exception
  146. */
  147. public function actionRefuse($id, $status, $msg)
  148. {
  149. $invoice = $this->findModel($id);
  150. if ($invoice->Status != $status) {
  151. return \GuzzleHttp\json_encode(['code' => 2, 'msg' => '发票状态已经发生变化,请刷新后再操作']);
  152. }
  153. $invoice->RejectReason = $msg;
  154. $invoice->Status = OrderInvoiceInfo::ORDER_REFUSE;
  155. if ($invoice->validate()) {
  156. if (!$invoice->refuse()) {
  157. return \GuzzleHttp\json_encode(['code' => 1, 'msg' => '驳回失败']);
  158. }
  159. $user = BaseUser::findOne(['CANCEL_FLAG' => 0, 'ID' => Yii::$app -> user -> id]);
  160. $appyUser = BaseUser::findOne(['CANCEL_FLAG' => 0, 'ID' => $invoice -> ApplyUser]);
  161. zOfficeWechat::sendMsg([
  162. 'agentid' => zOfficeWechat::SEND_HOTEL,
  163. "title" => '【发票通知】发票驳回:',
  164. "msg" => '关联订单号:'.$id . "\n" .'操作人:'. $user -> TRUE_NAME . "\n驳回原因:" .$msg,
  165. "touser" => $appyUser -> USER_NAME.'|panlj',]
  166. );
  167. return \GuzzleHttp\json_encode(['code' => 0]);
  168. } else {
  169. return \GuzzleHttp\json_encode(['code' => 1, 'msg' => $invoice->getErrors()]);
  170. }
  171. }
  172. /**
  173. * @Author wanglg
  174. * @Desc 将发票详情导出
  175. */
  176. public function actionExport()
  177. {
  178. $id = Yii::$app -> request -> get('id');
  179. $model = new OrderInvoiceInfo();
  180. $InvoiceInfo = OrderInvoiceInfo::find()
  181. -> select(['order_main.*', 'a.*'])
  182. -> joinWith('orderMain')
  183. -> joinWith('orderMain.operaHotel')
  184. -> joinWith('orderMain.operaHotelRoom')
  185. -> joinWith('orderMain.baseChannel')
  186. -> joinWith('orderMain.statusLabel d1')
  187. -> joinWith('orderMain.channelStatusLabel d2')
  188. -> from('order_invoice_info a')
  189. -> where(['a.ID' => $id])
  190. -> one();
  191. $invoiceType = $InvoiceInfo -> InvoiceType;
  192. $str = $InvoiceInfo -> orderMain -> ORDER_DESCRIPTION;
  193. $arr = explode('|', trim($str, '|'));
  194. $order_description = '';
  195. foreach ($arr as $v) {
  196. $fdc = explode(',', $v);
  197. if (count($fdc) >= 3)
  198. $order_description .= $fdc[1] . '*' . $fdc[2] . '间' . ' ';
  199. }
  200. $html = '<!DOCTYPE html>
  201. <html>
  202. <head>
  203. <meta charset="utf-8">
  204. <title>发票详情</title>
  205. <style>
  206. td, th {
  207. padding: 4px; height: 33px;
  208. font-size: 15px;
  209. font-family: "宋体";
  210. }
  211. table
  212. {
  213. border-width: 0px;
  214. }
  215. .second
  216. {
  217. width: 190px;
  218. }
  219. </style>
  220. </head>
  221. <body style="margin: 0 auto; width: 800px; font-size: 15px; font-family: 宋体">
  222. <table border="2" cellpadding="0" cellspacing="0" style="border-color: #a9c6c9; border-collapse: collapse;">
  223. <tr>
  224. <td style="width: 20%">订单号</td>
  225. <td style="width: 35%">'.$InvoiceInfo -> orderMain -> ORDER_ID .'</td>
  226. <td style="width: 20%">渠道名称</td>
  227. <td style="width: 25%">'. $InvoiceInfo -> orderMain -> baseChannel -> SUPPLIER_NAME .'</td>
  228. </tr>
  229. <tr>
  230. <td>渠道单号</td>
  231. <td>'.$InvoiceInfo -> orderMain -> OUTSIDE_ORDER_NO .'</td>
  232. <td>订单状态</td>
  233. <td>'.$InvoiceInfo -> orderMain -> statusLabel -> TYPE_NAME .'</td>
  234. </tr>
  235. <tr>
  236. <td>预定时间</td>
  237. <td>'.$InvoiceInfo -> orderMain -> CREATE_TIME .'</td>
  238. <td>订单金额</td>
  239. <td>'.$InvoiceInfo -> orderMain -> ORDER_PRICE .'</td>
  240. </tr>
  241. <tr>
  242. <td>客人姓名</td>
  243. <td>'.$InvoiceInfo -> orderMain -> CUSTOMER_NAME .'</td>
  244. <td>客人电话</td>
  245. <td>'.$InvoiceInfo -> orderMain -> CUSTOMER_MOBILE .'</td>
  246. </tr>
  247. <tr>
  248. <td>酒店名称</td>
  249. <td colspan="3">'. $InvoiceInfo -> orderMain -> operaHotel -> HOTEL_NAME .'</td>
  250. </tr>
  251. <tr>
  252. <td>子房型名称</td>
  253. <td colspan="3">'.$InvoiceInfo -> orderMain -> operaHotelRoom -> ROOM_NAME . ' ' .$InvoiceInfo -> orderMain -> operaHotelRoom -> INNER_IDENTIFY .'</td>
  254. </tr>
  255. <tr>
  256. <td>入住信息</td>
  257. <td colspan="3">'. $order_description .'</td>
  258. </tr>
  259. </table>
  260. <br/>
  261. <br/>
  262. <table border="2" cellpadding="0" cellspacing="0" style="width: 100%;height: 100%; text-align: left; line-height: 100% border-color: #a9c6c9;border-collapse: collapse;">
  263. <tr>
  264. <td class="second">发票类型:</td>
  265. <td><input type="radio" id="ordinary" '. ($invoiceType == 1 ? 'checked' : "") .' name="type"> <label for="ordinary">普通发票</label>
  266. <input type="radio" id="exclusive" '. ($invoiceType == 2 ? 'checked' : "") .' name="type"><label for="exclusive">专用发票</label></td>
  267. </tr>
  268. <tr>
  269. <td class="second">发票抬头:</td>
  270. <td>'. $InvoiceInfo -> InvoiceTitle .'</td>
  271. </tr>
  272. <tr>
  273. <td class="second">纳税人识别号:</td>
  274. <td>'. $InvoiceInfo -> CompanyTax .'</td>
  275. </tr>
  276. <tr>
  277. <td class="second">地址、电话</td>
  278. <td>'. $InvoiceInfo -> RegisterAddress .' <br>'. $InvoiceInfo -> CompanyTel .' </td>
  279. </tr>
  280. <tr>
  281. <td class="second">开户行及账号:</td>
  282. <td>'. $InvoiceInfo -> Bank .' <br> '. $InvoiceInfo -> BankAccount .'</td>
  283. </tr>
  284. <tr>
  285. <td class="second">开票金额(含税):</td>
  286. <td> '.$InvoiceInfo -> InvoiceMoney .' </td>
  287. </tr>
  288. <tr>
  289. <td class="second"> 开票内容 </td>
  290. <td>'.$InvoiceInfo -> Comment .'</td>
  291. </tr>
  292. <tr>
  293. <td class="second">收件人姓名、地址、电话:</td>
  294. <td> '.$InvoiceInfo -> ReceiverName .' <br> '.$InvoiceInfo -> ReceiverAddress .' <br> '.$InvoiceInfo -> ReceiverMobile .' </td>
  295. </tr>
  296. <tr>
  297. <td class="second">申请人:</td>
  298. <td>'.$InvoiceInfo -> baseUser -> TRUE_NAME .'</td>
  299. </tr>
  300. <tr>
  301. <td class="second">CS 订单号:</td>
  302. <td> '.$InvoiceInfo -> OrderID .' </td>
  303. </tr>
  304. <tr>
  305. <td class="second">发票备注:</td>
  306. <td> '.$InvoiceInfo -> Remark .' </td>
  307. </tr>
  308. </table>
  309. </body>
  310. </html>';
  311. $model -> startWord();
  312. $wordname = '【'.$InvoiceInfo -> OrderID.'】 '. $InvoiceInfo -> ReceiverName . date('Y-m-d') . '发票详情.doc';
  313. echo $html;
  314. header('Content-type: application/word');
  315. header("Content-Disposition: attachment; filename='{$wordname}'");
  316. ob_flush();
  317. flush();
  318. exit();
  319. }
  320. /**
  321. * Finds the OrderMain model based on its primary key value.
  322. * If the model is not found, a 404 HTTP exception will be thrown.
  323. * @param integer $id
  324. * @return OrderInvoiceInfo the loaded model
  325. * @throws NotFoundHttpException if the model cannot be found
  326. */
  327. protected function findModel($id)
  328. {
  329. if (($model = OrderInvoiceInfo::findOne($id)) !== null) {
  330. return $model;
  331. } else {
  332. throw new NotFoundHttpException('The requested page does not exist.');
  333. }
  334. }
  335. }