|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Admin\Controller;
|
|
|
|
|
|
|
|
use User\Api\UserApi as UserApi;
|
|
|
|
use OSS\OssClient;
|
|
|
|
use OSS\Core\OSsException;
|
|
|
|
use Think\Controller;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 后台首页控制器
|
|
|
|
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
|
|
|
*/
|
|
|
|
class PartnerController extends ThinkController
|
|
|
|
{
|
|
|
|
private $modelName = 'Partner';
|
|
|
|
|
|
|
|
//列表
|
|
|
|
public function lists()
|
|
|
|
{
|
|
|
|
$model = M($this->modelName, 'tab_');
|
|
|
|
$map = [];
|
|
|
|
$id = intval(I('id', 0));
|
|
|
|
if (!empty($id)) {
|
|
|
|
$map['tab_partner.id'] = $id;
|
|
|
|
$parameter['id'] = $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_REQUEST['status']) && $_REQUEST['status'] !== '') {
|
|
|
|
$status = intval($_REQUEST['status']);
|
|
|
|
$map['tab_partner.status'] = $status;
|
|
|
|
$parameter['status'] = $status;
|
|
|
|
}
|
|
|
|
if (!empty(I('company_type'))) {
|
|
|
|
$map['company_type'] = I('company_type');
|
|
|
|
}
|
|
|
|
if (!empty(I('partner'))) {
|
|
|
|
$map['partner'] = ['like', '%' . I('partner') . '%'];
|
|
|
|
}
|
|
|
|
if (!empty(I('timestart'))) {
|
|
|
|
$timestart = strtotime(I('timestart'));
|
|
|
|
$map['_string'] = "contract_start_time >= {$timestart}";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty(I('timeend'))) {
|
|
|
|
$timeend = strtotime(I('timeend') . ' 23:59:59');
|
|
|
|
if (!empty($map['_string'])) {
|
|
|
|
$map['_string'] .= " and ";
|
|
|
|
}
|
|
|
|
$map['_string'] .= " contract_end_time < {$timeend}";
|
|
|
|
}
|
|
|
|
$page = intval(I('get.p', 0));
|
|
|
|
$page = $page ? $page : 1; //默认显示第一页数据
|
|
|
|
$row = intval(I('row', 0));
|
|
|
|
$row = empty($row) ? 10 : $row;//每页条数
|
|
|
|
|
|
|
|
$is_export= false;
|
|
|
|
if (isset($_REQUEST['export']) && $_REQUEST['export']==1){
|
|
|
|
$is_export = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取分页数据
|
|
|
|
$query = $model->alias('p')
|
|
|
|
->field("p.partner,p.matche_platform,p.invoice_rate,p.settlement_type,p.bank_account,
|
|
|
|
p.opening_bank,p.id,p.contract_start_time,p.contract_end_time,p.remark,p.company_type")
|
|
|
|
->where($map)
|
|
|
|
->order("id desc");
|
|
|
|
if($is_export){
|
|
|
|
$partners = $query
|
|
|
|
->select();
|
|
|
|
}else{
|
|
|
|
$partners = $query
|
|
|
|
->page($page,$row)
|
|
|
|
->select();
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取公司id
|
|
|
|
$partner_ids = array_column($partners, 'id');
|
|
|
|
$partner_ids = $partner_ids ? $partner_ids : [0];
|
|
|
|
$game_map['partner_id'] = ["in",$partner_ids];
|
|
|
|
$games = M("game","tab_")->alias('g')
|
|
|
|
->field("g.game_type_name,g.relation_game_name,g.original_package_name,g.partner_id,g.relation_game_id as id")
|
|
|
|
->where($game_map)
|
|
|
|
->group('relation_game_id')
|
|
|
|
->select();
|
|
|
|
|
|
|
|
$game_ids = array_column($games, 'id');
|
|
|
|
$game_ids = $game_ids ? $game_ids : [0];
|
|
|
|
$cp_game_ratio_map['game_id'] = ["in", $game_ids];
|
|
|
|
$cp_game_ratio_map['is_del'] = '0';
|
|
|
|
//获取游戏比例
|
|
|
|
$gameradiores = M("cp_game_ratio","tab_")
|
|
|
|
->alias("cg")
|
|
|
|
->join("tab_game ga ON cg.game_id = ga.id")
|
|
|
|
->field("cg.ratio,cg.instanceof,cg.game_id,cg.begin_total_amount")
|
|
|
|
->where($cp_game_ratio_map)
|
|
|
|
->group('relation_game_id,begin_total_amount')
|
|
|
|
->select();
|
|
|
|
|
|
|
|
// dd($cp_game_ratio_map);
|
|
|
|
$parseGameRadiores = array();//合作方分成比例
|
|
|
|
foreach ($gameradiores as $key =>$val) {
|
|
|
|
$val['row'] = 1;
|
|
|
|
$val['my_ratio'] = 100 - $val['ratio'];
|
|
|
|
if ($val['begin_total_amount'] == 0) {
|
|
|
|
$val['name'] = '默认比例';
|
|
|
|
if (isset($parseGameRadiores[$val['game_id']])) {
|
|
|
|
$parseGameRadiores[$val['game_id']] = [];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if($val['instanceof']=='1'){
|
|
|
|
$val['name']="月流水≥".$val['begin_total_amount'];
|
|
|
|
}else{
|
|
|
|
$val['name']="月流水>".$val['begin_total_amount'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$parseGameRadiores[$val['game_id']][] = $val;
|
|
|
|
}
|
|
|
|
$myGameRadiores = $parseGameRadiores;//我方分成比例
|
|
|
|
foreach ($myGameRadiores as $key => &$val) {
|
|
|
|
foreach ($val as $k => &$v) {
|
|
|
|
$v['ratio'] = 100 - $v['ratio'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$parseGames = array();
|
|
|
|
|
|
|
|
foreach ($games as $key =>$val) {
|
|
|
|
$val['game_ratio'] = $parseGameRadiores[$val['id']];
|
|
|
|
$val['my_game_ratio'] = $myGameRadiores[$val['id']];
|
|
|
|
if(array_key_exists($val['id'],$parseGameRadiores)){//游戏有比例
|
|
|
|
$row2 = array_sum(array_column($val['game_ratio'], 'row')) ;
|
|
|
|
$val['row'] = empty($row2) ? 1: $row2;
|
|
|
|
} else {
|
|
|
|
$val["row"] = 1;
|
|
|
|
}
|
|
|
|
$val['original_package_name'] = $val['original_package_name'] ?: '-';
|
|
|
|
$parseGames[$val['partner_id']][] = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$parseData = array();
|
|
|
|
foreach ($partners as $key =>$value) {
|
|
|
|
$value['game'] = $parseGames[$value['id']];
|
|
|
|
$value['has_game_evidence'] = $parseGames['has_game_evidence'] ? '有' : '没有';
|
|
|
|
$value['is_sign_contract'] = $parseGames['is_sign_contract'] ? '是' : '否';
|
|
|
|
$value['channel_rate'] *= 100;
|
|
|
|
$value['invoice_rate'] *= 100;
|
|
|
|
if ($value['settlement_type'] == 0) {
|
|
|
|
$value['settlement_type'] = '未配置';
|
|
|
|
} elseif ($value['settlement_type'] == 1) {
|
|
|
|
$value['settlement_type'] = '周结';
|
|
|
|
} elseif ($value['settlement_type'] == 2) {
|
|
|
|
$value['settlement_type'] = '月结';
|
|
|
|
}
|
|
|
|
$value['company_type'] = $value['company_type'] == 2 ? '个人' : '公司';
|
|
|
|
$contract_start_time = $value['contract_start_time'] ?
|
|
|
|
time_format($value['contract_start_time'], 'Y/m/d') : '-';
|
|
|
|
$contract_end_time = $value['contract_end_time'] ?
|
|
|
|
time_format($value['contract_end_time'], 'Y/m/d') : '-';
|
|
|
|
$value['contract_time'] = $contract_start_time . '-' . $contract_end_time;
|
|
|
|
$row2 = array_sum(array_column($value['game'], 'row')) ;
|
|
|
|
$value['row'] = empty($row2) ? 1: $row2;
|
|
|
|
$parseData[$value['partner_id']][] = $value;
|
|
|
|
}
|
|
|
|
$parseData = array_values($parseData);
|
|
|
|
if($is_export){
|
|
|
|
$this->assign('listData', $parseData[0]);
|
|
|
|
$this->display("export");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 查询记录总数 */
|
|
|
|
$count = $model
|
|
|
|
->where($map)
|
|
|
|
->count();
|
|
|
|
//分页
|
|
|
|
$parameter['p'] = $page;
|
|
|
|
$parameter['row'] = $row;
|
|
|
|
$page = set_pagination($count, $row, $parameter);
|
|
|
|
if ($page) {
|
|
|
|
$this->assign('_page', $page);
|
|
|
|
}
|
|
|
|
// dd($parseData[0]);
|
|
|
|
$this->assign('listData', $parseData[0]);
|
|
|
|
$this->assign('count', $count);
|
|
|
|
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Partner/lists'])->find());
|
|
|
|
$this->meta_title = '合作方管理';
|
|
|
|
$this->display();
|
|
|
|
}
|
|
|
|
|
|
|
|
//添加
|
|
|
|
public function add()
|
|
|
|
{
|
|
|
|
if ($_POST) {
|
|
|
|
$partner = I('post.partner', '');
|
|
|
|
$status = intval(I('post.status', 1));
|
|
|
|
|
|
|
|
if (empty($partner)) {
|
|
|
|
$this->error('请输入合作方名称');
|
|
|
|
}
|
|
|
|
if (!strlen(I('is_sign_contract'))) {
|
|
|
|
$this->error('请选择是否签署合同');
|
|
|
|
}
|
|
|
|
if (empty(I('settlement_type'))) {
|
|
|
|
$this->error('请选择结算方式');
|
|
|
|
}
|
|
|
|
if (empty(I('company_type'))) {
|
|
|
|
$this->error('请输入公司性质');
|
|
|
|
}
|
|
|
|
if (!strlen(I('has_game_evidence'))) {
|
|
|
|
$this->error('请选择是否有游戏资质');
|
|
|
|
}
|
|
|
|
if (empty(I('link_man'))) {
|
|
|
|
$this->error('请输入联系人');
|
|
|
|
}
|
|
|
|
if (empty(I('link_phone'))) {
|
|
|
|
$this->error('请输入联系电话');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$model = M($this->modelName, 'tab_');
|
|
|
|
$map['partner'] = $partner;
|
|
|
|
$res = $model->where($map)->getField('id');
|
|
|
|
if ($res) {
|
|
|
|
$this->error('合作方已存在');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!checkPhone(I('link_phone'))) {
|
|
|
|
$this->error('联系电话格式不正确');
|
|
|
|
}
|
|
|
|
$res2 = $model->where(['link_phone' => I('link_phone')])->getField('id');
|
|
|
|
if ($res2) {
|
|
|
|
$this->error('已存在此联系电话');
|
|
|
|
}
|
|
|
|
$time = time();
|
|
|
|
$save['partner'] = $partner;
|
|
|
|
$save['status'] = $status;
|
|
|
|
|
|
|
|
$save['link_man'] = I('link_man');
|
|
|
|
$save['link_phone'] = I('link_phone');
|
|
|
|
$save['address'] = I('address');
|
|
|
|
$save['company_tax_no'] = I('company_tax_no');
|
|
|
|
$save['payee_name'] = I('payee_name');
|
|
|
|
$save['bank_account'] = I('bank_account');
|
|
|
|
$save['opening_bank'] = I('opening_bank');
|
|
|
|
|
|
|
|
$save['matche_platform'] = I('matche_platform');
|
|
|
|
$save['contract_start_time'] = strtotime(I('contract_start_time'));
|
|
|
|
$save['contract_end_time'] = strtotime(I('contract_end_time'));
|
|
|
|
$save['channel_rate'] = I('channel_rate')/100;
|
|
|
|
$save['invoice_rate'] = (I('invoice_rate') ?: 0)/100;
|
|
|
|
$save['is_sign_contract'] = I('is_sign_contract');
|
|
|
|
$save['settlement_type'] = I('settlement_type');
|
|
|
|
$save['has_game_evidence'] = I('has_game_evidence');
|
|
|
|
$save['company_type'] = I('company_type');
|
|
|
|
$save['remark'] = I('remark');
|
|
|
|
if (!empty(I('file_info'))) {
|
|
|
|
$save['file_info'] = I('file_info');
|
|
|
|
}
|
|
|
|
|
|
|
|
$save['uid'] = UID;
|
|
|
|
$save['create_time'] = $time;
|
|
|
|
$save['last_up_time'] = $time;
|
|
|
|
|
|
|
|
$res = $model->add($save);
|
|
|
|
if ($res) {
|
|
|
|
\Think\Log::actionLog('Partner/add', 'partner', $res);
|
|
|
|
$this->success('保存成功', U('lists'));
|
|
|
|
} else {
|
|
|
|
$this->error('保存失败');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Partner/add'])->find());
|
|
|
|
$this->meta_title = '新增合作方';
|
|
|
|
$this->display();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//编辑
|
|
|
|
public function edit()
|
|
|
|
{
|
|
|
|
$model = M($this->modelName, 'tab_');
|
|
|
|
|
|
|
|
if ($_POST) {
|
|
|
|
$partner = I('post.partner', '');
|
|
|
|
$status = intval(I('post.status', 1));
|
|
|
|
$id = intval(I('post.id', 0));
|
|
|
|
|
|
|
|
if (empty($partner)) {
|
|
|
|
$this->error('请输入合作方名称');
|
|
|
|
}
|
|
|
|
if (!strlen(I('is_sign_contract'))) {
|
|
|
|
$this->error('请选择是否签署合同');
|
|
|
|
}
|
|
|
|
if (empty(I('settlement_type'))) {
|
|
|
|
$this->error('请选择结算方式');
|
|
|
|
}
|
|
|
|
if (empty(I('company_type'))) {
|
|
|
|
$this->error('请输入公司性质');
|
|
|
|
}
|
|
|
|
if (!strlen(I('has_game_evidence'))) {
|
|
|
|
$this->error('请选择是否有游戏资质');
|
|
|
|
}
|
|
|
|
if (empty(I('link_man'))) {
|
|
|
|
$this->error('请输入联系人');
|
|
|
|
}
|
|
|
|
if (empty(I('link_phone'))) {
|
|
|
|
$this->error('请输入联系电话');
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = $model
|
|
|
|
->field('id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank')
|
|
|
|
->find($id);
|
|
|
|
if (empty($data)) {
|
|
|
|
$this->error('数据异常');
|
|
|
|
}
|
|
|
|
|
|
|
|
$map['partner'] = $partner;
|
|
|
|
$res = $model->where($map)->getField('id');
|
|
|
|
if ($res && $res != $id) {
|
|
|
|
$this->error('合作方已存在');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!checkPhone(I('link_phone'))) {
|
|
|
|
$this->error('联系电话格式不正确');
|
|
|
|
}
|
|
|
|
$res2 = $model->where([
|
|
|
|
'link_phone' => I('link_phone'),
|
|
|
|
'id' => ['neq', $id]
|
|
|
|
])->getField('id');
|
|
|
|
|
|
|
|
if ($res2) {
|
|
|
|
$this->error('已存在此联系电话');
|
|
|
|
}
|
|
|
|
$time = time();
|
|
|
|
$save['id'] = $id;
|
|
|
|
$save['partner'] = $partner;
|
|
|
|
|
|
|
|
$save['link_man'] = I('link_man');
|
|
|
|
$save['link_phone'] = I('link_phone');
|
|
|
|
$save['address'] = I('address');
|
|
|
|
$save['company_tax_no'] = I('company_tax_no');
|
|
|
|
$save['payee_name'] = I('payee_name');
|
|
|
|
$save['bank_account'] = I('bank_account');
|
|
|
|
$save['opening_bank'] = I('opening_bank');
|
|
|
|
|
|
|
|
$save['matche_platform'] = I('matche_platform');
|
|
|
|
$save['contract_start_time'] = strtotime(I('contract_start_time'));
|
|
|
|
$save['contract_end_time'] = strtotime(I('contract_end_time'));
|
|
|
|
$save['channel_rate'] = I('channel_rate')/100;
|
|
|
|
$save['invoice_rate'] = (I('invoice_rate') ?: 0)/100;
|
|
|
|
|
|
|
|
$save['is_sign_contract'] = I('is_sign_contract');
|
|
|
|
$save['settlement_type'] = I('settlement_type');
|
|
|
|
$save['has_game_evidence'] = I('has_game_evidence');
|
|
|
|
$save['company_type'] = I('company_type');
|
|
|
|
$save['remark'] = I('remark');
|
|
|
|
$save['file_info'] = I('file_info');
|
|
|
|
|
|
|
|
$save['status'] = $status;
|
|
|
|
$save['last_up_time'] = $time;
|
|
|
|
$res = $model->save($save);
|
|
|
|
if ($res === false) {
|
|
|
|
$this->error('保存失败');
|
|
|
|
} else {
|
|
|
|
\Think\Log::actionLog('Partner/edit', 'partner', $id);
|
|
|
|
$this->success('保存成功', U('lists'));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$id = intval(I('get.id', 0));
|
|
|
|
$map['id'] = $id;
|
|
|
|
$data = $model
|
|
|
|
->find($id);
|
|
|
|
if (empty($data)) {
|
|
|
|
$this->error('数据异常', U('lists'));
|
|
|
|
}
|
|
|
|
if ($data['contract_start_time']) {
|
|
|
|
$data['contract_start_time'] = date('Y-m-d', $data['contract_start_time']);
|
|
|
|
}
|
|
|
|
if ($data['contract_end_time']) {
|
|
|
|
$data['contract_end_time'] = date('Y-m-d', $data['contract_end_time']);
|
|
|
|
}
|
|
|
|
$data['channel_rate'] *= 100;//存的是小数,显示百分比
|
|
|
|
$data['invoice_rate'] *= 100;//存的是小数,显示百分比
|
|
|
|
// dd($data);
|
|
|
|
$this->assign('data', $data);
|
|
|
|
$action = I('action');
|
|
|
|
$this->assign('action', $action);
|
|
|
|
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Partner/edit'])->find());
|
|
|
|
$this->meta_title = $action ? '查看合作方' : '编辑合作方';
|
|
|
|
$this->display($action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//删除
|
|
|
|
public function del()
|
|
|
|
{
|
|
|
|
if (!empty($_POST['ids'])) {
|
|
|
|
if (!is_array($_POST['ids'])) {
|
|
|
|
$this->error('参数异常');
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = implode(',', $_POST['ids']);
|
|
|
|
} else {
|
|
|
|
$id = intval(I('get.id', 0));
|
|
|
|
if ($id == 0) {
|
|
|
|
$this->error('参数异常');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$res = M($this->modelName, 'tab_')->delete($id);
|
|
|
|
if ($res === false) {
|
|
|
|
$this->error('删除失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->success('删除成功', U('lists'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|