如何开发陪玩系统源码的列表页面,相关实现代码

如何开发陪玩系统源码的列表页面,相关实现代码

在陪玩系统源码开发过程中,需要实现的列表页面还是非常多的,如何保证列表页面的流畅、整洁很重要,接下来我们一起来看看具体的实现代码吧。route.php<?phpusethink\Route;Route::get('test','api/test/index');Route::put('test/:id','api/test/update');Route::delete('test/:id','api/test/delete');Route::resource('test','api/test');Route::get('api/:ver/cat','api/:ver.cat/read');Route::get('api/:ver/index','api/:ver.index/index');Route::resource('api/:ver/news','api/:ver.news');News.php(Model)<?php/***CreatedbyPhpStorm.*User:tong*Date:2017/11/20*Time:16:34*/namespaceapp\common\model;classNewsextendsBase{publicfunctiongetNews($data=[]){$data['status']=['neq',config('code.status_delete'),];$order=['id'=>'desc'];$result=$this->where($data)->order($order)->paginate();return$result;}publicfunctiongetNewsByCondition($condition=[],$from,$size=5){if(!isset($condition['status'])){$condition['status']=['neq',config('code.status_delete')];}$order=['id'=>'desc'];$result=$this->where($condition)->field($this->getListField())->limit($from,$size)->order($order)->select();return$result;}publicfunctiongetNewsByCountCondition($condition=[]){if(!isset($condition['status'])){$condition['status']=['neq',config('code.status_delete')];}return$this->where($condition)->count();}publicfunctiongetIndexHadNormalNews($num=4){$data=['status'=>1,'is_head_figure'=>1,];$order=['id'=>'desc',];return$this->where($data)->field($this->getListField())->order($order)->limit($num)->select();}publicfunctiongetPositionNormalNews($num=20){$data=['status'=>1,'is_position'=>1,];$order=['id'=>'desc',];return$this->where($data)->field($this->getListField())->order($order)->limit($num)->select();}privatefunctiongetListField(){return['id','catid','image','title','read_count','status','is_position','update_time','create_time',];}}->field($this->getListField())privatefunctiongetListField(){return['id','catid','image','title','read_count','status','is_position','update_time','create_time',];}Common.php<?php/***CreatedbyPhpStorm.*User:tong*Date:2017/11/23*Time:11:30*/namespaceapp\api\controller;useapp\common\lib\Aes;useapp\common\lib\exception\ApiException;useapp\common\lib\IAuth;useapp\common\lib\Time;usethink\Cache;usethink\Controller;classCommonextendsController{public$headers='';public$page=1;public$size=5;public$from=0;protectedfunction_initialize(){$this->checkRequestAuth();//$this->testAes();}publicfunctioncheckRequestAuth(){$headers=request()->header();if(empty($headers['sign'])){thrownewApiException('sign不存在',400);}if(!in_array($headers['app_type'],config('app.apptypes'))){thrownewApiException('app_type不合法',400);}if(!IAuth::checkSignPass($headers)){thrownewApiException('授权码sign失败',401);}Cache::set($headers['sign'],config('app.app_sign_cache_time'));$headers=$this->headers;}publicfunctiontestAes(){$data=['did'=>'12345dg','version'=>1,'time'=>Time::get13TimeStamp(),];//$str='sRCvj52mZ8G+u2OdHYwmysvczmCw+RrAYWiEaXFI/5A=';//echo(newAes())->decrypt($str);//exit;echoIAuth::setSign($data);exit;}publicfunctiongetDealNews($news=[]){if(empty($news)){return[];}$cats=config('cat.list');foreach($newsas$key=>$new){$news[$key]['catname']=$cats[$new['catid']]?$cats[$new['catid']]:'-';}return$news;}publicfunctiongetPageAndSize($data){$this->page=!empty($data['page'])?$data['page']:1;$this->size=!empty($data['size'])?$data['size']:config('paginate.list_rows');$this->from=($this->page-1)*$this->size;}}public$page=1;public$size=5;public$from=0;publicfunctiongetPageAndSize($data){$this->page=!empty($data['page'])?$data['page']:1;$this->size=!empty($data['size'])?$data['size']:config('paginate.list_rows');$this->from=($this->page-1)*$this->size;}News.php(Controller)<?php/***CreatedbyPhpStorm.*User:tong*Date:2017/11/23*Time:17:03*/namespaceapp\api\controller\v1;useapp\api\controller\Common;classNewsextendsCommon{publicfunctionindex(){//仿照之前讲解的validate验证机制做相关检验$data=input('get.');$whereData['status']=config('code.status_normal');$whereData['catid']=input('get.catid');$this->getPageAndSize($data);$total=model('News')->getNewsByCountCondition($whereData);$news=model('News')->getNewsByCondition($whereData,$this->from,$this->size);$result=['total'=>$total,'page_num'=>ceil($total/$this->size),'list'=>$this->getDealNews($news),];returnshow(1,'OK',$result,200);}}以上就是“陪玩系统源码开发,如何实现列表页面的开发?”的全部内容,陪玩系统源码的开发不是一蹴而就的,在开发完成只有还需要不断的进行优化和更新,希望本篇内容能为大家开发陪玩系统源码提供一些帮助。本文转载自网络,转载仅为分享干货知识,如有侵权欢迎联系云豹科技进行删除处理

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Proudly powered by WordPress | Theme: HoneyWaves by SpiceThemes