赛亿提成统计系统

Company.php 1.9KB

    <?php namespace app\index\controller; use daswork\Controller; use daswork\lib\Config; use app\index\model\MonthPicker; use app\index\model\Commission; use app\index\model\Company as CompanyModel; class Company extends Controller { private $model; public function __construct() { parent::__construct(); $this->model = new CompanyModel(); } public function index() { $key = isset($_GET['key']) ? $_GET['key'] : ''; $where = ''; if ($key) { $where = "WHERE name LIKE '$key%' "; $this->assign('key', $key); } $page = isset($_GET['page']) ? escapeString($_GET['page']) : 1; $data = $this->model->pageList($where, $page, 20); $this->assign("data", $data); $this->fetch(); } public function save() { $params = escapeString($_POST); $id = $params['id']; $name = $params['name']; $initial_balance = $params['initial_balance']; if ($id) { $res = $this->model->exec("UPDATE `company` SET `name`='$name', `initial_balance`='$initial_balance' WHERE `id`=$id;"); // var_dump($res); } else { $res = $this->model->exec("INSERT INTO `company`(`name`,`initial_balance`) VALUES('" . $name . "','" . $initial_balance . "');"); } if ($res===false) { echo json_encode(['code' => 1, "msg"=>$this->model->lastErrorMsg()]); } else { echo json_encode(['code' => 0, "msg"=>"操作成功"]); } } public function delete() { $id = escapeString($_POST['id']); $res = $this->model->exec("DELETE FROM `company` WHERE `id`=$id;"); if ($res===false) { echo json_encode(['code' => 1, "msg"=>$this->model->lastErrorMsg()]); } else { echo json_encode(['code' => 0, "msg"=>"操作成功"]); } } }