diff --git a/Application/Admin/Conf/config.php b/Application/Admin/Conf/config.php index 6c0807fa0..1ad717e8e 100644 --- a/Application/Admin/Conf/config.php +++ b/Application/Admin/Conf/config.php @@ -28,7 +28,7 @@ return array( 'DOWNLOAD_UPLOAD' => array( 'mimes' => '', //允许上传的文件MiMe类型 'maxSize' => 0, //上传的文件大小限制 (0-不做限制) - 'exts' => 'jpg,gif,png,jpeg,zip,rar,tar,gz,7z,doc,docx,txt,xml,mp4', //允许上传的文件后缀 + 'exts' => 'jpg,gif,png,jpeg,zip,rar,tar,gz,7z,doc,docx,txt,xml,mp4,xlsx', //允许上传的文件后缀 'autoSub' => true, //自动子目录保存文件 'subName' => array('date', 'Y-m-d'), //子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组 'rootPath' => './Uploads/Download/', //保存根路径 diff --git a/Application/Admin/Controller/AutoController.class.php b/Application/Admin/Controller/AutoController.class.php index c704aec94..e75d464ac 100644 --- a/Application/Admin/Controller/AutoController.class.php +++ b/Application/Admin/Controller/AutoController.class.php @@ -8,6 +8,7 @@ */ namespace Admin\Controller; use Admin\Model\SpendModel; +use Admin\Model\WithdrawModel; use Think\Think; use Org\RedisSDK\Redis; @@ -1034,4 +1035,94 @@ public function auto_rrdae(){ ]; return $ret; } + + //会长周结--初始化 + public function promoteWithdrawWeeklyInitial() + { + $this->promoteWithdraw(1, true); + } + + //会长月结--初始化 + public function promoteWithdrawPerMonthInitial() + { + $this->promoteWithdraw(2, true); + } + + //会长周结 + public function promoteWithdrawWeekly() + { + $this->promoteWithdraw(1); + } + + //会长月结 + public function promoteWithdrawPerMonth() + { + $this->promoteWithdraw(2); + } + + //会长周结月补点 + public function promoteWithdrawRecoup() + { + $this->promoteWithdraw(3); + } + + //会长提现 $settlement 1-周结算 2-月结算 + private function promoteWithdraw($settlement = 1, $initial = false) + { + $withdrawModel = new WithdrawModel(); + $map['id'] = 84; + $map['level'] = 1; + $map['ver_status'] = 1; + $map['settlement_type'] = ($settlement == 3) ? 1 : $settlement; + $promotes = M('promote', 'tab_')->field('id, account, chain, settlement_type')->where($map)->select(); + $success = 0; + $error_withdraw = 0; + $error_spend = 0; + $error_balance = 0; + $error_unset = 0; + $error_repeat = 0; + + if (!empty($promotes)) { + switch ($settlement) { + case 1: + $fun = 'promoteWithdrawWeeklyByPromote'; + break; + case 2: + $fun = 'promoteWithdrawPerMonthByPromote'; + break; + case 3: + $fun = 'promoteWithdrawRecoupByPromote'; + break; + } + foreach ($promotes as $promote) { + if ($fun == 'promoteWithdrawRecoupByPromote') { + $result = $withdrawModel->$fun($promote); + } else { + $result = $withdrawModel->$fun($promote, $initial); + } + switch ($result) { + case -4: + $error_repeat++; + break; + case -3: + $error_unset++; + break; + 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} error_unset:{$error_unset} error_repeat:{$error_repeat}"; + } } diff --git a/Application/Admin/Controller/PromoteController.class.php b/Application/Admin/Controller/PromoteController.class.php index bb9a5ff77..7b4476a2c 100644 --- a/Application/Admin/Controller/PromoteController.class.php +++ b/Application/Admin/Controller/PromoteController.class.php @@ -339,7 +339,10 @@ class PromoteController extends ThinkController $data['company_belong'] = I('company_belong');//工会归属 $data['company_relation'] = I('company_relation');//工会关系 } - + $settlementType = intval(I('settlement_type', 1)); + if (!empty(I('settlement_type')) && in_array($settlementType, [1, 2])) { + $data['settlement_type'] = $settlementType; + } $res = M("promote", "tab_")->where(array("id"=>$_POST['id']))->save($data); if ($res !== false) { if ($promote['level'] == 1) {//修改会长底下推广员的推广公司 diff --git a/Application/Admin/Controller/PromoteGameRatioController.class.php b/Application/Admin/Controller/PromoteGameRatioController.class.php index 7952b4fa2..0d08c400c 100644 --- a/Application/Admin/Controller/PromoteGameRatioController.class.php +++ b/Application/Admin/Controller/PromoteGameRatioController.class.php @@ -3,6 +3,7 @@ namespace Admin\Controller; use Think\Controller; +use Admin\Model\PromoteGameRatioModel; class PromoteGameRatioController extends ThinkController { @@ -20,6 +21,7 @@ class PromoteGameRatioController extends ThinkController public function lists() { $params = I('get.'); + $group = $params['group'] ?? 1; $promoteId = $params['promote_id'] ?? 0; $gameId = $params['game_id'] ?? 0; $status = $params['status'] ?? ''; @@ -38,12 +40,24 @@ class PromoteGameRatioController extends ThinkController } $field = 'create_time, update_time'; - $promoteGameRatios = D(self::MODEL_NAME)->field($field, true) - ->where($map) - ->page($page, $row) - ->order('update_time desc, id desc') - ->select(); - $count = D(self::MODEL_NAME)->where($map)->count(); + if ($group == 1) { + $query = D(self::MODEL_NAME)->field($field, true) + ->where($map) + ->order('update_time desc, id desc'); + $metaTitle = $csvTitle = '公会分成管理'; + } else { + $query = M(self::MODEL_NAME . '_log', 'tab_')->field($field, true) + ->where($map) + ->order('create_time desc, id desc'); + $metaTitle = $csvTitle = '公会分成申请记录'; + } + if (I('export', 0) != 1) { + $query->page($page, $row); + } + $promoteGameRatios = $query->select(); + if (I('export', 0) != 1) { + $count = D(self::MODEL_NAME)->where($map)->count(); + } $records = []; if ($promoteGameRatios) { @@ -62,34 +76,39 @@ class PromoteGameRatioController extends ThinkController $thisPromoteAccount = '未知'; $thisPromoteMobilePhone = '未知'; $thisPromoteCreateTime = '未知'; - $thisPromoteStatus = '未知'; + $thisPromoteStatus = '待审核'; $thisPromoteVerStatus = '未知'; $thisGameName = '未知'; - $thisGameRatio = '0.00'; - $thisLastRatio = $promoteGameRatio['last_ratio']; + $thisGameRatio = '0.00%'; + $thisLastRatio = $promoteGameRatio['last_ratio'] . '%'; + $thisLastTurnoverRatio = $promoteGameRatio['last_turnover_ratio'] ? json_decode($promoteGameRatio['last_turnover_ratio'], true) : []; + $thisLastRatio = $thisLastTurnoverRatio ? "{$thisLastRatio} - " . $thisLastTurnoverRatio[count($thisLastTurnoverRatio) - 1]['ratio'] . '%' : $thisLastRatio; + $thisRatio = $promoteGameRatio['ratio'] . '%'; + $thisTurnoverRatio = $promoteGameRatio['turnover_ratio'] ? json_decode($promoteGameRatio['turnover_ratio'], true) : []; + $thisRatio = $thisTurnoverRatio ? "{$thisRatio} - " . $thisTurnoverRatio[count($thisTurnoverRatio) - 1]['ratio'] . '%' : $thisRatio; $thisLastRatioStatus = $promoteGameRatio['last_ratio_status']; $thisStatusText = self::$statusList[$promoteGameRatio['status']]; $thisStatusText = ($promoteGameRatio['status'] == -1) ? '' . $thisStatusText . '' : $thisStatusText; $thisApplicant = get_admin_account($promoteGameRatio['applicant_id']); $thisReviewer = $promoteGameRatio['reviewer_id'] ? get_admin_account($promoteGameRatio['reviewer_id']) : '待确认'; - $thisBeninTime = date('Y/m/d', $promoteGameRatio['begin_time']); - $thisEndTime = $promoteGameRatio['end_time'] ? date('Y/m/d', $promoteGameRatio['end_time']) : '永久'; + $thisBeninTime = date('Y/m', $promoteGameRatio['begin_time']); + $thisEndTime = $promoteGameRatio['end_time'] ? date('Y/m', $promoteGameRatio['end_time']) : '永久'; $validDate = $thisBeninTime . ' - ' . $thisEndTime; if ($issetPromote) { $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']; $thisGameRatio = $games[$thisGameId]['ratio']; - $thisGameRatio = $thisGameRatio ?? '0.00'; + $thisGameRatio = ($thisGameRatio ?? '0.00') . '%'; } - $records[] = [ + $record = [ 'id' => $promoteGameRatio['id'], 'promote_id' => $promoteGameRatio['promote_id'], 'promote_account' => $thisPromoteAccount, @@ -98,27 +117,56 @@ class PromoteGameRatioController extends ThinkController 'promote_status_text' => $thisPromoteStatus, 'promote_ver_status_text' => $thisPromoteVerStatus, 'game_name' => $thisGameName, - 'last_ratio' => (($thisLastRatioStatus == 1) ? $thisLastRatio : $thisGameRatio) . '%', - 'ratio' => $promoteGameRatio['ratio'] . '%', + 'last_ratio' => (($thisLastRatioStatus == 1 || $group != 1) ? $thisLastRatio : $thisGameRatio), + 'ratio' => $thisRatio, 'valid_date' => $validDate, 'remark' => $promoteGameRatio['remark'], - 'status' => $promoteGameRatio['status'], 'status_text' => $thisStatusText, 'applicant' => $thisApplicant ?? '未知', 'reviewer' => $thisReviewer ?? '未知', ]; + if (I('export', 0) != 1) { + $record['status'] = $promoteGameRatio['status']; + } + $records[] = $record; } } - $reviewRule = $this->getReviewRule(); + if (I('export', 0) == 1) { + $field = [ + 'promote_id' => '会长Id', + 'promote_account' => '会长账号', + 'promote_mobile_phone' => '手机号码', + 'promote_create_time' => '注册时间', + 'promote_status_text' => '状态', + 'promote_ver_status_text' => '身份状态', + 'game_name' => '已申请游戏', + 'last_ratio' => '原分成比例', + 'ratio' => '当前分成比例', + 'valid_date' => '开始时间', + 'remark' => '备注', + 'status_text' => '分成比例审核', + 'applicant' => '申请人', + 'reviewer' => '确认人', + ]; + data2csv($records,$csvTitle, $field); + exit; + } + $reviewRule = $this->getReviewRule(); + $page = set_pagination($count, $row); + if($page) { + $this->assign('_page', $page); + } + $this->assign('group', $group); $this->assign('records', $records); $this->assign('count', $count); $this->assign('gameList', getAllGameList()); $this->assign('promoteList', getPromoteByLevel(1)); $this->assign('statusList', self::$statusList); $this->assign('reviewRule', $reviewRule); - $this->meta_title = '公会分成管理'; + $this->assign('is_admin', is_administrator()); + $this->meta_title = $metaTitle; $this->display(); } @@ -135,9 +183,52 @@ class PromoteGameRatioController extends ThinkController $this->error('结束时间不得小于开始时间'); } } + if (!isset($params['ratio']) || $params['ratio'] === '') { + $this->error('默认分成比例不能为空'); + } + $save['turnover_ratio'] = []; + if (!empty(array_filter($params['turnover'])) || !empty(array_filter($params['turnover_ratio']))) { + if (is_array($params['turnover']) && is_array($params['turnover_ratio'])) { + foreach ($params['turnover'] as $turnover) { + if (empty($turnover)) { + $this->error('月流水不能为空'); + } + } + foreach ($params['turnover_ratio'] as $turnoverRatio) { + if (empty($turnoverRatio)) { + $this->error('月流水分成比例不能为空'); + } + } + $turnoverCount = count($params['turnover']); + $sortTurnover = $params['turnover']; + sort($sortTurnover); + if ($params['turnover'] != $sortTurnover || $turnoverCount != count(array_unique($params['turnover']))) { + $this->error('月流水必须以正序的方式填写,且必须大于上一个月流水'); + } + $ratio = $params['ratio'] ?? 0; + if ($params['turnover_ratio'][0] <= $ratio) { + $this->error('月流水分成比例必须大于默认分成比例'); + } + $turnoverRatioCount = count($params['turnover_ratio']); + $sortTurnoverRatio = $params['turnover_ratio']; + sort($sortTurnoverRatio); + if ($params['turnover_ratio'] != $sortTurnoverRatio || $turnoverRatioCount != count(array_unique($params['turnover_ratio']))) { + $this->error('月流水分成比例必须以正序的方式填写,且必须大于上一个月流水分成比例'); + } + + foreach ($params['turnover'] as $key => $turnover) { + $save['turnover_ratio'][] = [ + 'turnover' => bcdiv($turnover, 1, 2), + 'ratio' => bcdiv($params['turnover_ratio'][$key], 1, 2), + ]; + } + $save['turnover_ratio'] = json_encode($save['turnover_ratio']); + } + } + $save['ratio'] = $params['ratio'] ?? 0; $save['begin_time'] = strtotime($params['begin_time']); - $save['end_time'] = $params['end_time'] ? strtotime($params['end_time']) : 0; + $save['end_time'] = $params['end_time'] ? (strtotime('+1 month', strtotime($params['end_time'])) - 1) : 0; $save['remark'] = $params['remark'] ?? ''; $save['status'] = 0; $save['update_time'] = $time; @@ -146,16 +237,21 @@ 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'] || $save['turnover_ratio'] != $promoteGameRatio['turnover_ratio']) { + $this->isWithdraw($promoteGameRatio['promote_id'], $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_turnover_ratio'] = $promoteGameRatio['turnover_ratio']; + $save['last_ratio'] = $promoteGameRatio['ratio']; + $save['last_ratio_status'] = 1; + } + $save['id'] = intval($params['id']); + $result = D(self::MODEL_NAME)->save($save); + $logResult = $result; + } else { + $result = true; + $logResult = false; } - $save['id'] = intval($params['id']); - $result = D(self::MODEL_NAME)->save($save); } else {//新增 if (empty($params['promote_id'])) { $this->error('请选择会长账号'); @@ -165,13 +261,14 @@ class PromoteGameRatioController extends ThinkController } $promoteId = intval($params['promote_id']); $gameId = intval($params['game_id']); - $this->isWithdraw($promoteId, $save['begin_time']);//是否存在开始时间后已提现数据 $promote = M('promote', 'tab_')->find($promoteId); if (empty($promote) || $promote['level'] != 1) { $this->error('参数异常'); } + $this->isWithdraw($promoteId, $save['begin_time']); + $map['promote_id'] = $promoteId; $map['game_id'] = $gameId; $promoteGameRatio = D(self::MODEL_NAME)->where($map)->find(); @@ -180,14 +277,27 @@ class PromoteGameRatioController extends ThinkController } $save['promote_id'] = $promoteId; $save['game_id'] = $gameId; + $save['last_turnover_ratio'] = ''; $save['applicant_id'] = is_login(); $save['create_time'] = $time; $result = D(self::MODEL_NAME)->add($save); + $logResult = $result; } if ($result === false) { $this->error('保存失败'); } else { + if ($logResult) { + if (empty($params['id'])) { + $promoteGameRatioId = $result; + } else { + $promoteGameRatioId = $params['id']; + } + + $model = new PromoteGameRatioModel(); + $model->addLog($promoteGameRatioId); + } + $this->success('保存成功', U('lists')); } } else { @@ -202,10 +312,11 @@ class PromoteGameRatioController extends ThinkController if (empty($promoteGameRatio)) { $this->error('数据异常'); } - $promoteGameRatio['begin_time'] = $promoteGameRatio['begin_time'] ? date('Y-m-d', $promoteGameRatio['begin_time']) : ''; - $promoteGameRatio['end_time'] = $promoteGameRatio['end_time'] ? date('Y-m-d', $promoteGameRatio['end_time']) : ''; + $promoteGameRatio['begin_time'] = $promoteGameRatio['begin_time'] ? date('Y-m', $promoteGameRatio['begin_time']) : ''; + $promoteGameRatio['end_time'] = $promoteGameRatio['end_time'] ? date('Y-m', $promoteGameRatio['end_time']) : ''; + $promoteGameRatio['turnover_ratio'] = $promoteGameRatio['turnover_ratio'] ? json_decode($promoteGameRatio['turnover_ratio'], true) : $promoteGameRatio['turnover_ratio']; if ($promoteGameRatio['last_ratio_status'] == 1) { - $lastRatio = $promoteGameRatio['last_ratio']; + $lastRatio = $promoteGameRatio['last_ratio'] . '%'; } else { $gameRatio = M('game', 'tab_')->where(array(['id' => $promoteGameRatio['game_id']]))->getField('ratio'); $lastRatio = ($gameRatio ?? '0.00') . '%'; @@ -234,11 +345,11 @@ class PromoteGameRatioController extends ThinkController $withdrawMap['promote_id'] = $promoteId; $withdrawMap['status'] = ['neq', -2]; - $withdrawMap['settlement_end_time'] = ['egt', $beginTime]; + $withdrawMap['settlement_begin_time'] = ['egt', $beginTime]; $withdraw = M('withdraw', 'tab_')->where($withdrawMap)->order('create_time desc')->find(); if (!empty($withdraw) && $withdraw['status'] != -2) { - $time = date('Y-m-d', $withdraw['create_time']); - $this->error("{$time}之前的订单已经申请提现, 无法变更分成比例,请重新选择开始时间"); + $time = date('Y-m', $beginTime); + $this->error("{$time}月已有订单申请提现, 无法变更分成比例,请重新选择开始时间"); } } @@ -266,8 +377,10 @@ class PromoteGameRatioController extends ThinkController } $result = D(self::MODEL_NAME)->where($map)->save($save); if ($result) { - if ($status == 1) { - foreach ($ids as $id) { + $model = new PromoteGameRatioModel(); + foreach ($ids as $id) { + $model->addLog($id); + if ($status == 1) { $promoteGameRatio = D(self::MODEL_NAME)->find($id); if (!empty($promoteGameRatio)) { if ($promoteGameRatio['begin_time'] <= strtotime(date('Y-m-d', time()))) { diff --git a/Application/Admin/Controller/QueryController.class.php b/Application/Admin/Controller/QueryController.class.php index 0b2d942e1..f2718ef75 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,511 @@ 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) + { + $settlementType = intval(I('settlement_type', 0)); + $settlementTypeList = WithdrawModel::$settlementTypeList; + $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()); + $this->assign('is_admin', is_administrator()); + $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); + unset($settlementTypeList[WithdrawModel::SETTLEMENT_TYPE_OTHER]); + $time = I('time', ''); + if (empty($promoteId) || empty($settlementType) || empty($time)) { + $this->assign('settlementTypeList', $settlementTypeList); + $this->display(); + } else { + $promoteIds = M('promote', 'tab_')->where(['chain' => ['like', "/{$promoteId}/%"]])->getField('id', true); + $promoteIds[] = $promoteId; + + if ($settlementType == 1) { + $time = explode(' 至 ', $time); + if (count($time) != 2) { + $this->display();die; + } + + $beginTime = strtotime($time[0]); + $endTime = strtotime($time[1]) + 3600 * 24 - 1; + } else { + $beginTime = strtotime($time); + $endTime = strtotime('+1 month', $beginTime) - 1; } - if ($start == '' || $end == '') { - $this->error('请选择结算周期!', '', 1); + + $promote = M('promote', 'tab_')->find($promoteId); + if (empty($promote) || $promote['level'] != 1 || empty($promote['settlement_type'])) { + $this->error('网络异常'); } - if ($_REQUEST['promote_account'] == '') { - $this->error('请选择渠道!', '', 1); + if ($promote['settlement_type'] == 1) { + unset($settlementTypeList[WithdrawModel::SETTLEMENT_TYPE_MONTH]); + } else { + unset($settlementTypeList[WithdrawModel::SETTLEMENT_TYPE_WEEK]); + unset($settlementTypeList[WithdrawModel::SETTLEMENT_TYPE_RECOUP]); + } + if ($settlementType == 3) { + $withdrawMap['promote_id'] = $promoteId; + $withdrawMap['status'] = ['neq', -2]; + $withdrawMap['settlement_begin_time'] = $beginTime; + $withdrawMap['settlement_end_time'] = $endTime; + $withdraw = D('withdraw')->where($withdrawMap)->find(); + if (!empty($withdraw)) { + $this->assign('settlementTypeList', $settlementTypeList); + $this->display();die; + } + } else { + $spendMap['tab_spend.selle_status'] = 0; + } + + $sortBy = I('sort_by', ''); + $sortColumn = I('sort_column', ''); + $order = 'day'; + $orderType = 'desc'; + + if (in_array($sortColumn, ['user_num', 'sum_amount'])) { + $order = $sortColumn; + } + if ($sortBy == 1) { + $orderType = 'desc'; + } elseif ($sortBy == 2) { + $orderType = 'asc'; } - } - $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'), ''); + $spendMap['tab_spend.pay_status'] = 1; + $spendMap['tab_spend.pay_time'] = ['between', [$beginTime, $endTime]]; + $spendMap['tab_spend.promote_id'] = ['in', $promoteIds]; + $spendField = "tab_spend.game_id, 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, FROM_UNIXTIME(tab_spend.`pay_time`, '%Y-%m-%d') as day"; + $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, day') + ->order("{$order} {$orderType}"); + if(I('export', 0) != 1){ + $query->page($page, $row); } - $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']); + $records = M()->table($query->buildSql()) + ->alias('record') + ->select(); + if(I('export', 0) != 1){ + $countQuery = M('spend', 'tab_')->field($spendField) + ->where($spendMap) + ->group('tab_spend.selle_ratio, tab_spend.game_id, day') + ->buildSql(); + $count = M()->table($countQuery) + ->alias('tab_spend') + ->count(); + $page = set_pagination($count, $row); } - 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); + + if (!empty($records)) { + foreach ($records as &$record) { + $record['promote_account'] = $promote['account'] ?? '未知'; + $record['settlement_amount'] = bcdiv($record['settlement_amount'], 100, 2); + } + } + + if ($settlementType != 3) { + $totalField = 'sum(if(tab_spend.selle_ratio > 0, tab_spend.pay_amount * tab_spend.selle_ratio, 0)) as settlement_amount'; + $zTotal = null_to_0(M('spend', 'tab_')->field($totalField)->where($spendMap)->find()['settlement_amount']);//累计 + $zTotal = bcdiv($zTotal, 100 ,2); } else { - $this->error('未选择渠道!', '', 1); + $spendMap['game_id'] = 157; + $totalField = 'sum(tab_spend.pay_amount) as sum_amount'; + $zTotal = null_to_0(M('spend', 'tab_')->field($totalField)->where($spendMap)->find()['sum_amount']);//累计 } - $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'); + if(I('export', 0) == 1) { + $data = []; + foreach ($records as $value) { + $data[] = [ + 'day' => $value['day'], + 'promote_account' => $value['promote_account'], + 'game_name' => $value['game_name'], + 'sum_amount' => $value['sum_amount'], + 'user_num' => $value['user_num'], + 'type' => 'CPS', + 'selle_ratio' => $value['selle_ratio'] . '%', + 'settlement_amount' => $value['settlement_amount'], + ]; + } + $field = [ + 'day' => '日期', + 'promote_account' => '会长账号', + 'game_name' => '游戏名称', + 'sum_amount' => '总充值', + 'user_num' => '总注册', + 'type' => '结算模式', + 'selle_ratio' => '分成比例', + 'settlement_amount' => '结算金额', + ]; + data2csv($data,"推广结算", $field); + exit; + } - $user->settlement($model, $p, $map); - } else { + if($page) { + $this->assign('_page', $page); + } + $this->assign('settlementTypeList', $settlementTypeList); + $this->assign('records', $records); + $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['status'])) { + $map['status'] = $status; + } + if ($opType) { + $map['op_type'] = $opType; + } + if ($settlementType) { + $map['settlement_type'] = $settlementType; + } + + $query = 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, settlement_type') + ->where($map) + ->order('create_time desc'); + if(I('export', 0) != 1){ + $query->page($page, $row); + } + $records = $query->select(); + if(I('export', 0) != 1){ + $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'] . ''; + } + $record['op_id_text'] = $this->getOpTypeText($record['op_type'], $record['op_id']); + $record['last_op_id_text'] = $this->getOpTypeText($record['last_op_type'], $record['last_op_id']); + $record['op_type_text'] = getPromoteWithdrawOpType($record['op_type']); + $record['last_op_type_text'] = getPromoteWithdrawOpType($record['last_op_type']); + $record['settlement_type_text'] = getPromoteWithdrawSettlementType($record['settlement_type']); } } - if (isset($_REQUEST['promote_account'])) { - if ($_REQUEST['promote_account'] == '全部') { - unset($_REQUEST['promote_account']); - } else { - $map['promote_account'] = $_REQUEST['promote_account']; + + if(I('export', 0) == 1) { + $data = []; + foreach ($records as $value) { + $data[] = [ + 'promote_account' => $value['promote_account'], + 'widthdraw_number' => $value['widthdraw_number'], + 'sum_money' => $value['sum_money'], + 'op_id_text' => $value['op_id_text'], + 'op_type_text' => $value['op_type_text'], + 'last_op_id_text' => $value['last_op_id_text'], + 'last_op_type_text' => $value['last_op_type_text'], + 'settlement_type_text' => $value['settlement_type_text'], + 'settlement_begin_time' => $value['settlement_begin_time'], + 'settlement_end_time' => $value['settlement_end_time'], + 'create_time' => $value['create_time'], + 'status_text' => promoteWithdrawStatus($value['status']), + 'respond' => $value['respond'], + ]; } + + $field = [ + 'promote_account' => '推广员账号', + 'widthdraw_number' => '结算单号', + 'sum_money' => '结算金额', + 'op_id_text' => '操作人', + 'op_type_text' => '操作人类型', + 'last_op_id_text' => '最后操作人', + 'last_op_type_text' => '最后操作人类型', + 'settlement_type_text' => '提现模式', + 'settlement_begin_time' => '结算开始时间', + 'settlement_end_time' => '结算截止时间', + 'create_time' => '提现时间', + 'status_text' => '提现状态', + 'respond' => '说明', + ]; + data2csv($data,"推广结算", $field); + exit; } - if (!empty($_REQUEST['settlement_number'])) { - $map['settlement_number'] = $_REQUEST['settlement_number']; + + $page = set_pagination($count, $row); + if($page) { + $this->assign('_page', $page); } + $this->assign('settlementTypeList', $settlementTypeList); + $this->assign('records', $records); + $this->display(); + } + } - $map['developers'] = 0; + private function getOpTypeText($type, $id) + { + switch ($type) { + case 1: + return get_promote_name($id); + break; + case 2: + return getAdminNickname($id); + break; + default: + return '自动'; + break; + } + } - $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; + public function settlementWithdraw() + { + $promoteId = intval(I('promote_id', 0)); + $settlementType = intval(I('settlement_type', 0)); + $time = I('time', ''); + if (empty($promoteId)) { + $data['status'] = 0; + $data['msg'] = '请选择会长账号'; + $this->ajaxReturn($data); + } + if (empty($settlementType)) { + $data['status'] = 0; + $data['msg'] = '请选择提现模式'; + $this->ajaxReturn($data); + } + if (empty($time)) { + $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'); + $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); + } + if ($promote['settlement_type'] == 1) { + if (!in_array($settlementType, [1, 3])) { + $data['status'] = 0; + $data['msg'] = '参数异常'; + $this->ajaxReturn($data); + } + } else { + if ($settlementType != 2) { + $data['status'] = 0; + $data['msg'] = '参数异常'; + $this->ajaxReturn($data); + } + } - $user->money_list($model, $p, $map); + if ($settlementType == 1) { + $time = explode(' 至 ', $time); + if (count($time) != 2) { + $data['status'] = 0; + $data['msg'] = '参数异常'; + $this->ajaxReturn($data); + } + $beginTime = strtotime($time[0]); + $endTime = strtotime($time[1]) + 3600 * 24 - 1; + } else { + $beginTime = strtotime($time); + $endTime = strtotime('+1 month', $beginTime) - 1; } + $withdrawModel = new WithdrawModel(); + $data['begin_time'] = $beginTime; + $data['end_time'] = $endTime; + $data['op_id'] = is_login(); + $data['op_type'] = 2; + switch ($settlementType) { + case 1: + $result = $withdrawModel->promoteWithdrawWeeklyByPromote($promote, false, $data); + break; + case 2: + $result = $withdrawModel->promoteWithdrawPerMonthByPromote($promote, false, $data); + break; + case 3: + $result = $withdrawModel->promoteWithdrawRecoupByPromote($promote, $data); + break; + } + + $data = []; + $data['status'] = 0; + switch ($result) { + case -4: + case -3: + $data['msg'] = '无可补点订单'; + break; + case -2: + if ($settlementType == 3) { + $data['msg'] = '无可补点订单'; + } else { + $data['msg'] = '累计结算低于100元,无法提现!'; + } + break; + case -1: + case 0: + $data['msg'] = '操作失败'; + break; + case 1: + $data['status'] = 1; + $data['msg'] = '操作成功'; + break; + } + + $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); + } + + $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); + } + + 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); + } + + $time = time(); + $data['status'] = 1; + $data['msg'] = '撤销成功'; + $withdrawSave['id'] = $id; + $withdrawSave['status'] = -2; + $withdrawSave['last_up_update_time'] = $time; + $withdrawSave['last_op_id'] = is_login(); + $withdrawSave['last_op_type'] = 2; + if ($data['settlement_type'] == 3) { + $withdrawRes = M('withdraw', 'tab_')->save($withdrawSave); + if ($withdrawRes === false) { + $data['status'] = 0; + $data['msg'] = '撤销失败'; + $this->ajaxReturn($data); + } + } else { + $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); + $withdrawSave['spend_ids'] = $spendIds; + + 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();//事物提交 + } + } + + $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) @@ -655,6 +1004,8 @@ class QueryController extends ThinkController public function withdraw() { + $page = I('p', 1); + $map['_string'] = '1=1'; $adminid = C('USER_ADMINISTRATOR');//获取超管id $adminmobile = M('UcenterMember')->field('mobile')->find($adminid); $this->assign('adminmobile', $adminmobile['mobile']); @@ -664,6 +1015,12 @@ 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['settlement_type'])) { + $map['settlement_type'] = $_REQUEST['settlement_type']; + } if (isset($_REQUEST['promote_account'])) { if ($_REQUEST['promote_account'] == '全部') { unset($_REQUEST['promote_account']); @@ -672,7 +1029,6 @@ class QueryController extends ThinkController } } else { $map['promote_id'] = array('gt', 0); - } $order = 'create_time desc'; @@ -686,6 +1042,58 @@ class QueryController extends ThinkController } } } + if (I('export', 0) == 1) { + $records = D('withdraw')->field('widthdraw_number, sum_money, promote_account, op_id, op_type, last_op_id, last_op_type, settlement_type, settlement_begin_time, settlement_end_time, create_time, status, respond, audit_time') + ->where($map) + ->order($order) + ->select(); + if (!empty($records)) { + $data = []; + foreach ($records as $record) { + $record['op_id_text'] = $this->getOpTypeText($record['op_type'], $record['op_id']); + $record['last_op_id_text'] = $this->getOpTypeText($record['last_op_type'], $record['last_op_id']); + $record['op_type_text'] = getPromoteWithdrawOpType($record['op_type']); + $record['last_op_type_text'] = getPromoteWithdrawOpType($record['last_op_type']); + $record['settlement_type_text'] = getPromoteWithdrawSettlementType($record['settlement_type']); + $data[] = [ + 'widthdraw_number' => $record['widthdraw_number'], + 'sum_money' => $record['sum_money'], + 'promote_account' => $record['promote_account'], + 'op_id_text' => $this->getOpTypeText($record['op_type'], $record['op_id']), + 'last_op_id_text' => $this->getOpTypeText($record['last_op_type'], $record['last_op_id']), + 'op_type_text' => getPromoteWithdrawOpType($record['op_type']), + 'last_op_type_text' => getPromoteWithdrawOpType($record['last_op_type']), + 'settlement_type_text' => getPromoteWithdrawSettlementType($record['settlement_type']), + 'settlement_begin_time' => $record['settlement_begin_time'] ? date('Y-m-d H:i:s', $record['settlement_begin_time']) : '--', + 'settlement_end_time' => date('Y-m-d H:i:s', $record['settlement_end_time']), + 'create_time' => date('Y-m-d H:i:s', $record['create_time']), + 'status_text' => promoteWithdrawStatus($record['status']), + 'respond' => $record['respond'], + 'audit_time' => $record['audit_time'] ? date('Y-m-d H:i:s', $record['audit_time']) : '--', + ]; + } + + $field = [ + 'widthdraw_number' => '结算单号', + 'sum_money' => '结算金额', + 'promote_account' => '推广员账号', + 'op_id_text' => '操作人', + 'op_type_text' => '操作人类型', + 'last_op_id_text' => '最后操作人', + 'last_op_type_text' => '最后操作人类型', + 'settlement_type_text' => '提现模式', + 'settlement_begin_time' => '结算开始时间', + 'settlement_end_time' => '结算截止时间', + 'create_time' => '申请时间', + 'status_text' => '提现状态', + 'respond' => '说明', + 'audit_time' => '审核时间', + ]; + data2csv($data,"推广结算", $field); + exit; + } + } + $model = array( 'm_name' => 'withdraw', 'order' => $order, @@ -710,8 +1118,43 @@ class QueryController extends ThinkController //为数据权限添加 setPowerPromoteIds($map); $this->assign('is_admin', is_administrator()); - $user->money_list($model, $p, $map); + $user->money_list($model, $page, $map); + } + public function getWithdraw() + { + $promoteId = intval(I('post.promote_id', 0)); + $beginTime = I('post.begin_time', ''); + $endTime = I('post.end_time', ''); + $msg = ''; + + if (empty($promoteId) || empty($beginTime) || empty($endTime)) { + $this->ajaxReturn(['msg' => $msg]); + } + $beginTime = strtotime($beginTime); + $endTime = strtotime($endTime) + 3600 * 24 - 1; + + $map['promote_id'] = $promoteId; + $map['settlement_end_time'] = ['between', [$beginTime, $endTime]]; + $map['status'] = ['neq', -2]; + + $withdraws = D('withdraw')->field('id, settlement_begin_time, settlement_end_time') + ->where($map) + ->select(); + if (!empty($withdraws)) { + foreach ($withdraws as $withdraw) { + $settlementEndTime = date('Y-m-d', $withdraw['settlement_end_time'] + 1); + if ($withdraw['settlement_begin_time'] > 0) { + $settlementBeginTime = date('Y-m-d', $withdraw['settlement_begin_time']); + $msg .= "{$settlementBeginTime}至{$settlementEndTime}之间的订单已经提现;"; + } else { + $msg .= "{$settlementEndTime}之前的订单已经提现;"; + } + $msg .= ''; + } + } + + $this->ajaxReturn(['msg' => $msg]); } public function set_withdraw_status() @@ -901,36 +1344,28 @@ class QueryController extends ThinkController public function withdrawDetails($id) { - $page = intval(I('p', 1)); - $row = intval(I('row', 10)); - $id = intval($id); - $map['withdraw_id'] = $id; - $model = M('Spend', 'tab_'); - $data = $model - ->field('pay_order_number,game_name,user_account,promote_account,pay_amount,pay_way,if(selle_ratio >= 0,selle_ratio,0) as selle_ratio,pay_time,selle_status,pay_status,withdraw_id') - ->where($map) - ->order('id desc') - ->page($page, $row) - ->select(); - $count = $model->where($map)->count('id'); - - //提现状态 - $withdrawStatus = M('withdraw', 'tab_') - ->where(array('id' => $id)) - ->getField('status'); - $withdrawStatus = \Home\Controller\FinanceController::$withdrawStatus[$withdrawStatus]; - - foreach ($data as &$list) { - $list['income'] = bcmul($list['pay_amount'], bcdiv($list['selle_ratio'], 100, 2), 2); - $list['pay_time'] = date('Y-m-d H:i:s', $list['pay_time']); + $withdrawId = intval($id); + $withdraw = D('withdraw')->find($withdrawId); + $records = []; + if (!empty($withdraw) && !empty($withdraw['game_ratio'])) { + $gameRatios = json_decode($withdraw['game_ratio'], true); + foreach ($gameRatios as $gameId => $gameRatio) { + $gameName = D('game')->where(array('id' => $gameId))->getField('game_name'); + foreach ($gameRatio as $list) { + $records[] = [ + 'settlement_time' => "{$list['begin_time']} - {$list['end_time']}", + 'game_name' => $gameName ?? '未知', + 'sum_amount' => $list['sum_amount'], + 'default_ratio' => $list['default_ratio'] ? $list['default_ratio'] . '%' : '未知', + 'ratio' => $list['selle_ratio'] . '%', + 'settlement_amount' => bcdiv(bcmul($list['sum_amount'], $list['selle_ratio'], 2), 100, 2), + ]; + } + } } - $page = set_pagination($count, $row); - if ($page) { - $this->assign('_page', $page); - } - $this->assign('listData', $data); - $this->assign('withdrawStatus', $withdrawStatus); + $this->assign('settlementType', $withdraw['settlement_type']); + $this->assign('records', $records); $this->display(); } @@ -1001,7 +1436,6 @@ class QueryController extends ThinkController } } - public function marketList($p=1) { $page = intval($p); @@ -1175,4 +1609,53 @@ class QueryController extends ThinkController } + public function getPromoteSettlementType() + { + $promoteId = intval(I('post.promote_id', 0)); + $settlementType = []; + if ($promoteId > 0) { + $promote = D('promote')->field('level, settlement_type')->where(array('id' => $promoteId))->find(); + if (empty($promote) || $promote['level'] != 1 || empty($promote['settlement_type'])) { + $settlementType = []; + } else { + $settlementType = WithdrawModel::$settlementTypeList; + unset($settlementType[WithdrawModel::SETTLEMENT_TYPE_OTHER]); + if ($promote['settlement_type'] == 1) { + unset($settlementType[WithdrawModel::SETTLEMENT_TYPE_MONTH]); + } else { + unset($settlementType[WithdrawModel::SETTLEMENT_TYPE_WEEK]); + unset($settlementType[WithdrawModel::SETTLEMENT_TYPE_RECOUP]); + } + } + } + + $this->ajaxReturn(['settlement_type' => $settlementType]); + } + + public function getAmountBySettlementType() + { + $withdrawModel = new WithdrawModel(); + $promoteId = intval(I('promote_id', 0)); + $settlementType = intval(I('settlement_type', 0)); + $time = I('time', ''); + + if (empty($promoteId) || !in_array($settlementType, [2, 3])) { + $this->ajaxReturn(['balance' => 0]); + } + + $promote = M('promote', 'tab_')->find($promoteId); + if (empty($promote) || $promote['level'] != 1 || $promote['ver_status'] != 1 || empty($time)) { + $this->ajaxReturn(['balance' => 0]); + } + + $data['begin_time'] = strtotime($time); + $data['end_time'] = strtotime('+1 month', $data['begin_time']) - 1; + + if ($settlementType == 2) { + $balance = $withdrawModel->getMonthAmount($promote, $data); + } else { + $balance = $withdrawModel->getRecoupAmount($promote, $data); + } + $this->ajaxReturn(['balance' => $balance]); + } } diff --git a/Application/Admin/Model/PromoteGameRatioModel.class.php b/Application/Admin/Model/PromoteGameRatioModel.class.php index b6715ba2d..ca31346c2 100644 --- a/Application/Admin/Model/PromoteGameRatioModel.class.php +++ b/Application/Admin/Model/PromoteGameRatioModel.class.php @@ -6,6 +6,23 @@ use Think\Model; class PromoteGameRatioModel extends Model { + protected $db = 'promote_game_ratio'; + // 数据表前缀 protected $tablePrefix = 'tab_'; + + public function addLog($id) + { + $logSave = $this->find($id); + if (!empty($logSave)) { + if (empty($logSave['last_ratio_status'])) { + $logSave['last_ratio'] = D('game')->where(array('id' => $logSave['game_id']))->getField('ratio'); + $logSave['last_ratio'] = $logSave['last_ratio'] ?? 0; + } + $logSave['create_time'] = $logSave['update_time']; + unset($logSave['id']); + unset($logSave['update_time']); + M('promote_game_ratio_log', 'tab_')->add($logSave); + } + } } \ No newline at end of file diff --git a/Application/Admin/Model/WithdrawModel.class.php b/Application/Admin/Model/WithdrawModel.class.php index 324bd151c..ea73951c1 100644 --- a/Application/Admin/Model/WithdrawModel.class.php +++ b/Application/Admin/Model/WithdrawModel.class.php @@ -15,6 +15,17 @@ use Think\Model; */ class WithdrawModel extends Model{ + //操作人类型 + const OP_TYPE_PROMOTE = 1; + const OP_TYPE_ADMIN = 2; + const OP_TYPE_AUTO = 3; + + //结算类型 + const SETTLEMENT_TYPE_WEEK = 1; + const SETTLEMENT_TYPE_MONTH = 2; + const SETTLEMENT_TYPE_RECOUP = 3; + const SETTLEMENT_TYPE_OTHER = 9; + /** * 构造函数 * @param string $name 模型名称 @@ -28,8 +39,18 @@ class WithdrawModel extends Model{ parent::__construct($name, $tablePrefix, $connection); } - - + public static $opTypeList = [ + self::OP_TYPE_PROMOTE => '推广员', + self::OP_TYPE_ADMIN => '管理员', + self::OP_TYPE_AUTO => '自动', + ]; + + public static $settlementTypeList = [ + self::SETTLEMENT_TYPE_WEEK => '周结', + self::SETTLEMENT_TYPE_MONTH => '月结', + self::SETTLEMENT_TYPE_RECOUP => '补点', + self::SETTLEMENT_TYPE_OTHER => '其他', + ]; /* * 开发者提现未处理列表 @@ -102,4 +123,495 @@ class WithdrawModel extends Model{ } + //生成提现单号 $type 1-周结 2-月结 3-补点 + public function produceWithdrawNumber($type = 1) + { + $prefix = 'WD_'; + $number = ''; + switch ($type) { + case 1: + $prefix = "{$prefix}W_"; + break; + case 2: + $prefix = "{$prefix}M_"; + break; + case 3: + $prefix = "{$prefix}R_"; + break; + } + 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; + } + + //周结 + public function promoteWithdrawWeeklyByPromote($promote, $initial = false, $data = []) + { + $promoteIds = $this->getPromoteChildren($promote); + $settlementType = $promote['settlement_type']; + $settlementBeginTime = $data['begin_time'] ?? strtotime(date('Y-m-d', strtotime('-7 day', time()))); + $settlementEndTime = $data['end_time'] ?? strtotime(date('Y-m-d')) - 1; + + if ($initial) { + $settlementType = 9; + $settlementBeginTime = 0; + } + + $spendMap['pay_status'] = 1; + $spendMap['selle_status'] = 0; + $spendMap['promote_id'] = ['in', $promoteIds]; + $spendMap['pay_time'] = ['between', [$settlementBeginTime, $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 = $balance ?? 0; + $balance = bcdiv($balance, 100, 2); + if ($balance < 100) { + return -2;//余额不足 + } + + if ($initial === false) { + $beginTime = date('Y-m-d', $settlementBeginTime); + } else { + $beginTime = '初始'; + } + $endTime = date('Y-m-d', $settlementEndTime); + $gameRatios = $this->getGameRatio($spendMap, $beginTime, $endTime); + $gameRatios = $gameRatios ? json_encode($gameRatios) : ''; + + $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(1); + $add['settlement_begin_time'] = $settlementBeginTime; + $add['settlement_end_time'] = $settlementEndTime; + $add['spend_ids'] = ''; + $add['op_id'] = $data['op_id'] ?? 0; + $add['op_type'] = $data['op_type'] ?? 3; + $add['last_op_id'] = $add['op_id']; + $add['last_op_type'] = $add['op_type']; + $add['settlement_type'] = $settlementType; + $add['game_ratio'] = $gameRatios; + + 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; + } + + //月结 + public function promoteWithdrawPerMonthByPromote($promote, $initial = false, $data = []) + { + $promoteIds = $this->getPromoteChildren($promote); + $settlementType = $promote['settlement_type']; + $settlementBeginTime = $data['begin_time'] ?? strtotime(date('Y-m', strtotime('-1 month', time()))); + $settlementEndTime = $data['end_time'] ?? strtotime(date('Y-m')) - 1; + + if ($initial) { + $settlementType = 9; + $settlementBeginTime = 0; + $beginTime = '初始'; + } else { + $beginTime = date('Y-m-d', $settlementBeginTime); + } + + $endTime = date('Y-m-d', $settlementEndTime); + $spendMap['pay_status'] = 1; + $spendMap['selle_status'] = 0; + $spendMap['promote_id'] = ['in', $promoteIds]; + $spendMap['pay_time'] = ['between', [$settlementBeginTime, $settlementEndTime]]; + $spendWhere = $spendMap; + $spendModel = M('spend', 'tab_'); + + $promoteGameRatioMap['status'] = 1; + $promoteGameRatioMap['promote_id'] = $promote['id']; + $promoteGameRatios = D('promote_game_ratio')->field('game_id, ratio, turnover_ratio, begin_time, end_time') + ->where($promoteGameRatioMap) + ->order('update_time desc') + ->select(); + + $gameRatios = $this->getGameRatio($spendMap, $beginTime, $endTime); + + if (empty($promoteGameRatios) || $initial) { + $balance = $spendModel->field("sum(if(selle_ratio > 0, pay_amount * selle_ratio, 0)) as balance") + ->where($spendMap) + ->find()['balance']; + $balance = $balance ?? 0; + } else { + $balance = 0; + $notInGameIds = [-1]; + foreach ($promoteGameRatios as $promoteGameRatio) { + $spendWhere['game_id'] = $promoteGameRatio['game_id']; + if (!empty($promoteGameRatio['turnover_ratio']) && $promoteGameRatio['begin_time'] <= $settlementBeginTime && (empty($promoteGameRatio['end_time']) || $promoteGameRatio['end_time'] >= $settlementEndTime)) { + $notInGameIds[] = $promoteGameRatio['game_id']; + $ratio = $promoteGameRatio['ratio']; + $promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true); + $turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']); + $sumAmount = $spendModel->field("sum(pay_amount) as sum_amount") + ->where($spendWhere) + ->find()['sum_amount']; + $sumAmount = $sumAmount ?? 0; + foreach ($turnoverRatios as $turnoverRatio) { + if ($sumAmount >= $turnoverRatio['turnover']) { + $ratio = $turnoverRatio['ratio']; + break; + } + } + + $thisBalance = $spendModel->field("sum(pay_amount * {$ratio}) as balance") + ->where($spendWhere) + ->find()['balance']; + $thisBalance = $thisBalance ?? 0; + $balance = bcadd($balance, $thisBalance, 2); + + $gameRatios[$promoteGameRatio['game_id']] = []; + $gameRatios[$promoteGameRatio['game_id']][] = [ + 'selle_ratio' => $ratio, + 'default_ratio' => $promoteGameRatio['ratio'], + 'sum_amount' => $sumAmount, + 'begin_time' => $beginTime, + 'end_time' => $endTime, + ]; + } + } + + $spendWhere['game_id'] = ['not in', $notInGameIds]; + $otherBalance = $spendModel->field("sum(if(selle_ratio > 0, pay_amount * selle_ratio, 0)) as balance") + ->where($spendWhere) + ->find()['balance']; + $otherBalance = $otherBalance ?? 0; + $balance = bcadd($balance, $otherBalance, 2); + } + + $balance = bcdiv($balance, 100, 2); + if ($balance < 100) { + return -2;//余额不足 + } + + $gameRatios = $gameRatios ? json_encode($gameRatios) : ''; + + $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(2); + $add['settlement_begin_time'] = $settlementBeginTime; + $add['settlement_end_time'] = $settlementEndTime; + $add['spend_ids'] = ''; + $add['op_id'] = $data['op_id'] ?? 0; + $add['op_type'] = $data['op_type'] ?? 3; + $add['last_op_id'] = $add['op_id']; + $add['last_op_type'] = $add['op_type']; + $add['settlement_type'] = $settlementType; + $add['game_ratio'] = $gameRatios; + + 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; + } + + //补点 + public function promoteWithdrawRecoupByPromote($promote, $data = []) + { + $promoteGameRatioMap['status'] = 1; + $promoteGameRatioMap['promote_id'] = $promote['id']; + $promoteGameRatios = D('promote_game_ratio')->field('game_id, ratio, turnover_ratio, begin_time, end_time') + ->where($promoteGameRatioMap) + ->order('update_time desc') + ->select(); + if (empty($promoteGameRatios)) { + return -3; + } + + $promoteIds = $this->getPromoteChildren($promote); + $settlementType = 3; + $settlementBeginTime = $data['begin_time'] ?? strtotime(date('Y-m', strtotime('-1 month', time()))); + $settlementEndTime = $data['end_time'] ?? strtotime(date('Y-m')) - 1; + + $withdrawMap['promote_id'] = $promote['id']; + $withdrawMap['status'] = ['neq', -2]; + $withdrawMap['settlement_begin_time'] = $settlementBeginTime; + $withdrawMap['settlement_end_time'] = $settlementEndTime; + $withdraw = D('withdraw')->where($withdrawMap)->find(); + if (!empty($withdraw)) { + return -4; + } + + $spendMap['pay_status'] = 1; + $spendMap['promote_id'] = ['in', $promoteIds]; + $spendMap['pay_time'] = ['between', [$settlementBeginTime, $settlementEndTime]]; + $spendModel = M('spend', 'tab_'); + + $balance = 0; + $gameRatios = []; + foreach ($promoteGameRatios as $promoteGameRatio) { + if (!empty($promoteGameRatio['turnover_ratio']) && $promoteGameRatio['begin_time'] <= $settlementBeginTime && (empty($promoteGameRatio['end_time']) || $promoteGameRatio['end_time'] >= $settlementEndTime)) { + $spendMap['game_id'] = $promoteGameRatio['game_id']; + $promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true); + $turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']); + $sumAmount = $spendModel->field("sum(pay_amount) as sum_amount") + ->where($spendMap) + ->find()['sum_amount']; + $sumAmount = $sumAmount ?? 0; + $ratio = 0; + foreach ($turnoverRatios as $turnoverRatio) { + if ($sumAmount >= $turnoverRatio['turnover']) { + $ratio = $turnoverRatio['ratio']; + break; + } + } + + if ($ratio > 0) { + $ratio = bcsub($ratio, $promoteGameRatio['ratio'], 2); + $thisBalance = bcdiv(bcmul($sumAmount, $ratio, 2), 100, 2); + $balance = bcadd($balance, $thisBalance, 2); + + $gameRatios[$promoteGameRatio['game_id']][] = [ + 'selle_ratio' => $ratio, + 'default_ratio' => $promoteGameRatio['ratio'], + 'sum_amount' => $sumAmount, + 'begin_time' => date('Y-m-d', $settlementBeginTime), + 'end_time' => date('Y-m-d', $settlementEndTime), + ]; + } + } + } + + if ($balance == 0) { + return -2;//无余额 + } + + $gameRatios = $gameRatios ? json_encode($gameRatios) : ''; + + $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(3); + $add['settlement_begin_time'] = $settlementBeginTime; + $add['settlement_end_time'] = $settlementEndTime; + $add['spend_ids'] = ''; + $add['op_id'] = $data['op_id'] ?? 0; + $add['op_type'] = $data['op_type'] ?? 3; + $add['last_op_id'] = $add['op_id']; + $add['last_op_type'] = $add['op_type']; + $add['settlement_type'] = $settlementType; + $add['game_ratio'] = $gameRatios; + + $withdrawId = D('withdraw')->add($add); + if (!$withdrawId) { + return 0;//补点失败 + } + + return 1; + } + + public function getRecoupAmount($promote, $data = []) + { + $promoteGameRatioMap['status'] = 1; + $promoteGameRatioMap['promote_id'] = $promote['id']; + $promoteGameRatios = D('promote_game_ratio')->field('game_id, ratio, turnover_ratio, begin_time, end_time') + ->where($promoteGameRatioMap) + ->order('update_time desc') + ->select(); + if (empty($promoteGameRatios)) { + return 0; + } + + $promoteIds = $this->getPromoteChildren($promote); + $settlementBeginTime = $data['begin_time'] ?? strtotime(date('Y-m', strtotime('-1 month', time()))); + $settlementEndTime = $data['end_time'] ?? strtotime(date('Y-m')) - 1; + + $spendMap['pay_status'] = 1; + $spendMap['promote_id'] = ['in', $promoteIds]; + $spendMap['pay_time'] = ['between', [$settlementBeginTime, $settlementEndTime]]; + $spendModel = M('spend', 'tab_'); + + $balance = 0; + foreach ($promoteGameRatios as $promoteGameRatio) { + if (!empty($promoteGameRatio['turnover_ratio']) && $promoteGameRatio['begin_time'] <= $settlementBeginTime && (empty($promoteGameRatio['end_time']) || $promoteGameRatio['end_time'] >= $settlementEndTime)) { + $spendMap['game_id'] = $promoteGameRatio['game_id']; + $promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true); + $turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']); + $sumAmount = $spendModel->field("sum(pay_amount) as sum_amount") + ->where($spendMap) + ->find()['sum_amount']; + $sumAmount = $sumAmount ?? 0; + $ratio = 0; + foreach ($turnoverRatios as $turnoverRatio) { + if ($sumAmount >= $turnoverRatio['turnover']) { + $ratio = $turnoverRatio['ratio']; + break; + } + } + + if ($ratio > 0) { + $ratio = bcsub($ratio, $promoteGameRatio['ratio'], 2); + $thisBalance = bcdiv(bcmul($sumAmount, $ratio, 2), 100, 2); + $balance = bcadd($balance, $thisBalance, 2); + } + } + } + + return $balance; + } + + public function getMonthAmount($promote, $data = []) + { + $promoteIds = $this->getPromoteChildren($promote); + $settlementBeginTime = $data['begin_time'] ?? strtotime(date('Y-m', strtotime('-1 month', time()))); + $settlementEndTime = $data['end_time'] ?? strtotime(date('Y-m')) - 1; + + $spendMap['pay_status'] = 1; + $spendMap['selle_status'] = 0; + $spendMap['promote_id'] = ['in', $promoteIds]; + $spendMap['pay_time'] = ['between', [$settlementBeginTime, $settlementEndTime]]; + $spendWhere = $spendMap; + $spendModel = M('spend', 'tab_'); + + $promoteGameRatioMap['status'] = 1; + $promoteGameRatioMap['promote_id'] = $promote['id']; + $promoteGameRatios = D('promote_game_ratio')->field('game_id, ratio, turnover_ratio, begin_time, end_time') + ->where($promoteGameRatioMap) + ->order('update_time desc') + ->select(); + + if (empty($promoteGameRatios)) { + $balance = $spendModel->field("sum(if(selle_ratio > 0, pay_amount * selle_ratio, 0)) as balance") + ->where($spendMap) + ->find()['balance']; + $balance = $balance ?? 0; + } else { + $balance = 0; + $notInGameIds = [-1]; + foreach ($promoteGameRatios as $promoteGameRatio) { + $spendWhere['game_id'] = $promoteGameRatio['game_id']; + if (!empty($promoteGameRatio['turnover_ratio']) && $promoteGameRatio['begin_time'] <= $settlementBeginTime && (empty($promoteGameRatio['end_time']) || $promoteGameRatio['end_time'] >= $settlementEndTime)) { + $notInGameIds[] = $promoteGameRatio['game_id']; + $ratio = $promoteGameRatio['ratio']; + $promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true); + $turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']); + $sumAmount = $spendModel->field("sum(pay_amount) as sum_amount") + ->where($spendWhere) + ->find()['sum_amount']; + $sumAmount = $sumAmount ?? 0; + foreach ($turnoverRatios as $turnoverRatio) { + if ($sumAmount >= $turnoverRatio['turnover']) { + $ratio = $turnoverRatio['ratio']; + break; + } + } + + $thisBalance = $spendModel->field("sum(pay_amount * {$ratio}) as balance") + ->where($spendWhere) + ->find()['balance']; + $thisBalance = $thisBalance ?? 0; + $balance = bcadd($balance, $thisBalance, 2); + } + } + + $spendWhere['game_id'] = ['not in', $notInGameIds]; + $otherBalance = $spendModel->field("sum(if(selle_ratio > 0, pay_amount * selle_ratio, 0)) as balance") + ->where($spendWhere) + ->find()['balance']; + $otherBalance = $otherBalance ?? 0; + $balance = bcadd($balance, $otherBalance, 2); + } + + $balance = bcdiv($balance, 100, 2); + return $balance; + } + + private function getSpendMessageByGame($map) + { + $field = 'game_id, selle_ratio, sum(pay_amount) as sum_amount, pay_time'; + $spendModel = M('spend', 'tab_'); + $gameSpendRatios = $spendModel->field($field) + ->where($map) + ->group('game_id, selle_ratio') + ->order('game_id asc, pay_time asc') + ->select(); + + return $gameSpendRatios; + } + + private function getPromoteChildren($promote) { + $promoteMap['chain'] = ['like', "{$promote['chain']}{$promote['id']}/%"]; + $promoteIds = M('promote', 'tab_')->where($promoteMap)->getField('id', true); + $promoteIds[] = $promote['id']; + + return $promoteIds; + } + + private function getGameRatio($map, $beginTime, $endTime) + { + $gameRatios = []; + $gameSpendRatios = $this->getSpendMessageByGame($map); + foreach ($gameSpendRatios as $gameSpendRatio) { + $gameRatios[$gameSpendRatio['game_id']][] = [ + 'selle_ratio' => $gameSpendRatio['selle_ratio'], + 'sum_amount' => $gameSpendRatio['sum_amount'], + 'begin_time' => date('Y-m-d', $gameSpendRatio['pay_time']), + 'end_time' => date('Y-m-d', $gameSpendRatio['pay_time']), + ]; + } + foreach ($gameRatios as $key => $gameRatio) { + $gameRatios[$key][0]['begin_time'] = $beginTime; + $gameRatios[$key][count($gameRatio) - 1]['end_time'] = $endTime; + if (count($gameRatio) > 1) { + foreach ($gameRatios[$key] as $childKey => $childList) { + $gameRatios[$key][$childKey]['end_time'] = isset($gameRatios[$key][$childKey + 1]) ? $gameRatios[$key][$childKey + 1]['begin_time'] : $gameRatios[$key][$childKey]['end_time']; + } + } + } + + return $gameRatios; + } } diff --git a/Application/Admin/View/Promote/edit.html b/Application/Admin/View/Promote/edit.html index 38af1c9f4..fdabbe255 100644 --- a/Application/Admin/View/Promote/edit.html +++ b/Application/Admin/View/Promote/edit.html @@ -302,6 +302,22 @@ 显示推广员的平台币余额,推广员平台币用于会长代充或者转移给下级推广员 + + + 结算模式: + + + + checked="checked">周结 + + + checked="checked">月结 + + + 会长推广结算模式 + + + diff --git a/Application/Admin/View/PromoteGameRatio/applyRatio.html b/Application/Admin/View/PromoteGameRatio/applyRatio.html index 3ce73e049..7d14a96be 100644 --- a/Application/Admin/View/PromoteGameRatio/applyRatio.html +++ b/Application/Admin/View/PromoteGameRatio/applyRatio.html @@ -3,6 +3,7 @@ + @@ -22,6 +23,48 @@ .tabcon1711 .mustmark { margin-left:-7px; } + .list-ratio { + display: table; + } + .list-ratio .li-ratio { + display: flex; + margin-bottom: 20px; + align-items: center; + } + .list-ratio .li-ratio .turnover, .list-ratio .li-ratio .turnover-ratio { + position: relative; + } + .list-ratio .li-ratio .turnover span, .list-ratio .li-ratio .turnover-ratio .error-message { + color: red; + position: absolute; + left: 0; + top: 30px; + white-space: nowrap; + display: none; + } + .iconfont-btn { + cursor: pointer; + } + .iconfont-style { + font-size: 18px; + color: #fff; + border-radius: 4px; + border: 0; + padding: 5px; + margin-left: 10px; + } + .iconfont-selected { + background-color: #0A9AF2; + } + .iconfont-selected:hover { + background-color: #03a9f4; + } + .iconfont-unselected { + background-color: #999; + } + .iconfont-unselected:hover { + background-color: #ababab; + } {$meta_title} @@ -83,11 +126,62 @@ 现分成比例: - + 默认分成比例: + % 当前需要修改成的分成比例 + + + + + + + + 月流水大于等于: + + + + + 分成比例: + + + % + sadasdas + + + + + + + + 月流水大于等于: + + + + + 分成比例: + + + % + + + + + + + + + + + + + + + + + *开始时间: @@ -147,13 +241,15 @@ $(".select_gallery").select2(); $(function(){ $('.time').datetimepicker({ - format: 'yyyy-mm-dd', + format: 'yyyy-mm', language: "zh-CN", - minView: 2, autoclose: true, scrollMonth: false, scrollTime: false, scrollInput: false, + startView: 'year', + minView:'year', + maxView:'year', }); showTab(); @@ -239,6 +335,119 @@ $(function(){ } }); }); + + $('.iconfont-btn-add').click(function (e) { + var delBtn = $('.iconfont-btn-del'); + var html = ''; + html += ''; + html += '月流水大于等于:'; + html += ''; + html += ''; + html += ''; + html += ''; + html += '分成比例:'; + html += ''; + html += ''; + html += '%'; + html += ''; + html += ''; + html += ''; + + $('.list-ratio').append(html); + + if ($('.list-ratio').children().length > 1 && delBtn.children('i').hasClass('iconfont-unselected')) { + delBtn.children('i').removeClass('iconfont-unselected'); + delBtn.children('i').addClass('iconfont-selected'); + } + + $('.list-ratio').children(':last-child').children('.turnover').children('input').change(function (e) { + turnoverChangeHandle(); + }); + + $('.list-ratio').children(':last-child').children('.turnover-ratio').children('input').change(function (e) { + turnoverRatioChangeHandle(); + }); + }); + + $('.list-ratio').children('.li-ratio').children('.turnover').children('input').change(function (e) { + turnoverChangeHandle(); + }); + + $('.list-ratio').children('.li-ratio').children('.turnover-ratio').children('input').change(function (e) { + turnoverRatioChangeHandle(); + }); + + function turnoverChangeHandle() + { + $('.list-ratio').children('.li-ratio').children('.turnover').children('input').each(function () { + var that = $(this); + var thatLiRatio = that.parent().parent(); + var thatLiRatioIndex = thatLiRatio.index(); + var prevTurnover = 0; + var prev = thatLiRatio.prev().children().children('input'); + var thatTurnover = parseFloat(that.val()); + + if (thatLiRatioIndex > 0) { + prevTurnover = parseFloat(prev.val()); + prevTurnoverHandle(thatTurnover, prevTurnover, that); + } + }); + } + + function turnoverRatioChangeHandle() { + var ratio = parseFloat($('#ratio').val()); + $('.list-ratio').children('.li-ratio').children('.turnover-ratio').children('input').each(function () { + var that = $(this); + var thatLiRatio = that.parent().parent(); + var thatLiRatioIndex = thatLiRatio.index(); + var thatTurnoverRatio = parseFloat(that.val()); + + if (thatLiRatioIndex === 0) { + console.log(111) + prevTurnoverRatio = ratio; + prevTurnoverRatioHandle(thatTurnoverRatio, prevTurnoverRatio, that, true); + } else { + var prev = thatLiRatio.prev().children('.turnover-ratio').children('input'); + var prevTurnoverRatio = parseFloat(prev.val()); + prevTurnoverRatioHandle(thatTurnoverRatio, prevTurnoverRatio, that); + } + }); + } + + function prevTurnoverHandle(thatTurnover, prevTurnover, that) + { + if (thatTurnover <= prevTurnover) { + that.parent().children('span').text('月流水必须大于上一个月流水'); + that.parent().children('span').show(); + } else { + that.parent().children('span').hide(); + } + return true; + } + + function prevTurnoverRatioHandle(thatTurnoverRatio, prevTurnoverRatio, that, isDefault = false) + { + if (thatTurnoverRatio <= prevTurnoverRatio) { + var msg = isDefault ? '月流水分成比例必须大于默认分成比例' : '月流水分成比例必须大于上一个月流水分成比例'; + that.parent().children('.error-message').text(msg); + that.parent().children('.error-message').show(); + } else { + that.parent().children('.error-message').hide(); + } + return true; + } + + $('.iconfont-btn-del').click(function (e) { + var that = $(this); + + if ($('.list-ratio').children().length > 1) { + $('.list-ratio').children(':last-child').remove(); + if ($('.list-ratio').children().length === 1) { + that.children('i').removeClass('iconfont-selected'); + that.children('i').addClass('iconfont-unselected'); + } + } + }); }); diff --git a/Application/Admin/View/PromoteGameRatio/lists.html b/Application/Admin/View/PromoteGameRatio/lists.html index 140ce4052..a9cb1d8f5 100644 --- a/Application/Admin/View/PromoteGameRatio/lists.html +++ b/Application/Admin/View/PromoteGameRatio/lists.html @@ -43,24 +43,30 @@ margin-left:-7px } - - - {$meta_title} - 说明:此功能可设置所有公会对应的游戏分成比例。 - - - - - 游戏分成比例申请 - - 审核通过 - 审核拒绝 - - + + + class="tabchose" href="{:U('lists?group=1')}">分成比例申请 + class="tabchose" href="{:U('lists?group=2')}">申请记录 + {$meta_title} + 说明:此功能可设置所有公会对应的游戏分成比例。 + + + + + + 游戏分成比例申请 + + 审核通过 + 审核拒绝 + + + + + @@ -91,7 +97,7 @@ - 搜索 + 搜索 @@ -119,7 +125,9 @@ 分成比例审核 申请人 确认人 - 操作 + + 操作 + @@ -153,9 +161,11 @@ {$record.status_text} {$record.applicant} {$record.reviewer} - - 修改 - + + + 修改 + + @@ -164,6 +174,15 @@ + + + + 导出 + + {$_page|default=''} + + @@ -334,5 +353,10 @@ function refuse() { $(".jsgamecheckall").click(function(){ $(this).closest('.jsgamecheckallbox').siblings("#game_list").find(".jsgameid").prop("checked", this.checked); }); + + $(".export-btn").on("click",function(e){ + e.preventDefault(); + window.location.href=$(this).attr("href") + }) diff --git a/Application/Admin/View/Query/settlement.html b/Application/Admin/View/Query/settlement.html index 12512b82d..4f1e6ad94 100644 --- a/Application/Admin/View/Query/settlement.html +++ b/Application/Admin/View/Query/settlement.html @@ -30,98 +30,100 @@ - - - 推广结算 - 结算记录 - - - 推广结算 - - - 说明:此功能是针对推广员下面的用户注册充值进行结算,充值数据是指消费到游戏的所有订单记录 - - 说明:此功能是查看所有的推广员结算记录 - + + class="tabchose" href="{:U('settlement?group=1')}">推广结算 + class="tabchose" href="{:U('settlement?group=2')}">结算记录 + + 推广结算 + + 说明:此功能是查看所有的会长未提现订单,并可进行后台提现 + + 说明:此功是查看所有会长的结算记录 + - - - - 参与结算设置: - - checked="checked"> 排除绑币 - - - - checked="checked"> 包含绑币 - - - - 注意①:推广结算只结算消费到游戏的所有订单记录。(系统默认全部排除绑币,可视情况自行勾选) - 注意②:包含绑币勾选请慎重,由于玩家账户部分绑币的来源属于后台发放或者会长代充等,涉及到成本盈亏,是否参与推广员结算请考虑清楚! - 注意③:推广结算时间请按规律时间统一结算,否则时间不统一容易导致个别游戏在统一时间内无法结算。(结算时间只可选到前一天) - - - - - - - - - 批量结算 - - - - + + + + 提 现 + + + + - - 搜索: + + 搜索: + + + + 会长账号 + + {$vo.account} + + + + + + + 提现模式 + $vo) :?> + {$vo} + + - - value="{:get_lastweek_name(7)}" value="{:I('timestart')}" placeholder="结算周期起始时间" /> - - - - value="{:get_lastweek_name(1)}" value="{:I('timeend')}" placeholder="结算周期结束时间" /> - - + + - - - 推广员账号 - - {$vo.account} - - - + + + + + - - - - 搜索 - - - - - - - - - - - - - - - 搜索 - - + + + + + 搜索 + + + + + + + + + 提现状态 + $value) :?> + =$value?> + + + + + + 操作人类型 + $value) :?> + =$value?> + + + + + + 提现模式 + $vo) :?> + {$vo} + + + + + 搜索 + + - - @@ -130,21 +132,14 @@ - - - - 结算周期 - 推广员账号 - 游戏名称 - 总充值 - - 总注册 - 结算模式 - 分成比例 - 注册单价 - 结算金额 - 状态 - + 日期 + 会长账号 + 游戏名称 + 总充值 + 总注册 + 结算模式 + 分成比例 + 结算金额 @@ -154,211 +149,87 @@ .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} - - - - - - CPS - - - - CPS - CPA - - - - - - - {$data.ratio}0% - 修改 - - - {$data.money}0 - 修改 - - - {:round($data['spay_amount'] * $data['ratio']/100,2)} - - - 已结算 - - 可结算 - - + + + {$record.day} + {$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']} + + + + 汇总 + + + 累计充值:{$zTotal}元 + + 累计结算:{$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} + {$record.op_id_text} + {$record.op_type_text} + {$record.last_op_id_text} + {$record.last_op_type_text} + {$record.settlement_type_text} + {$record.settlement_begin_time} + {$record.settlement_end_time} + {$record.create_time} + {$record.status_text} + {$record.respond} + + + 汇款证明 + + 重新审核 + + + 撤销提现 + + - - 汇总 - 当页结算:{$total}元 ; 今日结算:{$ttotal}元 ; 昨日结算:{$ytotal}元 ; 累计结算:{$ztotal}元 - @@ -366,18 +237,8 @@ - - 导出 - + 导出 {$_page|default=''} @@ -395,79 +256,51 @@ - - if(C('COLOR_STYLE')=='blue_color') echo ''; - - - - - - - + + + + + + + + + + diff --git a/Application/Admin/View/Query/withdraw.html b/Application/Admin/View/Query/withdraw.html index 4a3131a7e..2eb696c61 100644 --- a/Application/Admin/View/Query/withdraw.html +++ b/Application/Admin/View/Query/withdraw.html @@ -78,13 +78,29 @@ - + 提现状态 $value) :?> =$value?> + + + 操作人类型 + $value) :?> + =$value?> + + + + + + 提现模式 + $value) :?> + =$value?> + + + 搜索 @@ -106,9 +122,16 @@ 提现单号 - 提现金额 + 提现金额 推广员账号 - 申请时间 + 操作人 + 操作人类型 + 最后操作人 + 最后操作人类型 + 提现模式 + 结算开始时间 + 结算截止时间 + 申请时间 提现状态 说明 审核时间 @@ -142,8 +165,31 @@ {: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'])} + {:getPromoteWithdrawSettlementType($data['settlement_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 +207,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(floor($total*100)/100)}元 @@ -169,7 +215,8 @@ - 导出 + 导出 {$_page|default=''} @@ -288,6 +335,11 @@ content: '/admin.php?s=/Query/withdrawDetails/id/'+id+'' //iframe的url }); } + + $(".export-btn").on("click",function(e){ + e.preventDefault(); + window.location.href=$(this).attr("href") + })
说明:此功能可设置所有公会对应的游戏分成比例。
说明:此功能是针对推广员下面的用户注册充值进行结算,充值数据是指消费到游戏的所有订单记录
说明:此功能是查看所有的推广员结算记录
说明:此功能是查看所有的会长未提现订单,并可进行后台提现
说明:此功是查看所有会长的结算记录
注意①:推广结算只结算消费到游戏的所有订单记录。(系统默认全部排除绑币,可视情况自行勾选)
注意②:包含绑币勾选请慎重,由于玩家账户部分绑币的来源属于后台发放或者会长代充等,涉及到成本盈亏,是否参与推广员结算请考虑清楚!
注意③:推广结算时间请按规律时间统一结算,否则时间不统一容易导致个别游戏在统一时间内无法结算。(结算时间只可选到前一天)