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.
315 lines
10 KiB
PHP
315 lines
10 KiB
PHP
<?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;
|
|
}
|
|
|
|
$page = intval(I('get.p', 0));
|
|
$page = $page ? $page : 1; //默认显示第一页数据
|
|
$row = intval(I('row', 0));
|
|
$row = empty($row) ? 10 : $row;//每页条数
|
|
|
|
$data = $model->alias('p')
|
|
->field('p.id,p.partner,p.status,p.create_time,link_man,link_phone,address,company_tax_no,payee_name,
|
|
bank_account,opening_bank,m.nickname')
|
|
->join('left join sys_member as m on m.uid = p.uid')
|
|
->where($map)
|
|
->order('id desc')
|
|
->page($page, $row)
|
|
->select();
|
|
|
|
/* 查询记录总数 */
|
|
$count = $model
|
|
->where($map)
|
|
->count();
|
|
|
|
if (!empty($data)) {
|
|
foreach ($data as &$list) {
|
|
$list['status'] = ($list['status'] == 0) ? '已关闭' : '已开启';
|
|
$list['create_time'] = date('Y-m-d H:i:s', $list['create_time']);
|
|
}
|
|
}
|
|
|
|
//分页
|
|
$parameter['p'] = $page;
|
|
$parameter['row'] = $row;
|
|
$page = set_pagination($count, $row, $parameter);
|
|
if ($page) {
|
|
$this->assign('_page', $page);
|
|
}
|
|
|
|
$this->assign('listData', $data);
|
|
$this->assign('count', $count);
|
|
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Partner/lists'])->find());
|
|
$this->meta_title = '合作方管理';
|
|
$this->display();
|
|
}
|
|
|
|
//添加
|
|
public function add()
|
|
{
|
|
if ($_POST) {
|
|
dd($_REQUEST);
|
|
$partner = I('post.partner', '');
|
|
$status = intval(I('post.status', 1));
|
|
|
|
if (empty($partner)) {
|
|
$this->error('请输入合作方名称');
|
|
}
|
|
if (empty(I('link_man'))) {
|
|
$this->error('请输入联系人');
|
|
}
|
|
if (empty(I('link_phone'))) {
|
|
$this->error('请输入联系电话');
|
|
}
|
|
if (!in_array($status, [0, 1])) {
|
|
$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');
|
|
$save['invoice_rate'] = I('invoice_rate');
|
|
$save['is_sign_contract'] = I('is_sign_contract');
|
|
$save['settlement_type'] = I('settlement_type');
|
|
$save['has_game_evidence'] = I('has_game_evidence');
|
|
$save['remark'] = I('remark');
|
|
if (isset($save['file_info'])) {
|
|
$save['file_info'] = json_encode($save['file_info'],JSON_UNESCAPED_UNICODE);
|
|
}
|
|
|
|
$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 (empty(I('link_man'))) {
|
|
$this->error('请输入联系人');
|
|
}
|
|
if (empty(I('link_phone'))) {
|
|
$this->error('请输入联系电话');
|
|
}
|
|
if (!in_array($status, [0, 1]) || $id == 0) {
|
|
$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['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
|
|
->field('id,partner,status,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank')
|
|
->find($id);
|
|
if (empty($data)) {
|
|
$this->error('数据异常', U('lists'));
|
|
}
|
|
|
|
$this->assign('config', $data);
|
|
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Partner/edit'])->find());
|
|
$this->meta_title = '编辑合作方';
|
|
$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 addfile()
|
|
{
|
|
$this->meta_title = '文档添加';
|
|
return $this->display();
|
|
}
|
|
|
|
//处理上传图片
|
|
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...
|
|
}
|
|
|
|
}
|