Currency.php 2.2 KB

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