Browse Source

报表相关优化

wufeng 2 years ago
parent
commit
0d3eb5eb19

+ 41 - 10
app/admin/controller/Report.php

@@ -597,6 +597,8 @@ class Report extends Base
             'companyName' => '',
             'start_date' => '',
             'end_date' => '',
+            'start_updatetime' => '',
+            'end_updatetime' => '',
             'page' => 1,
             'size' => 15,
         ], 'post', 'trim');
@@ -604,6 +606,8 @@ class Report extends Base
         $val_params = Validate::rule([
             'start_date' => 'date|elt:end_date',
             'end_date' => 'date',
+            'start_updatetime' => 'date|elt:end_updatetime',
+            'end_updatetime' => 'date',
         ]);
 
         if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
@@ -612,6 +616,9 @@ class Report extends Base
 
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
         if ($param['companyName'] != '') $where[] = ['csi.companyName', 'like', '%' . $param['companyName'] . '%'];
+        if ($param['start_updatetime'] != '' && $param['end_updatetime'] != '') $where[] = ['ci.updatetime', 'between', [$param['start_updatetime'] . ' 00:00:00', $param['end_updatetime'] . ' 23:59:59']];
+
+        $status = [1 => '招标进行中', 2 => '招标已结束', 3 => '等待议价结果', 4 => '确认商品', 5 => '成功转单', 6 => '取消转单', 7 => '招标已暂停'];
 
         $count = Db::name('consult_info')
             ->alias('ci')
@@ -625,7 +632,7 @@ class Report extends Base
 
         $data = Db::name('consult_info')
             ->alias('ci')
-            ->field('ci.zxNo,ci.good_name,ci.num,csi.companyName,ci.addtime,ci.arrival_time endtime')
+            ->field('ci.zxNo,ci.good_name,ci.num,csi.companyName,ci.addtime,ci.arrival_time endtime,ci.updatetime,ci.status')
             ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
             ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
             ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
@@ -633,6 +640,9 @@ class Report extends Base
             ->whereNull('cb.id')//未采反,即咨询单没有对应的反馈单,所以反馈单id应该是null
             ->order('ci.arrival_time', 'desc')
             ->page($param['page'], $param['size'])
+            ->withAttr('status', function ($val) use ($status) {
+                return isset($status[$val]) ? $status[$val] : '';
+            })
             ->select()
             ->toArray();
 
@@ -649,11 +659,15 @@ class Report extends Base
             'companyName' => '',
             'start_date' => '',
             'end_date' => '',
+            'start_updatetime' => '',
+            'end_updatetime' => '',
         ], 'post', 'trim');
 
         $val_params = Validate::rule([
             'start_date' => 'date|elt:end_date',
             'end_date' => 'date',
+            'start_updatetime' => 'date|elt:end_updatetime',
+            'end_updatetime' => 'date',
         ]);
 
         if (!$val_params->check($param)) return error_show(1004, $val_params->getError());
@@ -662,16 +676,22 @@ class Report extends Base
 
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
         if ($param['companyName'] != '') $where[] = ['csi.companyName', 'like', '%' . $param['companyName'] . '%'];
+        if ($param['start_updatetime'] != '' && $param['end_updatetime'] != '') $where[] = ['ci.updatetime', 'between', [$param['start_updatetime'] . ' 00:00:00', $param['end_updatetime'] . ' 23:59:59']];
+
+        $status = [1 => '招标进行中', 2 => '招标已结束', 3 => '等待议价结果', 4 => '确认商品', 5 => '成功转单', 6 => '取消转单', 7 => '招标已暂停'];
 
         $data = Db::name('consult_info')
             ->alias('ci')
-            ->field('ci.zxNo 咨询订单号,ci.good_name 产品名称,ci.num 需求数量,csi.companyName 客户名称,ci.addtime 咨询时间,ci.arrival_time 截止时间')
+            ->field('ci.zxNo 咨询订单号,ci.good_name 产品名称,ci.num 需求数量,csi.companyName 客户名称,ci.addtime 咨询时间,ci.arrival_time 截止时间,ci.status 状态')
             ->leftJoin('consult_bids cb', 'cb.infoNo=ci.infoNo')
             ->leftJoin('consult_order co', 'co.zxNo=ci.zxNo')
             ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
             ->where($where)
             ->whereNull('cb.id')
             ->order('ci.arrival_time', 'desc')
+            ->withAttr('状态', function ($val) use ($status) {
+                return isset($status[$val]) ? $status[$val] : '';
+            })
             ->select()
             ->toArray();
 
@@ -1965,6 +1985,7 @@ class Report extends Base
             'token',
             'start_date' => '',
             'end_date' => '',
+            'spuCode' => '',
             'page' => 1,
             'size' => 15
         ], 'post', 'trim');
@@ -1978,21 +1999,24 @@ class Report extends Base
 
         $where = [];
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
+        if ($param['spuCode'] != '') $where[] = ['gp.spuCode', 'like', '%' . $param['spuCode'] . '%'];
 
         $count = Db::name('good_platform')
             ->alias('gp')
             ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
             ->leftJoin('platform p', 'p.id=gp.platform_code')
             ->leftJoin('good_nake gn', 'gn.spuCode=gb.spuCode')
+            ->leftJoin('good_ladder c', 'c.skuCode=gp.skuCode AND c.is_del=0')
             ->where($where)
             ->count('gp.id');
 
         $data = Db::name('good_platform')
             ->alias('gp')
-            ->field('gp.skuCode,gp.spuCode,gp.plat_code,gb.good_name,p.platform_name,gp.online_time,gb.moq,gn.nake_fee,gb.cost_fee,gn.delivery_fee,gb.cert_fee,gb.mark_fee,gb.packing_fee,gn.other_fee,gn.nake_total,gp.addtime')
+            ->field('gp.skuCode,gp.spuCode,gp.plat_code,gb.good_name,p.platform_name,gp.online_time,c.min_num moq,gn.nake_fee,gb.cost_fee,gn.delivery_fee,gb.cert_fee,gb.mark_fee,gb.packing_fee,gn.other_fee,gn.nake_total,gp.addtime')
             ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
             ->leftJoin('platform p', 'p.id=gp.platform_code')
             ->leftJoin('good_nake gn', 'gn.spuCode=gb.spuCode')
+            ->leftJoin('good_ladder c', 'c.skuCode=gp.skuCode AND c.is_del=0')//加入c.is_del可以命中索引
             ->where($where)
             ->order('gp.id', 'desc')
             ->page($param['page'], $param['size'])
@@ -2009,7 +2033,8 @@ class Report extends Base
         $param = $this->request->only([
             'token',
             'start_date' => '',
-            'end_date' => ''
+            'end_date' => '',
+            'spuCode' => '',
         ], 'post', 'trim');
 
         $val_params = Validate::rule([
@@ -2021,14 +2046,16 @@ class Report extends Base
 
         $where = [];
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
+        if ($param['spuCode'] != '') $where[] = ['gp.spuCode', 'like', '%' . $param['spuCode'] . '%'];
 
         $data = Db::name('good_platform')
             ->alias('gp')
-            ->field('gp.skuCode as 商品上线编号,gp.spuCode as 商品成本编号,gp.plat_code as 平台商品编码,gb.good_name as 商品名称,p.platform_name as 上线平台,gp.online_time as 上线完成时间,gb.moq 起订量,gn.nake_fee 成本单价,gb.cost_fee 工艺费,gn.delivery_fee 物流费,gb.cert_fee 证书费,gb.mark_fee 加标费,gb.packing_fee 包装费,gn.other_fee 其他费用,gn.nake_total 成本合计,gp.addtime 申请上线时间')
+            ->field('gp.skuCode as 商品上线编号,gp.spuCode as 商品成本编号,gp.plat_code as 平台商品编码,gb.good_name as 商品名称,p.platform_name as 上线平台,gp.online_time as 上线完成时间,c.min_num 起订量,gn.nake_fee 成本单价,gb.cost_fee 工艺费,gn.delivery_fee 物流费,gb.cert_fee 证书费,gb.mark_fee 加标费,gb.packing_fee 包装费,gn.other_fee 其他费用,gn.nake_total 成本合计,gp.addtime 申请上线时间')
             ->where($where)
             ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
             ->leftJoin('platform p', 'p.id=gp.platform_code')
             ->leftJoin('good_nake gn', 'gn.spuCode=gb.spuCode')
+            ->leftJoin('good_ladder c', 'c.skuCode=gp.skuCode AND c.is_del=0')
             ->order('gp.id', 'desc')
             ->select()
             ->toArray();
@@ -2047,6 +2074,7 @@ class Report extends Base
             'token',
             'start_date' => '',
             'end_date' => '',
+            'spuCode' => '',
             'page' => 1,
             'size' => 15
         ], 'post', 'trim');
@@ -2060,6 +2088,7 @@ class Report extends Base
 
         $where = [];
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
+        if ($param['spuCode'] != '') $where[] = ['gp.spuCode', 'like', '%' . $param['spuCode'] . '%'];
 
         $count = Db::name('good_platform')
             ->alias('gp')
@@ -2071,11 +2100,11 @@ class Report extends Base
 
         $data = Db::name('good_platform')
             ->alias('gp')
-            ->field('gp.skuCode,gp.spuCode,gp.plat_code,gb.good_name,p.platform_name,gp.online_time,gb.moq,gl.sale_price,gl.cost_fee,gl.market_price,gl.market_platform,gp.addtime')
+            ->field('gp.skuCode,gp.spuCode,gp.plat_code,gb.good_name,p.platform_name,gp.online_time,gl.min_num moq,gl.sale_price,gl.cost_fee,gl.market_price,gl.market_platform,gp.addtime')
             ->where($where)
             ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
             ->leftJoin('platform p', 'p.id=gp.platform_code')
-            ->leftJoin('good_ladder gl', 'gl.skuCode=gp.skuCode')
+            ->leftJoin('good_ladder gl', 'gl.skuCode=gp.skuCode AND gl.is_del=0')//加入is_del可以命中索引
             ->order('gp.id', 'desc')
             ->page($param['page'], $param['size'])
             ->select()
@@ -2091,7 +2120,8 @@ class Report extends Base
         $param = $this->request->only([
             'token',
             'start_date' => '',
-            'end_date' => ''
+            'end_date' => '',
+            'spuCode' => ''
         ], 'post', 'trim');
 
         $val_params = Validate::rule([
@@ -2103,14 +2133,15 @@ class Report extends Base
 
         $where = [];
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['gp.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
+        if ($param['spuCode'] != '') $where[] = ['gp.spuCode', 'like', '%' . $param['spuCode'] . '%'];
 
         $data = Db::name('good_platform')
             ->alias('gp')
-            ->field('gp.skuCode as 商品上线编号,gp.spuCode as 商品成本编号,gp.plat_code as 平台商品编码,gb.good_name as 商品名称,p.platform_name as 上线平台,gp.online_time as 上线完成时间,gb.moq 起订量,gl.sale_price 售价,gl.cost_fee 工艺费,gl.market_price 市场价,gl.market_platform 对比平台,gp.addtime 申请上线时间')
+            ->field('gp.skuCode as 商品上线编号,gp.spuCode as 商品成本编号,gp.plat_code as 平台商品编码,gb.good_name as 商品名称,p.platform_name as 上线平台,gp.online_time as 上线完成时间,gl.min_num 起订量,gl.sale_price 售价,gl.cost_fee 工艺费,gl.market_price 市场价,gl.market_platform 对比平台,gp.addtime 申请上线时间')
             ->where($where)
             ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
             ->leftJoin('platform p', 'p.id=gp.platform_code')
-            ->leftJoin('good_ladder gl', 'gl.skuCode=gp.skuCode')
+            ->leftJoin('good_ladder gl', 'gl.skuCode=gp.skuCode AND gl.is_del=0')
             ->order('gp.id', 'desc')
             ->select()
             ->toArray();

+ 13 - 5
app/admin/controller/Sale.php

@@ -3227,6 +3227,14 @@ class Sale extends Base
         $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
         if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
 
+        //发货时间筛选
+        $start_sendtime = isset($this->post['start_sendtime']) && $this->post['start_sendtime'] !== "" ? $this->post['start_sendtime'] : "";
+        if ($start_sendtime != "") $where[] = ["a.sendtime", '>=', $start_sendtime];
+
+        $end_sendtime = isset($this->post['end_sendtime']) && $this->post['end_sendtime'] !== "" ? $this->post['end_sendtime'] : "";
+        if ($end_sendtime != "") $where[] = ["a.sendtime", '<=', $end_sendtime];
+
+
         $count = Db::name('order_out')
             ->alias('a')
             ->join("sale b", "b.orderCode=a.orderCode", "left")
@@ -3244,7 +3252,7 @@ class Sale extends Base
             ->alias('a')
             ->join("sale b", "b.orderCode=a.orderCode", "left")
             ->join("customer_info v", "v.companyNo=b.customer_code", "left")
-            ->join("warehouse_info n", "n.wsm_code=a.wsm_code", "left")
+            ->join("warehouse_info n", "n.wsm_code=a.wsm_code AND n.is_del=0", "left")
             ->leftJoin("order_send os", "os.outCode=a.outCode")
             ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
             ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
@@ -3254,16 +3262,16 @@ class Sale extends Base
             ->order("addtime desc")
             ->page($page, $size)
             ->cursor();
+
         $data = [];
         foreach ($list as $value) {
             $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
                 ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
             $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
             if ($value['order_type'] == 3) {
-                $goon = Db::name("good_zixun")->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
+                $goon = Db::name("good_zixun")->field('id,cat_id')->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
             } else {
-                $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
-                    ->where(['a.skuCode' => $value['skuCode']])->find();
+                $goon = Db::name('good_platform')->field('a.id,b.cat_id')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')->where(['a.skuCode' => $value['skuCode']])->find();
             }
             $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
             $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
@@ -4262,9 +4270,9 @@ class Sale extends Base
                     $stock = Db::name("good_stock")
                         ->field('id,wait_out_stock,usable_stock,total_stock,updatetime')
                         ->where([
+                            "is_del" => 0,
                             'spuCode' => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code'],
                             "wsm_code" => $order_out_infos[$value['outCode']]['wsm_code'],
-                            "is_del" => 0
                         ])->find();
                     if ($stock == false) throw new Exception($value['outCode'] . '未找到库存数据');
                     else {

+ 17 - 17
app/admin/controller/SaleReport.php

@@ -820,14 +820,14 @@ class SaleReport extends Base
     {
         $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'use_desc' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
 
-        $where = [['s.order_type', '=', 3], ['s.is_del', '=', 0]];
+        $where = [['ci.is_del', '=', 0]];
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
         if ($param['use_desc'] != '') $where[] = ['ci.use_desc', 'like', '%' . $param['use_desc'] . '%'];
 
-        $count = Db::name('sale')
-            ->alias('s')
-            ->leftJoin('consult_bids cb', 'cb.bidNo=s.zxNo')
-            ->leftJoin('consult_info ci', 'ci.zxNo=cb.zxNo')
+        $count = Db::name('consult_info')
+            ->alias('ci')
+            ->leftJoin('consult_bids cb', 'cb.bidNo=ci.zxNo')
+            ->leftJoin('sale s', 's.zxNo=ci.zxNo AND s.is_del=0')
             ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
             ->leftJoin('company_item item', 'item.id=co.depart')
             ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
@@ -837,11 +837,11 @@ class SaleReport extends Base
             ->order('ci.addtime', 'desc')
             ->count('ci.id');
 
-        $data = Db::name('sale')
-            ->alias('s')
-            ->field('ci.addtime,co.salesman,item.name,cb.infoNo,csi.companyName,ci.use_desc,ci.good_name,b.brand_name,ci.model,s.good_code,ci.cat_id,ci.budget_price,u.unit,ci.num,s.sale_price,ci.arrival_time,ci.is_addrs,ci.is_custom,ci.remark,ci.status,ci.bargain_code,csi.itemid')
-            ->leftJoin('consult_bids cb', 'cb.bidNo=s.zxNo')
-            ->leftJoin('consult_info ci', 'ci.zxNo=cb.zxNo')
+        $data = Db::name('consult_info')
+            ->alias('ci')
+            ->field('ci.addtime,co.salesman,item.name,cb.infoNo,csi.companyName,ci.use_desc,ci.good_name,b.brand_name,ci.model,s.good_code,ci.cat_id,ci.budget_price,u.unit,ci.num,s.sale_price,ci.arrival_time,ci.is_addrs,ci.is_custom,ci.remark,ci.status,ci.bargain_code,csi.itemid,s.orderCode')
+            ->leftJoin('consult_bids cb', 'cb.bidNo=ci.zxNo')
+            ->leftJoin('sale s', 's.zxNo=ci.zxNo AND s.is_del=0')
             ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
             ->leftJoin('company_item item', 'item.id=co.depart')
             ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
@@ -883,15 +883,15 @@ class SaleReport extends Base
 
         $param = $this->request->only(['token', 'start_date' => '', 'end_date' => '', 'use_desc' => ''], 'post', 'trim');
 
-        $where = [['s.order_type', '=', 3], ['s.is_del', '=', 0]];
+        $where = [['ci.is_del', '=', 0]];
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['ci.addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
         if ($param['use_desc'] != '') $where[] = ['ci.use_desc', 'like', '%' . $param['use_desc'] . '%'];
 
-        $data = Db::name('sale')
-            ->alias('s')
-            ->field('ci.addtime 咨询时间,co.salesman 业务员,item.name 业务部门,cb.infoNo 咨询单号,"" 一级组织,"" 二级组织,csi.companyName 客户名称,ci.use_desc 产品用途,ci.good_name 产品名称,b.brand_name 品牌,ci.model 型号,s.good_code 产品编码,"" 一级分类,ci.cat_id,ci.budget_price 预算单价,u.unit 单位,ci.num 需求数量,"" 预算总价,s.sale_price 单价,ci.arrival_time 要求到货时间,ci.is_addrs 是否一地,ci.is_custom 定制,ci.remark 咨询备注,ci.status 竞单状态,ci.bargain_code 上次咨询单单号,csi.itemid')
-            ->leftJoin('consult_bids cb', 'cb.bidNo=s.zxNo')
-            ->leftJoin('consult_info ci', 'ci.zxNo=cb.zxNo')
+        $data = Db::name('consult_info')
+            ->alias('ci')
+            ->field('ci.addtime 咨询时间,co.salesman 业务员,item.name 业务部门,cb.infoNo 咨询单号,"" 一级组织,"" 二级组织,csi.companyName 客户名称,ci.use_desc 产品用途,ci.good_name 产品名称,b.brand_name 品牌,ci.model 型号,s.good_code 产品编码,"" 一级分类,ci.cat_id,ci.budget_price 预算单价,u.unit 单位,ci.num 需求数量,"" 预算总价,s.sale_price 单价,ci.arrival_time 要求到货时间,ci.is_addrs 是否一地,ci.is_custom 定制,ci.remark 咨询备注,ci.status 竞单状态,ci.bargain_code 上次咨询单单号,s.orderCode 销售订单编号,csi.itemid')
+            ->leftJoin('consult_bids cb', 'cb.bidNo=ci.zxNo')
+            ->leftJoin('sale s', 's.zxNo=ci.zxNo')
             ->leftJoin('consult_order co', 'co.zxNo=cb.zxNo')
             ->leftJoin('company_item item', 'item.id=co.depart')
             ->leftJoin('customer_info csi', 'csi.companyNo=co.khNo')
@@ -1117,7 +1117,7 @@ class SaleReport extends Base
 
             $list[] = $value;
         }
-        
+
         return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
 
     }

+ 0 - 1
app/command/getLogisticsInformationByKuaidi.php

@@ -27,7 +27,6 @@ class getLogisticsInformationByKuaidi extends Command
             ->alias('oo')
             ->where('oo.status', 2)//status==2 已发货待收货
             ->leftJoin('order_addr oa', 'oa.id=oo.addrid AND oa.is_del=0')
-            ->lock(true)
             ->field('oo.id,oo.post_code,oo.updatetime,oa.mobile,oo.post_name')
             ->cursor();