lvhao 1 hete
szülő
commit
91199d6695
2 módosított fájl, 116 hozzáadás és 283 törlés
  1. 60 212
      core/CoreApp/controllers/Boss.php
  2. 56 71
      template/erp/boss_qtcs.html

+ 60 - 212
core/CoreApp/controllers/Boss.php

@@ -98,6 +98,8 @@ class Boss extends Start_Controller
 			$this->_bossyxdpdcx();
 		}else if($arg == 'spexceljs'){
 			$this->_spexceljs();	
+		}else if($arg == 'excellkhjs'){
+			$this->_excellkhjs();	
 		} else {
 			$this->_index();
 		}
@@ -1546,228 +1548,74 @@ class Boss extends Start_Controller
 
 	}
 
-
-
-
-	private function _spexceljsbak()
-	{
-		$tcjm = $tmp_typeclass =  $tc = [];
-		$typeclass = $this->typeclass->find_all();
-		foreach ($typeclass as $v) {
-			$tc[$v['id']] = $v;
-			$tcjm[$v['id']] = array($v['jm'], $v['classid']);
-			$tmp_typeclass[$v['id']] = array('zh' => $v['zh'], 'classid' => $v['classid'], 'bm' => $v['bm'], 'title' => $v['title'], 'jm' => $v['jm']);
-		}
-		$typeclass = $tmp_typeclass;
-		if(isset($_SESSION['api'])){
+	private function _excellkhjs(){
+		if (isset($_SESSION['api'])) {
 			$user = $this->user->get_api($_SESSION['api']);
-			if(empty($user)){
-				exit(json_encode(array('code' => 0, 'msg' => '登录信息异常')));
-			}
-			if(empty($user['shop'])){
-				exit(json_encode(array('code' => 0, 'msg' => '该账号没有所属店铺excel导出权限')));
+			$usp = $user;
+			$fgshop = "";
+			$sid = "";
+			$user = explode('|', trim($user['shop'], '|'));
+			foreach ($user as $value) {
+				if ($value != '18' && $value != '19' && $value != '12' && $value != '13' && $value != '9' && $value != '15' && $value != '27') {
+					$fgshop .= " shop = " . $value . " or"; //去掉指定的店铺
+				}
+				$sid .= " id = " . $value . " or";
 			}
-			$excelshop = explode('|', trim($user['shop'], '|'));
-		}else{
-			exit(json_encode(array('code' => 0, 'msg' => '请先登录')));
 		}
-		$classid = $this->classid->sku();
-
-		$post = $this->input->post(NULL, TRUE);
-		$timetk = strtotime($post['timetk']);
-		$timetj = strtotime($post['timetj']);
-
-
-
-		$where = $post['time']." > ".$timetk." and ".$post['time']." < ".$timetj."  ";
-
-		if(!empty($post['warehouse'])){
-			$where .= " and type = ".$post['warehouse']." ";
-		}
-
-		if(!empty($post['shop'])){
-			$where .= " and shop = ".$post['shop']." ";
-		}else{
-			$where .= " and shop in (".implode(',',$excelshop).") ";
-		}
-
-		if(!empty($post['category'])){
-			$where .=" and fpdata like '%-".$post['category']."-%' ";
-		}
-		if(!empty($post['color'])){
-			$where .=" and fpdata like '%-".$post['color']."-%' ";
-		}
-		if(!empty($post['size'])){
-			$where .=" and fpdata like '%-".$post['size']."-%' ";
-		}
-		if(!empty($post['grade'])){
-			$where .=" and fpdata like '%-".$post['grade']."-%' ";
-		}
-		if(!empty($post['lowe'])){
-			$where .=" and fpdata like '%-".$post['lowe']."-%' ";
-		}
-		if(!empty($post['density'])){
-			$where .=" and fpdata like '%-".$post['density']."-%' ";
-		}
-		if(!empty($post['lacetype'])){
-			$where .=" and fpdata like '%-".$post['lacetype']."-%' ";
-		}
-
-		$filed_list = "fpdata,number,whlabel,type";
-
-		$data_dlz = $this->db->from('fullorder')->where($where)->select($filed_list)->order_by('id desc')->get()->result_array();
-		$data_smt = $this->db->from('fullordersmt')->where($where." and shop != '9'")->select($filed_list)->order_by('id desc')->get()->result_array();
-		$data_tt = $this->db->from('fullordertt')->where($where)->select($filed_list)->order_by('id desc')->get()->result_array();
-		$data_amz = $this->db->from('fullorderamz')->where($where)->select($filed_list)->order_by('id desc')->get()->result_array();
-	
-		$data = $data_dlz + $data_smt + $data_tt + $data_amz;
-		if(empty($data)){
-			exit(json_encode(array('code' => 0, 'msg' => '暂无数据')));	
-		}
-		if(count($data) >= 65535){
-			exit(json_encode(array('code' => 0, 'msg' => '数据量超过65535条,请缩小查询范围')));
-		}
-
-		$warehouses = $this->warehouse->find_all('1=1', 'id,title');
-		$warehouses = array_column($warehouses, 'title', 'id');
-		$sp = [];
-
-		foreach ($data as $val) {
-			$f = explode(';', trim($val['fpdata'], ';'));
-			$w = explode('|', trim($val['whlabel'], '|'));
-			foreach ($f as $k => $v) {
-				if(!empty($post['category'])){
-					if(stripos($v,'-'.$post['category'].'-') === false){
-						continue;
-					}
-				}
-				if(!empty($post['color'])){
-					if(stripos($v,'-'.$post['color'].'-') === false){
-						continue;
-					}
-				}
-				if(!empty($post['lowe'])){
-					if(stripos($v,'-'.$post['lowe'].'-') === false){
-						continue;
-					}
-				}
-				if(!empty($post['size'])){
-					if(stripos($v,'-'.$post['size'].',') === false){
-						continue;
-					}
-				}
-				if(!empty($post['grade'])){
-					if(stripos($v,'-'.$post['grade'].'-') === false){
-						continue;
-					}
-				}
-				if(!empty($post['lacetype'])){
-					if(stripos($v,'-'.$post['lacetype'].'-') === false){
-						continue;
-					}
-				}
-				if(!empty($post['density'])){
-					if(stripos($v,'-'.$post['density'].'-') === false){
-						continue;
-					}
-				}
-				$title = explode('|', $v);
-				$fg = str_replace(array('-163-', '-164-', '-165-', '-166-', '-0-', '-126-', '-127-', '-128-', '-197-', '-195-'), '-', $title[0]);
-				$fg = explode(',', $fg);
-				$tmp_c = $this->getCate($title[0]);
-				if (isset($fg[1])) {
-					$fg = explode('-', trim($fg[1] . $fg[0], '-'));
-				} else {
-					$fg = [];
-				}
-				$pm = array();
-				foreach ($fg as $vv) {
-					if (isset($tc[$vv]['zh'])) {
-						$zh = explode('|', trim($tc[$vv]['zh'], '|'));
-						$pm[$tc[$vv]['classid']] = $zh[0];
-					}
-				}
-				$features = str_replace(array('-163-', '-164-', '-165-', '-166-'), '-', $v);
-
-				$tsk = explode('|', trim($features, '|'));
-				if (stripos($tsk[0], ',') !== false) {
-					$ftt = explode(',', $tsk[0]);
-					$features = explode('-', trim($ftt[1], '-'));
-					$features[] = $ftt[0];
-				} else {
-					$features = explode('-', trim($tsk[0], '-'));
-				}
-				$jm = $classid;
-				$jm = $classid;
-				foreach ($features as $vv) {
-					if ($vv != 0) {
-						if (!isset($typeclass[$vv])) {
-							continue;
-						}
-						if (isset($jm[$typeclass[$vv]['classid']])) {
-							if ($typeclass[$vv]['jm']) {
-								$jm[$typeclass[$vv]['classid']] = $typeclass[$vv]['jm'];
+		if (isset($_GET['time'])) {
+			$s = $this->input->get('shop', true);
+			$time = $this->input->get('time', true);
+			$timetk = $this->input->get('timetk', true);
+			$timetj = $this->input->get('timetj', true);
+			$timetk = strtotime($timetk);
+			$timetj = strtotime($timetj);
+			if ($s) {
+				$shop = $this->shop->find_all("id = '$shop'");
+			} else {
+				$shop = $this->shop->find_all("(type = 269 or type = 2768 ) and (" . rtrim($sid, 'or') . ')');
+			}
+			$d = array();
+			$k = $timetk - 24 * 3600; //少一天为增加选择开始天时间
+			$j = $timetj;
+			$n = ($j - $k) / (24 * 3600);
+			if ($n < 1) {
+				$n = 1;
+			}
+			for ($i = 1; $i < $n; $i++) {
+				$t = $j - ($n * 24 * 60 * 60) + ($i * 24 * 60 * 60);
+				foreach ($shop as $val) {
+					$data = $this->fullorder->find_all("source != 1 and $time > '$t' and $time < '" . ($t + 24 * 3600) . "' and shop = '" . $val['id'] . "'");
+					$dd = 0;
+					$m = 0;
+					foreach ($data as $v) {
+						$customer = $this->customer->get_email($v['email'], $v['shop']);
+						$customernum = $this->fullorder->find_count("$time < '" . ($t + 24 * 3600) . "' and email = '" . $v['email'] . "' and shop = '" . $v['shop'] . "'   and  extra_status = 0 ");
+						preg_match_all('/[0-9]/u', $v['phone'], $result);
+						$numphone = join('', $result[0]);
+						//$customerc = $this->customer->find_all("shop = '".$v['shop']."' and address = '".$v['address']."' and numphone = '".$numphone."'",'*','id desc');
+						if ($customer) {
+							if ($customernum > 1) // || (isset($customerc[0]['num']) && $customerc[0]['num'] > 1) // || $customerc['type'] == 1 && $customerc['num'] > 1
+							{
+								$dd++;
+								$m += $v['shouldmoney'];
 							}
 						}
 					}
+					$ddzb = ($dd == 0 || count($data) == 0) ? 0 : sprintf("%01.2f", $dd / count($data) * 100) . '%';
+					$ddjezb = ($m == 0 || array_sum(array_column($data, 'shouldmoney')) == 0) ? 0 : sprintf("%01.2f", $m / array_sum(array_column($data, 'shouldmoney')) * 100) . '%';
+					$d[] = array(date('Y-m-d', $t), $val['shopname'], count($data), sprintf("%01.2f", array_sum(array_column($data, 'shouldmoney'))), $dd, $m, $ddzb, $ddjezb);
 				}
-				$jm = array_filter($jm); //去除空值
-				$jm = implode("-", $jm);
-				$zh = implode(" ", $pm);
-				$zh = str_replace('自然色 ', '', rtrim($zh, ' '));
-				$zh = str_replace(array('        ', '       ', '      ', '     ', '    ', '   ', '  '), ' ', $zh);
-				if (isset($title[1])) {
-					if (isset($sp[$title[1]])) {
-						$sp[$title[1]]['n'] += $title[2];
-						if (isset($sp[$title[1]]['warehouse'][$val['type']])) {
-							$sp[$title[1]]['warehouse'][$val['type']] += $title[2];
-						} else {
-							$sp[$title[1]]['warehouse'][$val['type']] = $title[2];
-						}
-						//美仓
-						if ($val['type'] == 5) {
-							$sp[$title[1]]['mc'] +=  $title[2];
-						} elseif ($val['type'] == 13) { //许昌仓
-							$sp[$title[1]]['xcc'] +=  $title[2];
-						} elseif ($val['type'] == 16) { //定制仓
-							$sp[$title[1]]['dzc'] +=  $title[2];
-						} else {
-							$sp[$title[1]]['qtc'] +=  $title[2];
-						}
-					} else {
-						$wh = explode('-', $w[$k]);
-						$wsku = $this->whlabel->find_all("number = '" . $wh[0] . "' and sku != 'Preset'");
-						$whs = (isset($wsku[0]['sku'])) ? $wsku[0]['sku'] : '';
-						$sp[$title[1]] = array('t' => $title[1], 'z' => $zh, 'c' => $tmp_c, 'w' => $whs, 'j' => $jm, 'n' => isset($title[2]) ? $title[2] : "异常 ", "warehouse" => [
-							$val['type'] => isset($title[2])? $title[2]:" 异常",
-						], "warehouse_show" => "", "xcc" => 0, "mc" => 0, "dzc" => 0, "qtc" => 0);
-						//美仓
-						if ($val['type'] == 5) {
-							$sp[$title[1]]['mc'] =  isset($title[2])? $title[2]:" 异常";
-						} elseif ($val['type'] == 13) { //许昌仓
-							$sp[$title[1]]['xcc'] = isset($title[2])? $title[2]:" 异常";
-						} elseif ($val['type'] == 16) { //定制仓
-							$sp[$title[1]]['dzc'] =  isset($title[2])? $title[2]:" 异常";
-						} else {
-							$sp[$title[1]]['qtc'] =  isset($title[2])? $title[2]:" 异常";
-						}
-					}
-				}
-
-
-
 			}
-		}
-		foreach ($sp as $k => $v) {
+			if(empty($d)){
+				exit(json_encode(array('code' => 0, 'msg' => '没有合适数据')));
+			}else{
+				$d = array_values($d);
+				$title = "老客户数据统计" . date('Y-m-d H-i-s', time());
+				echo json_encode(array('code' => 1,'msg'=>"获取成功", 'data' => $d,'filename'=>$title));
+				die;
 				
-			unset($sp[$k]['warehouse']);
-			unset($sp[$k]['warehouse_show']);
+			}
 		}
-		$sp = array_values($sp);
-		$title = "商品统计" . date('Y-m-d H-i-s', time());
-
-		echo json_encode(array('code' => 1,'msg'=>"获取成功", 'data' => $sp,'filename'=>$title));
-		die;
 	}
 
 

+ 56 - 71
template/erp/boss_qtcs.html

@@ -103,7 +103,7 @@
 <li><font class="new_bossok" onclick="bossspexcel('bossspexcel')">下载结果</font></li>
 </ul>
 
-<ul class="search excellkh" style="border-bottom: 1px solid #ccc;padding:16px 0">
+<ul class="search bosslkhexcel" style="border-bottom: 1px solid #ccc;padding:16px 0">
 <p style="color:#333;font-size: 18px;line-height:50px;">下载老客户数据: <font style="color:#888;font-size: 16px;">数据仅包含店内订单。分母:店内全部订单,分子:购买次数大于1的店内订单</font></p>
 <li>
 店铺:<select name="shop" class="select">
@@ -117,7 +117,8 @@
 <option value="dtime">订单时间</option>
 </select> :<input id="lkhk"  value="{date('Y-m-d',time()-24*3600)} 0:00" name="timetk" type="text" onClick="laydate({istime: true,format:'YYYY-MM-DD hh:mm'})" readonly>
 至&nbsp;&nbsp;&nbsp;&nbsp; <input id="lkhj" value="{date('Y-m-d',time())} 23:59" name="timetj" type="text" onClick="laydate({istime: true,format:'YYYY-MM-DD hh:mm'})" readonly></li>
-<li><font class="bossok" data-c="excellkh" data-u="excellkh" data-e="1">下载结果</font></li>
+<!-- <li><font class="new_bossok" data-c="excellkh" data-u="excellkh" data-e="1">下载结果</font></li> -->
+<li><font class="new_bossok" onclick="bosslkhexcel('bosslkhexcel')">下载结果</font></li> 
 </ul>
 
 <ul class="search excelshop" style="border-bottom: 1px solid #ccc;padding:16px 0">
@@ -319,58 +320,24 @@ var f = {}; var i = 0;
             }
         },'json')
     }
-    function bossspexcelbak(id_name){
-        let obj = {}
-        let shop = $("select[name='shop']").val();
-        if(shop){
-            obj.shop = shop;
-        }
-        let category = $("select[name='category']").val();
-        if(category){
-            obj.category = category;
-        }
-        let color = $("select[name='color']").val();
-        if(color){
-            obj.color = color;
-        }
-        let grade = $("select[name='grade']").val();
-        if(grade){
-            obj.grade = grade;
-        }
-        let lowe = $("select[name='lowe']").val();
-        if(lowe){
-            obj.lowe = lowe;
-        }
-        let density = $("select[name='density']").val();
-        if(density){
-            obj.density = density;
-        }
-        let lacetype = $("select[name='lacetype']").val();
-        if(lacetype){
-            obj.lacetype = lacetype;
-        }
-        let size = $("select[name='size']").val();
-        if(size){
-            obj.size = size;
-        }
-        let warehouse = $("select[name='warehouse']").val();
-        if(warehouse){
-            obj.warehouse = warehouse;
-        }
-        let time = $("select[name='time']").val();
-        if(time){
-            obj.time = time;
-        }
-        let timetk = $("input[name='timetk']").val();
-        if(timetk){
-            obj.timetk = timetk;
-        }
-        let timetj = $("input[name='timetj']").val();
-        if(timetj){
-            obj.timetj = timetj;
-        }
+
+    function  bosslkhexcel(id_name){
         layx.load('loadId','处理中,请稍后');
-        $.post("/boss/spexceljs",obj,function(res){
+        var f = "";
+        $("."+id_name+" input:text").each(function() {
+            var str2 = escape($(this).val());
+            str2 = $(this).val().replace(/\</g,"&lt;");
+            str2 = str2.replace(/\>/g,"&gt;");
+            str2 = str2.replace(/\+/g,"%2B");
+            str2 = str2.replace(/&/g,"%26");
+            f = f + $(this).attr("name") + "=" + str2 + "&";
+        });
+        $("."+id_name+" .select").each(function() {
+            f = f + $(this).attr("name") + "=" + $(this).children("option:selected").val() + "&";
+        });
+        
+        let url = "/boss/excellkhjs?"+f;
+        $.get(url,function(res){
             if(res.code==0){
                 layx.destroy('loadId');
                 layx.confirm('提示',res.msg,null,{
@@ -390,18 +357,17 @@ var f = {}; var i = 0;
 
                 let  list = [];
                 let  data = res.data;
+                console.log(data)
                 for(let item in data){
                     list.push({
-                        "名称":data[item].t,
-                        "中文":data[item].z,
-                        "类型":data[item].c,
-                        "SKU":data[item].w,
-                        "用友料号":data[item].j,
-                        "数量":data[item].n*1,
-                        "许昌仓发货量":data[item].xcc*1,
-                        "美仓发货量":data[item].mc*1,
-                        "定制仓发货量":data[item].dzc*1,
-                        "其他仓发货量":data[item].qtc*1,
+                        "时间":data[item][0],
+                        "店铺":data[item][1],
+                        "订单数":data[item][2],
+                        "订单金额":data[item][3],
+                        "老客户订单数":data[item][4],
+                        "老客户订单金额":data[item][5],
+                        "老客户订单占比":data[item][6],
+                        "老客户订单金额占比":data[item][7],
                     })
                 }
                 const worksheet = XLSX.utils.json_to_sheet(list);
@@ -410,23 +376,42 @@ var f = {}; var i = 0;
             
                 worksheet['!cols'] = 
                 [
-                    { wch: 80 }, 
-                    { wch: 80 },  
-                    { wch: 20 },  
-                    { wch: 20 },  
+                    { wch: 15 }, 
                     { wch: 20 },  
                     { wch: 10 },  
-                    { wch: 10 },
-                    { wch: 10 },
-                    { wch: 10 },
-                    { wch: 10 },
+                    { wch: 10 },  
+                    { wch: 15 },  
+                    { wch: 15 },  
+                    { wch: 15 },
+                    { wch: 18 },
                 ];
+
+                const range = XLSX.utils.decode_range(worksheet['!ref']);
+
+                for (let row = range.s.r; row <= range.e.r; row++) {
+                    for (let col = range.s.c; col <= range.e.c; col++) {
+                        const cellAddress = XLSX.utils.encode_cell({ r: row, c: col });
+                        
+                        if (worksheet[cellAddress]) {
+                            // 初始化样式对象
+                            worksheet[cellAddress].s = worksheet[cellAddress].s || {};
+                            worksheet[cellAddress].s.alignment = worksheet[cellAddress].s.alignment || {};
+                            
+                            // 只为前两列(名称和中文)设置自动换行
+                            if (col <= 1) { // 0=名称列, 1=中文列
+                                worksheet[cellAddress].s.alignment.wrapText = true;
+                                worksheet[cellAddress].s.alignment.vertical = 'top';
+                            }
+                        }
+                    }
+                }
                 // 将工作表添加到工作簿
                 XLSX.utils.book_append_sheet(workbook, worksheet, res.filename);
                 
                 // 导出文件
                 XLSX.writeFile(workbook, fileName);
                 layx.destroy('loadId');
+
             }
         },'json')
     }