TuanbonusController.class.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. * ==========================================================================
  6. * @link https://www.nanodreamtech.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.nanodreamtech.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. * 处理订单相关内容
  13. */
  14. namespace Home\Controller;
  15. class TuanbonusController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->cur_page = 'tuanbonus';
  20. }
  21. public function apply()
  22. {
  23. //token
  24. $token = I('get.token');
  25. $member_id = is_login();
  26. $result = array('code' => 0);
  27. $member_commiss_apply = M('member_commiss_apply')->where(array('member_id' =>$member_id, 'state' =>0))->find();
  28. if(!empty($member_commiss_apply)) {
  29. $result['code'] = 1;
  30. $result['msg'] = '您已经申请,等待审核!';
  31. } else {
  32. $data = array();
  33. $data['member_id'] = $member_id;
  34. $data['state'] = 0;
  35. $data['addtime'] = time();
  36. $res = M('member_commiss_apply')->add($data);
  37. if($res){
  38. } else {
  39. $result['code'] = 1;
  40. $result['msg'] = '提交失败';
  41. }
  42. }
  43. echo json_encode($result);
  44. die();
  45. }
  46. /**
  47. groupleaderindex
  48. 分销商资料获取
  49. **/
  50. public function groupleaderindex()
  51. {
  52. $member_id = is_login();
  53. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  54. $this->commiss_level_num = C('commiss_level_num');
  55. //查找一级数量
  56. $tuanyuan_arr = M('member')->field('member_id')->where( array('share_id' => $member_id) )->select();
  57. $tuanyuan_count = count($tuanyuan_arr);// $tuanyuan_count;
  58. //查找二级数量
  59. $second_tuanyuan_count = 0;
  60. $second_arr = array();
  61. if( !empty($tuanyuan_arr) )
  62. {
  63. $ids_arr = array();
  64. foreach($tuanyuan_arr as $val)
  65. {
  66. $ids_arr[] = $val['member_id'];
  67. }
  68. $second_arr = M('member')->field('member_id')->where( array('share_id' => array('in', $ids_arr) ) )->select();
  69. $second_tuanyuan_count = count($second_arr);
  70. }
  71. $second_tuanyuan_count = $second_tuanyuan_count;
  72. //查找三级数量
  73. $three_tuanyuan_count = 0;
  74. if( !empty($second_arr) )
  75. {
  76. $ids_arr = array();
  77. foreach($second_arr as $val)
  78. {
  79. $ids_arr[] = $val['member_id'];
  80. }
  81. $three_tuanyuan_count = M('member')->field('member_id')->where( array('share_id' => array('in', $ids_arr) ) )->count();
  82. }
  83. $three_tuanyuan_count = $three_tuanyuan_count;
  84. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  85. //$this->member_commiss = $member_commiss;
  86. $opencommiss_arr = M('config')->where( array('name' => 'opencommiss') )->find();
  87. $is_open_commiss = $opencommiss_arr['value'];
  88. $tuijian_ren = '平台';
  89. if($member_info['share_id'] > 0)
  90. {
  91. $tui_member = M('member')->field('uname')->where( array('member_id' => $member_info['share_id']) )->find();
  92. $tuijian_ren = $tui_member['uname'];
  93. }
  94. //$this->tuijian_ren = $tuijian_ren;
  95. $this->tuanyuan_count = $tuanyuan_count;
  96. $this->second_tuanyuan_count = $second_tuanyuan_count;
  97. $this->three_tuanyuan_count = $three_tuanyuan_count;
  98. $this->member_commiss = $member_commiss;
  99. $this->is_open_commiss = $is_open_commiss;
  100. $this->tuijian_ren = $tuijian_ren;
  101. $this->member_info = $member_info;
  102. $this->commiss_level_num = C('commiss_level_num');
  103. $need_data = array();
  104. $need_data['tuanyuan_count'] = $tuanyuan_count;
  105. $need_data['second_tuanyuan_count'] = $second_tuanyuan_count;
  106. $need_data['three_tuanyuan_count'] = $three_tuanyuan_count;
  107. $need_data['member_commiss'] = $member_commiss;
  108. $need_data['is_open_commiss'] = $is_open_commiss;
  109. $need_data['tuijian_ren'] = $tuijian_ren;
  110. $need_data['member_info'] = $member_info;
  111. $need_data['commiss_level_num'] = C('commiss_level_num');
  112. $this->display();
  113. //echo json_encode( array('code' =>0 , 'data' => $need_data) );
  114. //die();
  115. }
  116. /**
  117. 获取佣金首页
  118. **/
  119. function tuanbonus_index()
  120. {
  121. $member_id = is_login();
  122. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  123. //sum_member_commiss($where = array())
  124. $member_model = D('Home/Member');
  125. //今日收入
  126. $today_begin_time = strtotime( date('Y-m-d'.' 00:00:00') );
  127. $today_end_time = $today_begin_time + 86400;
  128. //$map['id'] = array('between','1,8'); $map['id'] = array('neq',100);
  129. $today_where = array();
  130. $today_where['member_id'] = $member_id;
  131. $today_where['state'] = array('neq',2);
  132. $today_where['addtime'] = array('between',$today_begin_time.','.$today_end_time);
  133. $today_commiss = $member_model->sum_member_commiss($today_where);
  134. //本月收入
  135. $month_begin_time = strtotime( date("Y-m-d ",mktime(0, 0 , 0,date("m"),1,date("Y"))).' 00:00:00' );
  136. $month_end_time = strtotime( date("Y-m-d ",mktime(23,59,59,date("m"),date("t"),date("Y"))).' 00:00:00' ) +86400;
  137. $month_where = array();
  138. $month_where['member_id'] = $member_id;
  139. $month_where['state'] = array('neq',2);
  140. $month_where['addtime'] = array('between',$month_begin_time.','.$month_end_time);
  141. $month_commiss = $member_model->sum_member_commiss($month_where);
  142. //累计收入
  143. $total_where = array();
  144. $total_where['member_id'] = $member_id;
  145. $total_where['state'] = array('neq',2);
  146. $total_commiss = $member_model->sum_member_commiss($total_where);
  147. //待确认收入
  148. $total_wait_where = array();
  149. $total_wait_where['member_id'] = $member_id;
  150. $total_wait_where['state'] = 0;
  151. $total_wait_commiss = $member_model->sum_member_commiss($total_wait_where);
  152. //可提现金额
  153. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  154. $this->today_commiss = round($today_commiss, 2);
  155. $this->month_commiss = round($month_commiss, 2);
  156. $this->total_commiss = round($total_commiss, 2);
  157. $this->total_wait_commiss = round($total_wait_commiss, 2);
  158. $can_tixian_money = 0;
  159. if(!empty($member_commiss)) {
  160. $can_tixian_money = $member_commiss['money'];
  161. }
  162. $this->can_tixian_money = round($can_tixian_money, 2);
  163. $comsiss_flag = $member_info['comsiss_flag'];
  164. if($member_info['comsiss_flag'] == 0)
  165. {
  166. //state
  167. $member_commiss_apply = M('member_commiss_apply')->where( array('member_id' =>$member_id, 'state' =>0) )
  168. ->find();
  169. if(!empty($member_commiss_apply)) {
  170. $comsiss_flag = 2;
  171. }
  172. }
  173. $this->comsiss_flag = $comsiss_flag;
  174. $need_data = array();
  175. $need_data['today_commiss'] = round($today_commiss, 2);
  176. $need_data['month_commiss'] = round($month_commiss, 2);
  177. $need_data['total_commiss'] = round($total_commiss, 2);
  178. $need_data['total_wait_commiss'] = round($total_wait_commiss, 2);
  179. $need_data['can_tixian_money'] = round($can_tixian_money, 2);
  180. $need_data['comsiss_flag'] = $comsiss_flag;
  181. //echo json_encode( array('code' =>0, 'data' => $need_data ) );
  182. //die();
  183. $this->display('index');
  184. }
  185. /**
  186. 获取账单详情
  187. **/
  188. public function listorder()
  189. {
  190. $member_id = is_login();
  191. $per_page = 6;
  192. $page = I('post.page',1);
  193. $offset = ($page - 1) * $per_page;
  194. $list = array();
  195. $where = '';
  196. $state = I('get.state',-1);
  197. //state
  198. if($state >=0)
  199. {
  200. $where = ' and mco.state = '.$state;
  201. }
  202. $this->state = $state;
  203. $sql = 'select mco.money,mco.child_member_id,mco.addtime,mco.state,o.order_status_id,o.order_num_alias,o.total,og.goods_id,og.quantity,og.name,mco.store_id,m.uname from '.C('DB_PREFIX')."member_commiss_order as mco , ".C('DB_PREFIX')."order_goods as og, ".C('DB_PREFIX')."order as o , ".C('DB_PREFIX')."member as m
  204. where mco.order_id=og.order_id and mco.order_id = o.order_id and m.member_id=mco.child_member_id and mco.member_id=".$member_id." {$where} order by mco.id desc limit {$offset},{$per_page}";
  205. $list = M()->query($sql);
  206. $order_status_list = M('order_status')->select();
  207. $status_arr = array();
  208. foreach($order_status_list as $vv)
  209. {
  210. $status_arr[$vv['order_status_id']] = $vv['name'];
  211. }
  212. foreach($list as $key =>$val)
  213. {
  214. $val['total'] = round($val['total'],2);
  215. $val['money'] = round($val['money'],2);
  216. $val['status_name'] = $status_arr[$val['order_status_id']];
  217. $val['addtime'] = date('Y-m-d', $val['addtime']);
  218. $goods_info = M('goods')->field('image')->where( array('goods_id' => $val['goods_id']) )->find();
  219. $val['image']=resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  220. $list[$key] = $val;
  221. }
  222. $this->list = $list;
  223. if($page > 1) {
  224. $result = array('code' => 0);
  225. if(!empty($list)) {
  226. $result['code'] = 1;
  227. $result['html'] = $this->fetch('Tuanbonus:listorder_ajax_fetch');
  228. }
  229. echo json_encode($result);
  230. die();
  231. }
  232. //今日新增
  233. $today_begin_time = strtotime( date('Y-m-d'.' 00:00:00') );
  234. $today_end_time = $today_begin_time + 86400;
  235. $today_where = array();
  236. $today_where['member_id'] = $member_id;
  237. $today_where['addtime'] = array('between',$today_begin_time.','.$today_end_time);
  238. $today_count = M('member_commiss_order')->where( $today_where )->count();
  239. //昨日新增
  240. $yes_begin_time = $today_begin_time - 86400;
  241. $yes_end_time = $today_begin_time;
  242. $yes_where = array();
  243. $yes_where['member_id'] = $member_id;
  244. $yes_where['addtime'] = array('between',$yes_begin_time.','.$yes_end_time);
  245. $yes_count = M('member_commiss_order')->where( $yes_where )->count();
  246. //总订单量
  247. $total_where = array();
  248. $total_where['member_id'] = $member_id;
  249. $total_count = M('member_commiss_order')->where( $total_where )->count();
  250. $need_data = array();
  251. $need_data['today_count'] = $today_count;
  252. $need_data['yes_count'] = $yes_count;
  253. $need_data['total_count'] = $total_count;
  254. $this->today_count = $today_count;
  255. $this->yes_count = $yes_count;
  256. $this->total_count = $total_count;
  257. $this->display();
  258. }
  259. /**
  260. 获取账单详情列表
  261. **/
  262. public function listorder_list()
  263. {
  264. $member_id = is_login();
  265. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  266. $per_page = 6;
  267. $page = I('get.page',1);
  268. $offset = ($page - 1) * $per_page;
  269. $list = array();
  270. $where = '';
  271. $state = I('get.state',-1);
  272. //state
  273. if($state >=0)
  274. {
  275. $where = ' and mco.state = '.$state;
  276. }
  277. $commiss_level_num = C('commiss_level_num');
  278. $where = ' and mco.level <= '.$commiss_level_num;
  279. //$commiss_level_num = C('commiss_level_num'); level
  280. $this->state = $state;
  281. $sql = 'select mco.level, mco.money,mco.child_member_id,mco.addtime,mco.state,o.order_status_id,o.order_num_alias,o.total,og.goods_id,og.quantity,og.name,mco.store_id,m.uname from '.C('DB_PREFIX')."member_commiss_order as mco , ".C('DB_PREFIX')."order_goods as og, ".C('DB_PREFIX')."order as o , ".C('DB_PREFIX')."member as m
  282. where mco.order_id=og.order_id and mco.order_id = o.order_id and m.member_id=mco.child_member_id and mco.member_id=".$member_id." {$where} order by mco.id desc limit {$offset},{$per_page}";
  283. $list = M()->query($sql);
  284. $order_status_list = M('order_status')->select();
  285. $status_arr = array();
  286. foreach($order_status_list as $vv)
  287. {
  288. $status_arr[$vv['order_status_id']] = $vv['name'];
  289. }
  290. foreach($list as $key =>$val)
  291. {
  292. $val['total'] = round($val['total'],2);
  293. $val['money'] = round($val['money'],2);
  294. $val['status_name'] = $status_arr[$val['order_status_id']];
  295. $val['addtime'] = date('Y-m-d', $val['addtime']);
  296. $goods_info = M('goods')->field('image')->where( array('goods_id' => $val['goods_id']) )->find();
  297. $val['image']=C('SITE_URL'). resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  298. $list[$key] = $val;
  299. }
  300. $this->list = $list;
  301. if(empty($list))
  302. {
  303. echo json_encode( array('code' => 1) );
  304. die();
  305. }else {
  306. echo json_encode( array('code' => 0, 'data' => $list) );
  307. die();
  308. }
  309. }
  310. /**
  311. 检测是否绑定了银行卡
  312. **/
  313. public function check_tixian()
  314. {
  315. $token = I('get.token');
  316. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  317. $member_id = $weprogram_token['member_id'];
  318. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  319. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  320. if( empty($member_commiss['bankname']) || empty($member_commiss['bankaccount']) || empty($member_commiss['bankusername']))
  321. {
  322. echo json_encode( array('code' =>0) );
  323. die();
  324. }else{
  325. echo json_encode( array('code' => 1) );
  326. die();
  327. }
  328. }
  329. /**
  330. 获取用户佣金信息
  331. **/
  332. public function get_tixian_info()
  333. {
  334. $token = I('get.token');
  335. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  336. $member_id = $weprogram_token['member_id'];
  337. $limit_money = C('commiss_money_limit');
  338. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  339. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  340. $member_commiss['limit_money'] = $limit_money;
  341. echo json_encode( array('code' =>0,'data' => $member_commiss) );
  342. die();
  343. }
  344. public function bindcard()
  345. {
  346. $bankusername = I('post.bankusername','','htmlspecialchars');
  347. $bankname = I('post.bankname','','htmlspecialchars');
  348. $bankaccount = I('post.bankaccount','','htmlspecialchars');
  349. $data = array();
  350. $data['bankusername'] = $bankusername;
  351. $data['bankname'] = $bankname;
  352. $data['bankaccount'] = $bankaccount;
  353. M('member_commiss')->where( array('member_id' => is_login() ) )->save($data);
  354. $this->redirect('Tuanbonus/tixian');
  355. }
  356. public function tixian()
  357. {
  358. $member_id = is_login();
  359. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  360. if($member_info['comsiss_flag'] != 1)
  361. {
  362. die();
  363. }
  364. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  365. $this->member_commiss = $member_commiss;
  366. if( empty($member_commiss['bankname']) || empty($member_commiss['bankaccount']) || empty($member_commiss['bankusername']))
  367. {
  368. $this->display();
  369. } else {
  370. $per_page = 5;
  371. $page = I('post.page',1);
  372. $offset = ($page - 1) * $per_page;
  373. $list = array();
  374. $sql = "select * from ".C('DB_PREFIX')."tixian_order
  375. where member_id=".$member_id." order by addtime desc limit {$offset},{$per_page}";
  376. $list = M()->query($sql);
  377. $this->list = $list;
  378. if($page > 1) {
  379. $result = array('code' => 0);
  380. if(!empty($list)) {
  381. $result['code'] = 1;
  382. $result['html'] = $this->fetch('Tuanbonus:tixianorder_ajax_fetch');
  383. }
  384. echo json_encode($result);
  385. die();
  386. }
  387. $commiss_money_limit = C('commiss_money_limit');
  388. $this->commiss_money_limit = $commiss_money_limit;
  389. $this->display('tixianorder');
  390. }
  391. }
  392. public function tixian_sub()
  393. {
  394. $member_id = is_login();
  395. $money = I('post.money',0,'floatval');
  396. $result = array('code' => 0,'msg' => '提现失败');
  397. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id ) )->find();
  398. $member_info = M('member')->where( array('member_id' =>$member_id ) )->find();
  399. $commiss_money_limit = C('commiss_money_limit');
  400. if(!empty($commiss_money_limit) && $commiss_money_limit >0)
  401. {
  402. if($member_commiss['money'] < $commiss_money_limit)
  403. {
  404. $result['msg'] = '佣金满'.$commiss_money_limit.'才能提现';
  405. echo json_encode($result);
  406. die();
  407. }
  408. }
  409. if($money > 0 && $money <= $member_commiss['money'])
  410. {
  411. $data = array();
  412. $data['member_id'] = $member_id;
  413. $data['money'] = $money;
  414. $data['state'] = 0;
  415. $data['shentime'] = 0;
  416. $data['addtime'] = time();
  417. M('tixian_order')->add($data);
  418. $com_arr = array();
  419. $com_arr['money'] = $member_commiss['money'] - $money;
  420. $com_arr['dongmoney'] = $member_commiss['dongmoney'] + $money;
  421. M('member_commiss')->where( array('member_id' => $member_id) )->save($com_arr);
  422. $result['code'] = 1;
  423. }
  424. echo json_encode($result);
  425. die();
  426. }
  427. /**
  428. 提现记录
  429. **/
  430. public function tixian_record()
  431. {
  432. $token = I('get.token');
  433. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  434. $member_id = $weprogram_token['member_id'];
  435. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  436. $per_page = 5;
  437. $page = I('get.page',1);
  438. $offset = ($page - 1) * $per_page;
  439. $list = array();
  440. $sql = "select * from ".C('DB_PREFIX')."tixian_order
  441. where member_id=".$member_id." order by addtime desc limit {$offset},{$per_page}";
  442. $list = M()->query($sql);
  443. foreach($list as $key => $val)
  444. {
  445. $val['addtime'] = date('Y-m-d', $val['addtime']);
  446. $list[$key] = $val;
  447. }
  448. if( !empty($list) )
  449. {
  450. echo json_encode( array('code' =>0, 'data'=>$list) );
  451. die();
  452. }else{
  453. echo json_encode( array('code' => 1) );
  454. die();
  455. }
  456. }
  457. public function cons_member_common($member_id)
  458. {
  459. $member_common = array('member_id'=>$member_id,'qrcode_img' => '');
  460. M('member_common')->add($member_common);
  461. return $member_common;
  462. }
  463. /**
  464. 团长二维码
  465. **/
  466. public function qrcode()
  467. {
  468. $member_id = is_login();
  469. $member_common = M('member_common')->where( array('member_id' => is_login()) )->find();
  470. if(empty($member_common))
  471. {
  472. $member_common = $this->cons_member_common($member_id);
  473. }
  474. $is_tan = 1;
  475. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  476. $hash_member_id = $hashids->encode($member_id);
  477. $url = C('SITE_URL')."index.php?s=/index/index/rmid/{$hash_member_id}";
  478. if(empty($member_common['qrcode_img']))
  479. {
  480. $content = $url;
  481. $target = C('SITE_URL').'Uploads/image/'.C('user_qrcode_image');
  482. $user_qrcodebg_x = C('user_qrcode_x');
  483. $user_qrcodebg_y = C('user_qrcode_y');
  484. if(empty($user_qrcodebg_x))
  485. {
  486. $user_qrcodebg_x = 0;
  487. }
  488. if(empty($user_qrcodebg_y))
  489. {
  490. $user_qrcodebg_y = 0;
  491. }
  492. $new_image = get_compare_qrcode($content,$target,$user_qrcodebg_x,$user_qrcodebg_y);
  493. $uarray = array( 'qrcode_img'=>$new_image);
  494. M('member_common')->where( array('member_id' => $member_id) )->save($uarray);
  495. $member_common['qrcode_img'] = $new_image;
  496. cookie('qrcode_tan', 1);
  497. } else {
  498. $tan_time = cookie('qrcode_tan');
  499. if(empty($tan_time))
  500. {
  501. cookie('qrcode_tan', 1);
  502. }else
  503. {
  504. cookie('qrcode_tan', $tan_time+1);
  505. if($tan_time >=2)
  506. {
  507. $is_tan = 2;
  508. }
  509. }
  510. $new_image = $login_user['qrcode'];
  511. }
  512. $this->member_common = $member_common;
  513. $this->display();
  514. }
  515. function tuanyuan()
  516. {
  517. $member_id = is_login();
  518. //$member_id = 599;
  519. //$token = I('get.token');
  520. //$weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  521. // $member_id = $weprogram_token['member_id'];
  522. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  523. $per_page = 6;
  524. $page = I('get.page',1);
  525. $offset = ($page - 1) * $per_page;
  526. //type 1 2 3
  527. $type = I('get.type',1);
  528. //6
  529. $list = array();
  530. if($type == 1)
  531. {
  532. $sql = 'select * from '.C('DB_PREFIX')."member
  533. where share_id = ".$member_id." order by member_id desc limit {$offset},{$per_page}";
  534. $list = M()->query($sql);
  535. //var_dump($list, $sql);die();
  536. }else if( $type ==2 ){
  537. $sql = 'select member_id from '.C('DB_PREFIX')."member
  538. where share_id = ".$member_id;
  539. $first_list = M()->query($sql);
  540. $list = array();
  541. if( !empty($first_list) )
  542. {
  543. $ids_arr = array();
  544. foreach( $first_list as $val )
  545. {
  546. $ids_arr[] = $val['member_id'];
  547. }
  548. $ids_str = implode(',', $ids_arr);
  549. $sql = 'select * from '.C('DB_PREFIX')."member
  550. where share_id in (".$ids_str.") order by member_id desc limit {$offset},{$per_page}";
  551. $list = M()->query($sql);
  552. }
  553. } else if( $type ==3 ){
  554. $sql = 'select member_id from '.C('DB_PREFIX')."member
  555. where share_id = ".$member_id;
  556. $first_list = M()->query($sql);
  557. $list = array();
  558. if( !empty($first_list) )
  559. {
  560. $ids_arr = array();
  561. foreach( $first_list as $val )
  562. {
  563. $ids_arr[] = $val['member_id'];
  564. }
  565. $ids_str = implode(',', $ids_arr);
  566. $sql = 'select member_id from '.C('DB_PREFIX')."member
  567. where share_id in (".$ids_str.") ";
  568. $second_list = M()->query($sql);
  569. if( !empty($second_list) )
  570. {
  571. $ids_arr = array();
  572. foreach( $second_list as $val )
  573. {
  574. $ids_arr[] = $val['member_id'];
  575. }
  576. $ids_str = implode(',', $ids_arr);
  577. $sql = 'select * from '.C('DB_PREFIX')."member
  578. where share_id in (".$ids_str.") order by member_id desc limit {$offset},{$per_page}";
  579. $list = M()->query($sql);
  580. }
  581. }
  582. }
  583. //{$member_info.uname}
  584. foreach($list as $key => $val)
  585. {
  586. $parent_name = M('member')->field('name')->where( array('member_id' => $val['share_id']) )->find();
  587. $val['parent_name'] = $parent_name['name'];
  588. $val['create_time'] = date('Y-m-d H:i:s', $val['create_time']);
  589. $list[$key] = $val;
  590. }
  591. $this->type = $type;
  592. $this->list = $list;
  593. /**
  594. if( empty($list) )
  595. {
  596. echo json_encode( array('code' => 1) );
  597. die();
  598. } else{
  599. echo json_encode( array('code' =>0 , 'data' => $list) );
  600. die();
  601. }
  602. **/
  603. if($page > 1) {
  604. $result = array('code' => 0);
  605. if(!empty($list)) {
  606. $result['code'] = 1;
  607. $result['html'] = $this->fetch('Tuanbonus:tuanyuan_ajax_fetch');
  608. }
  609. echo json_encode($result);
  610. die();
  611. }
  612. $this->display();
  613. }
  614. public function yongjing()
  615. {
  616. $per_page = 10;
  617. $page = I('get.page',1);
  618. $gid = I('get.gid',0);
  619. $offset = ($page - 1) * $per_page;
  620. $where = "";
  621. //danprice pin_price
  622. if( !empty($gid) && $gid >0 )
  623. {
  624. $goods_ids_arr = M('goods_to_category')->where("class_id1 ={$gid} or class_id2 ={$gid} or class_id3 = {$gid} ")->field('goods_id')->select();
  625. $ids_arr = array();
  626. foreach($goods_ids_arr as $val){
  627. $ids_arr[] = $val['goods_id'];
  628. }
  629. $ids_str = implode(',',$ids_arr);
  630. if( !empty($ids_str) )
  631. {
  632. $where .= " and a.goods_id in ({$ids_str}) ";
  633. //a.goods_id
  634. }
  635. }
  636. $sql = " SELECT a.goods_id,a.name,a.quantity,a.danprice,b.pin_price,a.commiss_one_dan_disc,( b.commiss_one_pin_disc * b.pin_price ) as pin_yong_money,( a.commiss_one_dan_disc * a.danprice ) as dan_yong_money, a.price,a.image
  637. FROM ".C('DB_PREFIX')."goods as a left join ".C('DB_PREFIX')."pin_goods as b on a.goods_id = b.goods_id WHERE (a.commiss_one_dan_disc >0 or b.commiss_one_pin_disc >0) and a.status = 1 {$where} and a.quantity >0 order by dan_yong_money desc, pin_yong_money desc
  638. limit {$offset},{$per_page}";
  639. /**
  640. $sql = 'select g.goods_id,g.name,g.quantity,g.pinprice,g.commiss_one_pin_disc,( g.pinprice * g.commiss_one_pin_disc ) as yong_money, g.price,g.image from '.C('DB_PREFIX')."goods as g
  641. where g.status =1 and g.quantity > 0 and g.commiss_one_pin_disc >0 order by yong_money desc limit {$offset},{$per_page}";
  642. **/
  643. $list = M()->query($sql);
  644. foreach ($list as $k => $v) {
  645. $v['image']=C('SITE_URL'). resize($v['image'], C('spike_thumb_width'), C('spike_thumb_height'));
  646. $pin_yong_money = round( $v['pin_yong_money'] /100 , 2);
  647. $dan_yong_money = round( $v['dan_yong_money'] /100 , 2);
  648. if( $pin_yong_money > $dan_yong_money )
  649. {
  650. $v['yong_money'] = $pin_yong_money;
  651. $v['price'] = $v['pin_price'];
  652. } else {
  653. $v['yong_money'] = $dan_yong_money;
  654. $v['price'] = $v['danprice'];
  655. }
  656. //"danprice":"0.04","pin_price":"0.01",
  657. $list[$k] = $v;
  658. }
  659. if( empty($list) )
  660. {
  661. echo json_encode( array('code' => 1) );
  662. die();
  663. } else {
  664. echo json_encode( array('code' =>0, 'data' => $list) );
  665. die();
  666. }
  667. /**
  668. SELECT a.goods_id, a.commiss_one_dan_disc, b.commiss_one_pin_disc
  669. FROM `oscshop_goods` as a left join oscshop_pin_goods as b on a.goods_id = b.goods_id WHERE a.commiss_one_dan_disc >0 and a.status = 1 and a.quantity >0 order by a.goods_id desc
  670. **/
  671. }
  672. }