IndexController.class.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. <?php
  2. namespace Home\Controller;
  3. /**
  4. * IndexController
  5. * 系统信息管理
  6. */
  7. class IndexController extends CommonController {
  8. public function wl_jieshao()
  9. {
  10. $this->display();
  11. }
  12. public function wl_xlmy()
  13. {
  14. $this->display();
  15. }
  16. public function wl_baom()
  17. {
  18. $this->assign('kangurl', U('Index/wl_baom_ins'));
  19. $this->display();
  20. }
  21. public function wl_baom_ins()
  22. {
  23. $username = htmlspecialchars($_POST['username']);
  24. $mobile = htmlspecialchars($_POST['mobile']);
  25. $sex = intval($_POST['sex']) == 1 ? '男': '女';
  26. $area = htmlspecialchars($_POST['area']);
  27. $lbtype = htmlspecialchars($_POST['lbtype']);
  28. $note = htmlspecialchars($_POST['note']);
  29. $data = array('username' => $username,'mobile' => $mobile,'sex' => $sex,'area' => $area,'lbtype' => $lbtype,'note' => $note,'addtime' => time());
  30. M('wl_bao')->add($data);
  31. echo json_encode(array('code'=>1));
  32. die();
  33. }
  34. public function wl_cbsx()
  35. {
  36. $list = M('wl_comment')->order('id desc ')->select();
  37. $this->assign('list', $list);
  38. $this->assign('kangurl', U('Index/wl_cbsx_ins'));
  39. $this->display();
  40. }
  41. public function wl_cbsx_ins()
  42. {
  43. //mess
  44. $mess = htmlspecialchars($_POST['mess']);
  45. $data = array('content' => $mess,'addtime' => time());
  46. M('wl_comment')->add($data);
  47. echo json_encode(array('code'=>1));
  48. die();
  49. }
  50. public function subbaoview()
  51. {
  52. $ar = array('ret'=>0);
  53. $param = array();
  54. $param['username'] = htmlspecialchars($_POST['username']);
  55. $param['mobile'] = htmlspecialchars($_POST['mobile']);
  56. $param['yixiang'] = htmlspecialchars($_POST['yixiang']);
  57. $param['area'] = htmlspecialchars($_POST['area']);
  58. $param['addtime'] = time();
  59. $rs = M('baoming')->add($param);
  60. if($rs)
  61. {
  62. $ar['ret'] = 1;
  63. }
  64. echo json_encode($ar);
  65. die();
  66. }
  67. public function auth()
  68. {
  69. $secret = 'mnwjxpx20150826';
  70. $openid = trim($_GET['openid']);
  71. $key = trim($_GET['key']);
  72. $ch_key = md5($secret.$openid);
  73. if($ch_key != $key)
  74. {
  75. echo '<script>alert("请关注闽南网,并点击菜单中驾校评选,进入投票");</script>';
  76. die();//这里以后放一片文章地址
  77. }
  78. $user_info = M('user')->where("openid ='{$openid}'")->find();
  79. if(!$user_info) {
  80. $param = array();
  81. $param['openid'] = $openid;
  82. $param['addtime'] = time();
  83. M('user')->add($param);
  84. }
  85. $this->redirect(U('Index/index','openid='.$openid));
  86. }
  87. public function wan_notice()
  88. {
  89. $this->display();
  90. }
  91. /**
  92. 从公众号进入的
  93. **/
  94. public function wan_index()
  95. {
  96. //$openid = 'DJKSDHUNCDNSDDSJDJH';
  97. $secret = 'mnwjxpx20150826';
  98. $openid = trim($_GET['openid']);
  99. $key = trim($_GET['key']);
  100. //$key = 'fa07413fdab048928525233486e78586';
  101. $ch_key = md5($secret.$openid);
  102. //cookie('name',array('name1','name2'));
  103. if($ch_key != $key)
  104. {
  105. $user_info = cookie('wan_userinfo');
  106. if(empty($user_info['openid']))
  107. {
  108. $this->redirect(U('Index/wan_notice'));
  109. die();//这里以后放一片文章地址
  110. }else {
  111. $openid = $user_info['openid'];
  112. }
  113. }
  114. $param = array(
  115. 'openid' => $openid,
  116. );
  117. $info = M('mobile')->where(array('openid' => $openid))->find();
  118. if($info)
  119. {
  120. $param['mobile'] = $info['mobile'];
  121. } else {
  122. $data_arr = array();
  123. $data_arr['openid'] = $openid;
  124. $mobile = cookie('wan_other_mobile');
  125. if(!$mobile)
  126. {
  127. $mobile = '';
  128. }
  129. $data_arr['mobile'] = $mobile;
  130. $param['mobile'] = '';
  131. M('mobile')->add($data_arr);
  132. }
  133. cookie('wan_userinfo',$param,86400*100);
  134. $item_list = M('item')->select();
  135. $item_first = array_slice($item_list,0,1);
  136. $item_second = array_slice($item_list,1,1);
  137. $length = count($item_list);
  138. $del_item = array_slice($item_list,2,$length - 2);
  139. $this->assign('item_first', $item_first);
  140. $this->assign('item_second', $item_second);
  141. $this->assign('del_item', $del_item);
  142. $this->assign('item_list', $item_list);
  143. $this->assign('kangurl', U('Index/wan_openorder'));
  144. $this->assign('bindurl', U('Index/wan_bindmobile'));
  145. $this->display();
  146. }
  147. /**
  148. 拆散情侣
  149. 绑定手机号
  150. **/
  151. public function cai_bindmobile()
  152. {
  153. $username = htmlspecialchars($_POST['username']);
  154. $mobile = htmlspecialchars($_POST['mobile']);
  155. $user_info = M('cais_user')->where( array( 'username' => $username,'mobile' => $mobile ) )->find();
  156. $result = array('code' => 1);
  157. if($user_info)
  158. {
  159. $param = array();
  160. $param = array( 'mobile' => $mobile );
  161. cookie('cai_userinfo',$param,86400*100);
  162. } else {
  163. $data = array();
  164. $data['username'] = $username;
  165. $data['mobile'] = $mobile;
  166. $data['addtime'] = time();
  167. $rs = M('cais_user')->add($data);
  168. if(!$rs)
  169. {
  170. $result['code'] = 2;
  171. }else {
  172. $param = array();
  173. $param = array( 'mobile' => $mobile );
  174. cookie('cai_userinfo',$param,86400*100);
  175. }
  176. $param = array();
  177. $param = array( 'mobile' => $mobile );
  178. }
  179. echo json_encode($result);
  180. die();
  181. }
  182. /**
  183. 拆散情侣
  184. 比赛结果入库
  185. **/
  186. public function cai_addrecord()
  187. {
  188. $score = intval($_POST['score']);
  189. //score:45
  190. $result = array();
  191. $user_info = cookie('cai_userinfo');
  192. if(!empty($user_info['mobile']))
  193. {
  194. $mobile = $user_info['mobile'];
  195. //cais_records
  196. $record = M('cais_records')->where( array('mobile' => $mobile) )->find();
  197. if($record) {
  198. if ($record['record'] <= $score) {
  199. $data = array();
  200. $data['record'] = $score;
  201. $data['addtime'] = time();
  202. $rs = M('cais_records')->where( array('mobile' => $mobile) )->save($data);
  203. if($rs){
  204. $result['code'] = 2;//更新成功
  205. } else {
  206. $result['code'] = 3;//更新出错
  207. }
  208. }
  209. } else {
  210. $data = array();
  211. $data['mobile'] = $mobile;
  212. $data['record'] = $score;
  213. $data['addtime'] = time();
  214. $rs = M('cais_records')->add($data);
  215. if($rs){
  216. $result['code'] = 2;//更新成功
  217. } else {
  218. $result['code'] = 3;//更新出错
  219. }
  220. }
  221. echo json_encode($result);
  222. die();
  223. }else {
  224. $result['code'] = 1;//未注册过
  225. echo json_encode($result);
  226. die();
  227. }
  228. }
  229. /**
  230. 拆散情侣
  231. 排行榜
  232. **/
  233. public function cai_top()
  234. {
  235. $rank_list = M('cais_records')->order('record desc,addtime')->limit('100')->select();
  236. $mobile = '';
  237. $count = 100;
  238. $user_info = cookie('cai_userinfo');
  239. if(empty($user_info['mobile']))
  240. {
  241. $mobile = '';
  242. }else {
  243. $mobile = $user_info['mobile'];
  244. }
  245. if(!empty($mobile))
  246. {
  247. $info = M('cais_records')->where( array('mobile' => $mobile) )->find();
  248. $count = M('cais_records')->where(' record> '.$info['record'])->count();
  249. }
  250. foreach($rank_list as $key => $val)
  251. {
  252. $val['mobile'] = substr($val['mobile'],0,3).'****'.substr($val['mobile'],-3,3);
  253. $rank_list[$key] = $val;
  254. }
  255. $result = array('list' =>$rank_list,'count' => $count );
  256. echo json_encode($result);
  257. die();
  258. }
  259. /**
  260. 拆散情侣
  261. 检测是否注册过
  262. **/
  263. public function cai_checkmobile()
  264. {
  265. $result = array();
  266. $user_info = cookie('cai_userinfo');
  267. if(empty($user_info['mobile']))
  268. {
  269. $result['code'] = 2;//需要弹窗绑定手机号
  270. }else {
  271. $result['code'] = 1;//已经注册过了
  272. }
  273. echo json_encode($result);
  274. die();
  275. }
  276. /**
  277. 开始绑定手机号
  278. **/
  279. public function wan_bindmobile()
  280. {
  281. $result = array('code' => 0);
  282. $user_info = cookie('wan_userinfo');
  283. if(empty($user_info['openid']))
  284. {
  285. $result['code'] = 2;//需要跳转到授权页面
  286. $result['url'] = U('Index/wan_notice');
  287. echo json_encode($result);
  288. die();
  289. }
  290. $mobile = htmlspecialchars($_POST['mobile']);
  291. $param = array( 'mobile' => $mobile );
  292. M('mobile')->where( array('openid' => $user_info['openid'] ) )->save($param);
  293. $user_info['mobile'] = $mobile;
  294. cookie('wan_userinfo',$param,86400*100);
  295. $result['code'] = 1;
  296. echo json_encode($result);
  297. die();
  298. }
  299. /**
  300. 帮忙别人砍价,绑定手机号
  301. **/
  302. public function wan_other_bindmobile()
  303. {
  304. $result = array( 'code' => 0);
  305. $mobile = htmlspecialchars($_POST['mobile']);
  306. cookie('wan_other_mobile',$mobile,86400*100);
  307. $user_info = cookie('wan_userinfo');
  308. if(!empty($user_info) && empty($user_info['mobile']))
  309. {
  310. $user_info['mobile'] =$mobile;
  311. cookie('wan_userinfo',$user_info,86400*100);
  312. }
  313. $result['code'] = 1;
  314. echo json_encode($result);
  315. die();
  316. }
  317. /**
  318. 帮忙别人砍价
  319. **/
  320. public function wan_other_kang()
  321. {
  322. $result = array('code' => 0);
  323. $mobile = cookie('wan_other_mobile');
  324. if(empty($mobile))
  325. {
  326. $user_info = cookie('wan_userinfo');
  327. if(!empty($user_info['mobile']))
  328. {
  329. $mobile = $user_info['mobile'];
  330. } else {
  331. $result['code'] = 2;//需要绑定一下手机号
  332. echo json_encode($result);
  333. die();
  334. }
  335. }
  336. $order_id = intval($_POST['order_id']);
  337. $order_info = M('order')->where('id='.$order_id)->find();
  338. if(empty($order_info))
  339. {
  340. $result['code'] = 3;
  341. echo json_encode($result);//订单不存在,非法操作
  342. die();
  343. }
  344. if($order_info['sy_price']<=0)
  345. {
  346. $result['code'] = 4;
  347. echo json_encode($result);//已成功
  348. die();
  349. }
  350. $item = M('item')->where('id='.$order_info['item_id'].' and num >0 ')->find();
  351. if(!$item)
  352. {
  353. $result['code'] = 5;
  354. echo json_encode($result);//商品已经抢光了
  355. die();
  356. }
  357. $order_kang = M('order_kang')->where( array('mobile' => $mobile, 'order_id' => $order_id ) )->find();
  358. if($order_kang)
  359. {
  360. $result['code'] = 6;
  361. echo json_encode($result);//您已经砍过了
  362. die();
  363. }
  364. //$order_kang
  365. $kang_arr = array();
  366. $kang_arr['order_id'] = $order_id;
  367. $kang_arr['money'] = 1;
  368. if($order_info['item_id'] == 1)
  369. {
  370. $kang_arr['money'] = 3;
  371. }
  372. $kang_arr['mobile'] = $mobile;
  373. $kang_arr['addtime'] = time();
  374. M('order_kang')->add($kang_arr);
  375. M('order')->where('id='.$order_id)->setDec('sy_price'); //
  376. if($order_info['item_id'] == 1)
  377. {
  378. M('order')->where('id='.$order_id)->setDec('sy_price'); //
  379. M('order')->where('id='.$order_id)->setDec('sy_price'); //
  380. }
  381. $order_info = M('order')->where('id='.$order_id)->find();
  382. if($order_info['sy_price']<=0)
  383. {
  384. M('order')->where('id='.$order_id)->save( array('state' =>1) );
  385. M('item')->where('id='.$order_info['item_id'])->setDec('num'); //
  386. }
  387. $result['code'] = 1;//砍价成功
  388. $result['sy_price'] = $order_info['sy_price'];
  389. echo json_encode($result);
  390. die();
  391. }
  392. //http://baby2015.mnw.cn/index.php?m=&c=Index&a=wan_detail&item_id=1
  393. public function wan_detailover()
  394. {
  395. $item_id = intval($_GET['item_id']);
  396. $item_info = M('item')->where('id='.$item_id)->find();
  397. $this->assign('kangurl', U('Index/wan_other_kang'));
  398. $this->assign('bindurl', U('Index/wan_other_bindmobile'));
  399. $pross = 100;
  400. $is_me = 1;
  401. $has_kang = 1;
  402. $jianglist = M('order')->where('item_id='.$item_id)->order('state desc,sy_price asc')->limit(20)->select();
  403. $this->assign('is_me', $is_me);
  404. $this->assign('jianglist', $jianglist);
  405. $this->assign('has_kang', $has_kang);
  406. //$this->assign('kangurl', U('Index/wan_openorder'));
  407. $this->assign('bangurl', U('Index/wan_other_kang'));
  408. $this->assign('bindmobileurl', U('Index/wan_other_bindmobile'));
  409. $this->assign('pross', $pross);
  410. $this->assign('item_info', $item_info);
  411. $this->assign('is_over', 1);
  412. $this->display('wan_detail');
  413. }
  414. public function wan_detail()
  415. {
  416. $item_id = intval($_GET['item_id']);
  417. $order_id = intval($_GET['order_id']);
  418. $item_info = M('item')->where('id='.$item_id)->find();
  419. $order_info = M('order')->where('id='.$order_id)->find();
  420. if(empty($order_info))
  421. {
  422. $this->redirect(U('Index/wan_index'));
  423. die();//这里以后放一片文章地址
  424. }
  425. $this->assign('kangurl', U('Index/wan_other_kang'));
  426. $this->assign('bindurl', U('Index/wan_other_bindmobile'));
  427. $pross = round(($item_info['price']-$order_info['sy_price']) / $item_info['price'] *100,2);
  428. if($pross > 100)
  429. {
  430. $pross = 100;
  431. }
  432. $is_me = 0;//是否是当前的人的
  433. $mobile = cookie('wan_other_mobile');
  434. $user_info = cookie('wan_userinfo');
  435. if(!empty($user_info['openid']))
  436. {
  437. $order_me = M('order')->where( array('openid'=>$user_info['openid'],'id' =>$order_id,'item_id' =>$item_id ) )->find();
  438. if($order_me)
  439. {
  440. $is_me = 1;
  441. }
  442. if(empty($mobile))
  443. $mobile = $user_info['mobile'];
  444. }
  445. //var_dump($is_me,M('order')->getLastSql());die();
  446. //是否已经砍过
  447. //$user_info['mobile']
  448. $has_kang = 0;
  449. if(!empty($mobile))
  450. {
  451. $order_kang = M('order_kang')->where( array('order_id' => $order_id,'mobile' => $mobile) )->find();
  452. if($order_kang)
  453. {
  454. $has_kang = 1;
  455. }
  456. }
  457. //var_dump($has_kang,$mobile);die();
  458. $jianglist = M('order')->where('item_id='.$item_id)->order('state desc,sy_price asc')->limit(20)->select();
  459. $this->assign('is_me', $is_me);
  460. $this->assign('jianglist', $jianglist);
  461. $this->assign('has_kang', $has_kang);
  462. //$this->assign('kangurl', U('Index/wan_openorder'));
  463. $this->assign('bangurl', U('Index/wan_other_kang'));
  464. $this->assign('bindmobileurl', U('Index/wan_other_bindmobile'));
  465. $this->assign('pross', $pross);
  466. $this->assign('item_info', $item_info);
  467. $this->assign('order_info', $order_info);
  468. $this->assign('is_over', 0);
  469. $this->display();
  470. }
  471. /**
  472. 开启一个砍价链接
  473. **/
  474. public function wan_openorder()
  475. {
  476. $result =array('code' => 0);
  477. $user_info = cookie('wan_userinfo');
  478. if(empty($user_info) || empty($user_info['mobile']))
  479. {
  480. //需要绑定手机号
  481. $result['code'] = 1;
  482. echo json_encode($result);
  483. die();
  484. }
  485. $item_id = trim($_POST['item_id']);
  486. $item = M('item')->where('id='.$item_id.' and num >0 ')->find();
  487. if($item)
  488. {
  489. $in_order = M('order')->where( array('item_id' => $item_id,'openid' => $user_info['openid'],'state' => 0) )->find();
  490. if($in_order)
  491. {
  492. $result['code'] = 3;//当前商品正在砍价中
  493. $result['order_id'] = $in_order['id'];
  494. echo json_encode($result);
  495. die();
  496. }else {
  497. $order_param = array();
  498. $order_param['openid'] = $user_info['openid'];
  499. $order_param['item_id'] = $item_id;
  500. if($item_id == 1)
  501. {
  502. $order_param['sy_price'] = $item['price'] - 3;
  503. }else
  504. $order_param['sy_price'] = $item['price'] - 1;
  505. $order_param['mobile'] = $user_info['mobile'];
  506. $order_param['state'] = 0;
  507. $order_param['stattime'] = time();
  508. $order_param['endtime'] = time();
  509. $insrt_id = M('order')->add($order_param);
  510. //$order_kang
  511. $kang_arr = array();
  512. $kang_arr['order_id'] = $insrt_id;
  513. $kang_arr['mobile'] = $user_info['mobile'];
  514. if($item_id == 1)
  515. {
  516. $kang_arr['money'] = 3;
  517. }else
  518. $kang_arr['money'] = 1;
  519. $kang_arr['addtime'] = time();
  520. $rs = M('order_kang')->add($kang_arr);
  521. $result['code'] = 5;//自己砍价成功
  522. $result['order_id'] = $insrt_id;
  523. echo json_encode($result);
  524. die();
  525. }
  526. } else {
  527. $result['code'] = 2;//商品数量已经抢光
  528. echo json_encode($result);
  529. die();
  530. }
  531. }
  532. /**
  533. * 网站,服务器基本信息
  534. * @return
  535. */
  536. public function index(){
  537. $openid = $_GET['openid'];
  538. $user_info = M('user')->where("openid ='{$openid}'")->find();
  539. if(!$user_info) {
  540. echo '<script>alert("请关注闽南网,并点击菜单中驾校评选,进入投票");</script>';
  541. die();//这里以后放一片文章地址
  542. }
  543. $cate_id = isset($_GET['cid']) ? intval($_GET['cid']) : 1;
  544. $p = isset($_GET['p']) ? intval($_GET['p']) : 1;
  545. $size = 10;
  546. $off_set = ($p -1) * $size;
  547. $is_ajax = isset($_GET['is_ajax']) ? true: false;
  548. $keyword = isset($_GET['keyword']) ? trim($_GET['keyword']) : '';
  549. $now_time = time();
  550. $where = 'begin_time<'.$now_time.' and end_time > '.$now_time;
  551. if(!empty($keyword))
  552. {
  553. $where .= ' and (username LIKE "%'.$keyword.'%" or id Like "%'.$keyword.'%") ';
  554. }
  555. if($cate_id > 0)
  556. {
  557. $where .= ' and cid ='.$cate_id;
  558. }
  559. $tou_list = array();
  560. $tou_list = M('toupiao')->where($where)->order('vote_count desc')->limit($off_set,$size)->select();
  561. $tou_list_left = array();
  562. $tou_list_right = array();
  563. $i = 1;
  564. $result_list = array();
  565. if(!empty($tou_list))
  566. {
  567. foreach($tou_list as $tou)
  568. {
  569. if($i % 2 == 1)
  570. {
  571. $tou_list_left[] = $tou;
  572. } else {
  573. $tou_list_right[] = $tou;
  574. }
  575. $i++;
  576. }
  577. $result_list['tou_list_left'] = $tou_list_left;
  578. $result_list['tou_list_right'] = $tou_list_right;
  579. }
  580. if($is_ajax) {
  581. $result = array('ret' =>1);
  582. if(!empty($result_list)) {
  583. $result = array('ret' =>0);
  584. $result['list'] = $result_list;
  585. }
  586. echo json_encode($result);
  587. die();
  588. }
  589. $this->assign('cate_id', $cate_id);
  590. $this->assign('result_list', $result_list);
  591. $this->assign('toup', U('Index/toupsub'));
  592. $this->assign('s_url', U('Index/index'));
  593. $this->assign('openid', $openid);
  594. $this->assign('siteurl', 'http://'.$_SERVER['HTTP_HOST']);
  595. $this->display();
  596. }
  597. public function touview()
  598. {
  599. $openid = htmlspecialchars($_GET['openid']);
  600. $tid = intval($_GET['id']);
  601. $tou_info = M('toupiao')->where("id ='{$tid}'")->find();
  602. $this->assign('toupsuburl', U('Index/toupsub','openid='.$openid));
  603. $this->assign('tou_info', $tou_info);
  604. $this->display();
  605. }
  606. public function weixinshow()
  607. {
  608. $cate_id = isset($_GET['cid']) ? intval($_GET['cid']) : 0;
  609. $p = isset($_GET['p']) ? intval($_GET['p']) : 1;
  610. $size = 10;
  611. $off_set = ($p -1) * $size;
  612. $is_ajax = isset($_GET['is_ajax']) ? true: false;
  613. $keyword = isset($_GET['keyword']) ? trim($_GET['keyword']) : '';
  614. $where = '1=1';
  615. if(!empty($keyword))
  616. {
  617. $where .= ' and username LIKE "%'.$keyword.'%"';
  618. }
  619. if($cate_id > 0)
  620. {
  621. //$cate_arr = array($cate_id=>$cate_arr[$cate_id]);
  622. $where .= ' and cid ='.$key;
  623. }
  624. $tou_list = array();
  625. $tou_list = M('toupiao')->where($where)->order('id asc')->limit($off_set,$size)->select();
  626. $tou_list_left = array();
  627. $tou_list_right = array();
  628. $i = 1;
  629. $result_list = array();
  630. if(!empty($tou_list))
  631. {
  632. foreach($tou_list as $tou)
  633. {
  634. if($i % 2 == 1)
  635. {
  636. $tou_list_left[] = $tou;
  637. } else {
  638. $tou_list_right[] = $tou;
  639. }
  640. $i++;
  641. }
  642. $result_list['tou_list_left'] = $tou_list_left;
  643. $result_list['tou_list_right'] = $tou_list_right;
  644. }
  645. if($is_ajax) {
  646. $result = array('ret' =>1);
  647. if(!empty($result_list)) {
  648. $result = array('ret' =>0);
  649. $result['list'] = $result_list;
  650. }
  651. echo json_encode($result);
  652. die();
  653. }
  654. $this->assign('result_list', $result_list);
  655. $this->assign('toup', U('Index/toup'));
  656. $this->assign('s_url', U('Index/weixinshow'));
  657. $this->assign('siteurl', 'http://'.$_SERVER['HTTP_HOST']);
  658. $this->display();
  659. }
  660. public function baommote()
  661. {
  662. $this->assign('baom', U('Index/baom'));
  663. $this->assign('toup', U('Index/toup'));
  664. $this->assign('siteurl', $_SERVER['HTTP_HOST']);
  665. $this->assign('suburl', U('Index/baosubmote'));
  666. $this->assign('toupurl', U('Index/toup'));
  667. $this->assign('uppicurl', U('Index/uppic'));
  668. $this->display();
  669. }
  670. public function baosubmote()
  671. {
  672. $data = $_POST;
  673. foreach($data as $key => $val)
  674. {
  675. if($key == 'team')
  676. {
  677. $data[$key] = $val == 1 ? '单人' : '组队';
  678. }
  679. if($key == 'sex')
  680. {
  681. $data[$key] = $val == 1 ? '男' : '女';
  682. }
  683. if($key == 'thumb_url' || $key == 'image_url' )
  684. {
  685. $data[$key] ='http://baby2015.mnw.cn/'.$val;
  686. }
  687. $data[$key] = htmlspecialchars($data[$key]);
  688. }
  689. $result = array('code'=>1,'mes' => '');
  690. $param = $data;
  691. $param['addtime'] = time();
  692. $insrt_id = M('mote')->add($param);
  693. if($insrt_id) {
  694. $result['code'] = 0;
  695. $result['insrt_id'] = $insrt_id;
  696. $result['mes'] = '报名成功.';
  697. echo json_encode($result);
  698. die();
  699. } else {
  700. $result['mes'] = '插入数据库失败.';
  701. echo json_encode($result);
  702. die();
  703. }
  704. }
  705. public function baom2017()
  706. {
  707. $this->assign('baom', U('Index/baom'));
  708. $this->assign('toup', U('Index/toup'));
  709. $this->assign('siteurl', $_SERVER['HTTP_HOST']);
  710. $this->assign('suburl', U('Index/baosub2017'));
  711. $this->assign('toupurl', U('Index/toup'));
  712. $this->assign('uppicurl', U('Index/uppic'));
  713. $this->display();
  714. }
  715. public function baosub2017()
  716. {
  717. $username = trim($_POST['babyname']);
  718. $sex = intval($_POST['sex']);
  719. $parname = trim($_POST['parname']);
  720. $mobile = trim($_POST['mobile']);
  721. $area = trim($_POST['area']);
  722. $age = 0;
  723. $birthday = trim($_POST['birthday']);
  724. $weixin = trim($_POST['weixin']);
  725. $parship = trim($_POST['parship']);
  726. $cid = intval($_POST['cid']);
  727. $thumb_url = trim($_POST['thumb_url']);
  728. $image_url = trim($_POST['image_url']);
  729. $result = array('code'=>1,'mes' => '');
  730. //$result['mes'] = '报名已结束';
  731. //echo json_encode($result);
  732. //die();
  733. if(empty($username)) {
  734. $result['mes'] = '姓名不能为空';
  735. echo json_encode($result);
  736. die();
  737. }
  738. if(empty($parname)) {
  739. $result['mes'] = '联系人姓名不能为空';
  740. echo json_encode($result);
  741. die();
  742. }
  743. if(empty($mobile)) {
  744. $result['mes'] = '手机号不能为空';
  745. echo json_encode($result);
  746. die();
  747. }
  748. if(empty($thumb_url)) {
  749. $result['mes'] = '请上传图片';
  750. echo json_encode($result);
  751. die();
  752. }
  753. $where_param = array();
  754. $where_param['parname'] = $parname;
  755. $where_param['username'] = $username;
  756. $where_param['mobile'] = $mobile;
  757. $idcard_info = M('toupiao2017')->where($where_param)->find();
  758. if($idcard_info) {
  759. $result['mes'] = '该宝宝已经报名,请勿重复报名.';
  760. echo json_encode($result);
  761. die();
  762. }
  763. $param = array();
  764. $param['created_at'] = time();
  765. $param['updated_at'] = time();
  766. $param['username'] = htmlspecialchars($username);
  767. $param['mobile'] = htmlspecialchars($mobile);
  768. $param['parname'] = htmlspecialchars($parname);
  769. $param['area'] = htmlspecialchars($area);
  770. $param['sex'] = htmlspecialchars($sex);
  771. $param['parship'] = htmlspecialchars($parship);
  772. $param['cid'] = htmlspecialchars($cid);
  773. $param['age'] = htmlspecialchars($age);
  774. $param['birthday'] = htmlspecialchars($birthday);
  775. $param['weixin'] = htmlspecialchars($weixin);
  776. $param['statu'] = 1;
  777. $param['idcard'] = time();
  778. $param['image_url'] = htmlspecialchars($image_url);
  779. $param['thumb_url'] = htmlspecialchars($thumb_url);
  780. $insrt_id = M('toupiao2017')->add($param);
  781. if($insrt_id) {
  782. $result['code'] = 0;
  783. $result['insrt_id'] = $insrt_id;
  784. $result['mes'] = '报名成功.';
  785. echo json_encode($result);
  786. die();
  787. } else {
  788. $result['mes'] = '插入数据库失败.';
  789. echo json_encode($result);
  790. die();
  791. }
  792. }
  793. public function baom()
  794. {
  795. $this->assign('baom', U('Index/baom'));
  796. $this->assign('toup', U('Index/toup'));
  797. $this->assign('siteurl', $_SERVER['HTTP_HOST']);
  798. $this->assign('suburl', U('Index/baosub'));
  799. $this->assign('toupurl', U('Index/toup'));
  800. $this->assign('uppicurl', U('Index/uppic'));
  801. $this->display();
  802. }
  803. public function baosub()
  804. {
  805. $username = trim($_POST['babyname']);
  806. $sex = intval($_POST['sex']);
  807. $parname = trim($_POST['parname']);
  808. $mobile = trim($_POST['mobile']);
  809. $area = trim($_POST['area']);
  810. $parship = trim($_POST['parship']);
  811. $cid = intval($_POST['cid']);
  812. $thumb_url = trim($_POST['thumb_url']);
  813. $image_url = trim($_POST['image_url']);
  814. $result = array('code'=>1,'mes' => '');
  815. //$result['mes'] = '报名已结束';
  816. //echo json_encode($result);
  817. //die();
  818. if(empty($username)) {
  819. $result['mes'] = '姓名不能为空';
  820. echo json_encode($result);
  821. die();
  822. }
  823. if(empty($parname)) {
  824. $result['mes'] = '家长姓名不能为空';
  825. echo json_encode($result);
  826. die();
  827. }
  828. if(empty($mobile)) {
  829. $result['mes'] = '手机号不能为空';
  830. echo json_encode($result);
  831. die();
  832. }
  833. if(empty($thumb_url)) {
  834. $result['mes'] = '请上传图片';
  835. echo json_encode($result);
  836. die();
  837. }
  838. $where_param = array();
  839. $where_param['parname'] = $parname;
  840. $where_param['username'] = $username;
  841. $where_param['mobile'] = $mobile;
  842. $idcard_info = M('toupiao')->where($where_param)->find();
  843. if($idcard_info) {
  844. $result['mes'] = '该宝宝已经报名,请勿重复报名.';
  845. echo json_encode($result);
  846. die();
  847. }
  848. $param = array();
  849. $param['created_at'] = time();
  850. $param['updated_at'] = time();
  851. $param['username'] = $username;
  852. $param['mobile'] = $mobile;
  853. $param['parname'] = $parname;
  854. $param['area'] = $area;
  855. $param['sex'] = $sex;
  856. $param['parship'] = $parship;
  857. $param['cid'] = $cid;
  858. $param['statu'] = 1;
  859. $param['idcard'] = time();
  860. $param['image_url'] = $image_url;
  861. $param['thumb_url'] = $thumb_url;
  862. $insrt_id = M('toupiao')->add($param);
  863. if($insrt_id) {
  864. $result['code'] = 0;
  865. $result['insrt_id'] = $insrt_id;
  866. $result['mes'] = '报名成功.';
  867. echo json_encode($result);
  868. die();
  869. } else {
  870. $result['mes'] = '插入数据库失败.';
  871. echo json_encode($result);
  872. die();
  873. }
  874. }
  875. public function toup()
  876. {
  877. $p = isset($_POST['p']) ? intval($_POST['p']) : 1;
  878. $size = 10;
  879. $off_set = ($p -1) * $size;
  880. $is_ajax = isset($_POST['is_ajax']) ? true: false;
  881. $tou_list = M('toupiao')->where()->order('vote_count desc')->limit($off_set.','.$size)->select();
  882. if($is_ajax) {
  883. $result = array('ret' =>1);
  884. if(!empty($tou_list)) {
  885. $result = array('ret' =>0);
  886. $result['list'] = $tou_list;
  887. }
  888. echo json_encode($result);
  889. die();
  890. }
  891. $tou_left = array();
  892. $tou_right = array();
  893. $is_left = true;
  894. foreach($tou_list as $val)
  895. {
  896. if($is_left)
  897. $tou_left[] = $val;
  898. else
  899. $tou_right[] = $val;
  900. $is_left = $is_left ? false : true;
  901. }
  902. $baom_count = M('toupiao')->count();
  903. $toup_count = M('toupiao_record')->count();
  904. $this->assign('baom_count', $baom_count);
  905. $this->assign('toup_count', $toup_count);
  906. $this->assign('siteurl', 'http://'.$_SERVER['HTTP_HOST']);
  907. $this->assign('tou_left', $tou_left);
  908. $this->assign('tou_right', $tou_right);
  909. $this->assign('baom', U('Index/baom'));
  910. $this->assign('toup', U('Index/toup'));
  911. $this->assign('toupsuburl', U('Index/toupsub'));
  912. $this->assign('tou_list', $tou_list);
  913. $this->display();
  914. }
  915. public function toupsub()
  916. {
  917. //data:{bid_str:bid_str,cid:cid,openid:openid},
  918. /**
  919. array(3) {
  920. ["bid_str"]=>
  921. string(40) "26,36,60,64,69,66,136,76,156,106,146,160"
  922. ["cid"]=>
  923. string(1) "1"
  924. ["openid"]=>
  925. string(28) "o0Vb0juyDM56F6ds32qv_cjiuCc8"
  926. }
  927. **/
  928. $cid = intval($_POST['cid']);
  929. $bid_str = $_POST['bid_str'];
  930. $bid_arr = explode(',', $bid_str);
  931. $openid = htmlspecialchars($_POST['openid']);
  932. $user_info = M('user')->where("openid ='{$openid}'")->find();
  933. $result = array();
  934. $result['ret'] = 0;
  935. if(!$user_info) {
  936. $result['msg'] = '请关注闽南网,并点击菜单中宝宝投票,进入投票';
  937. echo json_encode($result);
  938. die();//
  939. }
  940. if(empty($bid_arr)) {
  941. $result['msg'] = '请选择要投票的宝贝';
  942. echo json_encode($result);
  943. die();//
  944. }
  945. if($cid != 1 && $cid !=2)
  946. {
  947. $result['msg'] = '非法操作';
  948. echo json_encode($result);
  949. die();//
  950. }
  951. $ck_info = M('toupiao_record')->where(array('openid'=>$openid,'cid'=>$cid))->find();
  952. if($ck_info){
  953. $result['msg'] = '该组别您已经投过票了。';
  954. echo json_encode($result);
  955. die();//
  956. }
  957. /**
  958. $end_time = '2015-09-30 23:59:39';
  959. if(time() >= strtotime($end_time))
  960. {
  961. $result['msg'] = '投票已结束,感谢您的参与。';
  962. echo json_encode($result);
  963. die();
  964. }
  965. **/
  966. $tip = get_client_ip();
  967. $ipkey = md5($tip.$_SERVER['HTTP_USER_AGENT']);
  968. $no_time = strtotime(date('Y-m-d'));
  969. $need_arr = array();
  970. foreach($bid_arr as $val)
  971. {
  972. if(empty($need_arr) || !in_array($val,$need_arr) )
  973. {
  974. $need_arr[] = $val;
  975. $tid = intval($val);
  976. $param = array();
  977. $param['tid'] = $tid;
  978. $param['tip'] = $tip;
  979. $param['cid'] = $cid;
  980. $param['openid'] = $openid;
  981. $param['ipkey'] = $ipkey;
  982. $param['createtime'] = $no_time;
  983. M('toupiao_record')->add($param);
  984. M('toupiao')->where('id='.$tid)->setInc('vote_count',1);
  985. }
  986. }
  987. $result['ret'] = 1;
  988. $result['msg'] = '投票成功';
  989. echo json_encode($result);
  990. die();
  991. }
  992. public function uppic(){
  993. $upload = new \Think\Upload();// 实例化上传类
  994. $upload->maxSize = 4194304;// 设置附件上传大小
  995. $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
  996. $upload->rootPath = './Uploads/'; // 设置附件上传根目录
  997. $upload->savePath = ''; // 设置附件上传(子)目录
  998. $upload->thumb = true; // 设置附件上传(子)目录
  999. $upload->thumbMaxWidth = 640;
  1000. $upload->thumbPath = './Uploads/';
  1001. $info = $upload->upload();
  1002. foreach($info as $key => &$val)
  1003. {
  1004. $image = new \Think\Image();
  1005. $image->open('./Uploads/'.$val['savepath'].$val['savename']);
  1006. // 按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.jpg
  1007. $val['thumb_url'] = './Uploads/'.date('Y-m-d').'/'.md5(time()).'.jpg';
  1008. $thumb = $image->thumb(640, 640)->save($val['thumb_url']);
  1009. }
  1010. if(!$info) {// 上传错误提示错误信息
  1011. $this->error($upload->getError());
  1012. }else{// 上传成功
  1013. echo json_encode($info);
  1014. }
  1015. die();
  1016. }
  1017. }
  1018. ?>