You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

402 lines
14 KiB
PHTML

5 years ago
<?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 PromoteCompanyController extends ThinkController
{
private $modelName = 'PromoteCompany';
//列表
public function lists()
{
$model = M($this->modelName, 'tab_');
$map = [];
$company_name = trim(I('company_name'));
if($company_name)
$map['tab_promote_company.company_name'] = array('like',"%{$company_name}%");
5 years ago
if (isset($_REQUEST['status']) && $_REQUEST['status'] !== '') {
$status = intval($_REQUEST['status']);
$map['tab_promote_company.status'] = $status;
$parameter['status'] = $status;
}
$page = intval(I('get.p', 0));
$page = $page ? $page : 1; //默认显示第一页数据
$row = intval(I('row', 0));
$row = empty($row) ? 10 : $row;//每页条数
//获取分页公司数据
$companyres = $model->field("*")
->where($map)
->order("last_up_time desc")
->page($page,$row)
->select();
//获取公司id
$companyids = implode(',', array_column($companyres, 'id'));
// //处理公司数据
// $company = array();
// foreach($companyres as $k=>$v){
// $company[]
// }
//获取所属会长及其游戏分成
$promoteres = M("Promote","tab_")
->field("id,company_id,account,settlement_type")
->where(array(
"company_id"=>["in",$companyids]
))
->select();
//获取会长id
$promoteids = implode(',', array_column($promoteres, 'id'));
//获取游戏比例
$gameradiores = M("PromoteGameRatio","tab_")
->alias("pg")
->field("pg.ratio,pg.relation_game_id,pg.turnover_ratio,pg.game_id,pg.promote_id,ga.relation_game_name,ga.game_type_name")
->join("tab_game ga ON pg.game_id = ga.id")
->where(array(
"status"=>1,
"promote_id"=>["in",$promoteids]
))
->group("relation_game_id,promote_id")
->select();
//比例数据处理
$gameradiotemp = array();
foreach($gameradiores as $k=>$v){
$turnover_ratio = json_decode($v['turnover_ratio'],true);
$v['turnover_ratio'] = array(
array("ratio"=>$v['ratio'],"name"=>"默认比例")
);
foreach($turnover_ratio as $ke=>$va){
$t=array("ratio"=>$va["ratio"]);
if(array_key_exists("instanceof",$va)){
//存在
if($va['instanceof']=='1'){
$t['name']="月流水≥".$va['turnover'];
}else{
$t['name']="月流水>".$va['turnover'];
}
}else{
$t['name']="月流水≥".$va['turnover'];
}
$v['turnover_ratio'][]=$t;
}
$v['row'] = count($v['turnover_ratio']);
unset($v["ratio"]);
unset($v["relation_game_id"]);
unset($v["game_id"]);
$gameradiotemp[$v['promote_id']][]=$v;
}
unset($gameradiores);
//会长数据处理
$promoterestemp=[];
foreach($promoteres as $k=>$v){
if(array_key_exists($v['id'],$gameradiotemp)){
//存在
$v['list'] = $gameradiotemp[$v['id']];
foreach($gameradiotemp[$v['id']] as $ke=>$va){
$v['row'] += $va['row'];
}
}else{
$v['list']=[
["relation_game_name"=>"--","game_type_name"=>"--",
"turnover_ratio"=>[
["name"=>"--","ratio"=>"--"]
],
"row"=>1
]
];
$v["row"]=1;
}
if($v['settlement_type'] == 1){
$v['settlement_type']="周结";
}else{
$v['settlement_type']="月结";
}
$promoterestemp[$v['company_id']]["list"][]=$v;
}
unset($promoteres);
//处理公司数据
foreach($companyres as $k=>&$v){
if(array_key_exists($v['id'],$promoterestemp)){
//存在
$v['list'] = $promoterestemp[$v['id']]['list'];
foreach($promoterestemp[$v['id']] as $ke=>$va){
foreach($va as $key=>$val){
$v['row'] += $val['row'];
}
}
}else{
//空值
$v['list']=[
[
"account"=>"--",
"settlement_type"=>"--",
'list'=>[
[
"relation_game_name"=>"--",
"game_type_name"=>"--",
"turnover_ratio"=>[
["name"=>"--","ratio"=>"--"]
],
"row"=>1
]
]
]
];
$v['row'] += 1;
}
if( $v["contact_begin"] >0 ){
$v["contact_begin"] = date('Y/m/d', $v["contact_begin"]);
}else{
$v["contact_begin"] = "--";
}
if( $v["contact_end"] > 0){
$v["contact_end"] = date('Y/m/d', $v["contact_end"]);
}else{
$v["contact_end"] = "--";
}
if($v['platform_name'] == '' || $v['platform_name'] == "0"){
$v['platform_name'] = "--";
}
$v["is_sign_contact"] = ($v["is_sign_contact"]=="1" ? "是" :'否');
}
// dd($companyres);
5 years ago
/* 查询记录总数 */
$count = $model
->where($map)
->count();
//分页
$parameter['p'] = $page;
$parameter['row'] = $row;
$page = set_pagination($count, $row, $parameter);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('listData', $companyres);
5 years ago
$this->assign('count', $count);
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Partner/lists'])->find());
$this->meta_title = '推广公司';
5 years ago
$this->display();
}
//添加
public function add()
{
if ($_POST) {
$company_name = I('post.company_name', '');
$model = M($this->modelName, 'tab_');
$map['company_name'] = $company_name;
$res = $model->where($map)->getField('id');
if ($res) {
$this->ajaxReturn(array(
'status' => 0,
'info' => "推广公司已经存在"
));
5 years ago
}
$time = time();
$save = I('post.');//前端已经验证
5 years ago
$save['create_time'] = $time;
$save['last_up_time'] = $time;
if(isset($save['resources'])){
$save['resources'] = json_encode($save['resources'],JSON_UNESCAPED_UNICODE);
}
5 years ago
$res = $model->add($save);
if ($res) {
\Think\Log::actionLog('PromoteCompany/add', 'partner', $res);
$array=array(
"info"=>"添加成功",
"status"=>1
);
$this->ajaxReturn($array);
5 years ago
} else {
$this->ajaxReturn(array(
'status' => 0,
'info' => "保存失败"
));
5 years ago
}
} else {
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'PromoteCompany/add'])->find());
$this->meta_title = '新增推广公司';
$this->display();
}
}
//编辑
public function edit()
{
$model = M($this->modelName, 'tab_');
if ($_POST) {
$company_name = I('post.company_name', '');
$status = intval(I('post.status', 1));
$id = intval(I('post.id', 0));
if (empty($company_name)) {
5 years ago
$this->error('请输入推广公司名称');
5 years ago
}
5 years ago
if (empty(I('post.settlement_contact'))) {
$this->error('请输入结算联系人');
}
if (empty(I('post.contact_phone'))) {
$this->error('请输入联系人电话');
}
$pattern = "/^1[3|4|5|6|7|8|9]\\d{9}$/i";//手机号验证修改
5 years ago
if(!preg_match($pattern, I('post.contact_phone'))) {
$this->error("手机号码格式不合法");
return false;
}
if (empty(I('post.address'))) {
$this->error('请输入所在地址');
}
if (empty(I('post.bank_card'))) {
$this->error('请输入银行卡号');
}
$bank_card_pattern = "/^\d{10,19}$/u";
if (!preg_match($bank_card_pattern, I('post.bank_card'))) {
$this->error('卡号格式错误');
return false;
}
if (empty(I('post.bank_cardname'))) {
$this->error('请输入银行卡名');
}
if (empty(I('post.bank_name'))) {
$this->error('请输入收款银行');
}
if (empty(I('post.bank_address'))) {
$this->error('请输入开户网点');
}
5 years ago
if (!in_array($status, [0, 1]) || $id == 0) {
$this->error('参数异常');
}
5 years ago
if (!empty(I('post.content'))) {
$save['content'] = I('post.content');
}
5 years ago
$data = $model->field('id,company_name')->find($id);
if (empty($data)) {
$this->error('数据异常');
}
$map['company_name'] = $company_name;
$res = $model->where($map)->getField('id');
if ($res && $res != $id) {
5 years ago
$this->error('推广公司已存在');
5 years ago
}
$time = time();
$save['id'] = $id;
$save['company_name'] = $company_name;
$save['status'] = $status;
$save['last_up_time'] = $time;
5 years ago
$save['settlement_contact'] = I('post.settlement_contact');
$save['contact_phone'] = I('post.contact_phone');
$save['address'] = I('post.address');
$save['bank_card'] = I('post.bank_card');
$save['bank_cardname'] = I('post.bank_cardname');
$save['bank_name'] = I('post.bank_name');
$save['bank_address'] = I('post.bank_address');
5 years ago
$res = $model->save($save);
if ($res === false) {
$this->error('保存失败');
} else {
\Think\Log::actionLog('PromoteCompany/edit', 'PromoteCompany', $id);
$this->success('保存成功', U('lists'));
}
} else {
$id = intval(I('get.id', 0));
$map['id'] = $id;
5 years ago
$data = $model->field('id,company_name,status,settlement_contact,contact_phone,address,bank_card,bank_cardname,bank_name,bank_address,content')->find($id);
5 years ago
if (empty($data)) {
$this->error('数据异常', U('lists'));
}
$this->assign('data', $data);
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'PromoteCompany/edit'])->find());
5 years ago
$this->meta_title = '编辑推广公司';
5 years ago
$this->display();
}
}
//删除
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'));
}
//处理上传图片
public function saveFile()
{
$path = '/Uploads/';
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 0 ;// 设置附件上传大小
$upload->exts = '';// 设置附件上传类型
$upload->rootPath = '.'.$path; // 设置附件上传根目录
$upload->savePath = ''; // 设置附件上传(子)目录
// 上传文件
$info = $upload->upload();
// dump($info);
if(!$info) {// 上传错误提示错误信息
$msg = $upload->getError();
$array= array('status' => 0, 'info' => $msg);
}else{// 上传成功
$array=array(
"info"=>"上传成功",
"status"=>1,
"file_path"=>$path.$info['file']['savepath'].$info['file']['savename'],
"file_name"=>$_POST['file_name'],
"file_type"=>$_FILES['file']['type'],
"file_size"=>$_FILES['file']['size'],
"upload_time"=>date("Y-m-d H:i:s",time())
);
}
$this->ajaxReturn($array);
}
//删除图片
public function delFile()
{
$id = $_REQUEST['id'];
$index = $_REQUEST['index'] ?: false;
$file_path = $_REQUEST['file_path'] ?: false;
if($id == 0){
//未存入数据库,不用管
unlink("./".$file_path);
$this->ajaxReturn(array(
'status' => 1,
'info' => "删除成功"
));
}
# code...
}
5 years ago
}