Expert.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\controller\admin;
  3. use app\extra\basic\Base;
  4. use app\extra\service\blue\ExpertService;
  5. use app\middleware\AuthMiddleware;
  6. use app\model\blue\BlueExpert;
  7. use app\model\blue\BlueExpertPlatform;
  8. use DI\Attribute\Inject;
  9. use LinFly\Annotation\Route\Controller;
  10. use LinFly\Annotation\Route\Middleware;
  11. use LinFly\Annotation\Route\Route;
  12. use support\Request;
  13. use support\Response;
  14. /**
  15. * 达人
  16. */
  17. #[Controller(prefix: "/api/expert"),Middleware(AuthMiddleware::class)]
  18. class Expert extends Base
  19. {
  20. #[Inject]
  21. protected BlueExpert $model;
  22. #[Inject]
  23. protected ExpertService $service;
  24. /**
  25. *
  26. * @param Request $request
  27. * @return Response
  28. */
  29. #[Route(path: "list",methods: "get")]
  30. public function getDataList(Request $request): Response
  31. {
  32. try {
  33. $param = $request->all();
  34. $list = $this->service->getList($param);
  35. return successTrans("success.data",pageFormat($list),200);
  36. } catch (\Throwable $throwable) {
  37. return error($throwable->getMessage());
  38. }
  39. }
  40. #[Route(path: "platform",methods: "get")]
  41. public function getPlatform(): Response
  42. {
  43. try {
  44. $param = $this->_valid([
  45. "id.require" => trans("empty.require")
  46. ]);
  47. if (!is_array($param)) return error($param);
  48. $user = $this->model->where("id",$param['id'])->findOrEmpty();
  49. if ($user->isEmpty()) return errorTrans("empty.data");
  50. $platform = (new BlueExpertPlatform)->where("openid",$user['openid'])->append(['source_name','aweme_count_format','follower_count_format','total_favorited_format'])->withAttr(['source_name' => function($data,$resp){
  51. return $this->service->source[$resp['source']];
  52. },'aweme_count_format' => function($data,$resp){
  53. // return formatMoneyKw($resp['aweme_count'],1);
  54. return $resp['aweme_count'];
  55. },'follower_count_format' => function($data,$resp){
  56. return formatMoneyKw($resp['follower_count'],1);
  57. },'total_favorited_format' => function($data,$resp){
  58. return formatMoneyKw($resp['total_favorited'],1);
  59. }])->select()->toArray();
  60. return success("ok",$platform);
  61. } catch (\Throwable $throwable) {
  62. return error($throwable->getMessage());
  63. }
  64. }
  65. }