panlumeng 3 năm trước cách đây
mục cha
commit
20d340d714

+ 1 - 1
.env

@@ -1 +1 @@
-APP_DEBUG = false

[APP]
DEFAULT_TIMEZONE = Asia/Shanghai


[LANG]
default_lang = zh-cn
+APP_DEBUG = true

[APP]
DEFAULT_TIMEZONE = Asia/Shanghai


[LANG]
default_lang = zh-cn

+ 77 - 0
application/Admin/common.php

@@ -119,3 +119,80 @@ function checkRole($roleid,$menu){
     return false;
 }
 
+function excelSave($fileName = '', $headArr = [], $data = [])
+{
+    $objPHPExcel = new PHPExcel();
+    $objPHPExcel->getProperties();
+    $keyA = 0; // 设置表头
+    foreach ($headArr as $v) {
+        $colum = PHPExcel_Cell::stringFromColumnIndex($keyA);
+        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v);
+        $keyA += 1;
+    }
+
+    $column = 2;
+    $objActSheet = $objPHPExcel->getActiveSheet();
+
+    foreach ($data as $key => $rows) { // 行写入
+        $span = 0;
+        foreach ($rows as $keyName => $value) { // 列写入
+            //判断数据是否有数组,如果有数组,转换成字符串
+
+            if(is_array($value)){
+                $value = implode("、", $value);
+            }
+            $objActSheet->setCellValue(PHPExcel_Cell::stringFromColumnIndex($span) . $column, $value);
+            $span++;
+        }
+        $column++;
+    }
+    //  var_dump($objActSheet->getActiveCell());
+    $file = $fileName. ".xls";
+    //$fileName .= "_" . date("Y_m_d", Request()->instance()->time()) . ".xls";
+    //$fileName = iconv("utf-8", "gb2312", $fileName); // 重命名表
+    $dir =ROOT_PATH. 'public/storage/report/'.date("YmdHis")."/";
+    if(!is_dir($dir)){
+        mkdir($dir,0777,true);
+    }
+    $objPHPExcel->setActiveSheetIndex(0); // 设置活动单指数到第一个表,所以Excel打开这是第一个表
+    $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
+    $objWriter->save($dir . $file); // 文件通过浏览器下载
+    $url = $dir . $file;
+    if(!file_exists($url)){
+        echo "文件生成失败";
+    }
+    $saveDir = ROOT_PATH."public/storage/zip/";
+    if(!is_dir( $saveDir)){
+        mkdir($saveDir,0777,true);
+    }
+    $datetime = date("Y-m-d H:i:s");
+    $file_dir = $saveDir.$datetime.".zip";
+    # 5.1 文件打包,提示:使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
+    $zip = new \ZipArchive ();
+    # 5.2 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip
+    if ($zip->open($file_dir, \ZipArchive::OVERWRITE) !== true && $zip->open($file_dir, \ZipArchive::CREATE) !==
+        true) echo '无法打开文件或者文件创建失败';
+
+    # 5.3 批量写入压缩包
+    $zip->addEmptyDir($fileName);
+    // @$zip->addFile($v['file_path'], 'resume'.DIRECTORY_SEPARATOR.basename($headername));
+    @$zip->addFile($url,$fileName.DIRECTORY_SEPARATOR.basename($url));
+    # 5.4 关闭压缩包写入
+    $zip->close();
+    @deldir($dir);
+    # 6. 检查文件是否存在,并输出文件
+    if (! file_exists ( $file_dir ))  echo '简历文件不存在';
+
+    ob_clean();
+    flush();
+    header("Cache-Control: max-age=0");
+    header("Content-Description: File Transfer");
+    header('Content-disposition: attachment; filename=' . basename($file_dir)); # 处理文件名
+    header("Content-Type: application/octet-stream");                           # 流文件输出
+    header("Content-Transfer-Encoding: binary");                                # 告诉浏览器,这是二进制文件
+    header('Content-Length: ' . filesize($file_dir));                           # 告诉浏览器,文件大小
+    readfile($file_dir);                                                        # 输出文件
+    @ unlink($file_dir);
+    exit();
+}
+

+ 151 - 99
application/Admin/controller/Order.php

@@ -4,55 +4,57 @@
 namespace app\Admin\controller;
 use think\Db;
 
+
 class Order extends Base
 {
- public function __construct()
- {
-     parent::__construct();
- }
+    public function __construct()
+    {
+        parent::__construct();
+    }
 
- public function list(){
-     $page = isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) : 1;
-     $size = isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :10;
-     $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']) :"";
-     $where=[];
-     if($status!==""){
-         $where['status'] = $status;
-     }
-     $username =  isset($this->post['username'])&&$this->post['username']!=="" ? trim($this->post['username']) :"";
-     if($username!=""){
-         $where['username'] = ["like","%{$username}%"];
-     }
-     $nickname =  isset($this->post['nickname'])&&$this->post['nickname']!=="" ? trim($this->post['nickname']) :"";
-     if($nickname!=""){
-         $where['nickname'] = ["like","%{$nickname}%"];
-     }
-     $mobile =  isset($this->post['mobile'])&&$this->post['mobile']!=="" ? trim($this->post['mobile']) :"";
-     if($mobile!=""){
-         $where['mobile'] = ["like","%{$mobile}%"];
-     }
-     $order_low =  isset($this->post['order_low'])&&$this->post['order_low']!=="" ? $this->post['order_low'] :"";
-     if($order_low!="") {
-         $order_low = date("Y-m-d H:i:s", strtotime($order_low . " 00:00:00"));
-     }else{
-         $order_low = "1970-01-01 00:00:00";
-     }
-     $order_up =  isset($this->post['order_up'])&&$this->post['order_up']!=="" ? $this->post['order_up'] :"";
-     if($order_up!=""){
-         $order_up = date("Y-m-d H:i:s",strtotime($order_up." 23:59:59"));
-     }else{
-         $order_up = date("Y-m-d H:i:s");
-     }
-     $where['order_time'] = ["between",[$order_low,$order_up]];
-     $count= Db::name("order")->where($where)->count();
-     $total = ceil($count/$size);
-     $page = $page>=$total? $total:$page;
-     $list = Db::name("order a")->where($where)->page($page,$size)->join("fc_order_post b","a.order_sn=b.order_sn","left")
-         ->join("fc_addr c","b.addrid = c.id","left")
-         ->join("fc_account e","a.accountid = e.id","left")
-         ->join("fc_rela_account f","a.accountid = f.accountid","left")
-         ->join("fc_account_info g","f.account_info =g.id","left")
-         ->field("`a`.`id` AS `id`,
+    public function list()
+    {
+        $page = isset($this->post['page']) && $this->post['page'] != "" ? intval($this->post['page']) : 1;
+        $size = isset($this->post['size']) && $this->post['size'] != "" ? intval($this->post['size']) : 10;
+        $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
+        $where = [];
+        if ($status !== "") {
+            $where['status'] = $status;
+        }
+        $username = isset($this->post['username']) && $this->post['username'] !== "" ? trim($this->post['username']) : "";
+        if ($username != "") {
+            $where['username'] = ["like", "%{$username}%"];
+        }
+        $nickname = isset($this->post['nickname']) && $this->post['nickname'] !== "" ? trim($this->post['nickname']) : "";
+        if ($nickname != "") {
+            $where['nickname'] = ["like", "%{$nickname}%"];
+        }
+        $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
+        if ($mobile != "") {
+            $where['mobile'] = ["like", "%{$mobile}%"];
+        }
+        $order_low = isset($this->post['order_low']) && $this->post['order_low'] !== "" ? $this->post['order_low'] : "";
+        if ($order_low != "") {
+            $order_low = date("Y-m-d H:i:s", strtotime($order_low . " 00:00:00"));
+        } else {
+            $order_low = "1970-01-01 00:00:00";
+        }
+        $order_up = isset($this->post['order_up']) && $this->post['order_up'] !== "" ? $this->post['order_up'] : "";
+        if ($order_up != "") {
+            $order_up = date("Y-m-d H:i:s", strtotime($order_up . " 23:59:59"));
+        } else {
+            $order_up = date("Y-m-d H:i:s");
+        }
+        $where['order_time'] = ["between", [$order_low, $order_up]];
+        $count = Db::name("order")->where($where)->count();
+        $total = ceil($count / $size);
+        $page = $page >= $total ? $total : $page;
+        $list = Db::name("order a")->where($where)->page($page, $size)->join("fc_order_post b", "a.order_sn=b.order_sn", "left")
+            ->join("fc_addr c", "b.addrid = c.id", "left")
+            ->join("fc_account e", "a.accountid = e.id", "left")
+            ->join("fc_rela_account f", "a.accountid = f.accountid", "left")
+            ->join("fc_account_info g", "f.account_info =g.id", "left")
+            ->field("`a`.`id` AS `id`,
 	`a`.`order_sn` AS `order_sn`,
 	`a`.`accountid` AS `accountid`,
 	`a`.`order_num` AS `order_num`,
@@ -80,64 +82,114 @@ class Order extends Base
 	`a`.`unit_weight` AS `unit_weight`,
 	`a`.`unit` AS `unit`
 	")
-         ->order("order_time desc")
-         ->select();
-     return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
+            ->order("order_time desc")
+            ->select();
+        return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
+    }
 
     /**
      * @param ordersn
      * @param post_code
      * @param post_company
      */
- public function OrderDelivery(){
-     $ordersn = isset($this->post['ordersn'])&&$this->post['ordersn']!="" ? trim($this->post['ordersn']):"";
-     if($ordersn==""){
-        return error_show(1004,"参数ordersn 不能为空");
-     }
-     $orderinfo = Db::name("order")->where(["order_sn"=>$ordersn])->find();
-     if(empty($orderinfo)){
-         return error_show(1005,"订单不存在");
-     }
-     if($orderinfo['is_del']==1){
-         return error_show(1005,"订单已删除");
-     }
-     if($orderinfo['status']!=1){
-         return error_show(1005,"订单状态有误");
-     }
-     $orderpost = Db::name("order_post")->where(["order_sn"=>$ordersn,"is_del"=>0])->find();
-     if(empty($orderpost)){
-         return error_show(1005,"订单地址信息不存在");
-     }
-     $post_code = isset($this->post['post_code'])&&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
-     if($post_code==""){
-         return error_show(1004,"参数post_code 不能为空");
-     }
-     $post_company = isset($this->post['post_company'])&&$this->post['post_company']!="" ? trim($this->post['post_company']):"";
-     if($post_company==""){
-         return error_show(1004,"参数post_company 不能为空");
-     }
-     $orderpost['post_code']=$post_code;
-     $orderpost['post_name']=$post_company;
-     $orderpost['updatetime']=date("Y-m-d H:i:s");
-     Db::startTrans();
-     try {
-         $psot=Db::name("order_post")->update($orderpost);
-         if($psot){
-             $orderinfo['status']=2;
-             $orderinfo['delivery_time']=date("Y-m-d H:i:s");
-            $order= Db::name("order")->update($orderinfo);
-            if($order){
-                write_log("订单{$ordersn}发货",$this->userinfo,"order","edit","0");
-                Db::commit();
-                return app_show(0,"订单物流信息新建成功");
+    public function OrderDelivery()
+    {
+        $ordersn = isset($this->post['ordersn']) && $this->post['ordersn'] != "" ? trim($this->post['ordersn']) : "";
+        if ($ordersn == "") {
+            return error_show(1004, "参数ordersn 不能为空");
+        }
+        $orderinfo = Db::name("order")->where(["order_sn" => $ordersn])->find();
+        if (empty($orderinfo)) {
+            return error_show(1005, "订单不存在");
+        }
+        if ($orderinfo['is_del'] == 1) {
+            return error_show(1005, "订单已删除");
+        }
+        if ($orderinfo['status'] != 1) {
+            return error_show(1005, "订单状态有误");
+        }
+        $orderpost = Db::name("order_post")->where(["order_sn" => $ordersn, "is_del" => 0])->find();
+        if (empty($orderpost)) {
+            return error_show(1005, "订单地址信息不存在");
+        }
+        $post_code = isset($this->post['post_code']) && $this->post['post_code'] != "" ? trim($this->post['post_code']) : "";
+        if ($post_code == "") {
+            return error_show(1004, "参数post_code 不能为空");
+        }
+        $post_company = isset($this->post['post_company']) && $this->post['post_company'] != "" ? trim($this->post['post_company']) : "";
+        if ($post_company == "") {
+            return error_show(1004, "参数post_company 不能为空");
+        }
+        $orderpost['post_code'] = $post_code;
+        $orderpost['post_name'] = $post_company;
+        $orderpost['updatetime'] = date("Y-m-d H:i:s");
+        Db::startTrans();
+        try {
+            $psot = Db::name("order_post")->update($orderpost);
+            if ($psot) {
+                $orderinfo['status'] = 2;
+                $orderinfo['delivery_time'] = date("Y-m-d H:i:s");
+                $order = Db::name("order")->update($orderinfo);
+                if ($order) {
+                    write_log("订单{$ordersn}发货", $this->userinfo, "order", "edit", "0");
+                    Db::commit();
+                    return app_show(0, "订单物流信息新建成功");
+                }
             }
-         }
-         Db::rollback();
-         return error_show(1004,"物流信息新建失败");
-     }catch (\Exception $e){
-         Db::rollback();
-         return error_show(1004,$e->getMessage());
-     }
- }
+            Db::rollback();
+            return error_show(1004, "物流信息新建失败");
+        } catch (\Exception $e) {
+            Db::rollback();
+            return error_show(1004, $e->getMessage());
+        }
+    }
+
+    public function uploud()
+    {
+        $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start']."00:00:00" :"";
+        $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end']."23:59:59" :"";
+        $where='';
+        if($start!==""){
+            $where.=" and addtime >='{$start}'";
+        }
+        if($end!==""){
+            $where.=" and addtime <= '{$end}'" ;
+        }
+        $sql = "SELECT
+	a.order_sn  '订单编号',
+	a.order_num '订单数量',
+	a.order_time '下单时间',
+	a.unit_weight '总重量',
+	a.STATUS,
+	a.delivery_time '发货时间',
+	b.post_code '快递编号',
+	b.post_name '快递公司',
+	k.username '账户名',
+	c.addr '收货地址',
+	c.provice_name '省级名称',
+	c.city_name '市级名称',
+	c.area_name '县区名称',
+	c.contector '收货人',
+	c.mobile '收货电话',
+	v.nickname '用户名',
+	v.mobile AS '用户电话'
+FROM
+	fc_order a
+	LEFT JOIN fc_order_post b ON b.order_sn = a.order_sn
+	LEFT JOIN fc_addr c ON c.id = b.addrid
+	LEFT JOIN fc_account k ON k.id = a.accountid
+	LEFT JOIN fc_rela_account n ON n.accountid = a.accountid
+	LEFT JOIN fc_account_info v ON v.id = n.account_info 
+    ";
+        $list = Db::query($sql);
+        if(empty($list)){
+            $list=[["未找到数据"=>""]];
+        }
+        $header = array_keys($list[0]);
+        array_walk($list, function (&$v) {
+            $v = array_values($v);
+        });
+        excelSave(date("Y-m-d",strtotime($start)).'至'.date("Y-m-d",strtotime($end))."未发货订单", $header, $list);
+    }
+
 }

+ 1 - 0
application/route.php

@@ -40,6 +40,7 @@ Route::rule('admin/checkpwd','Admin/Account/checkPwd');
 
 Route::rule('admin/orderlist','Admin/Order/list');
 Route::rule('admin/orderdelivery','Admin/Order/OrderDelivery');
+Route::rule('admin/orderuploud','Admin/Order/uploud');
 
 Route::rule('admin/stocklist','Admin/Stock/StockList');
 Route::rule('admin/stocksave','Admin/Stock/Save');

+ 2 - 1
composer.json

@@ -17,7 +17,8 @@
     ],
     "require": {
         "php": ">=5.4.0",
-        "topthink/framework": "5.0.*"
+        "topthink/framework": "5.0.*",
+        "phpoffice/phpexcel": "^1.8"
     },
     "autoload": {
         "psr-4": {

+ 1 - 5
thinkphp/library/think/App.php

@@ -501,11 +501,7 @@ class App
 
         if ($config['app_multi_module']) {
             // 多模块部署
-            if($convert){ //增加模块的大小写是否自动转换的功能
-                $module    = strip_tags(strtolower($result[0] ?: $config['default_module']));
-            }else{
-                $module    = strip_tags($result[0] ?: $config['default_module']);
-            }
+            $module    = strip_tags(strtolower($result[0] ?: $config['default_module']));
             $bind      = Route::getBind('module');
             $available = false;
 

+ 1 - 1
thinkphp/library/think/db/Connection.php

@@ -117,7 +117,7 @@ abstract class Connection
         PDO::ATTR_CASE              => PDO::CASE_NATURAL,
         PDO::ATTR_ERRMODE           => PDO::ERRMODE_EXCEPTION,
         PDO::ATTR_ORACLE_NULLS      => PDO::NULL_NATURAL,
-        PDO::ATTR_STRINGIFY_FETCHES => true,
+        PDO::ATTR_STRINGIFY_FETCHES => false,
         PDO::ATTR_EMULATE_PREPARES  => false,
     ];