[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], ], ], ]; } public function actionError() { $exception = Yii::$app->errorHandler->exception; if ($exception !== null) { return $this->render('error', ['exception' => $exception,'url'=>'index']); } } /** * Lists all Orderreturn models. * @return mixed */ public function actionIndex() { $request = Yii::$app->request; $shop=$request->get('shop',1); $searchModel = new OrderreturnSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'shop'=>$shop, ]); } /** * Displays a single Orderreturn model. * @param integer $id * @return mixed * @throws NotFoundHttpException if the model cannot be found */ public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), ]); } /** * Creates a new Orderreturn model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $request = Yii::$app->request; $shop = $request->getBodyParam('shop')??1; $model = new Orderreturn(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } return $this->render('create', [ 'model' => $model, 'shop'=>$shop, ]); } /** * Updates an existing Orderreturn model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed * @throws NotFoundHttpException if the model cannot be found */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } return $this->render('update', [ 'model' => $model, ]); } /** * Deletes an existing Orderreturn model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed * @throws NotFoundHttpException if the model cannot be found */ public function actionDelete($id) { $this->findModel($id)->delete(); return $this->redirect(['index']); } public function actionDeleteAll() { $request = Yii::$app->request; $id = $request->post('id'); if(is_array($id)){ $ids=implode(',',$id); } $model = new Orderreturn(); //你要批量删除的表 $model->deleteAll('id in (' . $ids . ')'); return $this->redirect(['index']); } public function actionExport(){ $request = Yii::$app->request; $shop = $request->post('shop')??1; // dd($shop); $model = new UploadExcel(); if (Yii::$app->request->isPost) { $model->excel = UploadedFile::getInstance($model, 'excel'); if ($inputFileName=$model->upload()) { $inputFileType = IOFactory::identify($inputFileName); $filterSubset = new ExcelFilter(3, 15, range('B', 'K')); $reader = IOFactory::createReader($inputFileType); $reader->setReadFilter($filterSubset); $spreadsheet = $reader->load($inputFileName); $spreadsheet->setActiveSheetIndex(0); $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); $key=['receiptdate','num','delivery','deliveryid','website','customer','origin_goodsinfo','goodsinfo','usage','mark','created_at','shop']; $data=[]; foreach($sheetData as $item){ if(!isset($item['E'])||empty($item['E'])){ continue; } $receiptdate=strtotime(str_replace('.','-',$item['B'])??''); $data[]=[ $receiptdate, $item['C'], $item['D'], $item['E'], $item['F'], $item['G'], $item['H'], $item['I'], $item['J'], $item['k'], time(), $shop, ]; } if(empty($data)){ throw new \yii\base\ErrorException('未读取到数据'); } $res=Yii::$app->db->createCommand()->batchInsert('order_return', $key, $data)->execute(); if(!$res){ throw new \yii\base\ErrorException('数据库异常'); return; }else{ return $this->redirect(['index']); } }else{ throw new \yii\base\ErrorException('上传文件失败'); return; } }else{ throw new \yii\web\NotFoundHttpException('错误请求'); } return $this->render('upload', ['model' => $model]); } /** * Finds the Orderreturn model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Orderreturn the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Orderreturn::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException('The requested page does not exist.'); } }