当前位置:

微赞微擎常用其他函数 媒体文件路径格式化|日期范围|城市地址|Excel导入

本文最后更新于2019-06-26,已超过 1年没有更新,如果文章内容、图片或者下载资源失效,请留言反馈,我会及时处理,谢谢!

温馨提示:本文共4134个字,读完预计11分钟。

  • 格式化图片路径:tomedia($src, $local_path = false)

函数路径:framework\function\global.func.php

PHP中引用

$picurl = tomedia($coupon[“respthumb”]);

模板页面引用

<td style='width:80px;'>
        <img src='" . tomedia($item[$options[‘thumb’]]) . "' style='width:70px;border:1px solid #ccc;padding:1px'>
</td>

eweishopV3 格式化媒体路径函数:set_medias($list = array(), $fields = null)

函数路径:addons\ewei_shopv2\core\inc\functions.php

PHP中引用

$list = set_medias($list, "thumb");

$coupons = set_medias(pdo_fetchall($sql, $param), "thumb");

$packages = set_medias($packages, array("thumb"));

$ds = set_medias($ds, array('thumb', 'advimg'));

  • 日期范围:tpl_form_field_daterange($name, $value = array(), $time = false)

模板页面引用 

<div class="form-group">
       <label class="col-xs-12 col-sm-3 col-md-2 control-label">日期范围</label>
       <div class="col-sm-6 col-xs-12 col-lg-8 col-xs-12">
            {php echo tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d', $starttime),'endtime'=>date('Y-m-d', $endtime)));}
       </div>
       <div class="pull-right col-xs-12 col-sm-3 col-lg-2">
            <button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
       </div>
</div>

  • 城市地址:tpl_form_field_district($name, $values = array())

 模板页面引用 

<div class="form-group">
   <label class="col-sm-2 control-label">收货地址</label>
 <div class="col-sm-9 col-xs-12">
            {php echo tpl_form_field_district("addaddress");}
      </div>
</div>

<div class="form-group">
       <label class="col-sm-2 control-label">收货地址</label>
       <div class="col-sm-9 col-xs-12">
            {php echo tpl_form_field_district("addaddress", array('province' => $_GPC[‘record’][‘province’], ‘city’ => $_GPC[‘record’][‘city’], ‘district’ => $_GPC[‘record’][‘district’]));}
       </div>
</div>

  •  获取input name的值
var buynumber = $('input[name^='buynumber']').map(function(){return this.value}).get();

$('input[name='nw']').val();
  •  循环覆盖

 foreach($list as $key => &$value){

$bnumber= pdo_fetchcolumn('SELECT COUNT(*) FROM '.tablename('bc_party_payment').' WHERE status = 1 AND partyid = '.$value['id'] );

$value['bbnumber']=$bnumber; 

}

  •  人人弹窗

 示例1:

t.confirm('确认要支付吗?', function () {

})

示例2:

tip.confirm('确认要支付吗?', function () {

})
  •  excel导入模板

<form action='{php echo $this->createWebUrl('excel', array());}' method='post' class='form-horizontal' role='form' enctype='multipart/form-data' onsubmit='return formcheck()'>
    <div class='form-group'>
       <label class='col-xs-2 control-label'>文件</label>
       <div class='col-xs-4 '>
           <input type='file' class='form-control' name='file' value='' />
       </div>
   <div class='col-xs-2'>
       <button class='btn btn-default'><i class='fa fa-search'></i> 导入</button>
   </div>
   <div class='col-xs-4'>
       <a class='btn btn-primary' href='{$_W[‘attachurl’]}phone.xls'>下载导入模板</a>
   </div>
  </div>
</form>

隐藏上传文件

PHP:::::

$url = $this->createWebUrl('eggManage',array());
  $file = $_FILES['file'];
  if(!$file['size']){
   message('文件上传不能为空!',  '', 'error');
  }
  if( $file['name'] && $file['error'] == 0){
   $type = @end( explode('.', $file['name']));
   $type = strtolower($type);
   if( !in_array($type, array('xls','xlsx')) ){
    message('文件类型错误!',  '', 'error');
   }
   set_time_limit(0);
   include_once IA_ROOT . '/framework/library/phpexcel/PHPExcel.php';
   include_once IA_ROOT . '/framework/library/phpexcel/PHPExcel/IOFactory.php';
   if( $type == 'xls' ){
    $inputFileType = 'Excel5';    //这个是读 xls的
   }else{
    $inputFileType = 'Excel2007';//这个是计xlsx的
   }
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($file['tmp_name']);
$sheet = $objPHPExcel->getSheet(0);
 //获取行数与列数,注意列数需要转换
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$highestColumnNum = PHPExcel_Cell::columnIndexFromString($highestColumn);
$usefullColumnNum = $highestColumnNum;
for ($row = 2;$row <= $highestRow;$row++){
$tel = $sheet->getCellByColumnAndRow(0, $row)->getValue();//身份证
    $data = array(
'tel' => $tel,
);
pdo_insert('mon_egg_success',$data);
   }
   message('导入成功', $url,'success');
  }else{
   message('导入失败', '','error');
  }
本文链接:,转发请注明来源!
评论已关闭。