Index.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. if(isset($_GET['type'])){
  94. $where[]=['type','=',input('type')];
  95. }
  96. //车龄
  97. $p1=input('p1',0);
  98. if(empty(input('p2'))){
  99. $p2=999999999;
  100. }else{
  101. $p2=input('p2');
  102. }
  103. $where[]=['jiage','between',[$p1,$p2]];
  104. //车辆特点
  105. if(input('biaoqian')){
  106. $where[]=['biaoqian','like','%'.input('biaoqian').'%'];
  107. }
  108. //车龄
  109. if(input('licheng')){
  110. foreach ($this->arr2 as $k=>$v){
  111. if($v['value']==input('cheling')){
  112. $where[]=['licheng','between',$v['key']];
  113. }
  114. }
  115. }
  116. $order='';
  117. if(input('shaixuan')){
  118. foreach ($this->arr3 as $k=>$v){
  119. if($v['value']==input('shaixuan')){
  120. $order=$v['order'];
  121. }
  122. }
  123. }
  124. //车型
  125. if(input('chengshi')){
  126. $where[]=['form_city','like','%'.input('chengshi').'%'];
  127. }
  128. $list=Db::table('p_car')->where('is_deleted',0)
  129. ->where($where)
  130. ->limit(getLimit())
  131. ->order($order)
  132. ->select();
  133. foreach ($list as $k=>&$v){
  134. $v['biaoqian']=explode(',',$v['biaoqian']);
  135. $v['biaoqian']=array_slice( $v['biaoqian'],0,4);
  136. $v['image']=explode('|',$v['image']);
  137. $v['licheng']=$v['licheng'].'万公里';
  138. $v['mali']=$v['mali'].'匹';
  139. if($v['cheling']<12){
  140. $v['cheling']=$v['cheling'].'个月';
  141. }elseif($v['cheling']==12){
  142. $v['cheling']='1年';
  143. }else{
  144. $a=floor($v['cheling']/12);
  145. $b=$v['cheling']%12;
  146. $v['cheling']=$a.'年'.$b.'个月';
  147. }
  148. $v['image']=$v['image'][0];
  149. }
  150. $this->success('操作成功',$list);
  151. }
  152. public function info(){
  153. $uid=$this->check_login();
  154. $id=input('id');
  155. if(empty($id)){
  156. $this->error('参数错误');
  157. }
  158. $info=Db::table('p_car')->where('id',$id)->find();
  159. $info['image']=explode('|',$info['image']);
  160. $info['biaoqian']=explode(',',$info['biaoqian']);
  161. $info['biaoqian']=array_slice( $info['biaoqian'],0,2);
  162. $info['is_collect']=Db::table('p_collect')->where('uid',$uid)->where('car_id',$info['id'])->count();
  163. $info['licheng']=$info['licheng'].'万公里';
  164. $info['mali']=$info['mali'].'匹';
  165. if($info['cheling']<12){
  166. $info['cheling']=$info['cheling'].'个月';
  167. }elseif($info['cheling']==12){
  168. $info['cheling']='1年';
  169. }else{
  170. $a=floor($info['cheling']/12);
  171. $b=$info['cheling']%12;
  172. $info['cheling']=$a.'年'.$b.'个月';
  173. }
  174. $info['pinpais']=Db::table('p_car_pinpai')->where('id',$info['pinpai'])->value('name');
  175. $info['chexings']=Db::table('p_car_chexing')->where('id',$info['chenxing'])->value('name');
  176. $info['mobile']='15192908098';
  177. $this->success('操作成功',$info);
  178. }
  179. public function collect(){
  180. $uid=$this->check_login();
  181. $car_id=input('car_id');
  182. if(empty($car_id)){
  183. $this->error('参数错误');
  184. }
  185. $r=Db::table('p_collect')->where('uid',$uid)->where('car_id',$car_id)->find();
  186. if($r){
  187. Db::table('p_collect')->where('uid',$uid)->where('car_id',$car_id)->delete();
  188. $this->success('取消收藏成功');
  189. }else{
  190. $data['car_id']=$car_id;
  191. $data['uid']=$uid;
  192. Db::table('p_collect')->insert($data);
  193. $this->success('收藏成功');
  194. }
  195. }
  196. public function order(){
  197. $uid=$this->check_login();
  198. $car_id=input('car_id');
  199. $username=input('username');
  200. $mobile=input('mobile');
  201. $data['car_id']=$car_id;
  202. $data['uid']=$uid;
  203. $data['username']=$username;
  204. $data['mobile']=$mobile;
  205. Db::table('p_order')->insert($data);
  206. $this->success('提交成功');
  207. }
  208. public function chexing(){
  209. //车型
  210. $where[]=['is_deleted','=',0];
  211. if(input('c')){
  212. $where[]=['name','=',input('c')];
  213. }
  214. $list=Db::table('p_car_chexing')->field('name,id as value')
  215. ->where($where)
  216. ->select();
  217. array_unshift($list,['name'=>'全部车型','value'=>0]);
  218. foreach ($list as $k=>&$v){
  219. if($v['value']){
  220. $v['submenu']=Db::table('p_car_pinpai')->where('find_in_set('.$v['value'].',chexing_id)')->field('name,id as value')->select();
  221. }else{
  222. $v['submenu']=Db::table('p_car_pinpai')->field('name,id as value')->select();
  223. }
  224. }
  225. $data1=[
  226. 'name'=>'车型',
  227. 'submenu'=>$list,
  228. 'type'=>'hierarchy',
  229. ];
  230. $data2=[
  231. 'name'=>'车龄',
  232. 'type'=>'radio',
  233. 'submenu'=>[
  234. [
  235. 'name'=>'车龄',
  236. 'submenu'=>$this->arr1,
  237. ]
  238. ],
  239. ];
  240. $data3=[
  241. 'name'=>'租金',
  242. 'type'=>'radio',
  243. 'submenu'=>[
  244. [
  245. 'name'=>'请输入租金价格',
  246. 'submenu'=>[],
  247. ]
  248. ],
  249. ];
  250. $list555=Db::table('p_car_biaoqian')->field('id as value,name')->select();
  251. foreach ($list555 as $kkk=>&$vvv){
  252. $vvv['value']=$vvv['name'];
  253. }
  254. $data4=[
  255. 'name'=>'筛选',
  256. 'type'=>'radio',
  257. 'submenu'=>[
  258. [
  259. 'name'=>'车辆特点',
  260. 'submenu'=>$list555,
  261. ],
  262. [
  263. 'name'=>'里程',
  264. 'submenu'=>$this->arr2
  265. ],
  266. ],
  267. ];
  268. $data5=[
  269. 'name'=>'排序',
  270. 'type'=>'radio',
  271. 'submenu'=>[
  272. [
  273. 'name'=>'排序',
  274. 'submenu'=>$this->arr3,
  275. ]
  276. ],
  277. ];
  278. $this->success('操作成功',[$data1,$data2,$data3,$data4,$data5]);
  279. }
  280. public function tm(){
  281. $this->success('操作成功',$this->arr);
  282. }
  283. }