joyo 发布的文章

最近在使用fastadmin框架(tp5.1)实现后台的基本功能,在selectpage需要显示更多信息,根据文档信息进行改造实现以下功能:

A-1.png

分别在控制器、以及view文件进行改造。

controller 控制器代码部分

#增加显示更多字段
protected $selectpageFields = "id,batch_number,coupons_date,coupons_money,coupons_remain";

View 视图部分 本实例在add.html

                <div class="col-xs-12 col-sm-8">
                    <input id="c-batch_number" data-rule="required" data-source="Batch/selectpage" class="form-control selectpage" name="row[batch_number]" type="text" value="" data-primary-key="batch_number" data-field="batch_number" data-format-item="{batch_number}-(有效期:{coupons_date}-剩余:{coupons_remain})">
                </div>

记录之,方便后期使用。

如出现乱码,请以utf-8文件编码保存

            #redis 统计访问量
        $redis = new \Redis();
        $redis_conf = config('redis');
        $redis->connect($redis_conf['host'],$redis_conf['port']);
        $redis_status =$redis->auth($redis_conf['password']) or false;
        if($redis_status){
              $redis->select($redis_conf['select']);
              $activity_id=$this->activity_id;
              #记录日访问
              $daily =$activity_id.'-'.date("Y-m-d");
              $viskey = $redis->exists($daily);
              $value =$redis->get($daily);
              if($viskey){
                 $redis->incr($daily);
              }else{
                 $redis->set($daily,1);
              }
        }

面对日益增大的数据表容量,mysql查询性能也随之下降。这时候就需要寻找一套解决方案来应对将来的局面。根据网络的过往经验,现将一些基本规范进行总结归纳。方便日后所用。

尽量用单表查询,禁止多于3表的join查询
禁止使用select * from 语句,尽量只或许需要的字段。
避免冗余的排序
全模糊查询无法使用索引,应尽可能避免
使用in代替or
禁止隐式装换
禁止使用负项查询 如not in , not like ,!=这种

controller

/**

  • 自定义selectpage
    */

public function select_goods(){

list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
            ->with(['goodslists'])
            ->field('goodslists.name as name,goods_id')
            ->where($where)
            ->order($sort, $order)
            ->paginate($limit);
    $result = array("total" => $list->total(), "rows" => $list->items());
    return json($result);

}

model

public function goodslists()
{

return $this->belongsTo('app\admin\model\gascard\Goods', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);

}