|
|
@@ -0,0 +1,140 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace ghs\controllers;
|
|
|
+
|
|
|
+use biz\admin\classes\AdminRoleClass;
|
|
|
+use bizGhs\item\classes\ItemClassClass;
|
|
|
+use bizGhs\merchant\classes\ShopClass;
|
|
|
+use bizGhs\product\classes\ProductClass;
|
|
|
+use bizGhs\product\models\Product;
|
|
|
+use bizGhs\product\services\ProductService;
|
|
|
+use common\components\stringUtil;
|
|
|
+use common\components\util;
|
|
|
+use Yii;
|
|
|
+
|
|
|
+class CsController extends PublicController
|
|
|
+{
|
|
|
+
|
|
|
+ public $sjId = 12568, $shopId = 214;
|
|
|
+
|
|
|
+ public function actionItem()
|
|
|
+ {
|
|
|
+
|
|
|
+ $shopId = 214;
|
|
|
+
|
|
|
+ if (getenv('YII_ENV', 'local') != 'production') {
|
|
|
+ $shopId = 36225;
|
|
|
+ $this->shopId = 36225;
|
|
|
+ $this->sjId = 12715;
|
|
|
+ }
|
|
|
+
|
|
|
+ $py = Yii::$app->request->get('py', '');
|
|
|
+ $type = Yii::$app->request->get('type', '');
|
|
|
+ //默认只显示上架的商品
|
|
|
+ $status = Yii::$app->request->get('status', 1);
|
|
|
+
|
|
|
+ //获取所有当前供应商的分类 (全部、常用)
|
|
|
+ //根据分类组装分类下的花材信息
|
|
|
+ $classIds = ItemClassClass::getGhsItemClassAll($this->sjId);
|
|
|
+
|
|
|
+ $where['sjId'] = $this->sjId;
|
|
|
+ if ($py) {
|
|
|
+ $pyName = strtolower($py);
|
|
|
+ $where['py'] = $pyName;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $where['shopId'] = $shopId;
|
|
|
+ if (!empty($status)) {
|
|
|
+ $where['status'] = $status;
|
|
|
+ }
|
|
|
+ $where['delStatus'] = 0;
|
|
|
+
|
|
|
+ $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*");
|
|
|
+ $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
|
|
|
+ //常用的itemIds
|
|
|
+ $oftenItemIds = [];
|
|
|
+ //$oftenItemIds = ProductClass::getOftenItemIds($shopId);
|
|
|
+ //获取供应商下所有花材ID (itemIds)
|
|
|
+ $itemIdsInfo = ProductClass::getGhsItemIds($this->sjId);
|
|
|
+
|
|
|
+ //dd($itemInfoData);
|
|
|
+ //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
|
|
|
+ $data = ProductService::assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, $type);
|
|
|
+
|
|
|
+ $formatData = [];
|
|
|
+
|
|
|
+ foreach ($data as $key => $class) {
|
|
|
+ $name = "【{$class['className']}】" ?? '';
|
|
|
+ $formatData[] = ['name' => $name, 'price' => ''];
|
|
|
+ if (isset($class['child']) && !empty($class['child'])) {
|
|
|
+ foreach ($class['child'] as $cKey => $child) {
|
|
|
+ $cName = $child['name'] ?? '';
|
|
|
+ $price = $child['price'] ?? '';
|
|
|
+ $formatData[] = [
|
|
|
+ 'name' => $cName,
|
|
|
+ 'price' => $price,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
|
|
|
+ require_once($phpExcelFile . 'Classes/PHPExcel.php');
|
|
|
+
|
|
|
+ $objPHPExcel = new \PHPExcel();
|
|
|
+
|
|
|
+ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
|
|
|
+ ->setLastModifiedBy("Maarten Balliauw")
|
|
|
+ ->setTitle("Office 2007 XLSX Test Document")
|
|
|
+ ->setSubject("Office 2007 XLSX Test Document")
|
|
|
+ ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
|
|
|
+ ->setKeywords("office 2007 openxml php")
|
|
|
+ ->setCategory("Test result file");
|
|
|
+
|
|
|
+ $i = 1;
|
|
|
+ foreach ($formatData as $key => $product) {
|
|
|
+
|
|
|
+
|
|
|
+// $objPHPExcel->setActiveSheetIndex(0)//表头的信息
|
|
|
+// ->setCellValue('A1', "编号")
|
|
|
+// ->setCellValue('B1', "所属上级")
|
|
|
+// ->setCellValue('C1', "路由名称")
|
|
|
+// ->setCellValue('D1', "菜单标题")
|
|
|
+// ->setCellValue('E1', "状态");
|
|
|
+// $i = 2;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $objPHPExcel->getActiveSheet()// 设置第一个内置表(一个xls文件里可以有多个表)为活动的
|
|
|
+ ->setCellValue('A' . $i, $product['name'])//给表的单元格设置数据
|
|
|
+ ->setCellValue('B' . $i, $product['price']);//数据格式可以为字符串
|
|
|
+ $i++;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $objPHPExcel->getActiveSheet()->setTitle('Simple');
|
|
|
+
|
|
|
+ $objPHPExcel->setActiveSheetIndex(0);
|
|
|
+
|
|
|
+ header('Content-Type: application/vnd.ms-excel');
|
|
|
+ header('Content-Disposition: attachment;filename="01simple.xls"');
|
|
|
+ header('Cache-Control: max-age=0');
|
|
|
+
|
|
|
+ header('Cache-Control: max-age=1');
|
|
|
+
|
|
|
+ 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
|
|
|
+
|
|
|
+ $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
|
|
|
+ $objWriter->save('php://output');
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|