function import()
 {
     $model = $this->getModel('import');
     if (IS_POST) {
         $column = array('A' => 'uid', 'B' => 'credit_title', 'C' => 'score', 'D' => 'cTime');
         $attach_id = I('attach', 0);
         $dateCol = array('D');
         $res = importFormExcel($attach_id, $column, $dateCol);
         if ($res['status'] == 0) {
             $this->error($res['data']);
         }
         $total = count($res['data']);
         $uidStr = '';
         foreach ($res['data'] as $vo) {
             $uidStr .= $vo['uid'] . ',';
             if (empty($vo['credit_title'])) {
                 $vo['credit_title'] = '手动导入';
             }
             if (empty($vo['cTime'])) {
                 $vo['cTime'] = time();
             } else {
                 $vo['cTime'] = strtotime($vo['cTime']);
             }
             add_credit('auto_add', 0, $vo);
         }
         $msg = "共导入" . $total . "条记录";
         // dump($arr);
         // $msg = trim ( $msg, ', ' );
         // dump($msg);exit;
         $this->success($msg, U('lists', array('uid' => $uidStr)));
     } else {
         $fields = get_model_attribute($model['id']);
         $this->assign('fields', $fields);
         $this->assign('post_url', U('import'));
         $this->assign('import_template', 'score_import.xls');
         $this->display('Addons/import');
     }
 }
Exemplo n.º 2
0
 function import()
 {
     $model = $this->getModel('import');
     if (IS_POST) {
         $column = array('A' => 'name', 'B' => 'phone', 'C' => 'address');
         $attach_id = I('attach', 0);
         $res = importFormExcel($attach_id, $column);
         if ($res['status'] == 0) {
             $this->error($res['data']);
         }
         $total = count($res['data']);
         foreach ($res['data'] as $vo) {
             if (empty($vo['name'])) {
                 $this->error('店名不能为空');
             }
             if (empty($vo['address'])) {
                 $this->error('详细地址不能为空');
             }
             $vo['token'] = get_token();
             $vo['manager_id'] = $this->mid;
             $r = M('coupon_shop')->add($vo);
         }
         $msg = "共导入" . $total . "条记录";
         // dump($arr);
         // $msg = trim ( $msg, ', ' );
         // dump($msg);exit;
         $this->success($msg, U('lists') . '&mdm=' . I('get.mdm'));
     } else {
         $fields = get_model_attribute($model['id']);
         $this->assign('fields', $fields);
         $this->assign('post_url', U('import') . '&mdm=' . I('mdm'));
         $this->assign('import_template', 'coupon_shop.xls');
         $this->display(T('Addons/import'));
     }
 }