fxlist.inc.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. global $_GPC, $_W;
  3. $GLOBALS['frames'] = $this->getMainMenu();
  4. pdo_update('zhtc_distribution',array('state'=>1),array('pay_state'=>1));
  5. $pageindex = max(1, intval($_GPC['page']));
  6. $pagesize=10;
  7. $where=' WHERE a.uniacid=:uniacid and a.pay_state=2';
  8. $where2=' WHERE uniacid=:uniacid and pay_state=2';
  9. $data[':uniacid']=$_W['uniacid'];
  10. if($_GPC['keywords']){
  11. $op=$_GPC['keywords'];
  12. $where.=" and (a.user_tel LIKE concat('%', :name,'%') || a.user_name LIKE concat('%', :name,'%'))";
  13. $where2.=" and (user_tel LIKE concat('%', :name,'%') || user_name LIKE concat('%', :name,'%'))";
  14. $data[':name']=$op;
  15. }
  16. $sql="select a.* ,b.img,b.commission,c.name as level_name from " . tablename("zhtc_distribution") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id " . " left join " . tablename("zhtc_fxlevel") . " c on c.id=a.level ". $where." ORDER BY id DESC";
  17. $total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zhtc_distribution') . "".$where2." ORDER BY id DESC",$data);
  18. $list=pdo_fetchall( $sql,$data);
  19. $select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  20. $list=pdo_fetchall($select_sql,$data);
  21. $pager = pagination($total, $pageindex, $pagesize);
  22. $operation=$_GPC['op'];
  23. if($operation=='adopt'){//审核通过
  24. $id=$_GPC['id'];
  25. $distribution=pdo_get('zhtc_distribution',array('id'=>$id));
  26. $res=pdo_update('zhtc_distribution',array('state'=>2),array('id'=>$id));
  27. $fx=pdo_get('zhtc_fxuser',array('fx_user'=>$distribution['user_id']));
  28. if(!$fx){
  29. pdo_insert("zhtc_fxuser",array('user_id'=>0,'fx_user'=>$distribution['user_id'],'time'=>time()));
  30. }
  31. if($res){
  32. message('审核成功',$this->createWebUrl('fxlist',array()),'success');
  33. }else{
  34. message('审核失败','','error');
  35. }
  36. }
  37. if($operation=='reject'){
  38. $id=$_GPC['id'];
  39. $res=pdo_update('zhtc_distribution',array('state'=>3),array('id'=>$id));
  40. if($res){
  41. message('拒绝成功',$this->createWebUrl('fxlist',array()),'success');
  42. }else{
  43. message('拒绝失败','','error');
  44. }
  45. }
  46. if($operation=='delete'){
  47. $id=$_GPC['id'];
  48. $res=pdo_delete('zhtc_distribution',array('id'=>$id));
  49. if($res){
  50. pdo_delete('zhtc_fxuser',array('user_id'=>$id));
  51. pdo_delete('zhtc_fxuser',array('fx_user'=>$id));
  52. message('删除成功',$this->createWebUrl('fxlist',array()),'success');
  53. }else{
  54. message('删除失败','','error');
  55. }
  56. }
  57. if($_GPC['id2']){
  58. $id=$_GPC['id2'];
  59. pdo_update('zhtc_user',array('commission +='=>$_GPC['reply']),array('id'=>$id));
  60. $data3['user_id']=$id;//上线id
  61. $data3['son_id']=0;
  62. $data3['money']=$_GPC['reply'];//金额
  63. $data3['time']=time();//时间
  64. $data3['uniacid']=$_W['uniacid'];
  65. $res=pdo_insert('zhtc_earnings',$data3);
  66. if($res){
  67. message('充值成功',$this->createWebUrl('fxlist',array()),'success');
  68. }else{
  69. message('充值失败','','error');
  70. }
  71. }
  72. if(checksubmit('export_submit', true)) {
  73. $time=date("Y-m-d");
  74. $time="'%$time%'";
  75. $start=$_GPC['time']['start'];
  76. $end=$_GPC['time']['end'];
  77. $count = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename("zhtc_distribution") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id " . " left join " . tablename("zhtc_fxlevel") . " c on c.id=a.level where a.uniacid={$_W['uniacid']} and a.pay_state=2 ");
  78. $pagesize = ceil($count/5000);
  79. //array_unshift( $names, '活动名称');
  80. $header = array(
  81. 'user_name'=>'粉丝',
  82. 'user_tel' => '手机号',
  83. 'level_name' => '级别',
  84. 'lei' => '累计佣金',
  85. 'cg' => '打款佣金',
  86. 'sji' => '上级分销商',
  87. 'time' => '申请时间',
  88. 'state' => '审核状态',
  89. );
  90. $keys = array_keys($header);
  91. $html = "\xEF\xBB\xBF";
  92. foreach ($header as $li) {
  93. $html .= $li . "\t ,";
  94. }
  95. $html .= "\n";
  96. for ($j = 1; $j <= $pagesize; $j++) {
  97. $sql = "select a.* ,b.img,b.commission,c.name as level_name from " . tablename("zhtc_distribution") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id " . " left join " . tablename("zhtc_fxlevel") . " c on c.id=a.level WHERE a.uniacid={$_W['uniacid']} and a.pay_state=2 limit " . ($j - 1) * 5000 . ",5000 ";
  98. $list = pdo_fetchall($sql);
  99. }
  100. if (!empty($list)) {
  101. $size = ceil(count($list) / 500);
  102. for ($i = 0; $i < $size; $i++) {
  103. $buffer = array_slice($list, $i * 500, 500);
  104. $user = array();
  105. foreach ($buffer as $k =>$row) {
  106. $lei = pdo_fetch("select sum(money) as tx_cost from " . tablename("zhtc_earnings")." WHERE user_id=".$row['user_id']);
  107. $cg = pdo_fetch("select sum(tx_cost) as tx_cost from " . tablename("zhtc_commission_withdrawal")." WHERE state=2 and user_id=".$row['user_id']);
  108. $sj=pdo_get('zhtc_fxuser',array('fx_user'=>$row['user_id']));
  109. $sj2=pdo_get('zhtc_distribution',array('user_id'=>$sj['user_id']));
  110. $row['lei']=$lei['tx_cost']?:'0.00';
  111. $row['cg']=$cg['tx_cost']?:'0.00';
  112. $row['sji']=$sj2['user_name']?:'总店';
  113. $row['time']=date("Y-m-d H:i:s",$row['time']);
  114. if($row['state']==1){
  115. $row['state']='待审核';
  116. }elseif($row['state']==2){
  117. $row['state']='已通过';
  118. }elseif($row['state']==3){
  119. $row['state']='已拒绝';
  120. }
  121. foreach ($keys as $key) {
  122. $data5[] = $row[$key];
  123. }
  124. $user[] = implode("\t ,", $data5) . "\t ,";
  125. unset($data5);
  126. }
  127. $html .= implode("\n", $user) . "\n";
  128. }
  129. }
  130. header("Content-type:text/csv");
  131. header("Content-Disposition:attachment; filename=商家数据.csv");
  132. echo $html;
  133. exit();
  134. }
  135. include $this->template('web/fxlist');