ApiController.class.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Home\Controller;
  15. class ApiController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->cur_page = 'api';
  20. $site_logo = M('config')->where( array('name'=>'SITE_ICON') )->find();
  21. $this->site_logo = $site_logo['value'];
  22. }
  23. /**
  24. 今日签到红包情况
  25. **/
  26. public function get_fissionbunus()
  27. {
  28. $token = I('get.token');
  29. $other_bonus_id = I('get.other_bonus_id', 0);
  30. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  31. $member_id = $weprogram_token['member_id'];
  32. if( empty($member_id) )
  33. {
  34. echo json_encode( array('code' => 3) );
  35. die();
  36. }
  37. $bonus_share_title_arr = M('config')->where( array('name' =>'bonus_share_title') )->find();
  38. $bonus_rule_arr = M('config')->where( array('name' =>'bonus_rule') )->find();
  39. $bonus_game_time_arr = M('config')->where( array('name' =>'bonus_game_time') )->find();
  40. $bonus_money_arr = M('config')->where( array('name' =>'bonus_money') )->find();
  41. $bonus_count_arr = M('config')->where( array('name' =>'bonus_count') )->find();
  42. $is_open_fissionbonus_arr = M('config')->where( array('name' =>'is_open_fissionbonus') )->find();
  43. $share_image_arr = M('config')->where( array('name' =>'fissionbonus_share_image') )->find();
  44. $share_image = '';
  45. if(!empty($share_image_arr['value']))
  46. {
  47. $share_image = C('SITE_URL').'Uploads/image/'.$share_image_arr['value'];
  48. }
  49. $need_data = array();
  50. $qian=array("\r\n");
  51. $hou=array("@F@");
  52. $bonus_rule_str = str_replace($qian,$hou,$bonus_rule_arr['value']);
  53. $bonus_rule_str = explode('@F@',$bonus_rule_str);
  54. $need_data['kan_description_str'] = $bonus_rule_str;
  55. $need_data['bonus_share_title'] = $bonus_share_title_arr['value'];
  56. $need_data['bonus_game_time'] = $bonus_game_time_arr['value'];
  57. $need_data['bonus_count'] = $bonus_count_arr['value'];
  58. $need_data['is_open_fissionbonus'] = $is_open_fissionbonus_arr['value'];
  59. if($is_open_fissionbonus_arr['value'] == 0)
  60. {
  61. echo json_encode(array('code'=>1));
  62. die();
  63. }
  64. //检测是否签到过了。
  65. $begin_time = strtotime( date('Y-m-d').' 00:00:00' );
  66. $now_time = time();
  67. $over_where = " member_id = {$member_id} and (state = 0 and end_time < {$now_time} ) ";
  68. M('fissionbonus')->where($over_where)->save( array('state' =>2) );
  69. $where = " member_id = {$member_id} and (state = 0 or state = 1 ) and begin_time > {$begin_time} ";
  70. $fissionbonus_info = M('fissionbonus')->where( $where )->find();
  71. $bonus_id = $fissionbonus_info['id'];
  72. if(empty($fissionbonus_info) && $is_open_fissionbonus_arr['value'] == 1)
  73. {
  74. //开启一个签到
  75. $bonus_id = D('Seller/Fissionbonus')->open_new_bonus($member_id);
  76. //给自己插入今天的bonus金额
  77. //D('Seller/Fissionbonus')->get_fissionbonus_order($bonus_id, $member_id);
  78. $fissionbonus_info = M('fissionbonus')->where( array('id' => $bonus_id) )->find();
  79. }
  80. //is_me , has_click
  81. $is_me = 0;
  82. $has_click = 0;
  83. if($member_id == $fissionbonus_info['member_id'])
  84. {
  85. $is_me = 1;
  86. }
  87. $has_click_info = M('fissionbonus_order')->where( array('fissionbonus_id' => $bonus_id, 'member_id' => $member_id) )->find();
  88. if( !empty($has_click_info) )
  89. {
  90. $has_click =1;
  91. }
  92. //order_list":null,"bonus_money":null,
  93. //获取今日签到的朋友名单
  94. $order_list = M('fissionbonus_order')->where( array('fissionbonus_id' => $bonus_id) )->order('id asc')->select();
  95. if( empty($order_list) )
  96. {
  97. $order_list = array();
  98. }else{
  99. foreach($order_list as $key => $val)
  100. {
  101. // array('avatar' =>)
  102. $mb_info = M('member')->field('avatar')->where( array('member_id' => $val['member_id']) )->find();
  103. $val['avatar'] = $mb_info['avatar'];
  104. $order_list[$key] = $val;
  105. }
  106. }
  107. //统计已经领走金额
  108. $bonus_money = M('fissionbonus_order')->where( array('fissionbonus_id' => $bonus_id) )->sum('money');
  109. $need_data['bonus_id'] = $bonus_id;
  110. $need_data['is_me'] = $is_me;
  111. $need_data['is_over'] = $fissionbonus_info['state'];
  112. $need_data['has_click'] = $has_click;
  113. $need_data['order_list'] = $order_list;
  114. $need_data['bonus_money'] = empty($bonus_money) ? 0 : $bonus_money;
  115. $need_data['cur_time'] = time();
  116. $need_data['share_image'] = $share_image;
  117. $need_data['end_time'] = $fissionbonus_info['end_time'];
  118. $need_data['del_count'] = $fissionbonus_info['count'] - count($order_list);
  119. //del_count
  120. $go_for = array();
  121. for($i =0; $i < $need_data['del_count']; $i++)
  122. {
  123. if($i == $need_data['del_count'] -1 )
  124. {
  125. $go_for[] = 88;
  126. }else{
  127. $go_for[] = 1;
  128. }
  129. }
  130. $need_data['go_for'] = $go_for;
  131. echo json_encode( array('code' =>0,'data' =>$need_data) );
  132. die();
  133. }
  134. /***
  135. 获取今日帮忙点击签到的提示效果
  136. **/
  137. public function get_fissionbunus_notify()
  138. {
  139. $token = I('get.token');
  140. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  141. $member_id = $weprogram_token['member_id'];
  142. if( empty($member_id) )
  143. {
  144. echo json_encode( array('code' => 1) );
  145. die();
  146. }
  147. $now_time = strtotime( date('Y-m-d').' 00:00:00' );
  148. $where = " member_id = {$member_id} and begin_time > {$now_time} ";
  149. $fissionbonus_info = M('fissionbonus')->where( $where )->find();
  150. if( !empty($fissionbonus_info) )
  151. {
  152. $bonus_id = $fissionbonus_info['id'];
  153. $order_info = M('fissionbonus_order')->where( array('fissionbonus_id' =>$bonus_id,'is_notify' => 0 ) )->order('id desc')->find();
  154. if( !empty($order_info) )
  155. {
  156. $member_info = M('member')->where( array('member_id' => $order_info['member_id']) )->find();
  157. M('fissionbonus_order')->where( array('fissionbonus_id' =>$bonus_id,'is_notify' => 0 ) )->save( array('is_notify' => 1) );
  158. echo json_encode( array('code' => 0, 'money' => $order_info['money'],'member_name' => $member_info['uname']) );
  159. die();
  160. }else{
  161. echo json_encode( array('code' => 1) );
  162. die();
  163. }
  164. }else{
  165. echo json_encode( array('code' => 1) );
  166. die();
  167. }
  168. }
  169. public function click_fissionbunus()
  170. {
  171. $token = I('get.token');
  172. /// Api/click_fissionbunus/token/fbd91bce7e444fda0a34ca479c590822/bonus_id/1/other_bonus_id/0
  173. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  174. $member_id = $weprogram_token['member_id'];
  175. if( empty($member_id) )
  176. {
  177. echo json_encode( array('code' => 1) );
  178. die();
  179. }
  180. $bonus_id = I('get.bonus_id', 0);
  181. $bonus_info = M('fissionbonus')->where( array('member_id' => $member_id,'id' =>$bonus_id ) )->find();
  182. if( empty($bonus_info) )
  183. {
  184. echo json_encode( array('code' => 1) );
  185. die();
  186. }
  187. $self_money = D('Seller/Fissionbonus')->get_fissionbonus_order($bonus_id, $member_id);
  188. $other_bonus_id = I('get.other_bonus_id', 0);
  189. $other_member_name = '';
  190. $other_money = 0;
  191. if( $other_bonus_id > 0 )
  192. {
  193. $other_money = D('Seller/Fissionbonus')->get_fissionbonus_order($other_bonus_id, $member_id);
  194. if($other_money > 0)
  195. {
  196. $other_bonus_info = M('fissionbonus')->where( array('id' => $other_bonus_id) )->find();
  197. $other_member_info = M('member')->where( array('member_id' => $other_bonus_info['member_id']) )->find();
  198. $other_member_name = $other_member_info['uname'];
  199. }
  200. }
  201. $need_data = array();
  202. $fissionbonus_info = M('fissionbonus')->where( array('id' => $bonus_id) )->find();
  203. //获取今日签到的朋友名单
  204. $order_list = M('fissionbonus_order')->where( array('fissionbonus_id' => $bonus_id) )->order('id asc')->select();
  205. foreach($order_list as $key => $val)
  206. {
  207. $mb_info = M('member')->field('avatar')->where( array('member_id' => $val['member_id']) )->find();
  208. $val['avatar'] = $mb_info['avatar'];
  209. $order_list[$key] = $val;
  210. }
  211. //统计已经领走金额
  212. $bonus_money = M('fissionbonus_order')->where( array('fissionbonus_id' => $bonus_id) )->sum('money');
  213. $need_data['bonus_id'] = $bonus_id;
  214. $need_data['is_over'] = $fissionbonus_info['state'];
  215. $need_data['has_click'] = 1;
  216. $need_data['order_list'] = $order_list;
  217. $need_data['bonus_money'] = $bonus_money;
  218. $need_data['other_money'] = $other_money;
  219. $need_data['self_money'] = $self_money;
  220. $need_data['other_member_name'] = $other_member_name;
  221. //$need_data['other_member_name'] = $other_member_name;
  222. $bonus_image = "https://mall.shiziyu888.com/dan/Common/images/5b0f6e9bNac244f75.png";
  223. $detai_image = M('config')->where( array('name' => 'fissionbonus_detail_image') )->find();
  224. if( !empty($detai_image['value']) )
  225. {
  226. $bonus_image = C('SITE_URL').'Uploads/image/'.$detai_image['value'];
  227. }
  228. $need_data['bonus_image'] = $bonus_image;
  229. $need_data['del_count'] = $fissionbonus_info['count'] - count($order_list);
  230. //del_count
  231. $go_for = array();
  232. for($i =0; $i < $need_data['del_count']; $i++)
  233. {
  234. if($i == $need_data['del_count'] -1 )
  235. {
  236. $go_for[] = 88;
  237. }else{
  238. $go_for[] = 1;
  239. }
  240. }
  241. $need_data['go_for'] = $go_for;
  242. echo json_encode( array('code' =>0,'data' =>$need_data) );
  243. die();
  244. }
  245. public function get_fissionbunus_info()
  246. {
  247. $token = I('get.token');
  248. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  249. $member_id = $weprogram_token['member_id'];
  250. if( empty($member_id) )
  251. {
  252. echo json_encode( array('code' => 1) );
  253. die();
  254. }
  255. $member_info = M('member')->field('account_money,avatar,uname')->where( array('member_id' => $member_id) )->find();
  256. //总获得的签到金额
  257. $total_get_money = M('fissionbonus_flow')->where( array('member_id' => $member_id ,'type' => array('in','1,2')) )->sum('money');
  258. $cur_get_money = $member_info['account_money'];
  259. $need_data = array();
  260. $need_data['total_get_money'] = $total_get_money;
  261. $need_data['cur_get_money'] = $cur_get_money;
  262. $need_data['avatar'] = $member_info['avatar'];
  263. $need_data['nickname'] = $member_info['uname'];
  264. echo json_encode( array('code'=>0, 'data' => $need_data) );
  265. die();
  266. }
  267. //https://mall.shiziyu888.com/dan/index.php?s=/Api/fissionbunus_order_list&page=1&token=bf9af064455d72cf9f69762fbee51cb2
  268. public function fissionbunus_order_list()
  269. {
  270. $token = I('get.token');
  271. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  272. $member_id = $weprogram_token['member_id'];
  273. $page = I('get.page',1);
  274. $pre_page = I('get.pre_page',15);
  275. $offset = ($page -1) * $pre_page;
  276. //$member
  277. $condition = array('member_id' => $member_id);
  278. $list = M('fissionbonus_flow')->where($condition)->order('id desc')->limit($offset,$pre_page)->select();
  279. $now_time = time();
  280. foreach($list as $key => $val)
  281. {
  282. if($val['type'] != 1)
  283. {
  284. $tmp_member = M('member')->field('uname')->where( array('member_id' => $val['send_member_id']) )->find();
  285. $val['send_member_name'] = $tmp_member['uname'];
  286. }
  287. $val['create_time'] = date('Y.m.d ', $val['addtime']);
  288. $list[$key] = $val;
  289. }
  290. if( empty($list) )
  291. {
  292. echo json_encode( array('code' =>1) );
  293. }else {
  294. echo json_encode( array('code' =>0, 'list' => $list) );
  295. }
  296. }
  297. public function banner_list()
  298. {
  299. if (!$slider_cache = S('xiao_index_cache')) {
  300. $slider=M('plugins_slider')->where( array('type' => 'xiao_index') )->field('image,url')->order('sort_order desc')->select();
  301. S('xiao_index_cache', $slider);
  302. $slider_cache=$slider;
  303. }
  304. $banner_list = array();
  305. foreach($slider_cache as $ad)
  306. {
  307. $tmp = array();
  308. //banner_type target_url image_url imageWidth imageheight
  309. $tmp['banner_type'] = $ad['type'];
  310. $tmp['target_url'] = $ad['url'];
  311. $tmp['image_url'] = str_replace('http','https',C('SITE_URL')).'/Uploads/image/'.$ad['image'];
  312. $img_info = getimagesize(ROOT_PATH.'/Uploads/image/'.$ad['image']);
  313. $tmp['imageWidth'] = $img_info[0];
  314. $tmp['imageheight'] = $img_info[1];
  315. $banner_list[] = $tmp;
  316. }
  317. $data = array('code' => 1, 'banners' => $banner_list);
  318. echo json_encode($data);
  319. die();
  320. }
  321. public function goodsCate()
  322. {
  323. $key='index_goodscategory_cache';
  324. if (!$hot_list = S($key)) {
  325. $hot_list = M('goods_category')->where( array('is_hot' => 1) )->order('sort_order desc')->select();
  326. S($key, $hot_list);
  327. }
  328. //cate_id cate_name id
  329. $need_data = array();
  330. foreach($hot_list as $key => $cate)
  331. {
  332. $tmp = array();
  333. $tmp['cate_id'] = $cate['id'];
  334. $tmp['cate_name'] = $cate['name'];
  335. $need_data[] = $tmp;
  336. }
  337. $data = array('code' => 1,'cates' => $need_data);
  338. echo json_encode($data);
  339. die();
  340. }
  341. public function goods_detail()
  342. {
  343. $goods_id = I('get.goods_id');
  344. //gallery =>img_url
  345. //goods goods.goods_desc goods_name group_price market_price sell_count group_number
  346. $sql="select g.*,gd.description,gd.summary,gd.tag from ".
  347. C('DB_PREFIX')."goods g,".C('DB_PREFIX')."goods_description gd where g.goods_id=gd.goods_id and g.goods_id=".$goods_id;
  348. $goods_arr=M()->query($sql);
  349. $qian=array("\r\n");
  350. $hou=array("<br/>");
  351. $goods_arr[0]['summary'] = str_replace($qian,$hou,$goods_arr[0]['summary']);
  352. $sql="select image from ".C('DB_PREFIX')."goods_image where goods_id=".$goods_id;
  353. $goods_image=M()->query($sql);
  354. $gallery = array();
  355. $default_image = '';
  356. foreach($goods_image as $val)
  357. {
  358. $val['img_url'] = str_replace('http','https',C('SITE_URL')).'/Uploads/image/'.$val['image'];
  359. if(empty($default_image))
  360. {
  361. $default_image = str_replace('http','https',C('SITE_URL')).resize($val['image'], C('goods_thumb_width'), C('goods_thumb_height'));
  362. }
  363. $gallery[] = array('img_url' => $val['img_url']);
  364. }
  365. $goods = $goods_arr[0];
  366. $need_goods = array();
  367. $need_goods['goods_id'] = $goods['goods_id'];
  368. $need_goods['goods_name'] = $goods['name'];
  369. $need_goods['group_price'] = $goods['pinprice'];
  370. $need_goods['alone_price'] = $goods['danprice'];
  371. $need_goods['market_price'] = $goods['price'];
  372. $need_goods['sell_count'] = $goods['seller_count'] + $goods['virtual_count'];
  373. $need_goods['group_number'] = $goods['pin_count'];
  374. $need_goods['goods_desc'] = $goods['description'];
  375. $need_goods['sell_type'] = 0;
  376. $options=$this->get_goods_options($goods_id);
  377. $goods_option_mult_value = M('goods_option_mult_value')->where( array('goods_id' =>$goods_id) )->select();
  378. foreach($goods_option_mult_value as $key => $val)
  379. {
  380. $val['image'] = str_replace('http','https',C('SITE_URL')).resize($val['image'],200,200);
  381. $goods_option_mult_value[$key] = $val;
  382. }
  383. $result = array('code' => 1,'default_image' =>$default_image,'goods' => $need_goods,'goods_option_mult_value' =>$goods_option_mult_value, 'sku_options' =>$options,'option_names'=>implode('、',$options['name']), 'gallery' => $gallery);
  384. echo json_encode($result);
  385. die();
  386. }
  387. public function get_goods_options($goods_id) {
  388. $result = array();
  389. $goods_option_name = array();
  390. $goods_option_data = array();
  391. $goods_option_query = M()->query("SELECT * FROM " . C('DB_PREFIX') . "goods_option po LEFT JOIN "
  392. . C('DB_PREFIX') . "option o ON po.option_id = o.option_id WHERE po.goods_id =".(int)$goods_id);
  393. foreach ($goods_option_query as $goods_option) {
  394. $goods_option_value_data = array();
  395. $goods_option_value_query = M()->query("SELECT pov.*,ov.value_name FROM " . C('DB_PREFIX')
  396. . "goods_option_value pov LEFT JOIN ". C('DB_PREFIX')
  397. ."option_value ov ON pov.option_value_id=ov.option_value_id"
  398. ." WHERE pov.goods_option_id = '"
  399. . (int)$goods_option['goods_option_id'] . "'");
  400. foreach ($goods_option_value_query as $goods_option_value) {
  401. $goods_option_value_data[] = array(
  402. 'goods_option_value_id' => $goods_option_value['goods_option_value_id'],
  403. 'option_value_id' => $goods_option_value['option_value_id'],
  404. 'quantity' => $goods_option_value['quantity'],
  405. 'name' =>$goods_option_value['value_name'],
  406. 'image' =>isset($goods_option_value['image'])?$goods_option_value['image']:'',
  407. 'price' =>'¥'.$goods_option_value['price'],
  408. 'price_prefix' => $goods_option_value['price_prefix'],
  409. 'checked' => 0,
  410. );
  411. }
  412. $goods_option_name[] = $goods_option['name'];
  413. $goods_option_data[] = array(
  414. 'goods_option_id' => $goods_option['goods_option_id'],
  415. 'option_id' => $goods_option['option_id'],
  416. 'name' => $goods_option['name'],
  417. 'type' => $goods_option['type'],
  418. 'option_value' => $goods_option_value_data,
  419. 'required' => $goods_option['required']
  420. );
  421. }
  422. $result['list'] = $goods_option_data;
  423. $result['name'] = $goods_option_name;
  424. return $result;
  425. }
  426. public function getGoods_bycate()
  427. {
  428. //&offset=0&size=5&cate_id=48
  429. $offset = I('get.offset',0);
  430. $pre_page = I('get.size',10);
  431. $cate_id = I('get.cate_id',0);
  432. $goods_ids_arr = M('goods_to_category')->where("class_id1 ={$cate_id} or class_id2 ={$cate_id} or class_id3 = {$cate_id} ")->field('goods_id')->select();
  433. $ids_arr = array();
  434. foreach($goods_ids_arr as $val){
  435. $ids_arr[] = $val['goods_id'];
  436. }
  437. $ids_str = implode(',',$ids_arr);
  438. $condition = array('goods_id' => array('in',$ids_str), 'status'=>1,'type'=>array('neq','lottery'),'quantity' =>array('gt',0) );
  439. $list = M('goods')->field('goods_id,name,image,pinprice,danprice')->where($condition)->order('seller_count desc,goods_id asc')->limit($offset,$pre_page)->select();
  440. $need_data = array();
  441. foreach($list as $goods)
  442. {
  443. $tmp = array();
  444. $tmp['goods_id'] = $goods['goods_id'];
  445. $tmp['image_url'] = C('SITE_URL').'/Uploads/image/'.$goods['image'];
  446. $tmp['goods_name'] = $goods['name'];
  447. $tmp['group_price'] = $goods['pinprice'];
  448. $tmp['alone_price'] = $goods['danprice'];
  449. $need_data[] = $tmp;
  450. }
  451. $result = array('goods' => $need_data);
  452. echo json_encode($result);
  453. die();
  454. }
  455. public function Goods_lists()
  456. {
  457. //data.goods.length
  458. // "offset" : offset,
  459. //"size" : size C('SITE_URL').'/Uploads/image/'
  460. //goods => goods_id image_url goods_name group_price group_number alone_price
  461. $offset = I('get.offset',0);
  462. $pre_page = I('get.size',10);
  463. $condition = array('status'=>1,'is_index_show' => 1,'type'=>array('neq','lottery'), 'quantity' =>array('gt',0) );
  464. $list = M('goods')->field('goods_id,name,image,pinprice,danprice')->where($condition)->order('index_sort desc ,seller_count desc,goods_id asc')->limit($offset,$pre_page)->select();
  465. $need_data = array();
  466. foreach($list as $goods)
  467. {
  468. $tmp = array();
  469. $tmp['goods_id'] = $goods['goods_id'];
  470. $tmp['image_url'] = C('SITE_URL').'/Uploads/image/'.$goods['image'];
  471. $tmp['goods_name'] = $goods['name'];
  472. $tmp['group_price'] = $goods['pinprice'];
  473. $tmp['alone_price'] = $goods['danprice'];
  474. $need_data[] = $tmp;
  475. }
  476. $result = array('goods' => $need_data);
  477. echo json_encode($result);
  478. die();
  479. }
  480. public function index(){
  481. $page = I('get.page',1);
  482. $pre_page = 4;
  483. $condition = array('status'=>1,'is_index_show' => 1, 'quantity' =>array('gt',0) );
  484. $offset = ($page -1) * $pre_page;
  485. $list = M('goods')->where($condition)->order('index_sort desc ,seller_count desc,goods_id asc')->limit($offset,$pre_page)->select();
  486. $goods_model = D('Home/Goods');
  487. if(!empty($list))
  488. {
  489. foreach($list as $key => $val)
  490. {
  491. $val['avatar_list'] = $goods_model->get_goods_pin_avatar($val['goods_id'],10);
  492. $list[$key] = $val;
  493. }
  494. }
  495. $this->list = $list;
  496. $subject_pre_page = 1;
  497. $sub_where = " begin_time <".time()." and end_time >".time()." and type != 'haitao' ";
  498. $subject_offset = ($page -1) * $subject_pre_page;
  499. $sublist_list = M('subject')->where( $sub_where )->order('begin_time desc')->limit($subject_offset,$subject_pre_page)->select();
  500. //quan_list
  501. $where = "total_count>send_count and store_id =0 and is_index_show=1 and end_time>".time();
  502. $quan_list = M('voucher')->where($where)->order('add_time desc')->limit(5)->select();
  503. $this->quan_list = $quan_list;
  504. if(!empty($sublist_list))
  505. {
  506. $can_subject_list = array();
  507. foreach($sublist_list as $key => $val)
  508. {
  509. $subject_goods = M('subject_goods')->where( array('state' => 1, 'subject_id' => $val['id']) )->order('id asc ')->limit(10)->select();
  510. $need_subject_goods = array();
  511. foreach($subject_goods as $kk => $vv)
  512. {
  513. $tp_goods = M('goods')->where( array('goods_id' => $vv['goods_id'],'status'=>1) )->find();
  514. if(empty($tp_goods))
  515. {
  516. continue;
  517. }
  518. if(!empty($tp_goods['fan_image'])){
  519. $tp_goods['image']=resize($tp_goods['fan_image'], 220, 220);
  520. }else {
  521. $tp_goods['image']=resize($tp_goods['image'], 220, 220);
  522. }
  523. $vv['goods'] = $tp_goods;
  524. //$subject_goods[$kk] = $vv;
  525. $need_subject_goods[$kk] = $vv;
  526. }
  527. if(!empty($subject_goods)) {
  528. $val['goods_list'] = $need_subject_goods;
  529. $can_subject_list[$key] = $val;
  530. }
  531. }
  532. }
  533. $this->sublist_list = $can_subject_list;
  534. if($page > 1) {
  535. $content = $this->fetch('Widget:index_ajax_goods_list_fetch');
  536. $result = array('code' => 0);
  537. if(!empty($list)) {
  538. $result['code'] = 1;
  539. $result['html'] = $this->fetch('Widget:index_ajax_goods_list_fetch');
  540. }
  541. echo json_encode($result);
  542. die();
  543. }
  544. $appid_info = M('config')->where( array('name' => 'APPID') )->find();
  545. $appsecret_info = M('config')->where( array('name' => 'APPSECRET') )->find();
  546. $weixin_config = array();
  547. $weixin_config['appid'] = $appid_info['value'];
  548. $weixin_config['appscert'] = $appsecret_info['value'];
  549. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  550. $uid = is_login();
  551. $member_info = M('member')->where( array('member_id' => $uid) )->find();
  552. $is_sub = $jssdk->cgigetinfo($member_info['openid']);
  553. $sub_url = C('SHORT_URL');
  554. $site_title = C('SITE_TITLE');
  555. $site_name = C('SITE_NAME');
  556. $site_logo = C('SITE_ICON');
  557. $this->is_sub = $is_sub;
  558. $this->sub_url = $sub_url;
  559. $this->site_title = $site_title;
  560. $this->site_name = $site_name;
  561. $this->site_logo = $site_logo;
  562. $this->display();
  563. }
  564. }