Your Name 3 jaren geleden
bovenliggende
commit
5c25be495e
2 gewijzigde bestanden met toevoegingen van 69 en 2 verwijderingen
  1. 8 2
      service/mail/database/area_entry.php
  2. 61 0
      service/mail/lib/Manage.php

+ 8 - 2
service/mail/database/area_entry.php

@@ -1,5 +1,10 @@
 <?php
-
+$excel = false;
+$button = array();
+if (Dever::load('manage/auth')->checkFunc('mail.area_entry', 'editareaentry', '数据导出')) {
+    $excel[] = array('数据导出','数据导出','mail/lib/manage.out_area_entry');
+    $button['数据导入'] = array('fast', '', 'import&project=upload&call=mail/lib/manage.import');
+}
 return array
 (
     # 表名
@@ -95,7 +100,8 @@ return array
         // 'insert' => false,
         'delete' => false,
         // 'edit' => false,
-        // 'excel' => true,
+        'excel' => $excel,
+        'button' => $button,
     ),
 
     'request' => array

+ 61 - 0
service/mail/lib/Manage.php

@@ -1110,4 +1110,65 @@ class Manage
             Dever::db('mail/area_entry')->update($where);
         }
     }
+
+    public function out_area_entry($data)
+    {
+        $header = array('月份','门店名称','门店编号','毛利');
+        $body = array();
+        if ($data) {
+            // print_R($data);die;
+            foreach ($data as $k => $v) {
+                $shop_name = '';
+                $sid = '';
+                $month = '';
+                if ($v['month']) {
+                    $month = date('Y-m',$v['month']);
+                }
+                $shop = Dever::db('shop/info')->find($v['shop_id']);
+                if ($shop) {
+                    $shop_name = $shop['name'];
+                    $sid = $shop['sid'];
+                }
+                // print_R($shop);die;
+                $d = array
+                (
+                    $month,
+                    $shop_name,
+                    $sid,
+                    $v['buy'],
+                );
+                $body[] = $d;
+            }
+            $file = Dever::input('excel_name');
+            return Dever::excelExport($body, $header, $file);
+        }
+    }
+    public function import($file)
+    {
+        $file = Dever::local($file);
+        $data = Dever::excelImport($file,0);
+        if ($data) {
+            $res = array();
+            foreach($data as $k=>$v){
+                if ($k>=2) {
+                    if ($v['A']) {
+                        $where['month'] = strtotime($v['A']);
+                    }
+                    if ($v['C']) {
+                        $v['C'] = trim($v['C']);
+                        $shop = Dever::db('shop/info')->find(array('sid'=>$v['C']));
+                        if ($shop) {
+                            $where['shop_id'] = $shop['id'];
+                        }
+                    }
+                    if ($v['D']) {
+                        $where['buy'] = $v['D'];
+                    }
+                    if ($where) {
+                        Dever::db('mail/area_entry')->insert($where);
+                    }
+                } 
+            }
+        }
+    }
 }