Portal.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\controller\api;
  3. use app\extra\basic\Base;
  4. use app\extra\service\blue\TaskService;
  5. use app\middleware\WxMiddleware;
  6. use app\model\blue\BlueBanner;
  7. use app\model\blue\BlueCategory;
  8. use app\model\blue\BlueTask;
  9. use DI\Attribute\Inject;
  10. use LinFly\Annotation\Route\Controller;
  11. use LinFly\Annotation\Route\Middleware;
  12. use LinFly\Annotation\Route\Route;
  13. use support\Request;
  14. use support\Response;
  15. #[Controller(prefix: "/wx_api/portal"),Middleware(WxMiddleware::class)]
  16. class Portal extends Base
  17. {
  18. protected array $noNeedLogin = ['getPortal'];
  19. #[Inject]
  20. protected TaskService $service;
  21. /**
  22. * 小程序首页信息
  23. * @param Request $request
  24. * @return Response
  25. */
  26. #[Route(path: "mini",methods: "get")]
  27. public function getPortal(Request $request): Response
  28. {
  29. try {
  30. $param = $this->_valid([
  31. "tid.default" => 0,
  32. "category.default" => "",
  33. "size.default" => 10,
  34. "page.default" => 1,
  35. ],$request->method());
  36. $banner = (new BlueBanner)->where("status",1)->field("title,img,path")->select()->toArray();
  37. $category = (new BlueCategory)->where("type",1)->field("name,icon,small_icon,sign")->append(['id'])->withAttr(['id' => function($data,$resp){
  38. return $resp['sign'];
  39. }])->select()->toArray();
  40. if (empty($param['category'])) {
  41. $param['category'] = $category[0]['id'];
  42. }
  43. $share = [
  44. "image" => sConf("wechat.share"),
  45. "title" => sConf("wechat.share_title")
  46. ];
  47. $list = $this->service->getHomeList(['category' => $param['category'],'pageSize' => $param['size'],'page' => $param['page']]);
  48. $task = pageFormat($list);
  49. return success("ok",compact("banner","category",'task','share'));
  50. } catch (\Throwable $throwable) {
  51. return error($throwable->getMessage());
  52. }
  53. }
  54. }