12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?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;
- protected $params;
- public function __construct()
- {
- parent::__construct();
- $this->model = new CompanyModel();
- $this->params = escapeString($_POST);
- }
- public function index()
- {
- $name = isset($_GET['company_name']) ? $_GET['company_name'] : '';
- $data = $this->model->listByName($name, "name");
- $this->assign("data", $data);
- $this->assign("company_name", $name);
- $this->fetch();
- }
- public function save()
- {
- $id = $this->params['id'];
- $name = $this->params['name'];
- $initial_balance = $this->params['initial_balance'];
- if ($id) {
- $res = $this->model->exec("UPDATE `company` SET `name`='$name', `initial_balance`='$initial_balance' WHERE `id`=$id;");
-
- } 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()
- {
- $res = $this->model->exec("DELETE FROM `company` WHERE `id`=$this->params['id'];");
- if ($res===false) {
- echo json_encode(['code' => 1, "msg"=>$this->model->lastErrorMsg()]);
- } else {
- echo json_encode(['code' => 0, "msg"=>"操作成功"]);
- }
- }
- }
|