AmountStandard.php 3.6 KB

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