AmountStandard.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace app\admin\controller;
  8. use app\admin\common\AdminController;
  9. use think\facade\Db;
  10. use app\common\api\Response;
  11. use app\common\api\DictApi;
  12. /**
  13. * Description of AmountStandard
  14. *
  15. * @author sgq
  16. */
  17. class AmountStandard extends AdminController {
  18. public function index() {
  19. return view("");
  20. }
  21. public function list() {
  22. $params = $this->request->param();
  23. $order = $params["order"] ?: "asc";
  24. $offset = $params["offset"] ?: 0;
  25. $limit = $params["limit"] ?: 10;
  26. $where[] = ["type", "=", $this->user["type"]];
  27. if ($params["allowanceType"]) {
  28. $where[] = ["allowanceType", "=", $params["allowanceType"]];
  29. }
  30. $count = Db::table("sys_amount_standard")->where($where)->count();
  31. $list = Db::table("sys_amount_standard")->where($where)->limit($offset, $limit)->order("createTime " . $order)->select()->toArray();
  32. $levelMap = DictApi::selectByParentCode("talent_arrange");
  33. foreach ($list as &$item) {
  34. $item["talentArrangeName"] = $levelMap[$item["talentArrange"]];
  35. }unset($item);
  36. return json(["total" => $count, "rows" => $list]);
  37. }
  38. public function add() {
  39. if ($this->request->isPost()) {
  40. return $this->save();
  41. }
  42. return view("edit", ["type" => $this->user["type"]]);
  43. }
  44. public function edit() {
  45. $info = Db::table("sys_amount_standard")->where("id", $this->request["id"])->find();
  46. if ($this->request->isPost()) {
  47. return $this->save();
  48. }
  49. return view("", ["info" => $info, "type" => $this->user["type"]]);
  50. }
  51. public function detail() {
  52. $info = Db::table("sys_amount_standard")->where("id", $this->request["id"])->find();
  53. return view("", ["info" => $info, "type" => $this->user["type"]]);
  54. }
  55. public function delete() {
  56. if (!$this->request["id"])
  57. return new Response(Response::ERROR, "删除失败");
  58. Db::table("sys_amount_standard")->where("id", $this->request["id"])->delete();
  59. return new Response(Response::SUCCESS, "删除成功");
  60. }
  61. private function save() {
  62. $param = $this->request->param();
  63. if (!$param) {
  64. return new Response(Response::ERROR, "请填写相关信息");
  65. }
  66. if (!$param["money"] || !is_numeric($param["money"]) || $param["money"] < 0) {
  67. return new Response(Response::ERROR, "金额填写错误");
  68. }
  69. $data["type"] = $this->user["type"];
  70. $data["allowanceType"] = $param["allowanceType"];
  71. $data["talentArrange"] = $param["talentArrange"];
  72. $data["money"] = $param["money"];
  73. $data["description"] = $param["description"];
  74. try {
  75. if ($param["id"]) {
  76. $data["id"] = $param["id"];
  77. $data["updateTime"] = date("Y-m-d H:i:s");
  78. $data["updateUser"] = $this->user["uid"];
  79. Db::table("sys_amount_standard")->save($data);
  80. $msg = "修改成功";
  81. } else {
  82. $data["id"] = getStringId();
  83. $data["createTime"] = date("Y-m-d H:i:s");
  84. $data["createUser"] = $this->user["uid"];
  85. Db::table("sys_amount_standard")->insert($data);
  86. $msg = "添加成功";
  87. }
  88. return new Response(Response::SUCCESS, $msg);
  89. } catch (\think\db\exception\DbException $ex) {
  90. return new Response(Response::ERROR, "数据异常,操作失败:" . $ex->getCode());
  91. }
  92. }
  93. }