Kaynağa Gözat

修改高级其它的导出

lvhao 1 hafta önce
ebeveyn
işleme
673564d82a
2 değiştirilmiş dosya ile 147 ekleme ve 3 silme
  1. 58 1
      core/CoreApp/controllers/Boss.php
  2. 89 2
      template/erp/boss_qtcs.html

+ 58 - 1
core/CoreApp/controllers/Boss.php

@@ -100,7 +100,9 @@ class Boss extends Start_Controller
 			$this->_spexceljs();	
 		}else if($arg == 'excellkhjs'){
 			$this->_excellkhjs();	
-		} else {
+		}else if ($arg == 'excelshopjs') {
+			$this->_excelshopjs();
+		}  else {
 			$this->_index();
 		}
 	}
@@ -1618,6 +1620,61 @@ class Boss extends Start_Controller
 		}
 	}
 
+	public function _excelshopjs()
+	{
+		if (isset($_SESSION['api'])) {
+			$user = $this->user->get_api($_SESSION['api']);
+			$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";
+			}
+		}
+		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("$time > '$t' and $time < '" . ($t + 24 * 3600) . "' and shop = '" . $val['id'] . "'");
+					$dd = 0;
+					$m = 0;
+					$d[] = array(date('Y-m-d', $t), $val['shopname'], count($data), sprintf("%01.2f", array_sum(array_column($data, 'shouldmoney'))));
+				}
+			}
+			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;
+				
+			}
+		}
+	}
+
 
 
 

+ 89 - 2
template/erp/boss_qtcs.html

@@ -121,7 +121,7 @@
 <li><font class="new_bossok" onclick="bosslkhexcel('bosslkhexcel')">下载结果</font></li> 
 </ul>
 
-<ul class="search excelshop" style="border-bottom: 1px solid #ccc;padding:16px 0">
+<ul class="search bossshopexcel" 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;">数据包含本店全部订单,含店内单和线下单。</font></p>
 <li>
 店铺:<select name="shop" class="select">
@@ -135,7 +135,8 @@
 <option value="dtime">订单时间</option>
 </select> :<input id="outk"  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="outj" 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="excelshop" data-u="excelshop" data-e="1">下载结果</font></li>
+<!-- <li><font class="bossok" data-c="excelshop" data-u="excelshop" data-e="1">下载结果</font></li> -->
+<li><font class="new_bossok" onclick="bossshopexcel('bossshopexcel')">下载结果</font></li>
 </ul>
 
 <ul class="search excelpass" style="border-bottom: 1px solid #ccc;padding:16px 0">
@@ -414,6 +415,92 @@ var f = {}; var i = 0;
             }
         },'json')
     }
+
+    function bossshopexcel(id_name){
+        layx.load('loadId','处理中,请稍后');
+        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/excelshopjs?"+f;
+        $.get(url,function(res){
+            if(res.code==0){
+                layx.destroy('loadId');
+                layx.confirm('提示',res.msg,null,{
+                    buttons:[
+                        {
+                            label:'确定',
+                            callback:function(id, button, event){
+                            
+                                layx.destroy(id);
+                            }
+                        }
+                    ],dialogIcon:'error',shadable:0.6
+                });
+            }else{
+                const fileName = res.filename+'.xlsx' ;
+                // 将数据转换为工作表
+
+                let  list = [];
+                let  data = res.data;
+                for(let item in data){
+                    list.push({
+                        "时间":data[item][0],
+                        "店铺":data[item][1],
+                        "订单数":data[item][2],
+                        "订单金额":data[item][3],
+                    })
+                }
+                const worksheet = XLSX.utils.json_to_sheet(list);
+                // 创建工作簿
+                const workbook = XLSX.utils.book_new();
+            
+                worksheet['!cols'] = 
+                [
+                    { wch: 15 }, 
+                    { wch: 20 },  
+                    { wch: 10 },  
+                    { wch: 10 },  
+                ];
+
+                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')
+    }
  </script>
  <script type="text/javascript" src="{$theme}js/excel/xlxs.js" ></script>
 {Template footer}