• 导入


    第一部分  判断和分页展示数据到前台

      public function executeIndex()
          {
            $this->statusArr = array('1' => '已充值', '0' => '未充值');
            //分页
            $this->size = $this->getRequestParameter('size') ? $this->getRequestParameter('size') : 10;
            $this->currentpage = $this->getRequestParameter('page');
            if ($this->currentpage) {
                    $page = ($this->currentpage - 1) * $this->size;
            } else {
                    $page = 0;
                    $this->currentpage = 1;
            }
            $this->typelist= [
              1=> '10元',
              2=> '20元',
              3=> '5元'
            ];
            //列表信息
            $c = new Criteria();
            $c->add(WhiteCouponPeer::ACCOUNT_ID, $this->account_id);
            if ($this->getRequest()->getMethod() == sfRequest::POST) {
                    $this->status = trim($this->getRequestParameter('status'));
                    $this->mobile = trim($this->getRequestParameter('mobile'));
                    $this->start = trim($this->getRequestParameter('start'));
                    $this->end = trim($this->getRequestParameter('end'));
                    if ($this->mobile) {
                            $c->add(WhiteCouponPeer::MOBILE, '%' . $this->mobile . '%', Criteria::LIKE);
                    }
                    if (strlen($this->status) > 0) {
                            $c->add(WhiteCouponPeer::IS_CHARGE, $this->status);
                    }
    
                    if ($this->start) {
                            $c->add(WhiteCouponPeer::CHARGE_TIME, $this->start . " 00:00:00", Criteria::GREATER_EQUAL);
                    }
                    if ($this->end) {
                            $c->addAnd(WhiteCouponPeer::CHARGE_TIME, $this->end . " 23:59:59", Criteria::LESS_EQUAL);
                    }
            }
            $c->addDescendingOrderByColumn(WhiteCouponPeer::ID);
            $this->totalCount = WhiteCouponPeer::doCount($c);
            $c->setOffset($page);
            $c->setLimit($this->size);
            $this->ShipmentList = WhiteCouponPeer::doSelect($c);
            // var_dump($this->ShipmentList);die;
            $this->totalPage = ceil($this->totalCount / $this->size);
            unset($orderArr);
          }

    第二部分 导入数据接口

      public function executeOrder($request){
        if ($this->getRequest()->getMethod() == sfRequest::POST) {
          if ($this->getRequest()->hasFiles()) {
            foreach ($this->getRequest()->getFileNames() as $uploadedFile) {
                    $fileNameupload = $request->getFileName($uploadedFile);
                    if ($fileNameupload) {
                            $uploadfileName = $this->getRequest()->getFileName($uploadedFile);    
                            if ($uploadfileName) {
                                    $arr = explode(".", $uploadfileName);
                                    $postfix = end($arr);//取csv
                            }
                            $batchNo = date('YmdHis') . rand(1000, 9999);
                            // var_dump($batchNo);die;
                            if ($postfix == 'csv') {
                              $fileName = "7777" . rand(100, 999) . time() . rand(100, 999) . "." . $postfix;
                              // var_dump($fileName);die;
                              $fileSize = $this->getRequest()->getFileSize($uploadedFile);
                              $fileError = $this->getRequest()->hasFileError($uploadedFile);
                              // var_dump($fileError);die;
                              $uploadDir = sfConfig::get('sf_upload_dir');
                              //  var_dump($uploadDir);die;
                              $this->getRequest()->moveFile($uploadedFile, $uploadDir . '/' . $fileName);
                              // echo 11;die;
                              if (!file_exists($uploadDir . '/' . $fileName)) {
                                      $this->showAlert('文件上传失败');
                              }
                              $row = 1;
                              $db = Helper::getDb();
                              if (($handle = fopen($uploadDir . '/' . $fileName, "r")) !== FALSE) {
                                      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                                              if (!is_numeric($data[0])) {
                                                      //Helper::logWeb()->addInfo('deliver no', $data);
                                                      continue;
                                              }
                                              $db->insert('white_coupon', [
                                                  'mobile' => trim($data[0]),
                                                  'total_amount' =>trim($data[1]),
                                                  'type' => $data[2],
                                                  'created_at' => date("Y-m-d H:i:s")
                                              ]);
                                              // var_dump($data);die;
                                      }
                                      fclose($handle);
                              }
                                  $this->showAlert('上传成功');
                                } else {
                                        $this->showAlert('文件格式错误,仅支持csv格式');
                                }
                        } else {
                                $this->showAlert('未获取到文件信息');
                        }
                }
                  $this->redirect('caches/index');
          } else {
                  $this->showAlert('请选择要上传的文件');
          }
        }
        // return sfView::NONE;
      }

     第三部分 showAlert封装 否则$this->showAlert()直接报错

      public function showAlert($msg) {
        $jumpUrl = $this->getController()->genUrl('caches/index');
        $str = '<meta charset="UTF-8">';
        $str .= '<script>alert("' . $msg . '"); location.href="' . $jumpUrl . '"; </script>';
        exit($str);
      }

    第四部分 前台展示   

    <table class="table table-striped table-bordered table-hover dataTables-example dataTable" id="DataTables_Table_0" >
     <thead>
      <tr>
        <th width="5">
                <input id="btSelectAll" type="checkbox"  class="i-checks" >
                </th>
                   <th>11111</th>
                   <th>11111</th>
                   <th>11111</th>
                   <th>11111</th>
                   <th width="100">操作</th>
                </tr>
        </thead>
              <tbody>
           <?php
        if($ShipmentList):
          foreach($ShipmentList as $list):
        ?>
       <tr class="gradeA">
              <td><input type="checkbox"  class="i-checks" name="input[]"></td>
              <td><?php echo $list->getMobile()?></td>
              <td><?php echo $list->getTotalAmount()?></td>
              <td><?php echo $typelist[$list->gettype()]?></td>
              <td><?php echo $list->getCreatedAt()?></td>
              <td class="center">
              <a href="javascript:void ;" onclick="url_for(<?php echo $list->getId();?>)" class="btn btn-white btn-sm text-info"><i class="fa fa-edit"></i>&nbsp;编辑</a>
              <a href="javascript:void ;" onclick="elem_del(<?php echo $list->getId();?>)" class="btn btn-white btn-sm text-danger"><i class="fa fa-eye"></i>&nbsp;删除</a>
            <button type="button" class="btn btn-white btn-sm text-success" onclick="javascript:window.location.href='<?php echo url_for('logistics/details?slipment_id='.$list->getId().'&page='.$currentpage)?>'"><i class="fa fa-eye"></i>&nbsp;详情</button>
         </td>
        </tr>                           
        <?php endforeach;else:?>
            <tr class="gradeA">
              <td colspan="9" style="text-align: center;">没有充值信息!</td>
            </tr>
        <?php endif;?>                                    
     </tbody>
    </table>                                                                                
  • 相关阅读:
    爬虫助手spider_tool-JUN
    frida 保存打印日志到本地
    frida get_frontmost_application报错
    adb shell安装证书/修改证书到系统级/
    利用celery进行分布式爬虫
    vscode Go插件安装失败解决方法,亲测2020.10.15
    Frida hook map集合遍历和修改
    frida_rpc dou音、饿le么 header加密
    Frida入门
    adb连接模拟器
  • 原文地址:https://www.cnblogs.com/zyx0623/p/13389188.html
Copyright © 2020-2023  润新知