/** * This function will handle the download Action * This takes three parameters and generated the excel file * @coupontype : This parameter will hold the value of coupon type [deal=>1 | coupon=>0] * @store : This parameter will hold the value of website ID * @category : This parameter will hold the value of category ID * @return filtered coupons to search view */ public function actionDownload($couponType, $Stores, $Category) { $coupontype = $_GET['couponType']; $store = isset($_GET['Stores']) ? $_GET['Stores'] : "all"; $category = isset($_GET['Category']) ? $_GET['Category'] : "all"; $coupons = $this->extractData(Coupon::find(), $category, $store, $category); $excel = new PHPExcel(); $excel->getActiveSheet()->setCellValue('B1', "Title")->setCellValue('C1', "Website Name")->setCellValue('D1', "Coupon Code")->setCellValue('E1', "Description"); $i = 2; foreach ($coupons as $coupon) { $excel->getActiveSheet()->setCellValue('B' . $i, $coupon->Title)->setCellValue('C' . $i, $coupon->website->WebsiteName)->setCellValue('D' . $i, $coupon->CouponCode)->setCellValue('E' . $i, $coupon->Description); $i++; } // Naming the active spread sheet $excel->getActiveSheet()->setTitle('List Of Coupons'); $excel->setActiveSheetIndex(0); // Redirect output to a clients web browser (Excel5) header('Cache-Control: max-age=0'); $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel5'); // We'll be outputting an excel file header('Content-type: application/vnd.ms-excel'); // It will be called file.xls header('Content-Disposition: attachment; filename="result.xls"'); // Write file to the browser $objWriter->save('php://output'); }
/** * 查看优惠券详情 * @return array */ public function actionCoupondetail() { $view = \Yii::$app->view; $view->params['moduleName'] = '优惠券管理'; $request = \Yii::$app->request; if ($request->isPost) { $editData['couponId'] = intval($request->post('couponId', 0)); $editData['couponName'] = $request->_post('couponName', ''); $editData['couponAmount'] = $request->_post('couponAmount', ''); $editData['dateFrom'] = $request->_post('dateFrom', ''); $editData['dateTo'] = $request->_post('dateTo', ''); $editData['deleted'] = $request->_post('deleted', ''); if (Coupon::saveCoupon($editData)) { return $this->redirect('/finace/coupon'); } } $couponId = $request->_get('couponId', 0); $data = Coupon::findOne(['couponId' => $couponId]); $couponStore = Coupon::getCouponStore($couponId); $token = Token::getToken(); return $this->render('coupondetail', ['data' => $data, 'couponStore' => $couponStore, 'token' => $token]); }