Index.php 9.2 KB

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