From 87fb1f526e6fe6f091c0ccbe873182b72aaebdc4 Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Mon, 30 Dec 2019 10:53:36 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A8=E5=B9=BF?= =?UTF-8?q?=E5=91=98=E6=B7=BB=E5=8A=A0=E6=97=B6=E5=88=9D=E5=A7=8B=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Base/Service/PromoteService.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Application/Base/Service/PromoteService.class.php b/Application/Base/Service/PromoteService.class.php index c513618d2..d1ba9e5d1 100644 --- a/Application/Base/Service/PromoteService.class.php +++ b/Application/Base/Service/PromoteService.class.php @@ -930,7 +930,7 @@ class PromoteService { 'real_name' => $params['real_name'], 'email' => $params['email'], 'idcard' => $params['idcard'] ?? '', - 'status' => $params['status'], + 'status' => $params['status'] ?? 0, 'mobile_phone' => $params['mobile_phone'], 'bank_name' => $params['bank_name'] ?? '', 'bank_card' => $params['bank_card'], From f1dc5f8920354e921ab59a64dfd470439621d75c Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Tue, 31 Dec 2019 13:34:55 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E5=91=98=E7=BB=A7?= =?UTF-8?q?=E6=89=BFcompany=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Base/Service/PromoteService.class.php | 2 +- Application/Home/Controller/PromoteController.class.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Application/Base/Service/PromoteService.class.php b/Application/Base/Service/PromoteService.class.php index d1ba9e5d1..06cf3c2f4 100644 --- a/Application/Base/Service/PromoteService.class.php +++ b/Application/Base/Service/PromoteService.class.php @@ -937,7 +937,7 @@ class PromoteService { 'parent_id' => $parent ? $parent['id'] : 0, 'parent_name' => $parent ? $parent['account'] : '官方渠道', 'admin_id' => $params['admin_id'] ?? 0, - 'company_id' => $params['company_id'] ?? 0, + 'company_id' => $params['company_id'] ?? 0, 'invite_code' => $params['invite_code'] ?? '', 'create_time' => time(), ]; diff --git a/Application/Home/Controller/PromoteController.class.php b/Application/Home/Controller/PromoteController.class.php index 6b6d5ead8..d43e3250f 100644 --- a/Application/Home/Controller/PromoteController.class.php +++ b/Application/Home/Controller/PromoteController.class.php @@ -985,6 +985,9 @@ class PromoteController extends BaseController } else { $parent = $loginPromote; } + if ($parent) { + $params['company_id'] = $parent['company_id']; + } if (C('PROMOTE_AUTO_AUDIT') == 1) { $params['status'] = 1; } From e884214546ffa236eaa63ae9640d577d27fc5ad2 Mon Sep 17 00:00:00 2001 From: chenxiaojun <956334972@qq.com> Date: Tue, 31 Dec 2019 14:07:24 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BC=9A=E9=95=BF=E6=8F=90=E7=8E=B0|?= =?UTF-8?q?=E5=85=AC=E4=BC=9A=E5=88=86=E6=88=90=E7=AE=A1=E7=90=86--?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Controller/AutoController.class.php | 90 +++ .../PromoteGameRatioController.class.php | 27 +- .../Controller/QueryController.class.php | 476 +++++++---- .../Admin/Model/WithdrawModel.class.php | 27 +- Application/Admin/View/Query/settlement.html | 751 +++++++----------- Application/Admin/View/Query/withdraw.html | 46 +- Application/Common/Common/function.php | 20 + .../Controller/FinanceController.class.php | 27 +- .../Home/View/default/Finance/index.html | 2 +- .../View/default/Finance/withdrawRecord.html | 14 +- Data/update.sql | 14 +- 11 files changed, 871 insertions(+), 623 deletions(-) diff --git a/Application/Admin/Controller/AutoController.class.php b/Application/Admin/Controller/AutoController.class.php index c704aec94..ff30dda40 100644 --- a/Application/Admin/Controller/AutoController.class.php +++ b/Application/Admin/Controller/AutoController.class.php @@ -1034,4 +1034,94 @@ public function auto_rrdae(){ ]; return $ret; } + + //会长提现 + public function promoteWithdraw() + { + $map['level'] = 1; + $map['ver_status'] = 1; + $promotes = M('promote', 'tab_')->field('id, account, chain')->where($map)->select(); + $success = 0; + $error_withdraw = 0; + $error_spend = 0; + $error_balance = 0; + + if (!empty($promotes)) { + foreach ($promotes as $promote) { + $result = $this->promoteWithdrawByPromote($promote); + switch ($result) { + case -2: + $error_balance++; + break; + case -1: + $error_spend++; + break; + case 0: + $error_withdraw++; + break; + case 1: + $success++; + break; + } + } + } + + echo "success:{$success} error_withdraw:{$error_withdraw} error_spend:{$error_spend} error_balance:{$error_balance}"; + } + + private function promoteWithdrawByPromote($promote) + { + $promoteMap['chain'] = ['like', "{$promote['chain']}{$promote['id']}/%"]; + $promoteIds = M('promote', 'tab_')->where($promoteMap)->getField('id', true); + $promoteIds[] = $promote['id']; + $settlementEndTime = strtotime(date('Y-m-d')) - 1; + + $spendMap['pay_status'] = 1; + $spendMap['selle_status'] = 0; + $spendMap['promote_id'] = ['in', $promoteIds]; + $spendMap['pay_time'] = ['elt', $settlementEndTime]; + $spendModel = M('spend', 'tab_'); + $balance = $spendModel->field("sum(if(selle_ratio > 0, pay_amount * selle_ratio, 0)) as balance") + ->where($spendMap) + ->find()['balance']; + $balance = bcdiv($balance, 100, 2); + if ($balance < 100) { + return -2;//余额不足 + } + + $thisTime = time(); + $add['sum_money'] = $balance; + $add['promote_id'] = $promote['id']; + $add['promote_account'] = $promote['account']; + $add['create_time'] = $thisTime; + $add['status'] = 0; + $add['widthdraw_number'] = D('withdraw')->produceWithdrawNumber(); + $add['settlement_begin_time'] = 0; + $add['settlement_end_time'] = $settlementEndTime; + $add['spend_ids'] = ''; + $add['op_id'] = 0; + $add['op_type'] = 3; + $add['last_op_id'] = $add['op_id']; + $add['last_op_type'] = 3; + + M()->startTrans();//开启事物 + $withdrawId = D('withdraw')->add($add); + if (!$withdrawId) { + M()->rollback();//事物回滚 + return 0;//提现失败 + } + + $save['selle_status'] = 1; + $save['selle_time'] = $thisTime; + $save['withdraw_id'] = $withdrawId; + $res = $spendModel->where($spendMap)->save($save); + if ($res === false) { + D('withdraw')->delete($withdrawId); + M()->rollback();//事物回滚 + return -1; + } + + M()->commit();//事物提交 + return 1; + } } diff --git a/Application/Admin/Controller/PromoteGameRatioController.class.php b/Application/Admin/Controller/PromoteGameRatioController.class.php index 7952b4fa2..e362834c7 100644 --- a/Application/Admin/Controller/PromoteGameRatioController.class.php +++ b/Application/Admin/Controller/PromoteGameRatioController.class.php @@ -62,7 +62,7 @@ class PromoteGameRatioController extends ThinkController $thisPromoteAccount = '未知'; $thisPromoteMobilePhone = '未知'; $thisPromoteCreateTime = '未知'; - $thisPromoteStatus = '未知'; + $thisPromoteStatus = '待审核'; $thisPromoteVerStatus = '未知'; $thisGameName = '未知'; $thisGameRatio = '0.00'; @@ -79,9 +79,9 @@ class PromoteGameRatioController extends ThinkController $thisPromoteAccount = $promotes[$thisPromoteId]['account']; $thisPromoteMobilePhone = $promotes[$thisPromoteId]['mobile_phone']; $thisPromoteCreateTime = date('Y-m-d H:i:s', $promotes[$thisPromoteId]['create_time']); - $thisPromoteStatus = get_status_title($promotes[$thisPromoteId]['status']); - $thisPromoteStatus = $thisPromoteStatus ?? '未知'; - $thisPromoteVerStatus = getPromoteVerStatus($promotes[$thisPromoteId]['status'], 2); + $thisPromoteStatus = get_info_status($promotes[$thisPromoteId]['status'], 3); + $thisPromoteStatus = $thisPromoteStatus ?? '待审核'; + $thisPromoteVerStatus = getPromoteVerStatus($promotes[$thisPromoteId]['ver_status'], 2); } if ($issetGame) { $thisGameName = $games[$thisGameId]['game_name']; @@ -146,16 +146,19 @@ class PromoteGameRatioController extends ThinkController if (empty($promoteGameRatio)) { $this->error('参数异常'); } + if ($promoteGameRatio['status'] == -1 || $save['begin_time'] != $promoteGameRatio['begin_time'] || $save['end_time'] != $promoteGameRatio['end_time'] || $save['ratio'] != $promoteGameRatio['ratio'] || $save['remark'] != $promoteGameRatio['remark']) { + $promoteId = $promoteGameRatio['promote_id']; + $this->isWithdraw($promoteId, $save['begin_time']);//是否存在开始时间后已提现数据 - $promoteId = $promoteGameRatio['promote_id']; - $this->isWithdraw($promoteId, $save['begin_time']);//是否存在开始时间后已提现数据 - - if ($promoteGameRatio['status'] == 1) { - $save['last_ratio'] = $promoteGameRatio['ratio']; - $save['last_ratio_status'] = 1; + if ($promoteGameRatio['status'] == 1) { + $save['last_ratio'] = $promoteGameRatio['ratio']; + $save['last_ratio_status'] = 1; + } + $save['id'] = intval($params['id']); + $result = D(self::MODEL_NAME)->save($save); + } else { + $result = true; } - $save['id'] = intval($params['id']); - $result = D(self::MODEL_NAME)->save($save); } else {//新增 if (empty($params['promote_id'])) { $this->error('请选择会长账号'); diff --git a/Application/Admin/Controller/QueryController.class.php b/Application/Admin/Controller/QueryController.class.php index 99a3a3e77..fde9a8bc0 100644 --- a/Application/Admin/Controller/QueryController.class.php +++ b/Application/Admin/Controller/QueryController.class.php @@ -2,7 +2,9 @@ namespace Admin\Controller; +use Home\Controller\FileController; use User\Api\UserApi as UserApi; +use Admin\Model\WithdrawModel; /** * 推广查询控制器 @@ -10,164 +12,369 @@ use User\Api\UserApi as UserApi; */ class QueryController extends ThinkController { - public function settlement($p = 0) + //生成提现单号 + public function produceWithdrawNumber() { + $prefix = 'WD_'; + $number = ''; + while (true) { + $randomNum = rand(10, 99); + $number = $prefix . time() . $randomNum; + $map['widthdraw_number'] = $number; + $res = M('withdraw', 'tab_')->where($map)->getField('id'); + if (!$res) { + break; + } + } + return $number; + } + public function settlement($p = 0) + { + $page = intval(I('p', 1)); //默认显示第一页数据 + $row = intval(I('row', 10)); $group = I('group', 1); $this->assign('group', $group); - if (isset($_REQUEST['total_status'])) { - unset($_REQUEST['total_status']); - } - - $this->m_title = '推广结算'; - $this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Query/settlement', 'status' => 1])->find()); + $promoteId = I('promote_id', 0); if ($group == 1) { - if ($_REQUEST['unum'] == 2) { - $order = 'unum'; - $order_type = SORT_ASC; - } else if ($_REQUEST['unum'] == 1) { - $order = 'unum'; - $order_type = SORT_DESC; - } - if ($_REQUEST['spay_amount'] == 2) { - $order = 'spay_amount'; - $order_type = SORT_ASC; - } else if ($_REQUEST['spay_amount'] == 1) { - $order = 'spay_amount'; - $order_type = SORT_DESC; - } - $model = array( - 'title' => '渠道结算', - 'template_list' => 'settlement', - 'order' => $order, - 'order_type' => $order_type//0倒序 1 正序 - ); - $start = $_REQUEST['timestart']; - $end = $_REQUEST['timeend']; - if (I('group') != '') { - if ($start == '' || $end == '' && $_REQUEST['promote_account'] == '') { - $this->error('结算周期、所属渠道不能为空!', '', 1); + if (empty($promoteId)) { + $this->display(); + } else { + $promoteIds = M('promote', 'tab_')->where(['chain' => ['like', "/{$promoteId}/%"]])->getField('id', true); + $promoteIds[] = $promoteId; + $beginTime = I('timestart', get_lastweek_name(7)); + $endTime = I('timeend', get_lastweek_name(1)); + $sortBy = I('sort_by', ''); + $sortColumn = I('sort_column', ''); + $order = 'tab_spend.pay_time'; + $orderType = 'desc'; + + if (in_array($sortColumn, ['user_num', 'sum_amount'])) { + $order = $sortColumn; } - if ($start == '' || $end == '') { - $this->error('请选择结算周期!', '', 1); + if ($sortBy == 1) { + $orderType = 'desc'; + } elseif ($sortBy == 2) { + $orderType = 'asc'; } - if ($_REQUEST['promote_account'] == '') { - $this->error('请选择渠道!', '', 1); + $beginTime = strtotime($beginTime); + $endTime = strtotime($endTime) + 3600 * 24 - 1; + + $spendMap['tab_spend.pay_status'] = 1; + $spendMap['tab_spend.selle_status'] = 0; + $spendMap['tab_spend.pay_time'] = ['between', [$beginTime, $endTime]]; + $spendMap['tab_spend.promote_id'] = ['in', $promoteIds]; + $spendField = 'tab_spend.promote_account, tab_spend.game_name, sum(tab_spend.pay_amount) as sum_amount, tab_spend.selle_ratio, sum(if(tab_spend.selle_ratio > 0, tab_spend.pay_amount * tab_spend.selle_ratio, 0)) as settlement_amount'; + $userMap['tab_user.promote_id'] = ['in', $promoteIds]; + $userMap['_string'] = 'tab_user.promote_id = tab_spend.promote_id'; + $userField = M('user', 'tab_')->field('count(tab_user.id) as user_num') + ->where($userMap) + ->buildSql(); + $field = "{$spendField}, {$userField} as user_num"; + + $query = M('spend', 'tab_')->field($field) + ->where($spendMap) + ->group('tab_spend.selle_ratio, tab_spend.game_id, tab_spend.promote_id') + ->order("{$order} {$orderType}") + ->page($page, $row) + ->buildSql(); + $records = M()->table($query) + ->alias('record') + ->select(); + $countQuery = M('spend', 'tab_')->field('tab_spend.id') + ->where($spendMap) + ->group('tab_spend.selle_ratio, tab_spend.game_id, tab_spend.promote_id') + ->buildSql(); + $count = M()->table($countQuery) + ->alias('tab_spend') + ->count(); + $page = set_pagination($count, $row); + + if (!empty($records)) { + $promote = M('promote', 'tab_')->find($promoteId); + foreach ($records as &$record) { + $record['promote_account'] = $promote['account'] ?? '未知'; + $record['settlement_amount'] = bcdiv($record['settlement_amount'], 100, 2); + } } - } - $smap['tab_spend.pay_status'] = 1; - //判断是否结算绑币 - if ($_REQUEST['bind_coin'] == 0) { - $smap['tab_spend.pay_way'] = array('neq', -1); - } - $this->meta_title = '渠道结算列表'; - $this->assign('setdate', date("Y-m-d", strtotime("-1 day"))); - $this->assign('is_admin', is_administrator()); - if ($start && $end) { - if ((strtotime($end) + 24 * 60 * 60 - 1) < strtotime($start)) { - $this->error('时间选择不正确!', U('Query/settlement'), ''); - } - $umap['register_time'] = array('BETWEEN', array(strtotime($start), strtotime($end) + 24 * 60 * 60 - 1)); - if (isset($_REQUEST['game_name']) && $_REQUEST['game_name'] != '') { - $umap['fgame_id'] = get_game_id($_REQUEST['game_name']); - $smap['tab_spend.game_id'] = get_game_id($_REQUEST['game_name']); + $totalField = 'sum(if(tab_spend.selle_ratio > 0, tab_spend.pay_amount * tab_spend.selle_ratio, 0)) as settlement_amount'; + $total = array_sum(array_column($records, 'settlement_amount'));//当页 + $zTotal = null_to_0(M('spend', 'tab_')->field($totalField)->where($spendMap)->find()['settlement_amount']);//累计 + $zTotal = bcdiv($zTotal, 100 ,2); + unset($spendMap['tab_spend.pay_time']); + $spendMap['_string'] = 'tab_spend.pay_time' . total(1); + $tTotal = null_to_0(M('spend', 'tab_')->field($totalField)->where($spendMap)->find()['settlement_amount']);//今日 + $tTotal = bcdiv($tTotal, 100 ,2); + $spendMap['_string'] = 'tab_spend.pay_time' . total(5); + $yTotal = null_to_0(M('spend', 'tab_')->field($totalField)->where($spendMap)->find()['settlement_amount']);//昨日 + $yTotal = bcdiv($yTotal, 100 ,2); + + if($page) { + $this->assign('_page', $page); } - if (isset($_REQUEST['promote_account']) && $_REQUEST['promote_account'] != '') { - $allid = get_subordinate_promote_($_REQUEST['promote_account']); - $allid[] = $_REQUEST['promote_account']; - $umap['tab_user.promote_account'] = array('in', $allid); - $smap['tab_spend.promote_account'] = array('in', $allid); - } else { - $this->error('未选择渠道!', '', 1); - } - $umap['is_check'] = 1; - $umap['settle_check'] = 0; - $smap['pay_time'] = array('BETWEEN', array(strtotime($start), strtotime($end) + 24 * 60 * 60 - 1)); - $smap['is_check'] = 1; - $smap['settle_check'] = 0; - //为数据权限添加 - setPowerPromoteIds($umap, 'tab_user.promote_id'); - setPowerPromoteIds($smap, 'tab_spend.promote_id'); - $map['umap'] = $umap; - $map['smap'] = $smap; - - $user = A('Settlement', 'Event'); - - - $user->settlement($model, $p, $map); - } else { + $this->assign('records', $records); + $this->assign('total', $total); + $this->assign('tTotal', $tTotal); + $this->assign('yTotal', $yTotal); + $this->assign('zTotal', $zTotal); + $this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Query/settlement', 'status' => 1])->find()); + $this->m_title = '推广结算'; $this->display(); } - } - if ($group == 2) { - if (isset($_REQUEST['stimestart']) && isset($_REQUEST['stimeend'])) { - $map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['stimestart']), strtotime($_REQUEST['stimeend']) + 24 * 60 * 60 - 1)); - } elseif (isset($_REQUEST['stimestart'])) { - $map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['stimestart']), time())); - } elseif (isset($_REQUEST['stimeend'])) { - $map['create_time'] = array('LT', (strtotime($_REQUEST['stimeend']) + 24 * 60 * 60 - 1)); + } elseif ($group == 2) { + $map['_string'] = '1 = 1'; + $createTime = strtotime(I('create_time', '')); + $withdrawNumber = I('widthdraw_number', ''); + $status = intval(I('status', '')); + $opType = intval(I('op_type', 0)); + if ($createTime) { + $createTimeEnd = $createTime + 3600 * 24 - 1; + $map['create_time'] = ['between', [$createTime, $createTimeEnd]]; } - if (isset($_REQUEST['timestart']) && isset($_REQUEST['timeend'])) { - $map['starttime'] = ['GT', strtotime($_REQUEST['timestart'])]; - $map['endtime'] = ['LT', strtotime($_REQUEST['timeend']) + 24 * 60 * 60]; - } elseif (isset($_REQUEST['timestart'])) { - $map['starttime'] = ['GT', strtotime($_REQUEST['timestart'])]; - } elseif (isset($_REQUEST['timeend'])) { - $map['endtime'] = ['LT', strtotime($_REQUEST['timeend']) + 24 * 60 * 60]; + if ($promoteId) { + $map['promote_id'] = $promoteId; } - if (isset($_REQUEST['game_name'])) { - if ($_REQUEST['game_name'] == '全部') { - unset($_REQUEST['game_name']); - } else { - $map['game_name'] = $_REQUEST['game_name']; - } + if ($withdrawNumber) { + $map['widthdraw_number'] = ['like', "{$withdrawNumber}%"]; } - if (isset($_REQUEST['promote_account'])) { - if ($_REQUEST['promote_account'] == '全部') { - unset($_REQUEST['promote_account']); - } else { - $map['promote_account'] = $_REQUEST['promote_account']; + if (isset($_REQUEST['status'])) { + $map['status'] = $status; + } + if ($opType) { + $map['op_type'] = $opType; + } + + $records = M('withdraw', 'tab_')->field('id, promote_account, widthdraw_number, sum_money, op_id, op_type, last_op_id, last_op_type, settlement_begin_time, settlement_end_time, create_time, status, respond') + ->where($map) + ->order('create_time desc') + ->page($page, $row) + ->select(); + $count = M('withdraw', 'tab_')->field('id, promote_account, widthdraw_number, sum_money, op_id, op_type, last_op_id, last_op_type, settlement_begin_time, settlement_end_time, create_time, status, respond') + ->where($map) + ->count(); + if (!empty($records)) { + foreach ($records as &$record) { + $record['settlement_begin_time'] = $record['settlement_begin_time'] ? date('Y-m-d H:i:s', $record['settlement_begin_time']) : '--'; + $record['settlement_end_time'] = date('Y-m-d H:i:s', $record['settlement_end_time']); + $record['create_time'] = date('Y-m-d H:i:s', $record['create_time']); + $record['status_text'] = promoteWithdrawStatus($record['status']); + if ($record['status'] == -2) { + $record['status_text'] = '' . $record['status_text'] . ''; + } } } - if (!empty($_REQUEST['settlement_number'])) { - $map['settlement_number'] = $_REQUEST['settlement_number']; + + $page = set_pagination($count, $row); + if($page) { + $this->assign('_page', $page); } + $this->assign('records', $records); + $this->display(); + } + } - $map['developers'] = 0; + public function settlementWithdraw() + { + $beginTime = strtotime(I('begin_time', '')); + $endTime = strtotime(I('end_time', '')); + $promoteId = intval(I('promote_id', 0)); + if ($beginTime == 0 || $endTime == 0) { + $data['status'] = 0; + $data['msg'] = '时间参数错误'; + $this->ajaxReturn($data); + } + if ($beginTime > $endTime) { + $data['status'] = 0; + $data['msg'] = '开始时间必须小于等于结束时间'; + $this->ajaxReturn($data); + } + if ($promoteId == 0) { + $data['status'] = 0; + $data['msg'] = '请选择会长账号'; + $this->ajaxReturn($data); + } - $model = array( - 'm_name' => 'settlement', - 'fields' => array( - 'settlement_number', - 'starttime', 'endtime', - 'promote_id', 'promote_account', - 'sum(total_money) as total_money', - 'sum(total_number) as total_number', - 'sum(sum_money) as sum_money', - 'bind_coin_status', - 'create_time'), - 'group' => 'promote_id,starttime,endtime,create_time,bind_coin_status', - 'order' => 'create_time desc ', - 'title' => '结算账单', - 'template_list' => 'settlement', - ); - //为数据权限添加 - setPowerPromoteIds($map); - $map1 = $map; + $promote = M('promote', 'tab_')->find($promoteId); + if (empty($promote)) { + $data['status'] = 0; + $data['msg'] = '数据异常'; + $this->ajaxReturn($data); + } + if ($promote['level'] != 1) { + $data['status'] = 0; + $data['msg'] = '非会长账号,无法执行此操作'; + $this->ajaxReturn($data); + } + if ($promote['ver_status'] != 1) { + $data['status'] = 0; + $data['msg'] = '该会长未通过资质认证审核,暂时无法提现'; + $this->ajaxReturn($data); + } + + $endTime += 3600 * 24 - 1; + $spendModel = M('spend', 'tab_'); + $map['chain'] = ['like', $promote['chain'] . $promote['id'] . '/%']; + $promoteIds = M('promote', 'tab_')->where($map)->getField('id', true); + $promoteIds[] = $promote['id']; + $promoteIds = implode(',', $promoteIds); + + $map = []; + $map['pay_status'] = 1; + $map['selle_status'] = 0; + $map['promote_id'] = ['in', $promoteIds]; + $map['pay_time'] = ['between', [$beginTime, $endTime]]; + $balance = $spendModel->field("sum(pay_amount * selle_ratio) as balance") + ->where($map) + ->find()['balance']; + $balance = bcdiv($balance, 100, 2); + if ($balance < 100) { + $data['status'] = 0; + $data['msg'] = '累计结算低于100元,无法提现!'; + $this->ajaxReturn($data); + } + $spendIds = $spendModel->where($map)->getField('id', true); + if (empty($spendIds)) { + $data['status'] = 0; + $data['msg'] = '数据异常'; + $this->ajaxReturn($data); + } + + $thisTime = time(); + $add['sum_money'] = $balance; + $add['promote_id'] = $promote['id']; + $add['promote_account'] = $promote['account']; + $add['create_time'] = $thisTime; + $add['status'] = 0; + $add['widthdraw_number'] = D('withdraw')->produceWithdrawNumber(); + $add['settlement_begin_time'] = $beginTime; + $add['settlement_end_time'] = $endTime; + $add['spend_ids'] = ''; + $add['op_id'] = is_login(); + $add['op_type'] = 2; + $add['last_op_id'] = $add['op_id']; + $add['last_op_type'] = 2; + + M()->startTrans();//开启事物 + $withdrawId = M('withdraw', 'tab_')->add($add); + if (!$withdrawId) { + M()->rollback();//事物回滚 + $data['status'] = 0; + $data['msg'] = '提现失败'; + $this->ajaxReturn($data); + } + + $map = []; + $map['id'] = ['in', $spendIds]; + $save['selle_status'] = 1; + $save['selle_time'] = $thisTime; + $save['withdraw_id'] = $withdrawId; + $res = $spendModel->where($map)->save($save); + if ($res === false) { + M('withdraw', 'tab_')->delete($withdrawId); + M()->rollback();//事物回滚 + $data['status'] = 0; + $data['msg'] = '提现失败'; + $this->ajaxReturn($data); + } + + M()->commit();//事物提交 + $data['status'] = 1; + $data['msg'] = '提现成功'; + $this->ajaxReturn($data); + } + + public function renewReview() + { + $id = intval(I('id', 0)); + $data = M('withdraw', 'tab_')->find($id); + if (empty($data) || $data['status'] != -1) { + $data['status'] = 0; + $data['msg'] = '数据异常'; + $this->ajaxReturn($data); + } - $ztotal = null_to_0(D('settlement')->where($map1)->sum('sum_money*10000') / 10000); - $this->assign('ztotal', $ztotal); - $ttotal = null_to_0(D('settlement')->where('create_time' . total(1))->sum('sum_money*10000') / 10000); - $this->assign('ttotal', $ttotal); - $ytotal = null_to_0(D('settlement')->where('create_time' . total(5))->sum('sum_money*10000') / 10000); - $this->assign('ytotal', $ytotal); - $user = A('Bill', 'Event'); + $save['id'] = $id; + $save['status'] = 0; + $save['last_up_update_time'] = time(); + $save['last_op_id'] = is_login(); + $save['last_op_type'] = 2; + $res = M('withdraw', 'tab_')->save($save); + if ($res === false) { + $data['status'] = 0; + $data['msg'] = '提交失败'; + } else { + $data['status'] = 1; + $data['msg'] = '提交成功'; + } + $this->ajaxReturn($data); + } - $user->money_list($model, $p, $map); + public function cancelWithdraw() + { + $id = intval(I('id', 0)); + $data = M('withdraw', 'tab_')->find($id); + if (empty($data) || !in_array($data['status'], [-1, 0])) { + $data['status'] = 0; + $data['msg'] = '数据异常'; + $this->ajaxReturn($data); } + $spendMap['withdraw_id'] = $id; + $spendIds = M('Spend', 'tab_')->where($spendMap)->getField('id', true); + if (empty($spendIds)) { + $data['status'] = 0; + $data['msg'] = '数据异常'; + $this->ajaxReturn($data); + } + $spendIds = implode(',', $spendIds); + $time = time(); + $withdrawSave['id'] = $id; + $withdrawSave['status'] = -2; + $withdrawSave['spend_ids'] = $spendIds; + $withdrawSave['last_up_update_time'] = $time; + $withdrawSave['last_op_id'] = is_login(); + $withdrawSave['last_op_type'] = 2; + + M('withdraw', 'tab_')->startTrans();//开启事物 + $withdrawRes = M('withdraw', 'tab_')->save($withdrawSave); + if ($withdrawRes === false) { + M('withdraw', 'tab_')->rollback();//事物回滚 + $data['status'] = 0; + $data['msg'] = '撤销失败'; + $this->ajaxReturn($data); + } + + $spendSave['selle_status'] = 0; + $spendSave['withdraw_id'] = 0; + $spendRes = M('spend', 'tab_')->where($spendMap)->save($spendSave); + if ($spendRes === false) { + M('withdraw', 'tab_')->rollback();//事物回滚 + $data['status'] = 0; + $data['msg'] = '撤销失败'; + } else { + M('withdraw', 'tab_')->commit();//事物提交 + $data['status'] = 1; + $data['msg'] = '撤销成功'; + } + $this->ajaxReturn($data); + } + + public function downloadProve() + { + $id = intval(I('id', 0)); + if ($id) { + $withdraw = M('withdraw', 'tab_')->find($id); + if (empty($withdraw) || $withdraw['status'] != 2 || !$withdraw['transfer_proof']) { + $this->error('网络异常'); + } + + $file = new FileController(); + $file->download($withdraw['transfer_proof']); + } else { + $this->error('参数异常'); + } } public function cpsettlement($p = 0) @@ -664,6 +871,9 @@ class QueryController extends ThinkController if (isset($_REQUEST['ti_status'])) { $map['status'] = $_REQUEST['ti_status']; } + if (isset($_REQUEST['op_type'])) { + $map['op_type'] = $_REQUEST['op_type']; + } if (isset($_REQUEST['promote_account'])) { if ($_REQUEST['promote_account'] == '全部') { unset($_REQUEST['promote_account']); diff --git a/Application/Admin/Model/WithdrawModel.class.php b/Application/Admin/Model/WithdrawModel.class.php index 324bd151c..87d60eb32 100644 --- a/Application/Admin/Model/WithdrawModel.class.php +++ b/Application/Admin/Model/WithdrawModel.class.php @@ -15,6 +15,10 @@ use Think\Model; */ class WithdrawModel extends Model{ + const OP_TYPE_PROMOTE = 1; + const OP_TYPE_ADMIN = 2; + const OP_TYPE_AUTO = 3; + /** * 构造函数 * @param string $name 模型名称 @@ -28,8 +32,11 @@ class WithdrawModel extends Model{ parent::__construct($name, $tablePrefix, $connection); } - - + public static $opTypeList = [ + self::OP_TYPE_PROMOTE => '推广员', + self::OP_TYPE_ADMIN => '管理员', + self::OP_TYPE_AUTO => '自动', + ]; /* * 开发者提现未处理列表 @@ -102,4 +109,20 @@ class WithdrawModel extends Model{ } + //生成提现单号 + public function produceWithdrawNumber() + { + $prefix = 'WD_'; + $number = ''; + while (true) { + $randomNum = rand(10, 99); + $number = $prefix . time() . $randomNum; + $map['widthdraw_number'] = $number; + $res = $this->where($map)->getField('id'); + if (!$res) { + break; + } + } + return $number; + } } diff --git a/Application/Admin/View/Query/settlement.html b/Application/Admin/View/Query/settlement.html index 12512b82d..e704735ff 100644 --- a/Application/Admin/View/Query/settlement.html +++ b/Application/Admin/View/Query/settlement.html @@ -30,98 +30,89 @@ -
说明:此功能是针对推广员下面的用户注册充值进行结算,充值数据是指消费到游戏的所有订单记录
-说明:此功能是查看所有的推广员结算记录
-说明:此功能是查看所有的会长未提现订单,并可进行后台提现
+说明:此功是查看并管理混服申请的功能
+注意①:推广结算只结算消费到游戏的所有订单记录。(系统默认全部排除绑币,可视情况自行勾选)
-注意②:包含绑币勾选请慎重,由于玩家账户部分绑币的来源属于后台发放或者会长代充等,涉及到成本盈亏,是否参与推广员结算请考虑清楚!
-注意③:推广结算时间请按规律时间统一结算,否则时间不统一容易导致个别游戏在统一时间内无法结算。(结算时间只可选到前一天)
-推广员账号 | -结算周期 | -结算单号 | -总充值 | -总注册 | -结算金额 | -结算范畴 | -结算时间 | -详情 | +推广员账号 | +结算单号 | +结算金额 | +操作人 | +操作人类型 | +最后操作人 | +最后操作人类型 | +结算开始时间 | +结算截止时间 | +提现时间 | +提现状态 | +说明 | +操作 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
- |
- {$data.starttime|date='Y-m-d',###}至{$data.endtime|date='Y-m-d',###} | -{$data.settlement_number} | -{$data.total_money} | -{$data.total_number} | -- {$data.sum_money} - | -{:get_bind_coin_status($data['bind_coin_status'])} | -- {$data.create_time|date='Y-m-d',###} - | -- 查看 - | +{$record.promote_account} | +{$record.widthdraw_number} | +{$record.sum_money} | +
+ |
+ {:getPromoteWithdrawOpType($record['op_type'])} | +
+ |
+ {:getPromoteWithdrawOpType($record['last_op_type'])} | +{$record.settlement_begin_time} | +{$record.settlement_end_time} | +{$record.create_time} | +{$record.status_text} | +{$record.respond} | +
+ |
汇总 | -当页结算:{$total}元 ; 今日结算:{$ttotal}元 ; 昨日结算:{$ytotal}元 ; 累计结算:{$ztotal}元 | -