FinanceController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\admin\controller\sys_manage;
  3. use app\controller\Curd;
  4. use app\model\Content;
  5. use support\exception\BusinessException;
  6. use support\Request;
  7. use support\Response;
  8. class FinanceController extends Curd
  9. {
  10. public function __construct()
  11. {
  12. $this->model = new Content();
  13. }
  14. public function info(Request $request): Response
  15. {
  16. $data = $this->model->where('content_category', 'FINANCE')->first();
  17. if (!empty($data->content_config_json)){
  18. $data->content_config_json = json_decode($data->content_config_json);
  19. }
  20. return json_success('', $data);
  21. }
  22. protected function updateInput(Request $request): array
  23. {
  24. $primary_key = $this->model->getKeyName();
  25. $id = $request->post($primary_key);
  26. $params = $request->post();
  27. if (is_array($params['content_config_json'])){
  28. $params['content_config_json'] = json_encode(array_filter($params['content_config_json'],function ($value){
  29. return ($value != '' && $value != ' ' && $value != null);
  30. }), JSON_UNESCAPED_UNICODE);
  31. }
  32. $data = $this->inputFilter($params);
  33. $model = $this->model->find($id);
  34. if (!$model) {
  35. throw new BusinessException('记录不存在', 2);
  36. }
  37. unset($data[$primary_key]);
  38. return [$id, $data];
  39. }
  40. }