ApiindexController.class.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. <?php
  2. namespace Home\Controller;
  3. class ApiindexController extends CommonController {
  4. protected function _initialize()
  5. {
  6. parent::_initialize();
  7. $this->cur_page = 'apiindex';
  8. }
  9. /**
  10. 获取当前前端小程序样式类型
  11. **/
  12. public function get_cur_theme_type()
  13. {
  14. $type = C('THEME_TYPE');
  15. $cpage = I('get.cpage','index');
  16. $title = C('SITE_NAME');
  17. switch($title)
  18. {
  19. case 'index':
  20. $title = C('SITE_NAME');
  21. break;
  22. }
  23. echo json_encode( array('code' => 0 , 'type' => $type, 'title' => $title) );
  24. die();
  25. }
  26. /** 加载首页广告位 **/
  27. public function load_index_addata() {
  28. $type = I('get.type','index_wepro_head');
  29. //if (!$slider_cache = S('slider_'.$type.'_cache')) {
  30. $slider=M('plugins_slider')->where( array('type' => $type) )->field('slider_id,slider_name,image,url')->order(' sort_order desc,slider_id desc')->select();
  31. S('slider_'.$type.'_cache', $slider);
  32. $slider_cache=$slider;
  33. //}
  34. //var_dump($slider, M('plugins_slider')->getLastSql());die();
  35. $need_data = array();
  36. foreach($slider_cache as $key => $val)
  37. {
  38. $need_data[$key]['name'] = $val['slider_name'];
  39. $need_data[$key]['slider_id'] = $val['slider_id'];
  40. $need_data[$key]['image'] = C('SITE_URL').'Uploads/image/'.$val['image'];
  41. $need_data[$key]['url'] = $val['url'];
  42. }
  43. echo json_encode( array('code' => 0, 'data' => $need_data) );
  44. die();
  45. }
  46. public function ad_detail()
  47. {
  48. $slider_id = I('get.slider_id');
  49. $info = M('plugins_slider')->where( array('slider_id' => $slider_id) )->find();
  50. $info['webview_url'] = htmlspecialchars_decode($info['webview_url']);
  51. echo json_encode( array('code' => 0 ,'info' =>$info ) );
  52. die();
  53. }
  54. /**
  55. 检测今天是否需要弹窗
  56. **/
  57. public function check_index_bonus_window()
  58. {
  59. $token = I('get.token');
  60. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  61. $member_id = $weprogram_token['member_id'];
  62. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  63. if( empty($member_info) )
  64. {
  65. echo json_encode( array('code' =>1) );
  66. die();
  67. }
  68. $tan_info = M('config')->where( array('name' => 'fissionbonus_index_tan') )->find();
  69. if( $tan_info['value'] ==1)
  70. {
  71. $begin_time = strtotime( date('Y-m-d').' 00:00:00' );
  72. $where = " member_id = {$member_id} and is_self = 1 and addtime > {$begin_time} ";
  73. $order_info = M('fissionbonus_order')->where($where)->find();
  74. if( !empty($order_info) )
  75. {
  76. //今日已经签到过了
  77. echo json_encode( array('code' =>1) );
  78. die();
  79. }else{
  80. //今日未签到,要弹出窗口
  81. //检测是否有图片
  82. $fissionbonus_index_image_info = M('config')->where( array('name' => 'fissionbonus_index_image') )->find();
  83. if( !empty($fissionbonus_index_image_info['value']) )
  84. {
  85. $image = C('SITE_URL').'Uploads/image/'.$fissionbonus_index_image_info['value'];
  86. echo json_encode( array('code' =>0,'image' => $image) );
  87. die();
  88. }else{
  89. echo json_encode( array('code' =>1) );
  90. die();
  91. }
  92. }
  93. }else{
  94. echo json_encode( array('code' =>1) );
  95. die();
  96. }
  97. }
  98. public function index_share()
  99. {
  100. $index_share_titile = C('index_share_titile');
  101. echo json_encode( array('code' => 0, 'title' => $index_share_titile) );
  102. die();
  103. }
  104. /** 加载分页的推荐拼团数据 **/
  105. public function load_index_pintuan()
  106. {
  107. $page = I('get.page',1,'intval');
  108. $per_page = I('get.per_page', 10, 'intval');
  109. $gid = I('get.gid', 0, 'intval');
  110. $store_id = I('get.store_id', 0, 'intval');
  111. $orderby = I('get.orderby', 'default');
  112. $is_index_show = I('get.is_index_show', 1, 'intval');
  113. $type = I('get.type', 'normal');
  114. //begin_time end_time
  115. $now_time = time();
  116. $offset = ($page -1) * $per_page;
  117. $where = "g.status =1 and (g.type != 'normal' and g.type != 'bargain' and g.type != 'integral') and g.quantity >0 and pg.type='{$type}' ";
  118. if( $type =='all' )
  119. {
  120. $where = "g.status =1 and g.quantity >0 ";
  121. }
  122. if( !empty($gid) && $gid >0 )
  123. {
  124. $goods_ids_arr = M('goods_to_category')->where("class_id1 ={$gid} or class_id2 ={$gid} or class_id3 = {$gid} ")->field('goods_id')->select();
  125. $ids_arr = array();
  126. foreach($goods_ids_arr as $val){
  127. $ids_arr[] = $val['goods_id'];
  128. }
  129. $ids_str = implode(',',$ids_arr);
  130. //$condition = array('goods_id' => array('in',$ids_str), 'status'=>1,'quantity' =>array('gt',0) );
  131. if( !empty($ids_str) )
  132. {
  133. $where .= " and g.goods_id in ({$ids_str})";
  134. } else{
  135. $where .= " and 0 ";
  136. }
  137. }
  138. if($store_id > 0)
  139. {
  140. $where .= " and g.store_id = {$store_id} ";
  141. }
  142. if($is_index_show == 1)
  143. {
  144. $where .= " and g.is_index_show = 1 ";
  145. }else if($is_index_show == 0){
  146. $where .= " and g.is_index_show = 0 ";
  147. }
  148. $sortby = ' pg.id desc ';
  149. if($orderby == 'default')
  150. {
  151. $sortby = ' g.index_sort desc,g.goods_id desc ';
  152. }
  153. else if($orderby == 'new')
  154. {
  155. $sortby = ' g.goods_id desc ';
  156. }
  157. else if($orderby == 'seller_count')
  158. {
  159. $sortby = ' (g.seller_count + g.virtual_count) desc ';
  160. }
  161. else if($orderby == 'rand'){
  162. $sortby = ' rand() ';
  163. }
  164. $goods_model = D('Home/goods');
  165. if($type != 'lottery')
  166. {
  167. $where .= " and pg.begin_time < {$now_time} and pg.end_time >{$now_time} ";
  168. }
  169. $ping_goods = D('Home/Pingoods')->get_pingoods_list('*', $where,$sortby,$offset,$per_page);
  170. $need_data = array();
  171. if( !empty($ping_goods) )
  172. {
  173. foreach($ping_goods as $key => $val)
  174. {
  175. if( !empty($val['fan_image']) )
  176. {
  177. $fan_image = C('SITE_URL').resize($val['fan_image'], 300, 300);
  178. $val['fan_image'] = $fan_image;
  179. }else {
  180. $val['fan_image'] = C('SITE_URL').resize($val['image'], 300, 300);
  181. }
  182. $val['url'] = U('/goods/'.$val['goods_id']);
  183. //["type"]=> ,'oneyuan','haitao','normal','bargain','integral'
  184. // string(7) "lottery"
  185. $val['is_open'] = -1;
  186. if($val['type'] == 'lottery')
  187. {
  188. //is_open_lottery
  189. $lottery_goods = M('lottery_goods')->where( array('goods_id' => $val['goods_id']) )->find();
  190. if($lottery_goods['is_open_lottery'] == 1)
  191. {
  192. $val['is_open'] = 1;
  193. }else if($lottery_goods['end_time'] < time() )
  194. {
  195. $val['is_open'] = 2;
  196. }
  197. }
  198. $desc_info = D('Home/Pingoods')->get_goods_description($val['goods_id'],'summary');
  199. $need_data[$key]['goods_id'] = $val['goods_id'];
  200. $need_data[$key]['is_open'] = $val['is_open'];
  201. $need_data[$key]['type'] = $val['type'];
  202. $need_data[$key]['image'] = $val['fan_image'];
  203. $need_data[$key]['orign_image'] = C('SITE_URL').'Uploads/image/'.$val['image'];
  204. $need_data[$key]['pin_price'] = $val['pin_price'];
  205. $need_data[$key]['danprice'] = $val['danprice'];
  206. $price_arr = $goods_model->get_goods_price($val['goods_id']);
  207. $need_data[$key]['pin_price'] = $price_arr['pin_price'];
  208. $need_data[$key]['danprice'] = $price_arr['danprice'];
  209. $need_data[$key]['price'] = $val['price'];
  210. $need_data[$key]['pin_hour'] = $val['pin_hour'];
  211. $need_data[$key]['pin_count'] = $val['pin_count'];
  212. $need_data[$key]['name'] = $val['name'];
  213. $need_data[$key]['seller_count'] = $val['seller_count']+ $val['virtual_count'];
  214. $fav_goods = M('user_favgoods')->where( array('goods_id' => $val['goods_id']) )->count();
  215. $need_data[$key]['fav_goods'] = $fav_goods;
  216. //summary
  217. $need_data[$key]['quantity'] = $val['quantity'];
  218. $need_data[$key]['summary'] = htmlspecialchars_decode($desc_info['summary']);
  219. $need_data[$key]['url'] = $val['url'];
  220. }
  221. }
  222. if( !empty($need_data) )
  223. {
  224. echo json_encode( array('code' =>0, 'data' => $need_data) );
  225. die();
  226. } else{
  227. echo json_encode( array('code' =>1) );
  228. die();
  229. }
  230. }
  231. public function load_user_qrcode()
  232. {
  233. $token = I('get.token');
  234. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  235. $member_id = $weprogram_token['member_id'];
  236. $member_info = M('member')->field('wepro_qrcode')->where( array('member_id' => $member_id) )->find();
  237. if(!empty($member_info['wepro_qrcode']))
  238. {
  239. $result = array('code' => 0, 'image_path' => $member_info['wepro_qrcode']);
  240. echo json_encode($result);
  241. die();
  242. }else{
  243. $goods_model = D('Home/Goods');
  244. $rocede_path = $goods_model->_get_index_user_wxqrcode(0,$member_id);
  245. $res = $goods_model->_get_compare_qrcode_bgimg(C('user_qrcode_image'), $rocede_path,C('user_qrcode_x'), C('user_qrcode_y'));
  246. M('member')->field('wepro_qrcode')->where( array('member_id' => $member_id) )->save( array('wepro_qrcode' => $res['full_path']) );
  247. $result = array('code' => 0, 'image_path' => $res['full_path']);
  248. echo json_encode($result);
  249. die();
  250. }
  251. }
  252. public function load_index_bargain_pintuan()
  253. {
  254. $page = I('get.page',1,'intval');
  255. $per_page = I('get.per_page', 5, 'intval');
  256. $gid = I('get.gid', 0, 'intval');
  257. $store_id = I('get.store_id', 0, 'intval');
  258. $orderby = I('get.orderby', 'default');
  259. $is_index_show = I('get.is_index_show', 1, 'intval');
  260. $kan_rules = C('kan_rules');
  261. $qian=array("\r\n");
  262. $hou=array("@F@");
  263. $kan_rules_str = str_replace($qian,$hou,$kan_rules);
  264. $kan_rules_str = explode('@F@',$kan_rules_str);
  265. $type = I('get.type', 'normal');
  266. //begin_time end_time
  267. $now_time = time();
  268. $offset = ($page -1) * $per_page;
  269. $where = "g.status =1 and g.type != 'normal' and g.quantity >0 ";
  270. if( $type =='all' )
  271. {
  272. $where = "g.status =1 and g.quantity >0 ";
  273. }
  274. if( !empty($gid) && $gid >0 )
  275. {
  276. $goods_ids_arr = M('goods_to_category')->where("class_id1 ={$gid} or class_id2 ={$gid} or class_id3 = {$gid} ")->field('goods_id')->select();
  277. $ids_arr = array();
  278. foreach($goods_ids_arr as $val){
  279. $ids_arr[] = $val['goods_id'];
  280. }
  281. $ids_str = implode(',',$ids_arr);
  282. //$condition = array('goods_id' => array('in',$ids_str), 'status'=>1,'quantity' =>array('gt',0) );
  283. if( !empty($ids_str) )
  284. {
  285. $where .= " and g.goods_id in ({$ids_str})";
  286. } else{
  287. $where .= " and 0 ";
  288. }
  289. }
  290. if($store_id > 0)
  291. {
  292. $where .= " and g.store_id = {$store_id} ";
  293. }
  294. if($is_index_show == 1)
  295. {
  296. $where .= " and g.is_index_show = 1 ";
  297. }else if($is_index_show == 0){
  298. $where .= " and g.is_index_show = 0 ";
  299. }
  300. $sortby = ' pg.id desc ';
  301. if($orderby == 'default')
  302. {
  303. $sortby = ' g.index_sort desc,g.goods_id desc ';
  304. }
  305. else if($orderby == 'new')
  306. {
  307. $sortby = ' g.goods_id desc ';
  308. }
  309. else if($orderby == 'seller_count')
  310. {
  311. $sortby = ' (g.seller_count + g.virtual_count) desc ';
  312. }
  313. else if($orderby == 'rand'){
  314. $sortby = ' rand() ';
  315. }
  316. $goods_model = D('Home/goods');
  317. if($type != 'lottery')
  318. {
  319. $where .= " and pg.begin_time < {$now_time} and pg.end_time >{$now_time} ";
  320. }
  321. $ping_goods = D('Home/Pingoods')->get_bargaingoods_list('*', $where,$sortby,$offset,$per_page);
  322. $need_data = array();
  323. if( !empty($ping_goods) )
  324. {
  325. foreach($ping_goods as $key => $val)
  326. {
  327. if( !empty($val['fan_image']) )
  328. {
  329. $fan_image = C('SITE_URL').resize($val['fan_image'], 300, 300);
  330. $val['fan_image'] = $fan_image;
  331. }else {
  332. $val['fan_image'] = C('SITE_URL').resize($val['image'], 300, 300);
  333. }
  334. $val['url'] = U('/goods/'.$val['goods_id']);
  335. //["type"]=>
  336. // string(7) "lottery"
  337. $val['is_open'] = -1;
  338. $desc_info = D('Home/Pingoods')->get_goods_description($val['goods_id'],'summary');
  339. $need_data[$key]['goods_id'] = $val['goods_id'];
  340. $need_data[$key]['is_open'] = $val['is_open'];
  341. $need_data[$key]['image'] = $val['fan_image'];
  342. $need_data[$key]['orign_image'] = C('SITE_URL').'Uploads/image/'.$val['image'];
  343. $need_data[$key]['pin_price'] = $val['pin_price'];
  344. $need_data[$key]['danprice'] = $val['danprice'];
  345. $price_arr = $goods_model->get_goods_price($val['goods_id']);
  346. $need_data[$key]['pin_price'] = $price_arr['pin_price'];
  347. $need_data[$key]['danprice'] = $price_arr['danprice'];
  348. $need_data[$key]['price'] = $val['price'];
  349. $need_data[$key]['options'] = $goods_model->get_goods_options($val['goods_id']);
  350. $need_data[$key]['pin_hour'] = $val['hour'];
  351. $need_data[$key]['pin_count'] = $val['bargain_count'];
  352. $need_data[$key]['name'] = $val['name'];
  353. $need_data[$key]['seller_count'] = $val['seller_count']+ $val['virtual_count'];
  354. $fav_goods = M('user_favgoods')->where( array('goods_id' => $val['goods_id']) )->count();
  355. $need_data[$key]['fav_goods'] = $fav_goods;
  356. $need_data[$key]['quantity'] = $val['quantity'];
  357. $need_data[$key]['summary'] = $desc_info['summary'];
  358. $need_data[$key]['url'] = $val['url'];
  359. }
  360. }
  361. $success_order_list = M('bargain_order')->where( array( 'state' => 1 ) )->order('id desc')->limit(10)->select();
  362. if( !empty($success_order_list) )
  363. {
  364. foreach($success_order_list as $key => $val)
  365. {
  366. $mem_info = M('member')->field('uname,avatar')->where( array('member_id' => $val['member_id']) )->find();
  367. $gd_info = M('goods')->field('name')->where( array('goods_id' => $val['goods_id']) )->find();
  368. $val['uname'] = $mem_info['uname'];
  369. $val['avatar'] = $mem_info['avatar'];
  370. $val['goods_name'] = $gd_info['name'];
  371. $success_order_list[$key] = $val;
  372. }
  373. }
  374. if( !empty($need_data) )
  375. {
  376. echo json_encode( array('code' =>0,'kan_rules_str' => $kan_rules_str, 'data' => $need_data,'success_order_list' => $success_order_list) );
  377. die();
  378. } else{
  379. echo json_encode( array('code' =>1,'kan_rules_str' => $kan_rules_str,'success_order_list' => $success_order_list) );
  380. die();
  381. }
  382. }
  383. /**
  384. * 加载推荐拼团数据
  385. */
  386. public function load_best_pintuan()
  387. {
  388. //if (!$api_best_pingoods_cache = S('api_best_pingoods_cache')) {
  389. $now_time = time();
  390. $where = "g.status =1 and g.type != 'normal' and g.quantity >0 and g.is_index_show =1 ";
  391. $where .= " and pg.begin_time < {$now_time} and pg.end_time >{$now_time} ";
  392. $ping_goods = D('Home/Pingoods')->get_pingoods_list('*', $where );
  393. $goods_model = D('Home/goods');
  394. if( !empty($ping_goods) )
  395. {
  396. foreach($ping_goods as $key => $val)
  397. {
  398. //goods
  399. if( !empty($val['fan_image']) )
  400. {
  401. $fan_image = C('SITE_URL').resize($val['fan_image'], 300, 300);
  402. $val['fan_image'] = $fan_image;
  403. }else {
  404. $val['fan_image'] = C('SITE_URL').resize($val['image'], 300, 300);
  405. }
  406. $val['url'] = U('/goods/'.$val['goods_id']);
  407. // $price_arr = array('price' =>$pin_goods_info['pin_price'],'danprice' =>$goods_info['danprice'], 'pin_price' =>$pin_goods_info['pin_price'],'pin_count' => $pin_goods_info['pin_count']);
  408. $price_arr = $goods_model->get_goods_price($val['goods_id']);
  409. $val['pin_price'] = $price_arr['pin_price'];
  410. $ping_goods[$key] = $val;
  411. }
  412. // }
  413. S('api_best_pingoods_cache', $ping_goods);
  414. $api_best_pingoods_cache=$ping_goods;
  415. }
  416. // var_dump($api_best_pingoods_cache);die();
  417. echo json_encode( array('code' => 1, 'list' => $api_best_pingoods_cache) );
  418. die();
  419. }
  420. /** 加载首页推荐分类数据 **/
  421. public function get_index_category()
  422. {
  423. $gid = I('get.gid',0);
  424. $key='index_goodscategory_cache';
  425. if (!$hot_list = S($key)) {
  426. $hot_list = M('goods_category')->where( array('is_hot' => 1) )->order('sort_order desc')->select();
  427. S($key, $hot_list);
  428. }
  429. $need_data = array();
  430. foreach($hot_list as $key => $cate)
  431. {
  432. $need_data[$key]['id'] = $cate['id'];
  433. $need_data[$key]['name'] = $cate['name'];
  434. $need_data[$key]['c_sort_order'] = $cate['c_sort_order'];
  435. }
  436. $result = array('code' =>0,'data' => $need_data);
  437. echo json_encode($result);
  438. die();
  439. }
  440. /**
  441. 获取分类下普通商品数量
  442. **/
  443. public function get_category_normal_goods()
  444. {
  445. $data_json = file_get_contents('php://input');
  446. $data = json_decode($data_json, true);
  447. $pre_page = !empty($data['pre_page']) ? $data['pre_page'] : 10;
  448. $page = !empty($data['page']) ? $data['page'] : 1;
  449. $id = !empty($data['gid']) ? $data['gid'] : 9;
  450. $goods_ids_arr = M('goods_to_category')->where("class_id1 ={$id} or class_id2 ={$id} or class_id3 = {$id} ")->field('goods_id')->select();
  451. $ids_arr = array();
  452. foreach($goods_ids_arr as $val){
  453. $ids_arr[] = $val['goods_id'];
  454. }
  455. $ids_str = implode(',',$ids_arr);
  456. $condition = array('goods_id' => array('in',$ids_str), 'status'=>1,'quantity' =>array('gt',0) );
  457. $condition['type'] = 'normal';
  458. $condition['lock_type'] = 'normal';
  459. $offset = ($page -1) * $pre_page;
  460. $list = M('goods')->field('goods_id,name,seller_count,virtual_count,quantity,image,fan_image,danprice,price,type')->where($condition)->order('seller_count desc,goods_id asc')->limit($offset,$pre_page)->select();
  461. if(!empty($list)) {
  462. foreach($list as $key => $v){
  463. if(empty($v['fan_image'])){
  464. $list[$key]['image']=C('SITE_URL'). resize($v['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  465. }else{
  466. $list[$key]['image']=C('SITE_URL'). resize($v['fan_image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  467. }
  468. }
  469. }
  470. foreach($list as $key => $val)
  471. {
  472. unset($val['fan_image']);
  473. $val['seller_count'] += $val['virtual_count'];
  474. unset($val['virtual_count']);
  475. $list[$key] = $val;
  476. }
  477. $need_data = array();
  478. $need_data['code'] = 1;
  479. if( !empty($list) )
  480. {
  481. $need_data['code'] = 0;
  482. $need_data['data'] = $list;
  483. }
  484. echo json_encode($need_data);
  485. die();
  486. }
  487. /**
  488. 获取分类下拼团商品数量
  489. **/
  490. public function get_category_pintuan_goods()
  491. {
  492. $data_json = file_get_contents('php://input');
  493. $data = json_decode($data_json, true);
  494. $pre_page = !empty($data['pre_page']) ? $data['pre_page'] : 10;
  495. $page = !empty($data['page']) ? $data['page'] : 1;
  496. $id = !empty($data['gid']) ? $data['gid'] : 9;
  497. $goods_ids_arr = M('goods_to_category')->where("class_id1 ={$id} or class_id2 ={$id} or class_id3 = {$id} ")->field('goods_id')->select();
  498. $ids_arr = array();
  499. foreach($goods_ids_arr as $val){
  500. $ids_arr[] = $val['goods_id'];
  501. }
  502. $ids_str = implode(',',$ids_arr);
  503. $condition = array('goods_id' => array('in',$ids_str), 'status'=>1,'quantity' =>array('gt',0) );
  504. $condition['type'] = 'pintuan';
  505. $offset = ($page -1) * $pre_page;
  506. $list = M('goods')->field('goods_id,name,seller_count,virtual_count,quantity,image,fan_image,danprice,price,type')->where($condition)->order('seller_count desc,goods_id asc')->limit($offset,$pre_page)->select();
  507. if(!empty($list)) {
  508. foreach($list as $key => $v){
  509. if(empty($v['fan_image'])){
  510. $list[$key]['image']=C('SITE_URL'). resize($v['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  511. }else{
  512. $list[$key]['image']=C('SITE_URL'). resize($v['fan_image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  513. }
  514. }
  515. }
  516. foreach($list as $key => $val)
  517. {
  518. unset($val['fan_image']);
  519. $val['seller_count'] += $val['virtual_count'];
  520. unset($val['virtual_count']);
  521. $pin_goods = M('pin_goods')->where( array('goods_id' =>$val['goods_id']) )->find();
  522. $val['pin_price'] = $pin_goods['pin_price'];
  523. $val['pintype'] = $pin_goods['type'];
  524. $val['pin_hour'] = $pin_goods['pin_hour'];
  525. $val['pin_count'] = $pin_goods['pin_count'];
  526. $list[$key] = $val;
  527. }
  528. $need_data = array();
  529. $need_data['code'] = 1;
  530. if( !empty($list) )
  531. {
  532. $need_data['code'] = 0;
  533. $need_data['data'] = $list;
  534. }
  535. echo json_encode($need_data);
  536. die();
  537. }
  538. /**
  539. 加载首页随机商品
  540. **/
  541. public function get_index_suijigoods()
  542. {
  543. $order_sort = ' rand() ';
  544. $goods_model = D('Home/goods');
  545. //get_goods_price($goods_id)
  546. $list = D('Home/goods')->get_goods_list(' * ', " type='normal' and status =1 and is_index_show =0 ",$order_sort,0,20);
  547. foreach($list as $key => $val)
  548. {
  549. if( !empty($val['fan_image']) )
  550. {
  551. $fan_image = C('SITE_URL').resize($val['fan_image'], 300, 300);
  552. $val['fan_image'] = $fan_image;
  553. }else {
  554. $val['fan_image'] = C('SITE_URL').resize($val['image'], 300, 300);
  555. }
  556. $price_arr = $goods_model->get_goods_price($val['goods_id']);
  557. $val['danprice'] = $price_arr['price'];
  558. $val['url'] = U('/goods/'.$val['goods_id']);
  559. $list[$key] = $val;
  560. }
  561. $this->list = $list;
  562. $html = $this->fetch('Index:suiji_goods_fetch');
  563. echo json_encode( array('code' => 1,'html' =>$html) );
  564. die();
  565. }
  566. /**
  567. 加载小程序首页普通商品
  568. **/
  569. public function wepro_index_goods()
  570. {
  571. $page = I('get.page',1);
  572. $type = I('get.type','normal');
  573. //orderby/rand
  574. $is_index_show = I('get.is_index_show',1);
  575. $pre_page = I('get.per_page',4);
  576. $orderby = I('get.orderby','');
  577. //$orderby == 'rand'
  578. //$sortby = ' rand() ';
  579. $condition = array( );
  580. $offset = ($page -1) * $pre_page;
  581. $order_sort = 'index_sort desc ,seller_count desc,goods_id asc';
  582. if( !empty($orderby) )
  583. {
  584. $order_sort = ' rand() ';
  585. }
  586. $where = " store_id = 1 ";
  587. if($type != 'normal')
  588. {
  589. $where .= ' and status =1 and (type="normal" or type ="pintuan") ';
  590. }else {
  591. $where .= ' and status =1 and type="normal" ';
  592. }
  593. //gid
  594. $gid = I('get.gid', 0, 'intval');
  595. if( !empty($gid) && $gid >0 )
  596. {
  597. $goods_ids_arr = M('goods_to_category')->where("class_id1 ={$gid} or class_id2 ={$gid} or class_id3 = {$gid} ")->field('goods_id')->select();
  598. $ids_arr = array();
  599. foreach($goods_ids_arr as $val){
  600. $ids_arr[] = $val['goods_id'];
  601. }
  602. $ids_str = implode(',',$ids_arr);
  603. //$condition = array('goods_id' => array('in',$ids_str), 'status'=>1,'quantity' =>array('gt',0) );
  604. if( !empty($ids_str) )
  605. {
  606. $where .= " and goods_id in ({$ids_str})";
  607. } else{
  608. $where .= " and 0 ";
  609. }
  610. }
  611. if($is_index_show == 1)
  612. {
  613. $where .= " and is_index_show =1 ";
  614. }
  615. $list = D('Home/goods')->get_goods_list(' * ', $where ,$order_sort,$offset,$pre_page);
  616. $goods_model = D('Home/goods');
  617. $need_data = array();
  618. foreach($list as $key => $val)
  619. {
  620. if($val['type'] == 'pintuan')
  621. {
  622. $pin_info = M('pin_goods')->where( array('goods_id' => $val['goods_id']) )->find();
  623. if($pin_info['end_time'] < time())
  624. {
  625. continue;
  626. }
  627. }
  628. if( !empty($val['fan_image']) )
  629. {
  630. $fan_image = C('SITE_URL').resize($val['fan_image'], 400, 400);
  631. $val['image'] = $fan_image;
  632. }else {
  633. $val['image'] = C('SITE_URL').resize($val['image'], 400, 400);
  634. }
  635. $price_arr = $goods_model->get_goods_price($val['goods_id']);
  636. $val['seller_count'] += $val['virtual_count'];
  637. $val['danprice'] = $price_arr['price'];
  638. $fav_goods = M('user_favgoods')->where( array('goods_id' => $val['goods_id']) )->count();
  639. $val['fav_goods'] = $fav_goods;
  640. //$val['url'] = U('/goods/'.$val['goods_id']);
  641. $need_data[$key] = $val;
  642. $list[$key] = $val;
  643. }
  644. if(!empty($need_data))
  645. {
  646. echo json_encode( array('code' => 0,'list' =>$need_data) );
  647. die();
  648. }else{
  649. echo json_encode( array('code' => 1,'list' =>$need_data) );
  650. die();
  651. }
  652. }
  653. /**
  654. * 加载首页商品数据列表
  655. */
  656. public function get_index_bestgoods()
  657. {
  658. $goods_rid = I('post.goods_rid',3);
  659. $page = I('post.page',1);
  660. $pre_page = 4;
  661. $condition = array( );
  662. $offset = ($page -1) * $pre_page;
  663. $order_sort = 'seller_count desc,goods_id asc';
  664. if($goods_rid == 1)
  665. {
  666. $order_sort = 'seller_count desc,goods_id asc';
  667. }else if($goods_rid == 2){
  668. $order_sort = 'goods_id asc';
  669. }else if($goods_rid == 3){
  670. $order_sort = 'index_sort desc ,seller_count desc,goods_id asc';
  671. }
  672. $where = ' status =1 and type="normal" ';
  673. $list = D('Home/goods')->get_goods_list(' * ', $where ,$order_sort,$offset,$pre_page);
  674. $goods_model = D('Home/goods');
  675. foreach($list as $key => $val)
  676. {
  677. if( !empty($val['fan_image']) )
  678. {
  679. $fan_image = C('SITE_URL').resize($val['fan_image'], 300, 300);
  680. $val['fan_image'] = $fan_image;
  681. }else {
  682. $val['fan_image'] = C('SITE_URL').resize($val['image'], 300, 300);
  683. }
  684. $price_arr = $goods_model->get_goods_price($val['goods_id']);
  685. $val['danprice'] = $price_arr['price'];
  686. $val['url'] = U('/goods/'.$val['goods_id']);
  687. $list[$key] = $val;
  688. }
  689. if(empty($list))
  690. {
  691. echo json_encode( array('code' => 0,'list' =>$list) );
  692. die();
  693. }else{
  694. echo json_encode( array('code' => 1,'list' =>$list) );
  695. die();
  696. }
  697. }
  698. }
  699. ?>