App.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace App\Http\Controllers\Miniprogram;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\AppProfileModel;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Redis;
  7. class App extends Controller
  8. {
  9. private $appModel;
  10. public function __construct()
  11. {
  12. $this->appModel = new AppProfileModel();
  13. }
  14. /**
  15. * 添加配置
  16. * @param Request $request
  17. * @return array
  18. * @throws \ApiException
  19. */
  20. public function store(Request $request)
  21. {
  22. $public_id = config('miniprogram.public_id');
  23. $configs = $request->toArray();
  24. foreach ($configs as $field => $value) {
  25. Redis::hset("app:config:{$public_id}", $field, $value);
  26. }
  27. return response([
  28. 'code' => 200,
  29. 'message' => 'success'
  30. ]);
  31. }
  32. /**
  33. * 更新配置
  34. * @param Request $request
  35. * @param string $app
  36. * @return array
  37. * @throws \ApiException
  38. */
  39. public function update(Request $request, string $app)
  40. {
  41. $public_id = config('miniprogram.public_id');
  42. $configs = $request->toArray();
  43. foreach ($configs as $field => $value) {
  44. Redis::hset("app:config:{$public_id}", $field, $value);
  45. }
  46. return response([
  47. 'code' => 200,
  48. 'message' => 'success'
  49. ]);
  50. }
  51. /**
  52. * 获取配置信息
  53. * @param string $app
  54. * @return array
  55. * @throws \ApiException
  56. */
  57. public function show(string $app)
  58. {
  59. $public_id = config('miniprogram.public_id');
  60. $profile = Redis::hgetall("app:config:{$public_id}");
  61. return response([
  62. 'code' => 200,
  63. 'message' => 'success',
  64. 'data' => $profile
  65. ]);
  66. }
  67. /**
  68. * 阅读教程
  69. * @param Request $request
  70. * @return \Illuminate\Http\JsonResponse
  71. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  72. */
  73. public function readCourse(Request $request)
  74. {
  75. $uid = \App\Http\Controllers\Miniprogram\Auth::auth();
  76. $version = $request->input('version');
  77. Redis::SETBIT("app:version:{$version}:course", $uid, 1);
  78. return response([
  79. 'code' => 200,
  80. 'message' => 'success'
  81. ]);
  82. }
  83. /**
  84. * 教程是否阅读
  85. * @param Request $request
  86. * @return \Illuminate\Http\JsonResponse
  87. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  88. */
  89. public function course($version)
  90. {
  91. $uid = \App\Http\Controllers\Miniprogram\Auth::auth();
  92. $course = Redis::getbit("app:version:{$version}:course", $uid);
  93. return response([
  94. 'code' => 200,
  95. 'message' => 'OK',
  96. 'data' => [
  97. 'course' => $course
  98. ]
  99. ]);
  100. }
  101. }