SupplyController.class.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. $psize = 20;
  130. $head_id = intval($_GPC['head_id']);
  131. $token = $_GPC['token'];
  132. $per_page = 20;
  133. $offset = ($pindex - 1) * $per_page;
  134. $limit = "{$offset},{$per_page}";
  135. $item = M('lionfish_comshop_supply')->where( array('state' => 1, 'id' => $id) )->order('id desc')->find();
  136. $goods_list = array();
  137. if(!empty($item)) {
  138. if(!empty($item['banner']))
  139. $item['banner'] = tomedia($item['banner']);
  140. $now_time = time();
  141. $where = ' g.grounding = 1 ';
  142. $where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  143. $where .= " and gc.supply_id = " . $item['id'];
  144. $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, $offset, $per_page);
  145. foreach ($community_goods as $key => $value) {
  146. if($value['is_all_sale']==1){
  147. $goods_list[] = $this->change_goods_form($value, $head_id, $token);
  148. } else {
  149. $is_head_shop = M('lionfish_community_head_goods')->field('id')->where( array('head_id' => $head_id,'goods_id' => $value['id'] ) )->order('id desc')->select();
  150. if(!empty($is_head_shop)) $goods_list[] = $this->change_goods_form($value, $head_id, $token);
  151. }
  152. }
  153. }
  154. if(!empty($item)){
  155. echo json_encode( array('code' => 0, 'data' => $item, 'list' => $goods_list) );
  156. die();
  157. }else{
  158. echo json_encode( array('code' => 1 ));
  159. die();
  160. }
  161. }
  162. private function change_goods_form ($val, $head_id="", $token=""){
  163. $tmp_data = array();
  164. $tmp_data['actId'] = $val['id'];
  165. $tmp_data['spuName'] = $val['goodsname'];
  166. $tmp_data['spuCanBuyNum'] = $val['total'];
  167. $tmp_data['spuDescribe'] = $val['subtitle'];
  168. $tmp_data['end_time'] = $val['end_time'];
  169. $tmp_data['soldNum'] = $val['seller_count'] + $val['sales'];
  170. $productprice = $val['productprice'];
  171. $tmp_data['marketPrice'] = explode('.', $productprice);
  172. if( !empty($val['big_img']) )
  173. {
  174. $tmp_data['bigImg'] = tomedia($val['big_img']);
  175. }
  176. $good_image = D('Home/Pingoods')->get_goods_images($val['id']);
  177. if( !empty($good_image) )
  178. {
  179. $tmp_data['skuImage'] = tomedia($good_image['image']);
  180. }
  181. $price_arr = D('Home/Pingoods')->get_goods_price($val['id'], $member_id);
  182. $price = $price_arr['price'];
  183. $tmp_data['actPrice'] = explode('.', $price);
  184. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'],$member_id);
  185. if( !empty($tmp_data['skuList']) )
  186. {
  187. $tmp_data['car_count'] = 0;
  188. }else{
  189. $car_count = D('Home/Car')->get_wecart_goods($val['id'],"",$head_id ,$token);
  190. if( empty($car_count) )
  191. {
  192. $tmp_data['car_count'] = 0;
  193. }else{
  194. $tmp_data['car_count'] = $car_count;
  195. }
  196. }
  197. if($is_open_fullreduction == 0)
  198. {
  199. $tmp_data['is_take_fullreduction'] = 0;
  200. }else if($is_open_fullreduction == 1){
  201. $tmp_data['is_take_fullreduction'] = $val['is_take_fullreduction'];
  202. }
  203. // 商品角标
  204. $label_id = unserialize($val['labelname']);
  205. if($label_id){
  206. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  207. if($label_info){
  208. if($label_info['type'] == 1){
  209. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  210. } else {
  211. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  212. }
  213. }
  214. $tmp_data['label_info'] = $label_info;
  215. }
  216. return $tmp_data;
  217. }
  218. }