204 lines
6.5 KiB
PHP
204 lines
6.5 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: xuxb
|
|
* Date: 2021/7/29
|
|
* Time: 17:38
|
|
*/
|
|
class Company extends HD_Controller{
|
|
|
|
protected $log_dir;
|
|
|
|
function __construct(){
|
|
parent::__construct();
|
|
|
|
$this->load->model("sys/sys_company_model", 'company_model');
|
|
|
|
$this->log_dir = 'sys_' . get_class($this);
|
|
}
|
|
|
|
public function index(){
|
|
return $this->lists();
|
|
}
|
|
|
|
public function lists(){
|
|
$params = $this->input->get();
|
|
|
|
$where = array();
|
|
if ($params['keyword']){
|
|
$where["(title like '%{$params['keyword']}%' or short like '%{$params['keyword']}%')"] = null;
|
|
}
|
|
|
|
if(strlen($params['status']) > 0){
|
|
$where['status'] = $params['status'];
|
|
} else {
|
|
$params['status'] = '';
|
|
}
|
|
|
|
$page = $params['page'];
|
|
$page = !$page ? 1 : $page;
|
|
$size = $params['size'];
|
|
$size = !$size ? 20 : $size;
|
|
|
|
$statusAry = $this->company_model->status_ary();
|
|
|
|
$count = $this->company_model->count($where);
|
|
$lists = array();
|
|
if($count){
|
|
$orderby = 'id desc';
|
|
$select = 'id, title, short, status';
|
|
$rows = $this->company_model->select($where, $orderby, $page, $size, $select);
|
|
foreach($rows as $k => $v){
|
|
$lists[] = array(
|
|
'id' => $v['id'],
|
|
'title' => $v['title'],
|
|
'short' => $v['short'],
|
|
'status' => $v['status'],
|
|
'status_name' => $statusAry[$v['status']],
|
|
);
|
|
}
|
|
}
|
|
|
|
$this->data['params'] = $params;
|
|
$this->data['lists'] = $lists;
|
|
$this->data['statusAry'] = $statusAry;
|
|
$this->data['pager'] = array('count'=>ceil($count/$size),'curr'=>$page,'totle'=>$count);
|
|
$this->data['_title'] = '公司管理';
|
|
$this->show_view('sys/company/lists',true);
|
|
}
|
|
|
|
public function get(){
|
|
$id = $this->input->get('id');
|
|
if($id){
|
|
$row = $this->company_model->get(array('id' => $id));
|
|
$info = array(
|
|
'id' => $row['id'],
|
|
'title' => $row['title'],
|
|
'short' => $row['short'],
|
|
'credit_code' => $row['credit_code'],
|
|
'wx_mchid' => $row['wx_mchid'],
|
|
'img_seal' => $row['img_seal'],
|
|
'img_seal_url' => $row['img_seal'] ? build_qiniu_image_url($row['img_seal']) : '',
|
|
'status' => $row['status'],
|
|
);
|
|
$action = '/sys/company/edit';
|
|
$title = '编辑公司';
|
|
} else {
|
|
$info = array(
|
|
'title' => '',
|
|
'short' => '',
|
|
'credit_code' => '',
|
|
'wx_mchid' => '',
|
|
'status' => 0,
|
|
);
|
|
$action = '/sys/company/add';
|
|
$title = '新增公司';
|
|
}
|
|
|
|
$this->data['info'] = $info;
|
|
$this->data['action'] = $action;
|
|
$this->data['statusAry'] = $this->company_model->status_ary();
|
|
$this->data['_title'] = $title;
|
|
$this->show_view('sys/company/get');
|
|
}
|
|
|
|
public function add(){
|
|
$info = $this->input->post('info');
|
|
$title = trim($info['title']);
|
|
$short = trim($info['short']);
|
|
if(!$title){
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入公司名称');
|
|
}
|
|
if(!$short){
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入公司简称');
|
|
}
|
|
|
|
$where = array("title like '{$title}'" => null);
|
|
$count = $this->company_model->count($where);
|
|
if($count>0){
|
|
return $this->show_json(SYS_CODE_FAIL, '公司已存在');
|
|
}
|
|
|
|
$add = array(
|
|
'title' => $title,
|
|
'short' => $short,
|
|
'credit_code' => $info['credit_code'] ? $info['credit_code'] : '',
|
|
'wx_mchid' => $info['wx_mchid'] ? $info['wx_mchid'] : '',
|
|
'img_seal' => $info['img_seal'] ? $info['img_seal'] : '',
|
|
'status' => intval($info['status'])
|
|
);
|
|
|
|
$id = $this->company_model->add($add);
|
|
if(!$id){
|
|
debug_log("[error]# " . $this->company_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
return $this->show_json(SYS_CODE_FAIL, '保存失败');
|
|
}
|
|
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
}
|
|
|
|
public function edit(){
|
|
$info = $this->input->post('info');
|
|
$title = trim($info['title']);
|
|
$short = trim($info['short']);
|
|
if(!$title){
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入公司名称');
|
|
}
|
|
if(!$short){
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入公司简称');
|
|
}
|
|
|
|
$where = array("title like '{$title}'" => null, "id<>{$info['id']}" => null);
|
|
$count = $this->company_model->count($where);
|
|
if($count>0){
|
|
return $this->show_json(SYS_CODE_FAIL, '公司已存在');
|
|
}
|
|
|
|
$upd = array(
|
|
'title' => $title,
|
|
'short' => $short ? $short : '',
|
|
'credit_code' => $info['credit_code'] ? $info['credit_code'] : '',
|
|
'wx_mchid' => $info['wx_mchid'] ? $info['wx_mchid'] : '',
|
|
'img_seal' => $info['img_seal'] ? $info['img_seal'] : '',
|
|
'status' => intval($info['status'])
|
|
);
|
|
|
|
$ret = $this->company_model->update($upd, array('id' => $info['id']));
|
|
if(!$ret){
|
|
debug_log("[error]# " . $this->company_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
return $this->show_json(SYS_CODE_FAIL, '保存失败');
|
|
}
|
|
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
}
|
|
|
|
function edit_status(){
|
|
$id = $this->input->post('id');
|
|
$status = $this->input->post('status');
|
|
|
|
$upd = array('status' => $status);
|
|
$where = array('id' => $id);
|
|
|
|
$ret = $this->company_model->update($upd, $where);
|
|
if(!$ret){
|
|
debug_log("[error]# " . $this->company_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
return $this->show_json(SYS_CODE_FAIL, '保存失败');
|
|
}
|
|
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
}
|
|
|
|
public function del(){
|
|
// TODO: Implement del() method.
|
|
}
|
|
|
|
public function batch(){
|
|
// TODO: Implement batch() method.
|
|
}
|
|
|
|
public function export(){
|
|
// TODO: Implement export() method.
|
|
}
|
|
|
|
} |