Backup.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\sys\controller;
  3. use app\model\Backup as BackupModel;
  4. use think\facade\Request;
  5. /**
  6. * 获取表单缓存信息
  7. * Class Backup
  8. * @package app\sys\controller
  9. */
  10. class Backup
  11. {
  12. /**
  13. * 获取历史缓存
  14. * @return \think\response\Json
  15. * @throws \think\db\exception\DataNotFoundException
  16. * @throws \think\db\exception\DbException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. */
  19. public function content(){
  20. $employee_id = request()->employee->id;
  21. $where[] = ['employee_id', '=', $employee_id];
  22. $type = input('type', '', 'trim');
  23. if (empty($type)) return json(['code'=> 0, 'data'=> [], 'msg'=> '获取成功']);
  24. $where[] = ['pipe_type', '=', $type];
  25. $find = BackupModel::where($where)->findOrEmpty();
  26. $content = [];
  27. if (!$find->isEmpty()){
  28. $content = $find['content'];
  29. }
  30. return json(['code'=> 0, 'msg'=> '获取成功', 'data'=> $content]);
  31. }
  32. /**
  33. * 缓存
  34. */
  35. public function save(){
  36. $employee_id = request()->employee->id;
  37. $where[] = ['employee_id', '=', $employee_id];
  38. $type = input('type', '', 'trim');
  39. if (empty($type)) return json(['code'=> 0, 'msg'=> '操作成功']);
  40. $where[] = ['pipe_type', '=', $type];
  41. $find = BackupModel::where($where)->findOrEmpty();
  42. $content = input('content', '', 'trim');
  43. if ($find->isEmpty()) {
  44. $data['employee_id'] = $employee_id;
  45. $data['pipe_type'] = $type;
  46. $data['content'] = $content;
  47. BackupModel::create($data);
  48. } else {
  49. $find->content = $content;
  50. $find->addtime = date('Y-m-d H:i:s');
  51. $find->save();
  52. }
  53. return json(['code'=> 0, 'msg'=> '操作成功']);
  54. }
  55. /**
  56. * 文件备份上传
  57. */
  58. public function upload(){
  59. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  60. $url = 'https://' . $ali_oss_bindurl . '/' . Request::param('file');
  61. return json(['code' => 0, 'data' => ['src' => $url]]);
  62. }
  63. }