138 lines
4.2 KiB
PHP
Executable File
138 lines
4.2 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: ORICO
|
|
* Date: 2019-01-15
|
|
* Time: 11:01
|
|
*/
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use think\Lang;
|
|
use think\Loader;
|
|
use think\Config;
|
|
|
|
class Agents extends BaseController
|
|
{
|
|
|
|
|
|
private function init_search(&$search){
|
|
$search['name'] = '';
|
|
$search['timebegin'] = '';
|
|
$search['timeend'] = '';
|
|
}
|
|
public function lists(){
|
|
$agent = Db('agents');
|
|
|
|
$data = $this->request->param();
|
|
$arg_where = ['siteid' => $this->siteid,'stat' => ['in','0,1'], 'country_code' => $this->country_code];
|
|
|
|
$search = [];
|
|
$this->init_search($search);
|
|
if (isset($data['name']) && $data['name'] != ''){
|
|
$arg_where['name|interest|phone'] = ['like', "%$data[name]%"];
|
|
$search['name'] = $data['name'];
|
|
}
|
|
|
|
|
|
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
|
|
// 时间有一个不为空就初始化
|
|
$arg_where['createtime'] = [];
|
|
if (isset($data['timebegin']) && $data['timebegin'] != '')
|
|
{
|
|
$time = $data['timebegin'];
|
|
array_push($arg_where['createtime'], ['>=', $time]);
|
|
$search['timebegin'] = $data['timebegin'];
|
|
}
|
|
else{
|
|
array_push($arg_where['createtime'], ['>=', "0000-00-00"]);
|
|
}
|
|
|
|
if (isset($data['timeend']) && $data['timeend'] != '')
|
|
{
|
|
$time = $data['timeend'];
|
|
array_push($arg_where['createtime'], ['<=', $time]);
|
|
$search['timeend'] = $data['timeend'];
|
|
}
|
|
else{
|
|
|
|
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
|
|
array_push($arg_where['createtime'], ['<=', $time]);
|
|
}
|
|
}
|
|
//
|
|
|
|
|
|
//$where = ['stat'=>0];
|
|
$list = $agent->where($arg_where)->select();
|
|
$count = count($list);
|
|
$list = $agent->where($arg_where)->paginate(20,$count);
|
|
$page = $list->render();
|
|
//dump($page);die;
|
|
$this->assign('search',$search);
|
|
$this->assign('page',$page);
|
|
$this->assign('list',$list);
|
|
|
|
return $this->fetch();
|
|
|
|
}
|
|
|
|
public function edit(){
|
|
$where = ['id '=>$_GET['id'],'stat'=>0];
|
|
$agent = Db('agents');
|
|
$data = $agent->where($where)->find();
|
|
$this->assign('data',$data);
|
|
return $this->fetch();
|
|
}
|
|
public function save(){
|
|
$data = $_POST;
|
|
$adent = Db('agents');
|
|
$inster = $adent->insert($data);
|
|
if($inster){
|
|
return $this->success('修改成功');
|
|
}else{
|
|
return $this->error('修改失败');
|
|
}
|
|
}
|
|
public function view($id = 0){
|
|
$id = intval($id);
|
|
$where = ['id '=>$id];
|
|
$agent = Db('agents');
|
|
$data = $agent->where($where)->find();
|
|
$this->assign('data',$data);
|
|
return $this->fetch();
|
|
}
|
|
|
|
|
|
//2021-05-29 申邵 控制删除
|
|
public function delete($id = 0) {
|
|
//echo "<pre>====="; print_r($id);die;
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$result = model('agents')->deleteRow($id);
|
|
|
|
if ($result) {
|
|
//echo $id."<pre>=+++++++++"; print_r($result);die;
|
|
return $this->success(Lang::get('operation successed'), url('/admin/agent/lists'));
|
|
} else {
|
|
//echo "<pre>====="; print_r($result);die;
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function deletes() {
|
|
$ids = $this->request->post('ids');
|
|
if ($this->request->isPost() && $ids) {
|
|
$result = model('agents')->deleteRows($ids);
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/agent/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
} |