ApiquanController.class.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <?php
  2. /**nanodreamtech.com
  3. * 小梦科技资源nanodreamtech.com
  4. * @author fish
  5. * 处理订单相关内容
  6. */
  7. namespace Home\Controller;
  8. class ApiquanController extends CommonController {
  9. protected function _initialize()
  10. {
  11. parent::_initialize();
  12. $this->cur_page = 'apiquan';
  13. }
  14. /**
  15. 判断是否有发布圈子的权限
  16. **/
  17. public function get_quan_authority()
  18. {
  19. $token = I('get.token');
  20. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  21. $member_id = $weprogram_token['member_id'];
  22. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  23. if( empty($member_info) )
  24. {
  25. echo json_encode( array('code' => 1) );
  26. die();
  27. }
  28. $group_info = M('group')->where( array('seller_id' => 1) )->find();
  29. if( empty($group_info) )
  30. {
  31. echo json_encode( array('code' => 1,'msg'=>'未开放圈子功能') );
  32. die();
  33. }
  34. if($group_info['status'] == 0)
  35. {
  36. echo json_encode( array('code' => 1,'msg'=>'未开放圈子功能') );
  37. die();
  38. }
  39. if($group_info['limit_send_member'] == 1)
  40. {
  41. $member_ids = explode(',', $group_info['member_ids']);
  42. if( empty($member_ids) || !in_array($member_id, $member_ids) )
  43. {
  44. echo json_encode( array('code' => 1,'msg'=>'没有发布权限') );
  45. die();
  46. }
  47. }
  48. echo json_encode( array('code' => 0) );
  49. die();
  50. }
  51. /**
  52. 发布帖子
  53. **/
  54. public function post_group()
  55. {
  56. $token = I('get.token');
  57. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  58. $member_id = $weprogram_token['member_id'];
  59. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  60. if( empty($member_info) )
  61. {
  62. echo json_encode( array('code' => 1,'msg' => '您未登录') );
  63. die();
  64. }
  65. $data_json = file_get_contents('php://input');
  66. $data = json_decode($data_json, true);
  67. $data = $data;
  68. $group_id = $data['group_id'];
  69. $goods_id = $data['goods_id'];
  70. $is_share = $data['is_share'];
  71. $content = htmlspecialchars($data['content']);
  72. $pics = $data['pics'];
  73. //模拟数据begin
  74. //$group_id = 1;
  75. //$goods_id = 85;
  76. //$content = '测试发布圈子';
  77. //$pics = array();
  78. //模拟数据end
  79. $quan_model = D('Home/Quan');
  80. $post_data['member_id'] = $member_id;
  81. $post_data['group_id'] = $group_id;
  82. $post_data['goods_id'] = $goods_id;
  83. $post_data['title'] = $content;
  84. $post_data['is_share'] = $is_share;
  85. $post_data['content'] = serialize($pics);
  86. $rs = $quan_model->send_group_post($post_data);
  87. if($rs)
  88. {
  89. echo json_encode( array('code' => 0) );
  90. die();
  91. } else{
  92. echo json_encode( array('code' => 1) );
  93. die();
  94. }
  95. }
  96. /**
  97. 获取圈子信息
  98. **/
  99. public function get_quan_info()
  100. {
  101. $seller_id = I('get.seller_id', 1);
  102. $group_info = M('group')->where( array('seller_id' => $seller_id) )->find();
  103. if( empty($group_info) )
  104. {
  105. echo json_encode( array('code' => 1) );
  106. die();
  107. }
  108. $data = array();
  109. $data['group_id'] = $group_info['id'];
  110. $data['quan_name'] = $group_info['title'];
  111. $data['post_count'] = $group_info['post_count'];
  112. $data['status'] = $group_info['status'];
  113. $data['quan_share'] = $group_info['quan_share'];
  114. $data['quan_logo'] = C('SITE_URL').'Uploads/image/'. $group_info['quan_logo'];
  115. $data['quan_banner'] = C('SITE_URL').'Uploads/image/'. $group_info['quan_banner'];
  116. echo json_encode( array('code' =>0 , 'data' => $data) );
  117. die();
  118. }
  119. /**
  120. 赞帖子/取消赞帖子
  121. **/
  122. public function member_fav_post()
  123. {
  124. $token = I('get.token');
  125. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  126. $member_id = $weprogram_token['member_id'];
  127. if(empty($member_id))
  128. {
  129. echo json_encode( array('code' => 0) );//未登录
  130. die();
  131. }
  132. //code = 1 喜欢成功 code =2 取消喜欢
  133. $post_id = I('post.post_id',1);
  134. $quan_model = D('Home/Quan');
  135. $res = $quan_model->member_fav_post($member_id,$post_id);
  136. echo json_encode( $res );
  137. die();
  138. }
  139. /**
  140. 对帖子进行评价
  141. **/
  142. public function comment_group_post()
  143. {
  144. $token = I('get.token');
  145. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  146. $member_id = $weprogram_token['member_id'];
  147. if(empty($member_id))
  148. {
  149. echo json_encode( array('code' => 1, 'msg' => '未登录') );//未登录
  150. die();
  151. }
  152. $data_json = file_get_contents('php://input');
  153. $data = json_decode($data_json, true);
  154. $post_id = $data['post_id'];
  155. $content = $data['content'];
  156. $to_member_id = $data['reply_id'];
  157. if( empty($post_id) )
  158. {
  159. echo json_encode( array('code' => 1, 'msg' => '数据错误,未选择帖子') );//未登录
  160. die();
  161. }
  162. if( empty($content) )
  163. {
  164. echo json_encode( array('code' => 1, 'msg' => '请填写评价内容') );//未登录
  165. die();
  166. }
  167. $quan_model = D('Home/Quan');
  168. $last_post_id = $quan_model->comment_group_post($post_id,$content,$member_id,$to_member_id);
  169. echo json_encode( array('code' => 0,'member_id' => $member_id,'last_post_id' => $last_post_id) );
  170. die();
  171. }
  172. /**
  173. 删除评论
  174. */
  175. public function del_post_comment()
  176. {
  177. $token = I('get.token');
  178. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  179. $member_id = $weprogram_token['member_id'];
  180. if( empty($member_id) )
  181. {
  182. echo json_encode( array('code' => 1, 'msg' =>'请先登录') );
  183. die();
  184. }
  185. $post_id = I('post.post_id');
  186. $comment_id = I('post.comment_id');
  187. $rs = M('group_lzl_reply')->where( array('post_id' => $post_id,'id' => $comment_id,'member_id' => $member_id) )->delete();
  188. if($rs)
  189. {
  190. echo json_encode(array('code' => 0));
  191. die();
  192. }else{
  193. echo json_encode(array('code' => 1, 'msg' =>'删除失败' ));
  194. die();
  195. }
  196. }
  197. /**
  198. 加载数据
  199. @param group_id 群组id
  200. @param post_id 帖子id
  201. @param up_down 加载方向:1 底部加载, 2顶部加载
  202. @param limit 加载10
  203. **/
  204. public function load()
  205. {
  206. //load_group_post($group_id,$post_id,$up_down,$limit=10)
  207. $group_id = I('get.group_id',1);
  208. $post_id = I('get.post_id',1);
  209. $up_down = I('get.up_down',0);
  210. $ht_s = I('get.ht_s',1);
  211. $limit = 10;
  212. $quan_model = D('Home/Quan');
  213. $list = $quan_model->load_group_post($group_id,$post_id,$up_down,10);
  214. if( empty($list) )
  215. {
  216. echo json_encode( array('code' => 1) );
  217. die();
  218. } else{
  219. reset($list);
  220. if($up_down == 1)
  221. {
  222. $end = current($list);
  223. $first = end($list);
  224. }else{
  225. $end = current($list);
  226. $first = end($list);
  227. }
  228. $this->ht_s = $ht_s/3;
  229. //up_post_id, down_post_id
  230. echo json_encode( array('code' => 0,'down_post_id'=>$first['id'],'up_post_id' => $end['id'] ,'list' => $list) );
  231. die();
  232. }
  233. }
  234. /**
  235. 发布页加载商品列表数据
  236. @param id 商家id
  237. @param limit 加载10
  238. **/
  239. public function load_fabu_goods()
  240. {
  241. $pre_page = 10;
  242. $data_json = file_get_contents('php://input');
  243. $data = json_decode($data_json, true);
  244. $page = isset($data['page']) ? $data['page']:1; //I('post.page',1);
  245. $seller_id = I('get.id',0);
  246. $order_by = 'sort_order asc';
  247. if(empty($seller_id))
  248. {
  249. $seller_id = isset($data['id']) ? $data['id']:0;
  250. }
  251. $condition= " status=1 and quantity > 0 and type != 'lottery' and type != 'bargain' and type != 'integral' ";
  252. $goods_model = D('Home/Goods');
  253. $offset = ($page -1) * $pre_page;
  254. $list = M('goods')->field('seller_count,virtual_count,goods_id,name,image,fan_image')->where($condition)->order($order_by)->limit($offset,$pre_page)->select();
  255. if(!empty($list)) {
  256. foreach($list as $key => $v){
  257. unset($v['virtual_count']);
  258. $price_arr = $goods_model->get_goods_price($v['goods_id']);
  259. $list[$key]['pin_price'] = $price_arr['pin_price'];
  260. $list[$key]['danprice'] = $price_arr['danprice'];
  261. $list[$key]['price'] = $price_arr['price'];
  262. $list[$key]['seller_count'] += $v['virtual_count'];
  263. if(!empty($v['fan_image'])){
  264. $list[$key]['image']= C('SITE_URL'). resize($v['fan_image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  265. }
  266. }
  267. }
  268. if( empty($list) )
  269. {
  270. echo json_encode( array('code' => 1) );
  271. die();
  272. } else {
  273. $this->list = $list;
  274. echo json_encode( array('code' => 0, 'list' => $list) );
  275. die();
  276. }
  277. }
  278. public function get_user_info()
  279. {
  280. $token = I('get.token');
  281. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  282. $member_id = $weprogram_token['member_id'];
  283. $member_info = M('member')->field('name,avatar,score,member_id,comsiss_flag,level_id,account_money')->where( array('member_id' => $member_id) )->find();
  284. echo json_encode( array('code' => 0,'member_level_list' => $member_level_list,'level_name' => $level_name,'member_level_is_open' => $member_level_is_open_arr['value'],'is_yue_open' => $config_name['value'], 'opencommiss' => $opencommiss,'data' =>$member_info ,'is_open_integral' => $is_open_integral) );
  285. die();
  286. }
  287. }