Index.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\Config;
  4. use app\common\model\User;
  5. use app\common\controller\Api;
  6. use hg\apidoc\Parser;
  7. use PhpOffice\PhpWord\Template;
  8. use PhpOffice\PhpWord\TemplateProcessor;
  9. use setasign\Fpdi\PdfParser\PdfParser;
  10. use think\Db;
  11. use think\facade\Validate;
  12. use function Sodium\add;
  13. use Mpdf\Mpdf;
  14. /**
  15. * @title 首页
  16. * @controller Index
  17. */
  18. class Index extends Api
  19. {
  20. protected $arr=[
  21. '一年内'=>[0,13],
  22. '1~2年'=>[11,25],
  23. '2~3年'=>[23,37],
  24. '3年以上'=>[35,999999],
  25. ];
  26. protected $arr1=[
  27. ['name'=>'一年内','value'=>'一年内','key'=>[0,12]],
  28. ['name'=>'1~2年','value'=>'1~2年','key'=>[12,24]],
  29. ['name'=>'2~3年','value'=>'2~3年','key'=>[24,36]],
  30. ['name'=>'3年以上','value'=>'3年以上','key'=>[36,999999]],
  31. ];
  32. protected $arr2=[
  33. ['name'=>'一万公里内','value'=>'一万公里内','key'=>[0,1]],
  34. ['name'=>'1~3万公里','value'=>'1~3万公里','key'=>[1,3]],
  35. ['name'=>'3~5万公里','value'=>'3~5万公里','key'=>[3,5]],
  36. ['name'=>'5~7万公里','value'=>'5~7万公里','key'=>[5,7]],
  37. ];
  38. protected $arr3=[
  39. ['name'=>'默认排序','value'=>'默认排序','order'=>'create_at desc'],
  40. ['name'=>'最新上架','value'=>'最新上架','order'=>'create_at desc'],
  41. ['name'=>'车龄最短','value'=>'车龄最短','order'=>'cheling asc'],
  42. ['name'=>'里程最短','value'=>'里程最短','order'=>'licheng asc'],
  43. ['name'=>'租金最低','value'=>'租金最低','order'=>'jiage asc'],
  44. ];
  45. public function index(){
  46. $data['banner']=Db::table('p_banner')->where('is_deleted',0)->select();
  47. $data['tm']=$this->arr;
  48. $list=Db::table('p_car_chexing')->where('is_deleted',0)
  49. ->limit(4)
  50. ->select();
  51. $data['chexing']=$list;
  52. $data['biaoqian']=Db::table('p_car_biaoqian')->where('is_deleted',0)
  53. ->limit(4)
  54. ->select();
  55. $this->success('操作成功',$data);
  56. }
  57. public function lists(){
  58. $where=[];
  59. //筛选
  60. if(input('search')){
  61. $where[]=['search','like','%'.input('search').'%'];
  62. }
  63. //收藏
  64. if(input('is_collect')){
  65. $uid=$this->check_login();
  66. $ids=Db::table('p_collect')->where('uid',$uid)->column('car_id');
  67. $where[]=['id','in',$ids];
  68. }
  69. //推荐
  70. if(input('is_tuijian')){
  71. $where[]=['is_tuijian','=',input('is_tuijian')];
  72. }
  73. //今日最新
  74. if(input('d')){
  75. $where[]=['create_at','=',date('Y-m-d')];
  76. }
  77. //品牌
  78. if(input('pinpai')){
  79. $where[]=['pinpai','=',input('pinpai')];
  80. }
  81. //车型
  82. if(input('chexing')){
  83. $where[]=['chexing','=',input('chexing')];
  84. }
  85. //车龄
  86. if(input('cheling')){
  87. foreach ($this->arr3 as $k=>$v){
  88. if($v['value']==input('cheling')){
  89. $where[]=['cheling','between',$v['key']];
  90. }
  91. }
  92. }
  93. $where[]=['type','=',input('type')];
  94. //车龄
  95. $p1=input('p1',0);
  96. if(empty(input('p2'))){
  97. $p2=999999999;
  98. }else{
  99. $p2=input('p2');
  100. }
  101. $where[]=['jiage','between',[$p1,$p2]];
  102. //车辆特点
  103. if(input('biaoqian')){
  104. $where[]=['biaoqian','like','%'.input('biaoqian').'%'];
  105. }
  106. //车龄
  107. if(input('licheng')){
  108. foreach ($this->arr2 as $k=>$v){
  109. if($v['value']==input('cheling')){
  110. $where[]=['licheng','between',$v['key']];
  111. }
  112. }
  113. }
  114. $order='';
  115. if(input('shaixuan')){
  116. foreach ($this->arr3 as $k=>$v){
  117. if($v['value']==input('shaixuan')){
  118. $order=$v['order'];
  119. }
  120. }
  121. }
  122. //车型
  123. if(input('chengshi')){
  124. $where[]=['form_city','=',input('chengshi')];
  125. }
  126. dump($where);die();die();
  127. $list=Db::table('p_car')->where('is_deleted',0)
  128. ->where($where)
  129. ->limit(getLimit())
  130. ->order($order)
  131. ->select();
  132. foreach ($list as $k=>&$v){
  133. $v['biaoqian']=explode(',',$v['biaoqian']);
  134. $v['biaoqian']=array_slice( $v['biaoqian'],0,4);
  135. $v['image']=explode('|',$v['image']);
  136. $v['licheng']=$v['licheng'].'万公里';
  137. $v['mali']=$v['mali'].'匹';
  138. if($v['cheling']<12){
  139. $v['cheling']=$v['cheling'].'个月';
  140. }elseif($v['cheling']==12){
  141. $v['cheling']='1年';
  142. }else{
  143. $a=floor($v['cheling']/12);
  144. $b=$v['cheling']%12;
  145. $v['cheling']=$a.'年'.$b.'个月';
  146. }
  147. $v['image']=$v['image'][0];
  148. }
  149. $this->success('操作成功',$list);
  150. }
  151. public function info(){
  152. $uid=$this->check_login();
  153. $id=input('id');
  154. if(empty($id)){
  155. $this->error('参数错误');
  156. }
  157. $info=Db::table('p_car')->where('id',$id)->find();
  158. $info['image']=explode('|',$info['image']);
  159. $info['biaoqian']=explode(',',$info['biaoqian']);
  160. $info['biaoqian']=array_slice( $info['biaoqian'],0,2);
  161. $info['is_collect']=Db::table('p_collect')->where('uid',$uid)->where('car_id',$info['id'])->count();
  162. $info['licheng']=$info['licheng'].'万公里';
  163. $info['mali']=$info['mali'].'匹';
  164. if($info['cheling']<12){
  165. $info['cheling']=$info['cheling'].'个月';
  166. }elseif($info['cheling']==12){
  167. $info['cheling']='1年';
  168. }else{
  169. $a=floor($info['cheling']/12);
  170. $b=$info['cheling']%12;
  171. $info['cheling']=$a.'年'.$b.'个月';
  172. }
  173. $info['mobile']='15192908098';
  174. $this->success('操作成功',$info);
  175. }
  176. public function collect(){
  177. $uid=$this->check_login();
  178. $car_id=input('car_id');
  179. if(empty($car_id)){
  180. $this->error('参数错误');
  181. }
  182. $r=Db::table('p_collect')->where('uid',$uid)->where('car_id',$car_id)->find();
  183. if($r){
  184. Db::table('p_collect')->where('uid',$uid)->where('car_id',$car_id)->delete();
  185. $this->success('取消收藏成功');
  186. }else{
  187. $data['car_id']=$car_id;
  188. $data['uid']=$uid;
  189. Db::table('p_collect')->insert($data);
  190. $this->success('收藏成功');
  191. }
  192. }
  193. public function order(){
  194. $uid=$this->check_login();
  195. $car_id=input('car_id');
  196. $username=input('username');
  197. $mobile=input('mobile');
  198. $data['car_id']=$car_id;
  199. $data['uid']=$uid;
  200. $data['username']=$username;
  201. $data['mobile']=$mobile;
  202. Db::table('p_order')->insert($data);
  203. $this->success('提交成功');
  204. }
  205. public function chexing(){
  206. //车型
  207. $where[]=['is_deleted','=',0];
  208. if(input('c')){
  209. $where[]=['name','=',input('c')];
  210. }
  211. $list=Db::table('p_car_chexing')->field('name,id as value')
  212. ->where($where)
  213. ->select();
  214. array_unshift($list,['name'=>'全部车型','value'=>0]);
  215. foreach ($list as $k=>&$v){
  216. if($v['value']){
  217. $v['submenu']=Db::table('p_car_pinpai')->where('find_in_set('.$v['value'].',chexing_id)')->field('name,id as value')->select();
  218. }else{
  219. $v['submenu']=Db::table('p_car_pinpai')->field('name,id as value')->select();
  220. }
  221. }
  222. $data1=[
  223. 'name'=>'车型',
  224. 'submenu'=>$list,
  225. 'type'=>'hierarchy',
  226. ];
  227. $data2=[
  228. 'name'=>'车龄',
  229. 'type'=>'radio',
  230. 'submenu'=>[
  231. [
  232. 'name'=>'车龄',
  233. 'submenu'=>$this->arr1,
  234. ]
  235. ],
  236. ];
  237. $data3=[
  238. 'name'=>'租金',
  239. 'type'=>'radio',
  240. 'submenu'=>[
  241. [
  242. 'name'=>'请输入租金价格',
  243. 'submenu'=>[],
  244. ]
  245. ],
  246. ];
  247. $list555=Db::table('p_car_biaoqian')->field('id as value,name')->select();
  248. foreach ($list555 as $kkk=>&$vvv){
  249. $vvv['value']=$vvv['name'];
  250. }
  251. $data4=[
  252. 'name'=>'筛选',
  253. 'type'=>'radio',
  254. 'submenu'=>[
  255. [
  256. 'name'=>'车辆特点',
  257. 'submenu'=>$list555,
  258. ],
  259. [
  260. 'name'=>'里程',
  261. 'submenu'=>$this->arr2
  262. ],
  263. ],
  264. ];
  265. $data5=[
  266. 'name'=>'排序',
  267. 'type'=>'radio',
  268. 'submenu'=>[
  269. [
  270. 'name'=>'排序',
  271. 'submenu'=>$this->arr3,
  272. ]
  273. ],
  274. ];
  275. $this->success('操作成功',[$data1,$data2,$data3,$data4,$data5]);
  276. }
  277. public function tm(){
  278. $this->success('操作成功',$this->arr);
  279. }
  280. }