Quellcode durchsuchen

非资源形式

shish vor 4 Jahren
Ursprung
Commit
701bf73a9b

+ 8 - 0
app-ghs/controllers/ProductController.php

@@ -557,4 +557,12 @@ class ProductController extends BaseController
         util::complete();
     }
 
+    //下载价格表 shish 20210922
+    public function actionGeneratePriceTable()
+    {
+        $file = ProductService::generatePriceTable($this->sjId, $this->shopId);
+        $fileUrl = Yii::$app->params['ghsHost'] .$file;
+        util::success(['file' => $fileUrl]);
+    }
+
 }

BIN
app-ghs/web/aaas.xls


+ 133 - 3
biz-ghs/product/services/ProductService.php

@@ -4,8 +4,10 @@ namespace bizGhs\product\services;
 
 
 use bizGhs\base\services\BaseService;
+use bizGhs\item\classes\ItemClassClass;
 use bizGhs\product\classes\ProductClass;
 use common\services\xhItemService;
+use Yii;
 
 class ProductService extends BaseService
 {
@@ -20,10 +22,10 @@ class ProductService extends BaseService
     {
         $saleItem = []; //今日特价
 
-        if($itemInfoData){
-            foreach ($itemInfoData as $v){
+        if ($itemInfoData) {
+            foreach ($itemInfoData as $v) {
                 $v['classId'] = self::ALL_CLASS_ID;
-                if($v['discountPrice'] > 0){
+                if ($v['discountPrice'] > 0) {
                     $saleItem[] = $v;
                 }
             }
@@ -112,4 +114,132 @@ class ProductService extends BaseService
         return $data;
     }
 
+    //生成价格表 shish 20210922
+    public static function generatePriceTable($sjId, $shopId)
+    {
+
+        $py = '';
+        $type = '';
+        //默认只显示上架的商品
+        $status = 1;
+
+        //获取所有当前供应商的分类 (全部、常用)
+        //根据分类组装分类下的花材信息
+        $classIds = ItemClassClass::getGhsItemClassAll($sjId);
+
+        $where['sjId'] = $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($sjId);
+
+        $data = self::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");
+
+
+        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(12);
+        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(4);
+
+        $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " 价格表");
+
+        $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.4);
+        $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0);
+        $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.1);
+        $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
+        $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
+        $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
+
+        $i = 1;
+        $letter = [1 => ['A', 'B'], 2 => ['C', 'D'], 3 => ['E', 'F'], 4 => ['G', 'H'], 5 => ['I', 'J'], 6 => ['K', 'L'], 7 => ['M', 'N'],
+            8 => ['O', 'P'], 9 => ['Q', 'R'], 10 => ['S', 'T'], 11 => ['U', 'V']];
+        $lastCell = '';
+        //最大行
+        $max = 50;
+        foreach ($formatData as $key => $product) {
+            $currentPage = ceil($i / $max);
+            $x = $i % $max == 0 ? $max : $i % $max;
+            $before = $letter[$currentPage][0] ?? 'A';
+            $after = $letter[$currentPage][1] ?? 'B';
+            if (isset($product['price']) == false || empty($product['price'])) {
+                //没有价格的合并单元格
+                $objPHPExcel->getActiveSheet()->mergeCells("{$before}{$x}:{$after}{$x}")->setCellValue($before . $x, $product['name']);
+                //加粗
+                $objPHPExcel->getActiveSheet()->getStyle($before . $x)->getFont()->setBold(true);
+                //居中
+                $objPHPExcel->getActiveSheet()->getStyle($before . $x)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            } else {
+                $objPHPExcel->getActiveSheet()->setCellValue($before . $x, $product['name'])->setCellValue($after . $x, $product['price']);
+                //字体大小
+                $objPHPExcel->getActiveSheet()->getStyle($before . $x)->getFont()->setSize(10);
+            }
+            $lastCell = $after . $max;
+            $i++;
+        }
+
+        //设置边框
+        $objPHPExcel->getActiveSheet()->getStyle('A1:' . $lastCell)->applyFromArray(array('borders' => array('allborders' => array('style' => \PHPExcel_Style_Border::BORDER_THIN),)));
+
+        $objPHPExcel->getActiveSheet()->setTitle('价格表');
+
+        $objPHPExcel->setActiveSheetIndex(0);
+
+        $dir = './priceTable/' . $sjId;
+        if (file_exists($dir) == false) {
+            mkdir($dir, 0777, true);
+        }
+        $date = date("m-d");
+        $file = $date . '.xls';
+        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+        if (file_exists($dir . '/' . $file)) {
+            unlink($dir . '/' . $file);
+        }
+        $objWriter->save($dir . '/' . $file);
+
+        return '/priceTable/' . $sjId.'/'.$file;
+    }
+
 }

+ 13 - 0
biz/product/classes/ProductClass.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\product\classes;
+
+use biz\base\classes\BaseClass;
+use bizGhs\item\classes\ItemClassClass;
+
+class ProductClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\product\models\Product';
+
+}

+ 15 - 0
biz/product/models/Product.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace biz\product\models;
+
+use biz\base\models\Base;
+
+class Product extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhGhsProduct';
+    }
+
+}