WorkRecord.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /*
  3. * @Descripttion:
  4. * @version: 1.0.0
  5. * @Author: likang
  6. * @Date: 2022-07-12 10:11:04
  7. * @LastEditors: likang
  8. * @LastEditTime: 2022-07-12 15:40:32
  9. */
  10. namespace catchAdmin\worklocation\controller;
  11. use catcher\base\CatchRequest as Request;
  12. use catcher\CatchResponse;
  13. use catcher\base\CatchController;
  14. use catchAdmin\worklocation\model\WorkRecord as workRecordModel;
  15. use think\facade\Db;
  16. class WorkRecord extends CatchController
  17. {
  18. protected $workRecordModel;
  19. public function __construct(WorkRecordModel $workRecordModel)
  20. {
  21. $this->workRecordModel = $workRecordModel;
  22. }
  23. /**
  24. * 列表
  25. * @time 2022年07月12日 10:11
  26. * @param Request $request
  27. */
  28. public function index(Request $request): \think\Response
  29. {
  30. return CatchResponse::paginate($this->workRecordModel->getList());
  31. }
  32. /**
  33. * 保存信息
  34. * @time 2022年07月12日 10:11
  35. * @param Request $request
  36. */
  37. public function save(Request $request): \think\Response
  38. {
  39. return CatchResponse::success($this->workRecordModel->storeBy($request->post()));
  40. }
  41. /**
  42. * 读取
  43. * @time 2022年07月12日 10:11
  44. * @param $id
  45. */
  46. public function read($id): \think\Response
  47. {
  48. return CatchResponse::success($this->workRecordModel->findBy($id));
  49. }
  50. /**
  51. * 更新
  52. * @time 2022年07月12日 10:11
  53. * @param Request $request
  54. * @param $id
  55. */
  56. public function update(Request $request, $id): \think\Response
  57. {
  58. return CatchResponse::success($this->workRecordModel->updateBy($id, $request->post()));
  59. }
  60. /**
  61. * 删除
  62. * @time 2022年07月12日 10:11
  63. * @param $id
  64. */
  65. public function delete($id): \think\Response
  66. {
  67. return CatchResponse::success($this->workRecordModel->deleteBy($id));
  68. }
  69. /**
  70. * @Descripttion: 统计
  71. * @name: likang
  72. * @param {Request} $request
  73. * @return {*}
  74. */
  75. public function getTotal(Request $request)
  76. {
  77. $device_model_list = Db::name('device_mold')->where('device_type', 4)->select();
  78. $array = [];
  79. // fan_id 风机 id 风机编号
  80. foreach ($device_model_list as $item) {
  81. $worklist = [];
  82. $where = [];
  83. $ids = Db::name('fan')->where('fan_model', $item["id"])->column('id');
  84. $where[] = ['fan_id', 'in', implode(",", $ids)];
  85. //创建时间 扭矩
  86. //排序 从小到大
  87. $list = $this->workLocationModel->where($where)->order('created_at', 'asc')->select();
  88. foreach ($list as $it) {
  89. $worklist[] = [$it['created_at'] => $it['torque']];
  90. }
  91. $array[] = ["name" => $item['name'], 'data' => $worklist];
  92. }
  93. return CatchResponse::success($array, 10000);
  94. }
  95. }