PriceAdjustCate.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\finance\controller;
  4. use app\base\BaseController;
  5. use app\finance\model\PriceAdjustCate as PriceAdjustCateModel;
  6. use think\facade\View;
  7. class PriceAdjustCate extends BaseController
  8. {
  9. protected $model;
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. $this->model = new PriceAdjustCateModel();
  14. }
  15. public function datalist()
  16. {
  17. if (request()->isAjax()) {
  18. $param = get_params();
  19. $type = isset($param['type']) ? (int) $param['type'] : 0;
  20. $where = [['delete_time', '=', 0]];
  21. if ($type > 0) {
  22. $where[] = ['type', '=', $type];
  23. }
  24. $list = $this->model->where($where)->order('sort asc, id asc')->select();
  25. return to_assign(0, '', $list);
  26. }
  27. return view();
  28. }
  29. public function add()
  30. {
  31. $param = get_params();
  32. if (request()->isAjax()) {
  33. if (!empty($param['id']) && $param['id'] > 0) {
  34. $this->model->edit($param);
  35. } else {
  36. $this->model->add($param);
  37. }
  38. } else {
  39. $id = isset($param['id']) ? (int) $param['id'] : 0;
  40. if ($id > 0) {
  41. View::assign('detail', $this->model->getById($id));
  42. }
  43. return view();
  44. }
  45. }
  46. public function set()
  47. {
  48. if (request()->isAjax()) {
  49. $param = get_params();
  50. $res = $this->model->strict(false)->field('id,status')->update($param);
  51. if ($res) {
  52. add_log($param['status'] == 1 ? 'recovery' : 'disable', $param['id'], $param);
  53. return to_assign();
  54. }
  55. return to_assign(0, '操作失败');
  56. }
  57. return to_assign(1, '错误的请求');
  58. }
  59. public function del()
  60. {
  61. if (request()->isDelete()) {
  62. $param = get_params();
  63. $id = isset($param['id']) ? (int) $param['id'] : 0;
  64. return $this->model->delById($id);
  65. }
  66. return to_assign(1, '错误的请求');
  67. }
  68. }