虚拟币交易平台源码修改 二次开发 btchanges 增加充值3级奖励分红功能
找到文件 Application/Admin/Controller/FinanceController.class.php
修改function myczQueren() 为
public function myczQueren()
{
$id = $_GET['id'];
if (empty($id)) {
$this->error('请选择要操作的数据!');
}
$mycz = M('Mycz')->where(array('id' => $id))->find();
if (($mycz['status'] != 0) && ($mycz['status'] != 3)) {
$this->error('已经处理,禁止再次操作!');
}
$mo = M();
$mo->execute('set autocommit=0');
$mo->execute('lock tables btchanges_user_coin write,btchanges_mycz write,btchanges_finance write,btchanges_invit write,btchanges_user write');
$rs = array();
$finance = $mo->table('btchanges_finance')->where(array('userid' => $mycz['userid']))->order('id desc')->find();
$finance_num_user_coin = $mo->table('btchanges_user_coin')->where(array('userid' => $mycz['userid']))->find();
$rs[] = $mo->table('btchanges_user_coin')->where(array('userid' => $mycz['userid']))->setInc('cny', $mycz['num']);
$rs[] = $mo->table('btchanges_mycz')->where(array('id' => $mycz['id']))->save(array('status' => 2, 'mum' => $mycz['num'], 'endtime' => time()));
$finance_mum_user_coin = $mo->table('btchanges_user_coin')->where(array('userid' => $mycz['userid']))->find();
$finance_hash = md5($mycz['userid'] . $finance_num_user_coin['cny'] . $finance_num_user_coin['cnyd'] . $mycz['num'] . $finance_mum_user_coin['cny'] . $finance_mum_user_coin['cnyd'] . MSCODE . 'auth.btchanges.com');
$finance_num = $finance_num_user_coin['cny'] + $finance_num_user_coin['cnyd'];
if ($finance['mum'] < $finance_num) {
$finance_status = (1 < ($finance_num - $finance['mum']) ? 0 : 1);
}
else {
$finance_status = (1 < ($finance['mum'] - $finance_num) ? 0 : 1);
}
$rs[] = $mo->table('btchanges_finance')->add(array('userid' => $mycz['userid'], 'coinname' => 'cny', 'num_a' => $finance_num_user_coin['cny'], 'num_b' => $finance_num_user_coin['cnyd'], 'num' => $finance_num_user_coin['cny'] + $finance_num_user_coin['cnyd'], 'fee' => $mycz['num'], 'type' => 1, 'name' => 'mycz', 'nameid' => $mycz['id'], 'remark' => '人民币充值-人工到账', 'mum_a' => $finance_mum_user_coin['cny'], 'mum_b' => $finance_mum_user_coin['cnyd'], 'mum' => $finance_mum_user_coin['cny'] + $finance_mum_user_coin['cnyd'], 'move' => $finance_hash, 'addtime' => time(), 'status' => $finance_status));
$cz_mes="成功充值[".$mycz['num']."]元.";
$cur_user_info = $mo->table('btchanges_user')->where(array('id' => $mycz['userid']))->find();
$cz_jiner = $mycz['num'];
if($cur_user_info['invit_1']&&$cur_user_info['invit_1']>0){
//存在一级推广人
$invit_1_jiner = round(($cz_jiner/100)*0.3, 6);
if ($invit_1_jiner) {
//处理前信息
$finance_1 = $mo->table('btchanges_finance')->where(array('userid' => $cur_user_info['invit_1']))->order('id desc')->find();
$finance_num_user_coin_1 = $mo->table('btchanges_user_coin')->where(array('userid' => $cur_user_info['invit_1']))->find();
//开始处理
$rs[] = $mo->table('btchanges_user_coin')->where(array('userid' => $cur_user_info['invit_1']))->setInc('cny',$invit_1_jiner);
$rs[] = $mo->table('btchanges_invit')->add(array('userid' => $cur_user_info['invit_1'], 'invit' => $mycz['userid'], 'name' => 'cny', 'type' => '一代充值奖励', 'num' => $cz_jiner, 'mum' => $cz_jiner, 'fee' => $invit_1_jiner, 'addtime' => time(), 'status' => 1));
//处理后
$finance_mum_user_coin_1 = $mo->table('btchanges_user_coin')->where(array('userid' => $cur_user_info['invit_1']))->find();
$finance_hash_1 = md5($cur_user_info['invit_1'].$finance_num_user_coin_1['cny'] . $finance_num_user_coin_1['cnyd'] . $invit_1_jiner . $finance_mum_user_coin_1['cny'] . $finance_mum_user_coin_1['cnyd'] . MSCODE . 'auth.btchanges.com');
$finance_num_1 = $finance_num_user_coin_1['cny'] + $finance_num_user_coin_1['cnyd'];
if ($finance_1['mum'] < $finance_num_1) {
$finance_status_1 = (1 < ($finance_num_1 - $finance_1['mum']) ? 0 : 1);
}
else {
$finance_status_1 = (1 < ($finance_1['mum'] - $finance_num_1) ? 0 : 1);
}
$rs[] = $mo->table('btchanges_finance')->add(array('userid' => $cur_user_info['invit_1'], 'coinname' => 'cny', 'num_a' => $finance_num_user_coin_1['cny'], 'num_b' => $finance_num_user_coin_1['cnyd'], 'num' => $finance_num_user_coin_1['cny'] + $finance_num_user_coin_1['cnyd'], 'fee' => $invit_1_jiner, 'type' => 1, 'name' => 'mycz', 'nameid' => $cur_user_info['invit_1'], 'remark' => '人民币充值-一代充值奖励-充值ID'.$mycz['userid'].',订单'.$mycz['tradeno'].',金额'.$cz_jiner.'元,奖励'.$invit_1_jiner.'元', 'mum_a' => $finance_mum_user_coin_1['cny'], 'mum_b' => $finance_mum_user_coin_1['cnyd'], 'mum' => $finance_mum_user_coin_1['cny'] + $finance_mum_user_coin_1['cnyd'], 'move' => $finance_hash_1, 'addtime' => time(), 'status' => $finance_status_1));
//处理结束提示信息
$cz_mes = $cz_mes."一代推荐奖励[".$invit_1_jiner."]元.";
}
}
if($cur_user_info['invit_2']&&$cur_user_info['invit_2']>0){
//存在二级推广人
$invit_2_jiner = round(($cz_jiner/100)*0.2, 6);
if ($invit_2_jiner) {
//处理前信息
$finance_2 = $mo->table('btchanges_finance')->where(array('userid' => $cur_user_info['invit_2']))->order('id desc')->find();
$finance_num_user_coin_2 = $mo->table('btchanges_user_coin')->where(array('userid' => $cur_user_info['invit_2']))->find();
//开始处理
$rs[] = $mo->table('btchanges_user_coin')->where(array('userid' => $cur_user_info['invit_2']))->setInc('cny',$invit_2_jiner);
$rs[] = $mo->table('btchanges_invit')->add(array('userid' => $cur_user_info['invit_2'], 'invit' => $mycz['userid'], 'name' => 'cny', 'type' => '二代充值奖励', 'num' => $cz_jiner, 'mum' => $cz_jiner, 'fee' => $invit_2_jiner, 'addtime' => time(), 'status' => 1));
//处理后
$finance_mum_user_coin_2 = $mo->table('btchanges_user_coin')->where(array('userid' => $cur_user_info['invit_2']))->find();
$finance_hash_2 = md5($cur_user_info['invit_2'].$finance_num_user_coin_2['cny'] . $finance_num_user_coin_2['cnyd'] . $invit_2_jiner . $finance_mum_user_coin_2['cny'] . $finance_mum_user_coin_2['cnyd'] . MSCODE . 'auth.btchanges.com');
$finance_num_2 = $finance_num_user_coin_2['cny'] + $finance_num_user_coin_2['cnyd'];
if ($finance_2['mum'] < $finance_num_2) {
$finance_status_2 = (1 < ($finance_num_2 - $finance_2['mum']) ? 0 : 1);
}
else {
$finance_status_2 = (1 < ($finance_2['mum'] - $finance_num_2) ? 0 : 1);
}
$rs[] = $mo->table('btchanges_finance')->add(array('userid' => $cur_user_info['invit_2'], 'coinname' => 'cny', 'num_a' => $finance_num_user_coin_2['cny'], 'num_b' => $finance_num_user_coin_2['cnyd'], 'num' => $finance_num_user_coin_2['cny'] + $finance_num_user_coin_2['cnyd'], 'fee' => $invit_2_jiner, 'type' => 1, 'name' => 'mycz', 'nameid' => $cur_user_info['invit_2'], 'remark' => '人民币充值-二代充值奖励-充值ID'.$mycz['userid'].',订单'.$mycz['tradeno'].',金额'.$cz_jiner.'元,奖励'.$invit_2_jiner.'元', 'mum_a' => $finance_mum_user_coin_2['cny'], 'mum_b' => $finance_mum_user_coin_2['cnyd'], 'mum' => $finance_mum_user_coin_2['cny'] + $finance_mum_user_coin_2['cnyd'], 'move' => $finance_hash_2, 'addtime' => time(), 'status' => $finance_status_2));
//处理结束提示信息
$cz_mes = $cz_mes."二代推荐奖励[".$invit_2_jiner."]元.";
}
}
if($cur_user_info['invit_3']&&$cur_user_info['invit_3']>0){
//存在三级推广人
$invit_3_jiner = round(($cz_jiner/100)*0.1, 6);
if ($invit_3_jiner) {
//处理前信息
$finance_3 = $mo->table('btchanges_finance')->where(array('userid' => $cur_user_info['invit_3']))->order('id desc')->find();
$finance_num_user_coin_3 = $mo->table('btchanges_user_coin')->where(array('userid' => $cur_user_info['invit_3']))->find();
//开始处理
$rs[] = $mo->table('btchanges_user_coin')->where(array('userid' => $cur_user_info['invit_3']))->setInc('cny',$invit_3_jiner);
$rs[] = $mo->table('btchanges_invit')->add(array('userid' => $cur_user_info['invit_3'], 'invit' => $mycz['userid'], 'name' => 'cny', 'type' => '三代充值奖励', 'num' => $cz_jiner, 'mum' => $cz_jiner, 'fee' => $invit_3_jiner, 'addtime' => time(), 'status' => 1));
//处理后
$finance_mum_user_coin_3 = $mo->table('btchanges_user_coin')->where(array('userid' => $cur_user_info['invit_3']))->find();
$finance_hash_3 = md5($cur_user_info['invit_3'].$finance_num_user_coin_3['cny'] . $finance_num_user_coin_3['cnyd'] . $invit_3_jiner . $finance_mum_user_coin_3['cny'] . $finance_mum_user_coin_3['cnyd'] . MSCODE . 'auth.btchanges.com');
$finance_num_3 = $finance_num_user_coin_3['cny'] + $finance_num_user_coin_3['cnyd'];
if ($finance_3['mum'] < $finance_num_3) {
$finance_status_3 = (1 < ($finance_num_3 - $finance_3['mum']) ? 0 : 1);
}
else {
$finance_status_3 = (1 < ($finance_3['mum'] - $finance_num_3) ? 0 : 1);
}
$rs[] = $mo->table('btchanges_finance')->add(array('userid' => $cur_user_info['invit_3'], 'coinname' => 'cny', 'num_a' => $finance_num_user_coin_3['cny'], 'num_b' => $finance_num_user_coin_3['cnyd'], 'num' => $finance_num_user_coin_3['cny'] + $finance_num_user_coin_3['cnyd'], 'fee' => $invit_3_jiner, 'type' => 1, 'name' => 'mycz', 'nameid' => $cur_user_info['invit_3'], 'remark' => '人民币充值-三代充值奖励-充值ID'.$mycz['userid'].',订单'.$mycz['tradeno'].',金额'.$cz_jiner.'元,奖励'.$invit_3_jiner.'元', 'mum_a' => $finance_mum_user_coin_3['cny'], 'mum_b' => $finance_mum_user_coin_3['cnyd'], 'mum' => $finance_mum_user_coin_3['cny'] + $finance_mum_user_coin_3['cnyd'], 'move' => $finance_hash_3, 'addtime' => time(), 'status' => $finance_status_3));
//处理结束提示信息
$cz_mes = $cz_mes."三代推荐奖励[".$invit_3_jiner."]元.";
}
}
if (check_arr($rs)) {
$mo->execute('commit');
$mo->execute('unlock tables');
$this->success($cz_mes);
}
else {
$mo->execute('rollback');
$this->error('操作失败!');
}
}
Home/controller 目录 新建文件 PromoteController.class.php
代码如下
class PromoteController extends HomeController
{
public function index($id = NULL)
{
$where = "invit_1<>'' and invit_1>0";
$list = M('User')->field(array('count(*)'=>'pnum', 'invit_1'=>'uid'))->where($where)->group('invit_1')->order('pnum desc')->limit(10)->select();
foreach ($list as $k => $v) {
$list[$k]['username'] = M('User')->where(array('id' => $v['uid']))->getField('username');
}
//select invit,sum(fee) as jiner from btchanges_invit where group by invit ORDER BY jiner desc
$where = "type like '%充值奖励%' and userid in (select id from btchanges_user)";
$list_jiner = M('Invit')->field(array('sum(fee)'=>'jiner', 'userid'))->where($where)->group('userid')->order('jiner desc')->limit(10)->select();
foreach ($list_jiner as $k => $v) {
$list_jiner[$k]['username'] = M('User')->where(array('id' => $v['userid']))->getField('username');
}
$this->assign('list_jiner', $list_jiner);
$this->assign('list', $list);
$this->display();
}
}
增加功能效果