123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- <?php
- namespace app\api\controller;
- use app\common\model\Config;
- use app\common\model\User;
- use app\common\controller\Api;
- use hg\apidoc\Parser;
- use PhpOffice\PhpWord\Template;
- use PhpOffice\PhpWord\TemplateProcessor;
- use setasign\Fpdi\PdfParser\PdfParser;
- use think\Db;
- use think\facade\Validate;
- use function Sodium\add;
- use Mpdf\Mpdf;
- /**
- * @title 首页
- * @controller Index
- */
- class Index extends Api
- {
- protected $arr=[
- '一年内'=>[0,13],
- '1~2年'=>[11,25],
- '2~3年'=>[23,37],
- '3年以上'=>[35,999999],
- ];
- protected $arr1=[
- ['name'=>'一年内','value'=>'一年内','key'=>[0,12]],
- ['name'=>'1~2年','value'=>'1~2年','key'=>[12,24]],
- ['name'=>'2~3年','value'=>'2~3年','key'=>[24,36]],
- ['name'=>'3年以上','value'=>'3年以上','key'=>[36,999999]],
- ];
- protected $arr2=[
- ['name'=>'一万公里内','value'=>'一万公里内','key'=>[0,1]],
- ['name'=>'1~3万公里','value'=>'1~3万公里','key'=>[1,3]],
- ['name'=>'3~5万公里','value'=>'3~5万公里','key'=>[3,5]],
- ['name'=>'5~7万公里','value'=>'5~7万公里','key'=>[5,7]],
- ];
- protected $arr3=[
- ['name'=>'默认排序','value'=>'默认排序','order'=>'create_at desc'],
- ['name'=>'最新上架','value'=>'最新上架','order'=>'create_at desc'],
- ['name'=>'车龄最短','value'=>'车龄最短','order'=>'cheling asc'],
- ['name'=>'里程最短','value'=>'里程最短','order'=>'licheng asc'],
- ['name'=>'租金最低','value'=>'租金最低','order'=>'jiage asc'],
- ];
- public function index(){
- $data['banner']=Db::table('p_banner')->where('is_deleted',0)->select();
- $data['tm']=$this->arr;
- $list=Db::table('p_car_chexing')->where('is_deleted',0)
- ->limit(4)
- ->select();
- $data['chexing']=$list;
- $data['biaoqian']=Db::table('p_car_biaoqian')->where('is_deleted',0)
- ->limit(4)
- ->select();
- $this->success('操作成功',$data);
- }
- public function lists(){
- $where=[];
- //筛选
- if(input('search')){
- $where[]=['search','like','%'.input('search').'%'];
- }
- //收藏
- if(input('is_collect')){
- $uid=$this->check_login();
- $ids=Db::table('p_collect')->where('uid',$uid)->column('car_id');
- $where[]=['id','in',$ids];
- }
- //推荐
- if(input('is_tuijian')){
- $where[]=['is_tuijian','=',input('is_tuijian')];
- }
- //今日最新
- if(input('d')){
- $where[]=['create_at','=',date('Y-m-d')];
- }
- //品牌
- if(input('pinpai')){
- $where[]=['pinpai','=',input('pinpai')];
- }
- //车型
- if(input('chexing')){
- $where[]=['chexing','=',input('chexing')];
- }
- //车龄
- if(input('cheling')){
- foreach ($this->arr3 as $k=>$v){
- if($v['value']==input('cheling')){
- $where[]=['cheling','between',$v['key']];
- }
- }
- }
- $where[]=['type','=',input('type')];
- //车龄
- $p1=input('p1',0);
- if(empty(input('p2'))){
- $p2=999999999;
- }else{
- $p2=input('p2');
- }
- $where[]=['jiage','between',[$p1,$p2]];
- //车辆特点
- if(input('biaoqian')){
- $where[]=['biaoqian','like','%'.input('biaoqian').'%'];
- }
- //车龄
- if(input('licheng')){
- foreach ($this->arr2 as $k=>$v){
- if($v['value']==input('cheling')){
- $where[]=['licheng','between',$v['key']];
- }
- }
- }
- $order='';
- if(input('shaixuan')){
- foreach ($this->arr3 as $k=>$v){
- if($v['value']==input('shaixuan')){
- $order=$v['order'];
- }
- }
- }
- //车型
- if(input('chengshi')){
- $where[]=['form_city','=',input('chengshi')];
- }
- dump($where);die();die();
- $list=Db::table('p_car')->where('is_deleted',0)
- ->where($where)
- ->limit(getLimit())
- ->order($order)
- ->select();
- foreach ($list as $k=>&$v){
- $v['biaoqian']=explode(',',$v['biaoqian']);
- $v['biaoqian']=array_slice( $v['biaoqian'],0,4);
- $v['image']=explode('|',$v['image']);
- $v['licheng']=$v['licheng'].'万公里';
- $v['mali']=$v['mali'].'匹';
- if($v['cheling']<12){
- $v['cheling']=$v['cheling'].'个月';
- }elseif($v['cheling']==12){
- $v['cheling']='1年';
- }else{
- $a=floor($v['cheling']/12);
- $b=$v['cheling']%12;
- $v['cheling']=$a.'年'.$b.'个月';
- }
- $v['image']=$v['image'][0];
- }
- $this->success('操作成功',$list);
- }
- public function info(){
- $uid=$this->check_login();
- $id=input('id');
- if(empty($id)){
- $this->error('参数错误');
- }
- $info=Db::table('p_car')->where('id',$id)->find();
- $info['image']=explode('|',$info['image']);
- $info['biaoqian']=explode(',',$info['biaoqian']);
- $info['biaoqian']=array_slice( $info['biaoqian'],0,2);
- $info['is_collect']=Db::table('p_collect')->where('uid',$uid)->where('car_id',$info['id'])->count();
- $info['licheng']=$info['licheng'].'万公里';
- $info['mali']=$info['mali'].'匹';
- if($info['cheling']<12){
- $info['cheling']=$info['cheling'].'个月';
- }elseif($info['cheling']==12){
- $info['cheling']='1年';
- }else{
- $a=floor($info['cheling']/12);
- $b=$info['cheling']%12;
- $info['cheling']=$a.'年'.$b.'个月';
- }
- $info['mobile']='15192908098';
- $this->success('操作成功',$info);
- }
- public function collect(){
- $uid=$this->check_login();
- $car_id=input('car_id');
- if(empty($car_id)){
- $this->error('参数错误');
- }
- $r=Db::table('p_collect')->where('uid',$uid)->where('car_id',$car_id)->find();
- if($r){
- Db::table('p_collect')->where('uid',$uid)->where('car_id',$car_id)->delete();
- $this->success('取消收藏成功');
- }else{
- $data['car_id']=$car_id;
- $data['uid']=$uid;
- Db::table('p_collect')->insert($data);
- $this->success('收藏成功');
- }
- }
- public function order(){
- $uid=$this->check_login();
- $car_id=input('car_id');
- $username=input('username');
- $mobile=input('mobile');
- $data['car_id']=$car_id;
- $data['uid']=$uid;
- $data['username']=$username;
- $data['mobile']=$mobile;
- Db::table('p_order')->insert($data);
- $this->success('提交成功');
- }
- public function chexing(){
- //车型
- $where[]=['is_deleted','=',0];
- if(input('c')){
- $where[]=['name','=',input('c')];
- }
- $list=Db::table('p_car_chexing')->field('name,id as value')
- ->where($where)
- ->select();
- array_unshift($list,['name'=>'全部车型','value'=>0]);
- foreach ($list as $k=>&$v){
- if($v['value']){
- $v['submenu']=Db::table('p_car_pinpai')->where('find_in_set('.$v['value'].',chexing_id)')->field('name,id as value')->select();
- }else{
- $v['submenu']=Db::table('p_car_pinpai')->field('name,id as value')->select();
- }
- }
- $data1=[
- 'name'=>'车型',
- 'submenu'=>$list,
- 'type'=>'hierarchy',
- ];
- $data2=[
- 'name'=>'车龄',
- 'type'=>'radio',
- 'submenu'=>[
- [
- 'name'=>'车龄',
- 'submenu'=>$this->arr1,
- ]
- ],
- ];
- $data3=[
- 'name'=>'租金',
- 'type'=>'radio',
- 'submenu'=>[
- [
- 'name'=>'请输入租金价格',
- 'submenu'=>[],
- ]
- ],
- ];
- $list555=Db::table('p_car_biaoqian')->field('id as value,name')->select();
- foreach ($list555 as $kkk=>&$vvv){
- $vvv['value']=$vvv['name'];
- }
- $data4=[
- 'name'=>'筛选',
- 'type'=>'radio',
- 'submenu'=>[
- [
- 'name'=>'车辆特点',
- 'submenu'=>$list555,
- ],
- [
- 'name'=>'里程',
- 'submenu'=>$this->arr2
- ],
- ],
- ];
- $data5=[
- 'name'=>'排序',
- 'type'=>'radio',
- 'submenu'=>[
- [
- 'name'=>'排序',
- 'submenu'=>$this->arr3,
- ]
- ],
- ];
- $this->success('操作成功',[$data1,$data2,$data3,$data4,$data5]);
- }
- public function tm(){
- $this->success('操作成功',$this->arr);
- }
- }
|