OssuploadController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\OssUpload;
  5. class OssuploadController extends Base
  6. {
  7. function index()
  8. {
  9. $weid = weid();
  10. $keyword = input('post.keyword', '', 'serach_in');
  11. OssUpload::datainitial();
  12. $query = OssUpload::where(['weid' => $weid]);
  13. if (!empty($keyword)) {
  14. $query->where('title', 'like', '%' . $keyword . '%');
  15. }
  16. $res = $query->order('id asc')
  17. ->paginate(getpage())
  18. ->toArray();
  19. $data['data'] = $res;
  20. return $this->json($data);
  21. }
  22. function listUpdate()
  23. {
  24. $data = only('id,status');
  25. if (!$data['id']) throw new ValidateException('参数错误');
  26. OssUpload::update($data);
  27. return $this->json(['msg' => '操作成功']);
  28. }
  29. public function update()
  30. {
  31. $id = $this->request->post('id');
  32. $data = input('post.');
  33. unset($data['create_time']);
  34. $data['settings'] = serialize($data['settings']);
  35. if (empty($id)) {
  36. $data['weid'] = weid();
  37. try {
  38. $res = OssUpload::create($data);
  39. } catch (\Exception $e) {
  40. throw new ValidateException($e->getMessage());
  41. }
  42. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  43. } else {
  44. try {
  45. OssUpload::update($data);
  46. } catch (\Exception $e) {
  47. throw new ValidateException($e->getMessage());
  48. }
  49. return $this->json(['msg' => '修改成功']);
  50. }
  51. }
  52. function getInfo()
  53. {
  54. $id = $this->request->post('id', '', 'serach_in');
  55. if (!$id) throw new ValidateException('参数错误');
  56. $data = OssUpload::field('*')->find($id)->toArray();
  57. $data['settings'] = iunserializer($data['settings']);
  58. $data['settings'] = OssUpload::setcompatible($data['settings'], $data['code']);
  59. if(empty($data['settings'])){
  60. $data['settings'] = ['mchid'=>'','signkey'=>''];
  61. }
  62. return $this->json(['data' => $data]);
  63. }
  64. }