StatisticsController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace plugin\admin\app\controller;
  3. use Illuminate\Support\Arr;
  4. use plugin\admin\app\model\Statistics;
  5. use plugin\admin\app\model\UserCark;
  6. use support\Db;
  7. use support\Request;
  8. use support\Response;
  9. use plugin\admin\app\model\ArticleType;
  10. use plugin\admin\app\controller\Crud;
  11. use support\exception\BusinessException;
  12. /**
  13. * 文章分类
  14. */
  15. class StatisticsController extends Crud
  16. {
  17. /**
  18. * @var Statistics
  19. */
  20. protected $model = null;
  21. /**
  22. * 构造函数
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. $this->model = new Statistics;
  28. }
  29. /**
  30. * 浏览
  31. * @return Response
  32. */
  33. public function index(): Response
  34. {
  35. return view('statistics/index');
  36. }
  37. /**
  38. * 插入
  39. * @param Request $request
  40. * @return Response
  41. * @throws BusinessException
  42. */
  43. public function insert(Request $request): Response
  44. {
  45. if ($request->method() === 'POST') {
  46. return parent::insert($request);
  47. }
  48. return view('statistics/insert');
  49. }
  50. /**
  51. * 更新
  52. * @param Request $request
  53. * @return Response
  54. * @throws BusinessException
  55. */
  56. public function update(Request $request): Response
  57. {
  58. if ($request->method() === 'POST') {
  59. return parent::update($request);
  60. }
  61. return view('statistics/update');
  62. }
  63. /**查询收银余额
  64. * @param Request $request
  65. * @return Response
  66. */
  67. public function select(Request $request): Response
  68. {
  69. $param = $request->all();
  70. $data = Statistics::query()->orderByDesc('id');
  71. $data = $data->paginate(Arr::get($param, 'limit', 10))
  72. ->toArray();
  73. $arr = [];
  74. foreach ($data['data'] as $k => $v) {
  75. $arr[] = [
  76. 'id' => $v['id'],
  77. 'open' => $v['open'],
  78. 'close' => $v['close'],
  79. 'up' => $v['up'],
  80. 'lower' => $v['lower'],
  81. 'created_at' => $v['created_at'],
  82. 'updated_at' => $v['updated_at'],
  83. ];
  84. }
  85. return json(['code' => 0, 'data' => $arr, 'msg' => 'ok', 'count' => $data['total']]);
  86. }
  87. }