diff --git a/Application/Admin/Common/function.php b/Application/Admin/Common/function.php index 0e0c82c80..f4beed6e2 100644 --- a/Application/Admin/Common/function.php +++ b/Application/Admin/Common/function.php @@ -608,7 +608,7 @@ function arrayPromoteWithdrawStatus($status, $param, $array = array()) { function getAllGame() { - $list = M("game", 'tab_')->field('relation_game_name as game_name')->group('relation_game_name')->select(); + $list = M("game", 'tab_')->field('relation_game_name as game_name, relation_game_id as game_id')->group('relation_game_name')->select(); return $list; } /** diff --git a/Application/Admin/Controller/StatementMangementController.class.php b/Application/Admin/Controller/StatementMangementController.class.php index 7062b1001..7ef2151ae 100644 --- a/Application/Admin/Controller/StatementMangementController.class.php +++ b/Application/Admin/Controller/StatementMangementController.class.php @@ -2,6 +2,7 @@ namespace Admin\Controller; +use Admin\Model\RewardModel; use User\Api\UserApi as UserApi; /** @@ -246,62 +247,173 @@ class StatementMangementController extends ThinkController public function rewardManageList($row = 10, $p = 1) { - $map = []; - if (!empty(I("game_name"))) { - $game_ids = array_column(getGameByName(I("game_name")), 'id'); - if ($game_ids) { - $map['tab_reward_record.relation_game_id'] = ['in', $game_ids]; - } + $companys[1] = array_column(M('partner', 'tab_')->field('id, partner as name')->select(), 'name', 'id'); + $companys[2] = array_column(M('promote_company', 'tab_')->field('id, company_name as name')->select(), 'name', 'id'); + $games = array_column(M('game', 'tab_')->field('relation_game_id, relation_game_name, partner_id')->group('relation_game_id')->select(), null, 'relation_game_id'); + $map = ' 1=1 '; + + $params = $_GET; + + if (!empty(I('reward_type'))) { + $map .= " and reward_type = {$params['reward_type']}"; + } + + if (I('game_id', -1) !== '' && I('game_id', -1) >= 0) { + $map .= " and r.relation_game_id = {$params['game_id']}"; } + if (!empty(I('partner_id'))) { - $map['tab_reward_record.company_id'] = I('partner_id'); + $gameIds = []; + foreach ($games as $item) { + if ($item['partner_id'] == I('partner_id')) { + $gameIds[] = $item['relation_game_id']; + } + } + if ($gameIds) { + $map .= " and r.relation_game_id in (".implode(',', $gameIds).")"; + } else { + $map .= " and 1<>1 "; + } } - if (strlen(I('company_type'))) { - $map['tab_reward_record.company_type'] = I('company_type'); + + if (!empty($params['settlement_type'])) { + $map .= " and rd.settlement_type = {$params['settlement_type']} "; + } + + if (!empty($params['detail_reward_type'])) { + $map .= " and rd.type = {$params['detail_reward_type']} "; + } + + if (!empty($params['settlement_time_range'])) { + list($settlment_time_start, $settlment_time_end) = explode('~', $params['settlement_time_range']); + $map .= " and r.settlement_time between " . strtotime(trim($settlment_time_start)) . " and " . (strtotime(trim($settlment_time_end))+86400); } - if (!empty(I('account'))) { - //$map['accounts'] = ['like', '%' . I('account') . '%']; - // 获取会长匹配的id - $promoterIds = M('promote', 'tab_')->where(['account'=>['like', '%' . I('account') . '%'], 'level'=>1])->getField('id'); - $map['tab_reward_record.promote_id'] = ['in', $promoterIds]; + + if (!empty($params['confirm_time_range'])) { + list($confirm_time_start, $confirm_time_end) = explode('~', $params['confirm_time_range']); + $map .= " and r.confirm_time between " . strtotime(trim($confirm_time_start)) . " and " . (strtotime(trim($confirm_time_end))+86400); + } + + if (!empty($params['detail_company_type'])) { + $map .= " and rd.company_type = {$params['detail_company_type']} "; } - $list = M('reward_record', 'tab_') - ->field('tab_reward_record.*, tab_promote.account as promote_account, tab_game.partner_id') + + // 判断公司 + if (I('detail_company_id', -1) >= 0) { + $map .= " and rd.company_id = {$params['detail_company_id']} "; + // if (!empty($params['detail_company_name'])) { + // $map .= " and rd.company_name = '{$params['detail_company_name']}' "; + // } + } + + if (!empty($params['detail_company_name'])) { + $map .= " and rd.company_name like '%{$params['detail_company_name']}%' "; + } + + // 判断会长 + if (I('detail_promote_account', -1) >= 0) { + $map .= " and rd.promote_account like ('%{$params['detail_promote_account']}%') "; + } + + if (!empty($params['detail_promote_account_input'])) { + $map .= " and rd.promote_account like ('%{$params['detail_promote_account_input']}%') "; + } + + $result = M('reward_record', 'tab_')->alias('r') + ->field('r.id') + ->join('tab_reward_detail as rd on rd.record_id = r.id', 'LEFT') + ->where($map) + ->group('rd.record_id') + ->select(); + + if ($result) { + $map = []; + $map['r.id'] = ['in', array_column($result, 'id')]; + } else { + $map = '1<>1'; + } + + $query = M('reward_record', 'tab_')->alias('r') + ->field(' + r.id, r.relation_game_id, r.settlement_time, r.confirm_time, r.content, r.reward_type, r.creater_id, + rd.id as rid, rd.type as detail_type, rd.company_type as detail_company_type, rd.company_id as detail_company_id , rd.company_name as detail_company_name, rd.settlement_type as detail_settlement_type, rd.promote_account as detail_promote_account,rd.amount as detail_amount + ') ->where($map) - ->join('tab_promote on tab_reward_record.promote_id = tab_promote.id', 'left') - ->join('tab_game on tab_game.relation_game_id = tab_reward_record.relation_game_id', 'left') - ->group('tab_reward_record.id') - ->page($p, $row) - ->select(); - if ($list) { - $companys[1] = array_column(M('partner', 'tab_')->field('id, partner as name')->select(), 'name', 'id'); - $companys[2] = array_column(M('promote_company', 'tab_')->field('id, company_name as name')->select(), 'name', 'id'); - $games = array_column(M('game', 'tab_')->field('relation_game_id, relation_game_name')->group('relation_game_id')->select(), 'relation_game_name', 'relation_game_id'); - foreach ($list as &$item) { - $item['company_name'] = $companys[$item['company_type']][$item['company_id']]; - $item['partner_name'] = $companys[1][$item['partner_id']] ?? '无'; - $item['accounts'] = json_decode($item['accounts'], true) ?: []; - $item['settlement_info'] = json_decode($item['settlement_info'], true) ?: []; - $item['reward_type_desc'] = $item['reward_type'] == 1 ? "奖励" : "惩罚"; - $item['company_type_desc'] = $item['company_type'] == 1 ? "上游公司" : "下游公司"; - $item['relation_game_name'] = $games[$item['relation_game_id']]; - $item['reward_time'] = $item['reward_time'] ? intval(date('m', $item['reward_time'])) . '月' : '-'; - $item['confirm_time'] = $item['confirm_time'] ? date('Y-m-d H:i:s', $item['confirm_time']) : '-'; - $item['row'] = sizeof($item['settlement_info']) ?? 1; - // if ($item['company_type'] == 1) { - - // } else { + ->join('tab_reward_detail as rd on rd.record_id = r.id', 'LEFT'); + + if(I('is_export', false)){ + $list = $query + ->select(); + }else{ + $list = $query + ->page($p,$row) + ->select(); + } - // } + if ($list) { + $record = []; + foreach ($list as $item) { + + if (!isset($record[$item['id']])) + { + $record[$item['id']] = [ + 'id' => $item['id'], + 'relation_game_name' => $games[$item['relation_game_id']]['relation_game_name'] ?? '其他', + 'relation_game_partner' => $companys[1][$games[$item['relation_game_id']]['partner_id']] ?? '无', + 'settlement_time' => $item['settlement_time'] ? date('Y年m月', $item['settlement_time']) : '-', + 'confirm_time' => $item['confirm_time'] ? date('Y-m-d', $item['confirm_time']) : '-', + 'content' => $item['content'], + 'reward_type_text' => RewardModel::$rewardTypes[$item['reward_type']], + 'maxCount' => 0, + 'creater_id' => $item['creater_id'], + 'totalReward' => 0, + 'totalPunish' => 0 + ]; + } + if (!empty($item['rid'])) { + $record[$item['id']]['detail'][$item['detail_type']][] = [ + 'company_type_text' => RewardModel::$companyTypes[$item['detail_company_type']] ?? '-', + 'settlement_type_text' => RewardModel::$settlementTypes[$item['detail_settlement_type']] ?? '-', + 'company_name' => empty($item['detail_company_name']) && !empty($item['detail_company_id']) ? ($companys[$item['detail_company_type']][$item['detail_company_id']] ?? '无') : ($item['detail_company_name'] ?? '无'), + 'amount' => $item['detail_type'] == RewardModel::REWARD_TYPE_PUNISH ? -$item['detail_amount'] : $item['detail_amount'], + 'promote_account' => $item['detail_promote_account'] ?? '无', + ]; + if ($item['detail_type'] == RewardModel::REWARD_TYPE_REWARD) { + $record[$item['id']]['totalReward'] += $item['detail_amount']; + } else { + $record[$item['id']]['totalPunish'] += $item['detail_amount']; + } + } + // 获取最大行数 + if (sizeof($record[$item['id']]['detail'][$item['detail_type']]) > $record[$item['id']]['maxCount']) { + $record[$item['id']]['maxCount'] = sizeof($record[$item['id']]['detail'][$item['detail_type']]); + } + } - } - $count = M('reward_record', 'tab_')->where($map)->count(); + } + + $count = sizeof($result); $page = set_pagination($count, $row); if ($page) { $this->assign('_page', $page); } - $this->assign('list', $list); - $this->assign('promoters', array_column(M('promote', 'tab_')->where(['level'=>1])->field('id, nickname')->select(), 'nickname', 'id')); + ksort($record); + $this->assign('list', $record); + $this->assign('promoters', array_column(M('promote', 'tab_')->where(['level'=>1])->field('id, nickname, account')->select(), null, 'id')); + + $this->checkListOrCountAuthRestMap($map,[]); + + if(I('is_export', false)){ + + $getData = $_GET; + unset($getData['export']); + + addOperationLog(['op_type'=>3,'key'=>getNowDate(),'op_name'=>'导出推广公司','url'=>U('PromoteCompany/lists'),'menu'=>'推广员-推广员管理-推广公司管理-导出推广公司']); + + //导出 + $this->display("rewardExport"); + die(); + } $this->display(); } @@ -317,27 +429,56 @@ class StatementMangementController extends ThinkController 'content' => I('content'), 'remark' => I('remark'), 'promote_id' => I('promote_id'), - 'settlement_info' => json_encode(I('settlement_info') ? array_values(I('settlement_info')) : []), + //'settlement_info' => json_encode(I('settlement_info') ? array_values(I('settlement_info')) : []), 'reward_time' => strtotime(I('reward_time')), - 'confirm_time' => strtotime(I('confirm_time')) + 'confirm_time' => strtotime(I('confirm_time')), + 'settlement_time' => strtotime(I('settlement_time')), ]; + $settlment_info = I('settlement_info'); $accounts = I('account'); $user_types = I('user_type'); + + // 处理结算信息 if ($settlment_info) { - foreach($settlment_info as $item) { - if (!is_numeric($item['price']) || empty($item['price'])) { - return $this->error('请填写完整的结算信息'); + $tmp = []; + foreach($settlment_info as &$item) { + if (empty($item)) { + unset($item); + continue; } + // if (!is_numeric($item['price']) || empty($item['price'])) { + // return $this->error('请填写正确的奖惩金额'); + // } + $item = json_decode($item, true); + if (!empty($id) && empty($item['id'])) { + $item['record_id'] = $id; + //$item['id'] = null; + } + + if (!empty($item['company_id'])) + { + $item['company_name'] = ''; + } + + $item['confirm_time'] = $data['settlement_time']; + //$item['settlement_flag'] = sprintf('%s-%s-%s', $item['company_type'], $item['company_name'], $item['']) + // 归类奖罚数组 + $tmp[$item['type']][] = $item; } - $promoterIds = array_column($settlment_info, 'promote_id'); - if (in_array(0, $promoterIds)) { - return $this->error('请选择合作方后再提交'); - } - if (sizeof(array_unique($promoterIds)) != sizeof($promoterIds)) { - return $this->error('含有重复的结算方,请确认!'); + if (empty($tmp)) { + return $this->error('请填写结算信息'); } + $settlment_info = $tmp; + // $promoterIds = array_column($settlment_info, 'promote_id'); + // if (in_array(0, $promoterIds)) { + // return $this->error('请选择合作方后再提交'); + // } + // if (sizeof(array_unique($promoterIds)) != sizeof($promoterIds)) { + // return $this->error('含有重复的结算方,请确认!'); + // } } + if ($accounts) { foreach ($accounts as $index => $account) { @@ -355,17 +496,35 @@ class StatementMangementController extends ThinkController $data['accounts']=a_array_unique($data['accounts']); // dump($data['accounts']);die(); $data['accounts'] = json_encode($data['accounts']); - if (!is_numeric(I('money'))) { - return $this->error('请输入正确的金额'); - } + // if (!is_numeric(I('money'))) { + // return $this->error('请输入正确的金额'); + // } if (empty(I('content'))) { return $this->error('请填写事件内容'); } + //dd($settlment_info); + // 更新结算信息 + if ($id) { + M('reward_detail', 'tab_')->where(['record_id'=>$id])->delete(); + } + if (!empty($settlment_info[RewardModel::REWARD_TYPE_REWARD]) && !empty($settlment_info[RewardModel::REWARD_TYPE_PUNISH])) { + $data['reward_type'] = RewardModel::REWARD_TYPE_ALL; + } else if (!empty($settlment_info[RewardModel::REWARD_TYPE_REWARD])) { + $data['reward_type'] = RewardModel::REWARD_TYPE_REWARD; + } else if (!empty($settlment_info[RewardModel::REWARD_TYPE_PUNISH])) { + $data['reward_type'] = RewardModel::REWARD_TYPE_PUNISH; + } + + $settlmentSet = array_merge($settlment_info[RewardModel::REWARD_TYPE_REWARD] ?? [], $settlment_info[RewardModel::REWARD_TYPE_PUNISH] ?? []); + if ($id) { $upt = M('reward_record', 'tab_')->where(['id'=>$id])->save($data); if ($upt === false) { $this->error('保存失败'); } else { + foreach ($settlmentSet as $item) { + M('reward_detail', 'tab_')->add($item); + } $companyName = M('partner','tab_')->field('partner')->where(['id'=>$data['company_id']])->find(); addOperationLog(['op_type'=>1,'key'=>$companyName['partner'].'/'.(($data['reward_type']==1)?'奖励':'惩罚').'/'.$data['money'],'op_name'=>'修改奖惩记录','url'=>U('Query/settlement'),'menu'=>'推广员-结算单管理-奖罚记录管理-修改奖惩记录']); @@ -376,6 +535,11 @@ class StatementMangementController extends ThinkController $data['creater_id'] = is_login(); $ins = M('reward_record', 'tab_')->add($data); + foreach ($settlmentSet as $item) { + $item['record_id'] = M('reward_record', 'tab_')->getLastInsID(); + M('reward_detail', 'tab_')->add($item); + } + $companyName = M('partner','tab_')->field('partner')->where(['id'=>$data['company_id']])->find(); addOperationLog(['op_type'=>0,'key'=>$companyName['partner'].'/'.(($data['reward_type']==1)?'奖励':'惩罚').'/'.$data['money'],'op_name'=>'新增奖惩记录','url'=>U('Query/settlement'),'menu'=>'推广员-结算单管理-奖罚记录管理-新增奖惩记录']); @@ -391,6 +555,8 @@ class StatementMangementController extends ThinkController $upt = M('reward_record', 'tab_')->where(['id'=>$id])->delete(); + M('reward_detail', 'tab_')->where(['record_id'=>$id])->delete(); + $companyName = M('partner','tab_')->field('partner')->where(['id'=>$rewardRecordData['company_id']])->find(); addOperationLog(['op_type'=>2,'key'=>$companyName['partner'].'/'.(($rewardRecordData['reward_type']==1)?'奖励':'惩罚').'/'.$rewardRecordData['money'],'op_name'=>'删除奖惩记录','url'=>U('StatementMangement/rewardManageList'),'menu'=>'推广员-结算单管理-奖罚记录管理']); @@ -402,13 +568,37 @@ class StatementMangementController extends ThinkController $data['confirm_time'] = $data['confirm_time'] ? date('Y-m-d H:i:s', $data['confirm_time']) : ''; $data['accounts'] = json_decode($data['accounts'], true) ?: []; $data['settlement_info'] = json_decode($data['settlement_info'], true) ?: []; - $this->assign('data', $data); + //$this->assign('data', $data); } } else { $data['reward_time'] = strtotime(date('Y-m-01')); - $this->assign('data', $data); + + } + $details = M('reward_detail', 'tab_')->where(['record_id'=>$id])->select(); + // 根据type 来合并 + foreach ($details as $item) { + $item['info'] = $item; + if (empty($item['company_name']) && $item['company_id']) { + if ($item['company_type'] == RewardModel::COMPANY_TYPE_PARTNER) { + $item['company_name'] = M('partner', 'tab_')->where(['id'=>$item['company_id']])->getField('partner'); + } else { + $item['company_name'] = M('promote_company', 'tab_')->where(['id'=>$item['company_id']])->getField('company_name'); + } + } + $tmp[$item['type']][] = $item; } + $data['rewardCount'] = sizeof($tmp[RewardModel::REWARD_TYPE_REWARD]); + $data['punishCount'] = sizeof($tmp[RewardModel::REWARD_TYPE_PUNISH]); + $data['rewardAmount'] = $data['rewardCount'] > 0 ? array_sum(array_column($tmp[RewardModel::REWARD_TYPE_REWARD], 'amount')) : 0; + $data['punishAmount'] = $data['punishCount'] > 0 ? array_sum(array_column($tmp[RewardModel::REWARD_TYPE_PUNISH], 'amount')) : 0; + $data['maxCount'] = $data['rewardCount'] > $data['punishCount'] ? $data['rewardCount'] : $data['punishCount']; + + $this->assign('details', $tmp); + $this->assign('data', $data); $this->assign('promoters', M('promote', 'tab_')->where(['level'=>1])->field('id, nickname')->select()); + $this->assign('rewardTypes', RewardModel::$rewardTypes); + $this->assign('settlementTypes', RewardModel::$settlementTypes); + $this->assign('companyTypes', RewardModel::$companyTypes); $this->display(); } diff --git a/Application/Admin/Model/RewardModel.class.php b/Application/Admin/Model/RewardModel.class.php new file mode 100644 index 000000000..372f17cbf --- /dev/null +++ b/Application/Admin/Model/RewardModel.class.php @@ -0,0 +1,56 @@ + +// +---------------------------------------------------------------------- + +namespace Admin\Model; + +use Common\Api\GameApi; +use Org\WeixinSDK\Weixin; +use Think\Model; + +/** + * 文档基础模型 + */ +class RewardModel extends Model +{ + const REWARD_TYPE_REWARD = 1; + const REWARD_TYPE_PUNISH = 2; + const REWARD_TYPE_ALL = 3; + + public static $rewardTypes = [ + self::REWARD_TYPE_REWARD => '奖励', + self::REWARD_TYPE_PUNISH => '惩罚', + self::REWARD_TYPE_ALL => '双向' + ]; + + const GAME_RELATION_OTHER = 0; + + const SETTLEMENT_TYPE_ONLINE = 2; + const SETTLMENT_TYPE_OFFLINE = 1; + + public static $settlementTypes = [ + self::SETTLEMENT_TYPE_ONLINE => '线上结算', + self::SETTLMENT_TYPE_OFFLINE => '线下结算' + ]; + + const COMPANY_TYPE_PARTNER = 1; + const COMPANY_TYPE_COMPANY = 2; + const COMPANY_TYPE_INSIDE = 3; + + public static $companyTypes = [ + self::COMPANY_TYPE_PARTNER => '上游公司', + self::COMPANY_TYPE_COMPANY => '下游公司', + self::COMPANY_TYPE_INSIDE => '内部' + ]; + + public function __construct($name = '', $tablePrefix = '', $connection = '') + { + $this->tablePrefix = 'tab_'; + parent::__construct($name, $tablePrefix, $connection); + } +} \ No newline at end of file diff --git a/Application/Admin/View/StatementMangement/rewardExport.html b/Application/Admin/View/StatementMangement/rewardExport.html new file mode 100644 index 000000000..cf1bce9bb --- /dev/null +++ b/Application/Admin/View/StatementMangement/rewardExport.html @@ -0,0 +1,178 @@ + + +
+ + +游戏名 | +游戏合作方 | +结算时间 | +奖惩确认时间 | +事件说明 | +奖惩性质 | + +奖惩类型 | +结算公司类型 | +结算方 | +会长账号 | +奖惩金额 | +结算方式 | + + +奖惩类型 | +结算公司类型 | +结算方 | +会长账号 | +奖惩金额 | +结算方式 | + +添加人 | +||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
aOh! 暂时还没有内容! | +||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{$data['relation_game_name']} | +{$data['relation_game_partner']} | +{$data['settlement_time']} | +{$data['confirm_time']} | +{$data['content']} | +{$data['reward_type_text']} | +惩罚方 | +无 | +无 | +无 | +无 | +无 | + +奖励方 | +无 | +无 | +无 | +无 | +无 | + +{:get_admin_name($data['creater_id'])} | +||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{$data['relation_game_name']} | +{$data['relation_game_partner']} | +{$data['settlement_time']} | +{$data['confirm_time']} | +{$data['content']} | +{$data['reward_type_text']} | +惩罚方 | +=$data['detail'][2][$i]['company_type_text'] ?? '无'?> | +=$data['detail'][2][$i]['company_name'] ?? '无'?> | +=$data['detail'][2][$i]['promote_account'] ?? '无'?> | +=$data['detail'][2][$i]['amount'] ?? '无'?> | +=$data['detail'][2][$i]['settlement_type_text'] ?? '无'?> | + +奖励方 | +=$data['detail'][1][$i]['company_type_text'] ?? '无'?> | +=$data['detail'][1][$i]['company_name'] ?? '无'?> | +=$data['detail'][1][$i]['promote_account'] ?? '无'?> | +=$data['detail'][1][$i]['amount'] ?? '无'?> | +=$data['detail'][1][$i]['settlement_type_text'] ?? '无'?> | + +{:get_admin_name($data['creater_id'])} | +||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
=$data['detail'][2][$i]['company_type_text'] ?? '无'?> | +=$data['detail'][2][$i]['company_name'] ?? '无'?> | +=$data['detail'][2][$i]['promote_account'] ?? '无'?> | +=$data['detail'][2][$i]['amount'] ?? '无'?> | +=$data['detail'][2][$i]['settlement_type_text'] ?? '无'?> | + +=$data['detail'][1][$i]['company_type_text'] ?? '无'?> | +=$data['detail'][1][$i]['company_name'] ?? '无'?> | +=$data['detail'][1][$i]['promote_account'] ?? '无'?> | +=$data['detail'][1][$i]['amount'] ?? '无'?> | +=$data['detail'][1][$i]['settlement_type_text'] ?? '无'?> | +|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
合计 | +-{:array_sum(array_column($list, 'totalPunish'))} | +合计 | +{:array_sum(array_column($list, 'totalReward'))} | ++ |