赛亿提成统计系统

Company.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\index\controller;
  3. use daswork\Controller;
  4. use daswork\lib\Config;
  5. use app\index\model\MonthPicker;
  6. use app\index\model\Commission;
  7. use app\index\model\Company as CompanyModel;
  8. class Company extends Controller
  9. {
  10. private $model;
  11. protected $params;
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. $this->model = new CompanyModel();
  16. $this->params = escapeString($_POST);
  17. }
  18. public function index()
  19. {
  20. $name = isset($_GET['company_name']) ? $_GET['company_name'] : '';
  21. $data = $this->model->listByName($name, "name");
  22. $this->assign("data", $data);
  23. $this->assign("company_name", $name);
  24. $this->fetch();
  25. }
  26. public function save()
  27. {
  28. $id = $this->params['id'];
  29. $name = $this->params['name'];
  30. $initial_balance = $this->params['initial_balance'];
  31. if ($id) {
  32. $res = $this->model->exec("UPDATE `company` SET `name`='$name', `initial_balance`='$initial_balance' WHERE `id`=$id;");
  33. // var_dump($res);
  34. } else {
  35. $res = $this->model->exec("INSERT INTO `company`(`name`,`initial_balance`) VALUES('" . $name . "','" . $initial_balance . "');");
  36. }
  37. if ($res===false) {
  38. echo json_encode(['code' => 1, "msg"=>$this->model->lastErrorMsg()]);
  39. } else {
  40. echo json_encode(['code' => 0, "msg"=>"操作成功"]);
  41. }
  42. }
  43. public function delete()
  44. {
  45. $res = $this->model->exec("DELETE FROM `company` WHERE `id`=$this->params['id'];");
  46. if ($res===false) {
  47. echo json_encode(['code' => 1, "msg"=>$this->model->lastErrorMsg()]);
  48. } else {
  49. echo json_encode(['code' => 0, "msg"=>"操作成功"]);
  50. }
  51. }
  52. }