SupplyController.class.php 9.3 KB

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