|
@@ -12,7 +12,9 @@ use yii\web\Controller;
|
|
|
use yii\web\NotFoundHttpException;
|
|
|
use yii\filters\VerbFilter;
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
use app\models\LoginForm;
|
|
|
+
|
|
|
/**
|
|
|
* SiteController implements the CRUD actions for Orderreturn model.
|
|
|
*/
|
|
@@ -46,9 +48,7 @@ class SiteController extends Controller
|
|
|
*/
|
|
|
public function actionIndex()
|
|
|
{
|
|
|
- if (Yii::$app->user->isGuest) {
|
|
|
- return $this->redirect(['login']);
|
|
|
- }
|
|
|
+
|
|
|
$request = Yii::$app->request;
|
|
|
$shop=$request->get('shop',1);
|
|
|
$searchModel = new OrderreturnSearch();
|
|
@@ -57,7 +57,129 @@ class SiteController extends Controller
|
|
|
'searchModel' => $searchModel,
|
|
|
'dataProvider' => $dataProvider,
|
|
|
'shop'=>$shop,
|
|
|
+ 'dayStatis'=>$dayStatis,
|
|
|
+ 'dayCount'=>$dayCount,
|
|
|
+ 'monthStatis'=>$monthStatis,
|
|
|
+ 'monthCount'=>$monthCount
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ public function actionStatis(){
|
|
|
+ if (Yii::$app->user->isGuest) {
|
|
|
+ return $this->redirect(['login']);
|
|
|
+ }
|
|
|
+ $request = Yii::$app->request;
|
|
|
+ $shop=$request->get('shop',1);
|
|
|
+ $dayStatis=Orderreturn::find()
|
|
|
+ ->select([ 'usage','count(*) as num'])
|
|
|
+ ->groupBy('usage')
|
|
|
+ ->where(['>','created_at',strtotime(date('Y-m-d'))])
|
|
|
+ ->where(['shop'=>$shop])
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
+ $dayCount=array_sum(array_column($dayStatis,'num'));
|
|
|
+ $monthStatis=Orderreturn::find()
|
|
|
+ ->select(['count(*) as num', 'usage'])
|
|
|
+ ->groupBy('usage')
|
|
|
+ ->where(['>','created_at',strtotime(date('Y-m'))])
|
|
|
+ ->where(['shop'=>$shop])
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
+ $monthCount=array_sum(array_column($monthStatis,'num'));
|
|
|
+ return $this->render('statis', [
|
|
|
+ 'shop'=>$shop,
|
|
|
+ 'dayStatis'=>$dayStatis,
|
|
|
+ 'dayCount'=>$dayCount,
|
|
|
+ 'monthStatis'=>$monthStatis,
|
|
|
+ 'monthCount'=>$monthCount
|
|
|
]);
|
|
|
+ }
|
|
|
+ public function actionStatisExport(){
|
|
|
+ $request = Yii::$app->request;
|
|
|
+ $shop=$request->get('shop',1);
|
|
|
+ $dayStatis=Orderreturn::find()
|
|
|
+ ->select([ 'usage','count(*) as num'])
|
|
|
+ ->groupBy('usage')
|
|
|
+ ->where(['>','created_at',strtotime(date('Y-m-d'))])
|
|
|
+ ->where(['shop'=>$shop])
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
+ $dayCount=array_sum(array_column($dayStatis,'num'));
|
|
|
+ $monthStatis=Orderreturn::find()
|
|
|
+ ->select(['count(*) as num', 'usage'])
|
|
|
+ ->groupBy('usage')
|
|
|
+ ->where(['>','created_at',strtotime(date('Y-m'))])
|
|
|
+ ->where(['shop'=>$shop])
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
+ $monthCount=array_sum(array_column($monthStatis,'num'));
|
|
|
+ $spreadsheet = new Spreadsheet();
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
|
|
|
+ //当日统计
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->mergeCells('A1:B1');
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->setCellValue('A1','当天退货数量统计 单位:个');
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->getStyle('A1')->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
|
|
|
+
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->setCellValue('A2','退货包裹数');
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->setCellValue('B2',$dayCount);
|
|
|
+ $i=3;
|
|
|
+ $usageType=['1' => "可用-请加库存",'2'=>'不可用-退回工厂','3'=>'精打理-退回国内','4'=>'精打理-留美仓','5'=>'泡发-发回国内'];
|
|
|
+ foreach($dayStatis as $item){
|
|
|
+ if(isset($usageType[$item['usage']])){
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->setCellValue('A'.$i,$usageType[$item['usage']]);
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->setCellValue('B'.$i,$item['num']);
|
|
|
+ }
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+
|
|
|
+ $i+=2;
|
|
|
+ //当月统计
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->mergeCells('A'.$i.':B'.$i);
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->setCellValue('A'.$i,'当月退货数量统计 单位:个');
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->getStyle('A'.$i)->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
|
|
|
+
|
|
|
+ $i++;
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->setCellValue('A'.$i,'退货包裹数');
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->setCellValue('B'.$i,$dayCount);
|
|
|
+ $i++;
|
|
|
+ foreach($monthStatis as $item){
|
|
|
+ if(isset($usageType[$item['usage']])){
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->setCellValue('A'.$i,$usageType[$item['usage']]);
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->setCellValue('B'.$i,$item['num']);
|
|
|
+ }
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+ $spreadsheet->setActiveSheetIndex(0)->getStyle('B1:B'.$i)->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
|
|
|
+
|
|
|
+ // Rename worksheet
|
|
|
+ $spreadsheet->getActiveSheet()->setTitle('Simple');
|
|
|
+
|
|
|
+ // Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
|
|
+ $spreadsheet->setActiveSheetIndex(0);
|
|
|
+ $filename=($shop==1 ? "美国仓":"亚马逊")."退货订单".date("Ymd").".xlsx";
|
|
|
+ // Redirect output to a client’s web browser (Xlsx)
|
|
|
+ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
+ header('Content-Disposition: attachment;filename="'.$filename.'"');
|
|
|
+ header('Cache-Control: max-age=0');
|
|
|
+ // If you're serving to IE 9, then the following may be needed
|
|
|
+ header('Cache-Control: max-age=1');
|
|
|
+
|
|
|
+ // If you're serving to IE over SSL, then the following may be needed
|
|
|
+ header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
|
|
|
+ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
|
|
|
+ header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
|
|
+ header('Pragma: public'); // HTTP/1.0
|
|
|
+
|
|
|
+ $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
|
|
+ $writer->save('php://output');
|
|
|
+ exit;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -68,8 +190,15 @@ class SiteController extends Controller
|
|
|
*/
|
|
|
public function actionView($id)
|
|
|
{
|
|
|
+ $is_create=false;
|
|
|
+ $headers = Yii::$app->request->headers;
|
|
|
+ $referer = $headers->get('Referer');
|
|
|
+ if(strpos($referer,'site/create')>-1){
|
|
|
+ $is_create=true;
|
|
|
+ }
|
|
|
return $this->render('view', [
|
|
|
'model' => $this->findModel($id),
|
|
|
+ 'is_create'=>$is_create,
|
|
|
]);
|
|
|
}
|
|
|
|
|
@@ -83,6 +212,7 @@ class SiteController extends Controller
|
|
|
$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]);
|
|
|
}
|
|
@@ -106,7 +236,6 @@ class SiteController extends Controller
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
|
|
return $this->redirect(['view', 'id' => $model->id]);
|
|
|
}
|
|
|
-
|
|
|
return $this->render('update', [
|
|
|
'model' => $model,
|
|
|
]);
|
|
@@ -139,7 +268,7 @@ class SiteController extends Controller
|
|
|
}
|
|
|
return $this->redirect(['index']);
|
|
|
}
|
|
|
- public function actionExport(){
|
|
|
+ public function actionImport(){
|
|
|
|
|
|
$request = Yii::$app->request;
|
|
|
$shop = $request->post('shop')??1;
|
|
@@ -195,13 +324,6 @@ class SiteController extends Controller
|
|
|
}else{
|
|
|
throw new \yii\web\NotFoundHttpException('错误请求');
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
return $this->render('upload', ['model' => $model]);
|
|
|
}
|
|
|
|