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 @@ -
- -
-
- 参与结算设置: - -      - -
-
-

注意①:推广结算只结算消费到游戏的所有订单记录。(系统默认全部排除绑币,可视情况自行勾选)

-

注意②:包含绑币勾选请慎重,由于玩家账户部分绑币的来源属于后台发放或者会长代充等,涉及到成本盈亏,是否参与推广员结算请考虑清楚!

-

注意③:推广结算时间请按规律时间统一结算,否则时间不统一容易导致个别游戏在统一时间内无法结算。(结算时间只可选到前一天)

-
-
-
- - - -
- -
-
-
+
+
+ + 提 现 + +
+
+
+
- value="{:get_lastweek_name(7)}" value="{:I('timestart')}" placeholder="结算周期起始时间" /> - - -
- value="{:get_lastweek_name(1)}" value="{:I('timeend')}" placeholder="结算周期结束时间" /> - -
+ + - +
+ + +
-
- - + + +
+
- - - -
- 搜索 -
-
- -
- - - -
- - -
-
- -
- 搜索 -
-
+
+
+ +
+ + + + +
+ 搜索 +
+
+ +
+ +
+
+ +
+
+ +
+
+ 搜索 +
+
- -
@@ -130,21 +121,13 @@ - - - - 结算周期 - 推广员账号 - 游戏名称 - 总充值 - - 总注册 - 结算模式 - 分成比例 - 注册单价 - 结算金额 - 状态 - + 推广员账号 + 游戏名称 + 总充值 + 总注册 + 结算模式 + 分成比例 + 结算金额 @@ -154,211 +137,94 @@ .data-table tbody td{border-right:1px solid #DDDDDD;} .d_list .drop-down ul {z-index:999;} - + aOh! 暂时还没有内容! - - - - - - {:I('timestart')} 至 {:I('timeend')} - {:get_promote_name($data['pid'])} - {:get_game_name($data['game_id'])} - {$data['spay_amount']|default=0} - {$data['unum']|default=0} - -
-
- -
-
- - - {$data.ratio}0% - 修改 - - - {$data.money}0 - 修改 - - - {:round($data['spay_amount'] * $data['ratio']/100,2)} - - - 已结算 - - 可结算 - - + + + {$record.promote_account} + {$record.game_name} + {$record['sum_amount']|default=0} + {$record['user_num']|default=0} + CPS + {$record['selle_ratio']|default=0}% + + {$record['settlement_amount']} + + + + 汇总 + 当页结算:{$total}元 ; 今日结算:{$tTotal}元 ; 昨日结算:{$yTotal}元 ; 累计结算:{$zTotal}元 +
- - - - - - - - - - + + + + + + + + + + + + + - + - - - - - - - - - + + + + + + + + + + + + + - - - -
推广员账号结算周期结算单号总充值总注册结算金额结算范畴结算时间详情推广员账号结算单号结算金额操作人操作人类型最后操作人最后操作人类型结算开始时间结算截止时间提现时间提现状态说明操作
- - {:get_promote_name($data['promote_id'])} - - {:encryptStr(get_promote_name($data['promote_id']))} - - {$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} + + {:get_promote_name($record['op_id'])} + + {:getAdminNickname($record['op_id'])} + + 自动 + + {:getPromoteWithdrawOpType($record['op_type'])} + + {:get_promote_name($record['last_op_id'])} + + {:getAdminNickname($record['last_op_id'])} + + 自动 + + {: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}元
@@ -369,7 +235,7 @@ - + diff --git a/Application/Admin/View/Query/withdraw.html b/Application/Admin/View/Query/withdraw.html index 4a3131a7e..c675cae0b 100644 --- a/Application/Admin/View/Query/withdraw.html +++ b/Application/Admin/View/Query/withdraw.html @@ -78,13 +78,21 @@
- $value) :?>
+
+ +
搜索 @@ -106,9 +114,15 @@ 提现单号 - 提现金额 + 提现金额 推广员账号 - 申请时间 + 操作人 + 操作人类型 + 最后操作人 + 最后操作人类型 + 结算开始时间 + 结算截止时间 + 申请时间 提现状态 说明 审核时间 @@ -142,8 +156,30 @@ {:encryptStr(get_promote_name($data['promote_id']))} + + + {:get_promote_name($data['op_id'])} + + {:getAdminNickname($data['op_id'])} + + 自动 + + + {:getPromoteWithdrawOpType($data['op_type'])} + + + {:get_promote_name($data['last_op_id'])} + + {:getAdminNickname($data['last_op_id'])} + + 自动 + + + {:getPromoteWithdrawOpType($data['last_op_type'])} + {$data.settlement_begin_time|date='Y-m-d H:i:s',###}--- + {$data.settlement_end_time|date='Y-m-d H:i:s',###}--- {$data.create_time|date='Y-m-d H:i:s',###}--- - {:promoteWithdrawStatus($data['status'])} + style="color: #999;">{:promoteWithdrawStatus($data['status'])} {$data.respond} {$data.audit_time|date='Y-m-d H:i:s',###}--- @@ -161,7 +197,7 @@ 汇总 - 当页提现:{:null_to_0(array_sum(array_column(arrayPromoteWithdrawStatus('status','',$list_data),'sum_money')))}元 ; 今日提现:{:null_to_0(floor($ttotal*100)/100)}元 ; 昨日提现:{:null_to_0(floor($ytotal*100)/100)}元 ; 累计提现:{:null_to_0(floor($total*100)/100)}元 + 当页提现:{:null_to_0(array_sum(array_column(arrayPromoteWithdrawStatus('status','',$list_data),'sum_money')))}元 ; 今日提现:{:null_to_0(floor($ttotal*100)/100)}元 ; 昨日提现:{:null_to_0(floor($ytotal*100)/100)}元 ; 累计提现:{:null_to_0(floor($total*100)/100)}元 diff --git a/Application/Common/Common/function.php b/Application/Common/Common/function.php index c7d4909d2..b45da22c6 100644 --- a/Application/Common/Common/function.php +++ b/Application/Common/Common/function.php @@ -1430,6 +1430,7 @@ if (!function_exists('dd')) { function promoteWithdrawStatus($status = null) { $statusData = [ + -2 => '已撤销', -1 => '审核未通过', 0 => '待审核', 1 => '汇款中', @@ -1443,3 +1444,22 @@ function promoteWithdrawStatus($status = null) return $statusData; } +//获取提现操作人类型 +function getPromoteWithdrawOpType($opType = null) +{ + if ($opType) { + return Admin\Model\WithdrawModel::$opTypeList[$opType] ?? '未知'; + } else { + return Admin\Model\WithdrawModel::$opTypeList; + } +} + +//获取管理员账号 +function getAdminNickname($adminId) +{ + $adminId = intval($adminId); + if ($adminId) { + return M('member')->where(array('id' => $adminId))->getField('nickname'); + } + return '未知'; +} diff --git a/Application/Home/Controller/FinanceController.class.php b/Application/Home/Controller/FinanceController.class.php index c0c245b2e..a61cc0b36 100644 --- a/Application/Home/Controller/FinanceController.class.php +++ b/Application/Home/Controller/FinanceController.class.php @@ -284,6 +284,7 @@ class FinanceController extends BaseController //提现 public function withdraw() { + $this->error('无法执行此操作'); //是否是会长 $this->purview(); //验证安全密码 @@ -414,7 +415,7 @@ class FinanceController extends BaseController } } - $data = $model->field('id,widthdraw_number,create_time,settlement_end_time,sum_money,status,respond,transfer_proof') + $data = $model->field('id, widthdraw_number, create_time, settlement_begin_time, settlement_end_time, sum_money, status, respond, transfer_proof, op_id, op_type, last_op_id, last_op_type') ->where($map) ->order('id desc') ->page($page, $row) @@ -426,8 +427,13 @@ class FinanceController extends BaseController if (!empty($data)) { foreach ($data as &$list) { $list['create_time'] = date('Y-m-d H:i:s', $list['create_time']); + $list['settlement_begin_time'] = $list['settlement_begin_time'] ? date('Y-m-d H:i:s', $list['settlement_begin_time']) : '--'; $list['settlement_end_time'] = date('Y-m-d H:i:s', $list['settlement_end_time']); $list['status_name'] = FinanceController::$withdrawStatus[$list['status']]; + $list['op_id'] = $this->getOpIdByType($list['op_id'], $list['op_type']); + $list['last_op_id'] = $this->getOpIdByType($list['last_op_id'], $list['last_op_type']); + $list['op_type'] = getPromoteWithdrawOpType($list['op_type']); + $list['last_op_type'] = getPromoteWithdrawOpType($list['last_op_type']); switch ($list['status']) { case -2: $list['status_name'] = '' . $list['status_name'] . ''; @@ -454,6 +460,23 @@ class FinanceController extends BaseController $this->display(); } + private function getOpIdByType($opId, $opType) + { + switch ($opType) { + case 1: + $opId = get_promote_name($opId); + break; + case 2: + $opId = getAdminNickname($opId); + break; + case 3: + $opId = '自动'; + break; + } + + return $opId; + } + //提现明细 public function withdrawDtl() { @@ -584,6 +607,7 @@ class FinanceController extends BaseController //审核拒绝 重新审核 public function renewReview() { + $this->error('无法执行此操作'); //是否是会长 $this->purview(); //验证安全密码 @@ -624,6 +648,7 @@ class FinanceController extends BaseController //撤销提现 public function cancelWithdraw() { + $this->error('无法执行此操作'); //是否是会长 $this->purview(); //验证安全密码 diff --git a/Application/Home/View/default/Finance/index.html b/Application/Home/View/default/Finance/index.html index c85e547f4..39dc54177 100644 --- a/Application/Home/View/default/Finance/index.html +++ b/Application/Home/View/default/Finance/index.html @@ -35,7 +35,7 @@
- +
{$meta_title}
diff --git a/Application/Home/View/default/Finance/withdrawRecord.html b/Application/Home/View/default/Finance/withdrawRecord.html index 6ab8a8c20..7bd43e1ef 100644 --- a/Application/Home/View/default/Finance/withdrawRecord.html +++ b/Application/Home/View/default/Finance/withdrawRecord.html @@ -149,7 +149,12 @@ 提现订单 提现日期 + 结算开始日期 结算截止日期 + 操作人 + 操作人类型 + 最后操作人 + 最后操作人类型 收益金额 实际提现金额 提现状态 @@ -168,7 +173,12 @@ {$vo.widthdraw_number} {$vo.create_time} + {$vo.settlement_begin_time} {$vo.settlement_end_time} + {$vo.op_id} + {$vo.op_type} + {$vo.last_op_id} + {$vo.last_op_type} {$vo.sum_money} {$vo.sum_money} {$vo.status_name} @@ -178,11 +188,11 @@ 汇款证明 - 重新审核 + 结算单 - 撤销提现 + diff --git a/Data/update.sql b/Data/update.sql index 391c988f2..12a8ead50 100644 --- a/Data/update.sql +++ b/Data/update.sql @@ -915,4 +915,16 @@ ADD COLUMN `beta_url` varchar(150) NOT NULL DEFAULT '' COMMENT 'Beta链接'; -- 游戏支付方式渠道配置 ALTER TABLE `tab_game` -ADD COLUMN `pay_config` varchar(255) NOT NULL COMMENT '支付渠道 wx 微信 zfb 支付宝 quick 快捷 (gf 官方 sq 双乾'; \ No newline at end of file +ADD COLUMN `pay_config` varchar(255) NOT NULL COMMENT '支付渠道 wx 微信 zfb 支付宝 quick 快捷 (gf 官方 sq 双乾'; + +-- 2019-12-30 +-- 会长管理后台提现 cxj +ALTER TABLE `tab_withdraw` +ADD COLUMN `settlement_begin_time` int(10) NOT NULL DEFAULT 0 COMMENT '结算开始时间' AFTER `old_promote_account`; +ALTER TABLE `tab_withdraw` +ADD COLUMN `op_id` int(11) NOT NULL DEFAULT 0 COMMENT '操作id'; +ALTER TABLE `tab_withdraw` +ADD COLUMN `op_type` tinyint(3) NOT NULL DEFAULT 1 COMMENT '操作人:1-推广员 2-管理员 3-自动'; +ALTER TABLE `tab_withdraw` +ADD COLUMN `last_op_id` int(11) NOT NULL DEFAULT 0 COMMENT '最后操作人id', +ADD COLUMN `last_op_type` tinyint(3) NOT NULL DEFAULT 1 COMMENT '最后操作人:1-推广员 2-管理员 3-自动'; \ No newline at end of file