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.
200 lines
6.1 KiB
PHP
200 lines
6.1 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 PromoteCompanyController extends ThinkController
|
|
{
|
|
private $modelName = 'PromoteCompany';
|
|
|
|
//列表
|
|
public function lists()
|
|
{
|
|
$model = M($this->modelName, 'tab_');
|
|
$map = [];
|
|
$id = intval(I('id', 0));
|
|
$company_name = trim(I('company_name'));
|
|
if (!empty($id)) {
|
|
$map['tab_promote_company.id'] = $id;
|
|
$parameter['id'] = $id;
|
|
}
|
|
if($company_name)
|
|
$map['tab_promote_company.company_name'] = array('like',"%{$company_name}%");
|
|
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;//每页条数
|
|
|
|
$data = $model
|
|
->field('tab_promote_company.id,tab_promote_company.company_name,tab_promote_company.status,
|
|
tab_promote_company.create_time,sys_member.nickname')
|
|
->join('left join sys_member on sys_member.uid = tab_promote_company.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) {
|
|
$company_name = I('post.company_name', '');
|
|
$status = intval(I('post.status', 1));
|
|
|
|
if (empty($company_name)) {
|
|
$this->error('请输入推广公司名称');
|
|
}
|
|
if (!in_array($status, [0, 1])) {
|
|
$this->error('参数异常');
|
|
}
|
|
|
|
$model = M($this->modelName, 'tab_');
|
|
$map['company_name'] = $company_name;
|
|
$res = $model->where($map)->getField('id');
|
|
if ($res) {
|
|
$this->error('推广公司已存在');
|
|
}
|
|
|
|
$time = time();
|
|
$save['company_name'] = $company_name;
|
|
$save['status'] = $status;
|
|
$save['uid'] = UID;
|
|
$save['create_time'] = $time;
|
|
$save['last_up_time'] = $time;
|
|
|
|
$res = $model->add($save);
|
|
if ($res) {
|
|
\Think\Log::actionLog('PromoteCompany/add', 'partner', $res);
|
|
$this->success('保存成功', U('lists'));
|
|
} else {
|
|
$this->error('保存失败');
|
|
}
|
|
} 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)) {
|
|
$this->error('请输入推广公司名称');
|
|
}
|
|
if (!in_array($status, [0, 1]) || $id == 0) {
|
|
$this->error('参数异常');
|
|
}
|
|
|
|
$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) {
|
|
$this->error('推广公司已存在');
|
|
}
|
|
|
|
$time = time();
|
|
$save['id'] = $id;
|
|
$save['company_name'] = $company_name;
|
|
$save['status'] = $status;
|
|
$save['last_up_time'] = $time;
|
|
|
|
$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;
|
|
$data = $model->field('id,company_name,status')->find($id);
|
|
if (empty($data)) {
|
|
$this->error('数据异常', U('lists'));
|
|
}
|
|
|
|
$this->assign('data', $data);
|
|
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'PromoteCompany/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'));
|
|
}
|
|
}
|