200 lines
6.5 KiB
PHP
200 lines
6.5 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: xuxb
|
|
* Date: 2021/7/30
|
|
* Time: 10:52
|
|
*/
|
|
class Finance extends HD_Controller{
|
|
protected $log_dir;
|
|
|
|
function __construct(){
|
|
parent::__construct();
|
|
|
|
$this->load->model("sys/sys_finance_model", 'finance_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']}%')"] = 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->finance_model->status_ary();
|
|
|
|
$count = $this->finance_model->count($where);
|
|
$lists = array();
|
|
if($count){
|
|
$orderby = 'id desc';
|
|
$select = 'id, title, money_min, money_max, first_pay, month_min, month_max, status';
|
|
$rows = $this->finance_model->select($where, $orderby, $page, $size, $select);
|
|
foreach($rows as $k => $v){
|
|
$lists[] = array(
|
|
'id' => $v['id'],
|
|
'title' => $v['title'],
|
|
'money' => "{$v['money_min']}-{$v['money_max']}",
|
|
'first_pay' => $v['first_pay'],
|
|
"month" => "{$v['month_min']}-{$v['month_max']}",
|
|
'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/finance/lists',true);
|
|
}
|
|
|
|
public function get(){
|
|
$id = $this->input->get('id');
|
|
if($id){
|
|
$row = $this->finance_model->get(array('id' => $id));
|
|
$info = array(
|
|
'id' => $row['id'],
|
|
'title' => $row['title'],
|
|
'logo' => $row['logo'],
|
|
'logo_url' => $row['logo'] ? build_qiniu_image_url($row['logo']) : '',
|
|
'money_min' => $row['money_min'],
|
|
'money_max' => $row['money_max'],
|
|
'first_pay' => $row['first_pay'],
|
|
'month_min' => $row['month_min'],
|
|
'month_max' => $row['month_max'],
|
|
'status' => $row['status'],
|
|
);
|
|
$action = '/sys/finance/edit';
|
|
$title = '编辑金融产品';
|
|
} else {
|
|
$info = array(
|
|
'title' => '',
|
|
'status' => 0,
|
|
);
|
|
$action = '/sys/finance/add';
|
|
$title = '新增金融产品';
|
|
}
|
|
|
|
$this->data['info'] = $info;
|
|
$this->data['action'] = $action;
|
|
$this->data['statusAry'] = $this->finance_model->status_ary();
|
|
$this->data['_title'] = $title;
|
|
$this->show_view('sys/finance/get');
|
|
}
|
|
|
|
public function add(){
|
|
$info = $this->input->post('info');
|
|
$title = trim($info['title']);
|
|
if(!$title){
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入标题');
|
|
}
|
|
|
|
$where = array("title like '{$title}'" => null);
|
|
$count = $this->finance_model->count($where);
|
|
if($count>0){
|
|
return $this->show_json(SYS_CODE_FAIL, '产品已经存在');
|
|
}
|
|
|
|
$add = array(
|
|
'title' => $title,
|
|
'logo' => $info['logo'] ? $info['logo'] : '',
|
|
'money_min' => floatval($info['money_min']),
|
|
'money_max' => floatval($info['money_max']),
|
|
'first_pay' => floatval($info['first_pay']),
|
|
'month_min' => intval($info['month_min']),
|
|
'month_max' => intval($info['month_max']),
|
|
'status' => intval($info['status']),
|
|
);
|
|
|
|
$id = $this->finance_model->add($add);
|
|
if(!$id){
|
|
debug_log("[error]# " . $this->finance_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']);
|
|
if(!$title){
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入产品名称');
|
|
}
|
|
|
|
$where = array("title like '{$title}'" => null, "id<>{$info['id']}" => null);
|
|
$count = $this->finance_model->count($where);
|
|
if($count>0){
|
|
return $this->show_json(SYS_CODE_FAIL, '产品已存在');
|
|
}
|
|
|
|
$upd = array(
|
|
'title' => $title,
|
|
'logo' => $info['logo'] ? $info['logo'] : '',
|
|
'money_min' => floatval($info['money_min']),
|
|
'money_max' => floatval($info['money_max']),
|
|
'first_pay' => floatval($info['first_pay']),
|
|
'month_min' => intval($info['month_min']),
|
|
'month_max' => intval($info['month_max']),
|
|
'status' => intval($info['status']),
|
|
);
|
|
|
|
$ret = $this->finance_model->update($upd, array('id' => $info['id']));
|
|
if(!$ret){
|
|
debug_log("[error]# " . $this->finance_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->finance_model->update($upd, $where);
|
|
if(!$ret){
|
|
debug_log("[error]# " . $this->finance_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.
|
|
}
|
|
}
|