SupplyController.class.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 SupplyController extends CommonController {
  16. /**
  17. * 获取申请页面
  18. */
  19. public function get_apply_page()
  20. {
  21. $info = M('lionfish_comshop_config')->where( array('name' => 'supply_apply_page') )->find();
  22. $supply_diy_name = D('Home/Front')->get_config_by_name('supply_diy_name');
  23. if(!empty($info['value'])){
  24. echo json_encode( array('code' => 0, 'data' => htmlspecialchars_decode(htmlspecialchars_decode($info['value'])) , 'supply_diy_name' => $supply_diy_name ) );
  25. die();
  26. }else{
  27. echo json_encode( array('code' => 1 , 'supply_diy_name' => $supply_diy_name));
  28. die();
  29. }
  30. }
  31. /**
  32. * 已申请信息
  33. */
  34. public function apply_info()
  35. {
  36. $_GPC = I('request.');
  37. $token = $_GPC['token'];
  38. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token ) )->find();
  39. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  40. {
  41. echo json_encode( array('code' => 1) );
  42. die();
  43. }
  44. $member_id = $weprogram_token['member_id'];
  45. $supp_info = M('lionfish_comshop_supply')->field('id,shopname,mobile,product,state')->where( array('member_id' => $member_id ) )->find();
  46. $supply_diy_name = D('Home/Front')->get_config_by_name('supply_diy_name');
  47. if( !empty($supp_info) )
  48. {
  49. echo json_encode( array('code' => 0,'data' => $supp_info , 'supply_diy_name' => $supply_diy_name) );
  50. die();
  51. } else {
  52. echo json_encode( array('code' => 2,'msg' => '未申请供应商' , 'supply_diy_name' => $supply_diy_name) );
  53. die();
  54. }
  55. echo json_encode( array('code' => 0 , 'supply_diy_name' => $supply_diy_name) );
  56. die();
  57. }
  58. /**
  59. * 供应商列表
  60. */
  61. public function get_list()
  62. {
  63. $_GPC = I('request.');
  64. $pindex = max(1, intval($_GPC['page']));
  65. $psize = 10;
  66. $head_id = intval($_GPC['head_id']);
  67. $token = $_GPC['token'];
  68. $sql = 'SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_supply WHERE state=1 order by id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  69. $list = M()->query($sql);
  70. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_supply WHERE state=1 ');
  71. $total = $total_arr[0]['count'];
  72. foreach( $list as $key => &$val )
  73. {
  74. $now_time = time();
  75. $val['banner'] = tomedia($val['banner']);
  76. //$goods_count_arr = M()->query("SELECT count(gc.id) as count FROM ".C('DB_PREFIX')."lionfish_comshop_good_common gc , ".C('DB_PREFIX')."lionfish_comshop_goods as g WHERE gc.goods_id = g.id and gc.supply_id = {$val['id']} and g.grounding = 1 and gc.begin_time < {$now_time} and gc.end_time > {$now_time} ");
  77. //$goods_count = $goods_count_arr[0]['count'];
  78. //$val['goods_count'] = $goods_count;
  79. // 统计商品数量
  80. $goods_supply_id_arr = $goods_supply_nolimit_arr = array();
  81. $goods_supply_id_arr = M()->query("SELECT g.id FROM ".C('DB_PREFIX')."lionfish_comshop_good_common as gc , ".C('DB_PREFIX')."lionfish_comshop_goods as g,
  82. ".C('DB_PREFIX')."lionfish_community_head_goods as hg WHERE gc.goods_id = g.id and gc.goods_id = hg.goods_id and gc.supply_id = {$val['id']}
  83. and g.grounding = 1 and gc.begin_time < {$now_time} and gc.end_time > {$now_time} and hg.head_id = {$head_id} ");
  84. $goods_supply_nolimit_arr = M()->query("SELECT g.id FROM ".C('DB_PREFIX')."lionfish_comshop_goods as g, ".C('DB_PREFIX')."lionfish_comshop_good_common as gc WHERE gc.goods_id = g.id and gc.supply_id = {$val['id']} and g.is_all_sale=1 and g.grounding = 1 and gc.begin_time < {$now_time} and gc.end_time > {$now_time} ");
  85. $goods_all = $goods_all_arr = array();
  86. $goods_all = array_merge($goods_supply_id_arr, $goods_supply_nolimit_arr);
  87. foreach($goods_all as $vv){
  88. $goods_all_arr[] = $vv['id'];
  89. }
  90. $goods_all_arr = array_unique($goods_all_arr);
  91. $val['goods_count'] = count($goods_all_arr);
  92. $val['goods_supply_id_arr'] = $goods_supply_id_arr;
  93. $val['goods_supply_nolimit_arr'] = $goods_supply_nolimit_arr;
  94. if( !empty($val['logo']) ) $val['logo'] = tomedia($val['logo']);
  95. $goods_list = array();
  96. $now_time = time();
  97. $where = ' g.grounding = 1 ';
  98. $where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  99. $where .= " and gc.supply_id = " . $val['id'];
  100. $community_goods = D('Home/Pingoods')->get_community_index_goods('g.*,gc.begin_time,gc.end_time,gc.big_img,gc.is_take_fullreduction,gc.labelname ', $where, 0, 10);
  101. foreach ($community_goods as $key => $value) {
  102. if($value['is_all_sale']==1){
  103. $goods_list[] = $this->change_goods_form($value, $head_id, $token);
  104. } else {
  105. $is_head_shop = M('lionfish_community_head_goods')->field('id')->where( array('goods_id' => $value['id'],'head_id' => $head_id) )->order('id desc')->select();
  106. if(!empty($is_head_shop)) $goods_list[] = $this->change_goods_form($value, $head_id, $token);
  107. }
  108. }
  109. $val['goods_list'] = $goods_list;
  110. //$list[$key] = $val;
  111. }
  112. $supply_diy_name = D('Home/Front')->get_config_by_name('supply_diy_name');
  113. if(!empty($list)){
  114. echo json_encode( array('code' => 0, 'data' => $list, 'supply_diy_name' => $supply_diy_name) );
  115. die();
  116. }else{
  117. echo json_encode( array('code' => 1 , 'supply_diy_name' => $supply_diy_name));
  118. die();
  119. }
  120. }
  121. /**
  122. * 供应商主页
  123. */
  124. public function get_details()
  125. {
  126. $_GPC = I('request.');
  127. $pindex = max(1, intval($_GPC['page']));
  128. $id = max(0, intval($_GPC['id']));
  129. $is_only_distribution = max(0, intval($_GPC['is_only_distribution']));
  130. $psize = 20;
  131. $head_id = intval($_GPC['head_id']);
  132. $token = $_GPC['token'];
  133. $per_page = 20;
  134. $offset = ($pindex - 1) * $per_page;
  135. $limit = "{$offset},{$per_page}";
  136. $item = M('lionfish_comshop_supply')->where( array('state' => 1, 'id' => $id) )->order('id desc')->find();
  137. $goods_list = array();
  138. if(!empty($item)) {
  139. if(!empty($item['banner']))
  140. $item['banner'] = tomedia($item['banner']);
  141. $now_time = time();
  142. $where = ' g.grounding = 1 ';
  143. $where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  144. $where .= " and gc.supply_id = " . $item['id'];
  145. if($is_only_distribution) {
  146. $where .= " and gc.is_only_distribution = " . $is_only_distribution;
  147. }
  148. $community_goods = D('Home/Pingoods')->get_community_index_goods('g.*,gc.begin_time,gc.end_time,gc.big_img,gc.is_take_fullreduction,gc.labelname,gc.goods_start_count,gc.oneday_limit_count, gc.total_limit_count, gc.one_limit_count ', $where, $offset, $per_page);
  149. foreach ($community_goods as $key => $value) {
  150. if($value['is_all_sale']==1){
  151. $goods_list[] = $this->change_goods_form($value, $head_id, $token);
  152. } else {
  153. $is_head_shop = M('lionfish_community_head_goods')->field('id')->where( array('head_id' => $head_id,'goods_id' => $value['id'] ) )->order('id desc')->select();
  154. if(!empty($is_head_shop)) $goods_list[] = $this->change_goods_form($value, $head_id, $token);
  155. }
  156. }
  157. }
  158. if(!empty($item)){
  159. echo json_encode( array('code' => 0, 'data' => $item, 'list' => $goods_list) );
  160. die();
  161. }else{
  162. echo json_encode( array('code' => 1 ));
  163. die();
  164. }
  165. }
  166. private function change_goods_form ($val, $head_id="", $token=""){
  167. $tmp_data = array();
  168. $tmp_data['actId'] = $val['id'];
  169. $tmp_data['spuName'] = $val['goodsname'];
  170. $tmp_data['spuCanBuyNum'] = $val['total'];
  171. $tmp_data['spuDescribe'] = $val['subtitle'];
  172. $tmp_data['end_time'] = $val['end_time'];
  173. $tmp_data['soldNum'] = $val['seller_count'] + $val['sales'];
  174. $tmp_data['oneday_limit_count'] = $val['oneday_limit_count'];
  175. $tmp_data['total_limit_count'] = $val['total_limit_count'];
  176. $tmp_data['one_limit_count'] = $val['one_limit_count'];
  177. $tmp_data['goods_start_count'] = $val['goods_start_count'];
  178. $productprice = $val['productprice'];
  179. $tmp_data['marketPrice'] = explode('.', $productprice);
  180. if( !empty($val['big_img']) )
  181. {
  182. $tmp_data['bigImg'] = tomedia($val['big_img']);
  183. }
  184. $good_image = D('Home/Pingoods')->get_goods_images($val['id']);
  185. if( !empty($good_image) )
  186. {
  187. $tmp_data['skuImage'] = tomedia($good_image['image']);
  188. }
  189. $price_arr = D('Home/Pingoods')->get_goods_price($val['id'], $member_id);
  190. $price = $price_arr['price'];
  191. $tmp_data['actPrice'] = explode('.', $price);
  192. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'],$member_id);
  193. if( !empty($tmp_data['skuList']) )
  194. {
  195. $tmp_data['car_count'] = 0;
  196. }else{
  197. $car_count = D('Home/Car')->get_wecart_goods($val['id'],"",$head_id ,$token);
  198. if( empty($car_count) )
  199. {
  200. $tmp_data['car_count'] = 0;
  201. }else{
  202. $tmp_data['car_count'] = $car_count;
  203. }
  204. }
  205. if($is_open_fullreduction == 0)
  206. {
  207. $tmp_data['is_take_fullreduction'] = 0;
  208. }else if($is_open_fullreduction == 1){
  209. $tmp_data['is_take_fullreduction'] = $val['is_take_fullreduction'];
  210. }
  211. // 商品角标
  212. $label_id = unserialize($val['labelname']);
  213. if($label_id){
  214. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  215. if($label_info){
  216. if($label_info['type'] == 1){
  217. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  218. } else {
  219. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  220. }
  221. }
  222. $tmp_data['label_info'] = $label_info;
  223. }
  224. return $tmp_data;
  225. }
  226. }