Browse Source

Merge branch 'dev_wf' of wugg/phpstock into version1.5

wufeng 2 years ago
parent
commit
be95b670ae
1 changed files with 18 additions and 36 deletions
  1. 18 36
      app/admin/controller/SaleReport.php

+ 18 - 36
app/admin/controller/SaleReport.php

@@ -1479,47 +1479,29 @@ class SaleReport extends Base
             ->leftJoin("company_item ci", "ci.id=u.itemid")
             ->where($where)
             ->order("a.addtime desc")
-            ->select()
-            ->toArray();
-//            ->cursor();
-
-
-        //所有部门名称
-        $all_company = [];
-        foreach ($data as $value) {
-            if (!isset($all_company[$value['apply_id']])) $all_company[$value['apply_id']] = get_company_name_by_uid($value['apply_id']);
-        }
-
-        //所有商品相关
-        $goon_3_4 = Db::name("good_zixun")
-            ->where('is_del', 0)
-            ->whereIn('spuCode', array_column($data, '商品编码'))
-            ->column('id,cat_id,customized', 'spuCode');
-
-        $goon_else = Db::name('good_platform')
-            ->alias('a')
-            ->join('good b', 'b.spuCode=a.spuCode', 'left')
-            ->where('a.is_del', 0)
-            ->whereIn('a.skuCode', array_column($data, 'skuCode'))
-            ->column('a.id,b.cat_id,b.customized', 'skuCode');
-
-        //所有分类
-        $all_cat = [];
-        $all_cat_id = array_unique(array_merge(array_column($goon_3_4, 'cat_id'), array_column($goon_else, 'cat_id')));
-        foreach ($all_cat_id as $cat_id) {
-            if (!isset($all_cat[$cat_id])) $all_cat[$cat_id] = implode('/', array_column(made($cat_id), 'name'));
-        }
-
+            ->cursor();
 
         $list = [];
         foreach ($data as $value) {
 
-            $value['部门'] = $all_company[$value['apply_id']] ?? '';
+            $value['部门'] = get_company_name_by_uid($value['apply_id']);
+
+            if ($value['order_type'] == 3 || $value['order_type'] == 4) {
+                $goon = Db::name("good_zixun")
+                    ->field('id,cat_id,customized')
+                    ->where(["spuCode" => $value['商品编码'], "is_del" => 0])
+                    ->find();
 
-            if ($value['order_type'] == 3 || $value['order_type'] == 4) $goon = $goon_3_4[$value['商品编码']];
-            else $goon = $goon_else[$value['skuCode']];
+            } else {
+                $goon = Db::name('good_platform')
+                    ->alias('a')
+                    ->field('a.id,b.cat_id,b.customized')
+                    ->join('good b', 'b.spuCode=a.spuCode', 'left')
+                    ->where(['a.is_del' => 0, 'a.skuCode' => $value['skuCode']])
+                    ->find();
+            }
 
-            $value['商品分类'] = $all_cat[$goon['cat_id']] ?? '';
+            $value['商品分类'] = implode('/', array_column(made($goon['cat_id']), 'name'));
             $value['应发货日期'] = date('Y-m-d H:i:s', strtotime($value['下单时间']) + $goon['customized'] * 24 * 3600);
 
             $value['状态'] = isset($this->order_out_status[$value['状态']]) ? $this->order_out_status[$value['状态']] : '';
@@ -1530,7 +1512,7 @@ class SaleReport extends Base
 
             $list[] = $value;
         }
-        
+
         if (empty($list)) $list[] = '没有相关可导出的数据';
         excelSave('无地址待发货订单' . date('YmdHis'), array_keys($list[0]), $list);