User.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\controller\api;
  3. use app\extra\basic\Base;
  4. use app\middleware\WxMiddleware;
  5. use app\model\blue\BlueCategory;
  6. use app\model\blue\BlueExpertPlatform;
  7. use app\model\blue\BlueUserOpen;
  8. use DI\Attribute\Inject;
  9. use LinFly\Annotation\Route\Controller;
  10. use LinFly\Annotation\Route\Route;
  11. use LinFly\Annotation\Route\Middleware;
  12. use support\Request;
  13. use support\Response;
  14. use think\db\exception\DataNotFoundException;
  15. use think\db\exception\DbException;
  16. use think\db\exception\ModelNotFoundException;
  17. #[Controller(prefix: "/wx_api/user"),Middleware(WxMiddleware::class)]
  18. class User extends Base
  19. {
  20. #[Inject]
  21. protected BlueUserOpen $model;
  22. #[Route(path: "data",methods: "get")]
  23. public function getUserData(Request $request): Response
  24. {
  25. try {
  26. $user = $request->user;
  27. if (empty($user)) return errorTrans("empty.data");
  28. $platform = $this->checkPlatform($user['openid']);
  29. $member = $this->model->where("openid",$user['openid'])->field("openid,headimg,nickname")
  30. ->append(["withdraw",'day','mon','bonus','task','sign','level','dy_level','platform'])
  31. ->withAttr(['withdraw' => function(){
  32. return 0; // 可提现金额
  33. },'day' => function(){
  34. return 0; // 今日佣金
  35. },'mon' => function(){
  36. return 0; // 本月佣金
  37. },'bonus' => function(){
  38. return 0; // 已获得奖金
  39. },'task' => function(){
  40. return 0; // 已接任务
  41. },'sign' => function(){
  42. return 0; // 0未签约,1已签约
  43. },'level' => function(){
  44. return 0; // 平台等级
  45. },'dy_level' => function(){
  46. return 0; // 抖音等级
  47. },'platform' => function() use($platform) {
  48. return $platform;
  49. }
  50. ])
  51. ->findOrEmpty();
  52. return success("ok",$member->toArray());
  53. } catch (\Throwable $th) {
  54. return error($th->getMessage());
  55. }
  56. }
  57. /**
  58. * 绑定平台信息
  59. * @param string $openId
  60. * @return array
  61. * @throws DataNotFoundException
  62. * @throws DbException
  63. * @throws ModelNotFoundException
  64. */
  65. protected function checkPlatform(string $openId = ""): array
  66. {
  67. $category = (new BlueCategory)->where("status",1)->where("type",1)->field("sign,name,icon")->select();
  68. if ($category->isEmpty()) return [];
  69. $platform = [];
  70. $platformModel = new BlueExpertPlatform();
  71. foreach ($category as $key=>$val)
  72. {
  73. $bind = $platformModel->where("source",$val['sign'])->where("openid",$openId)->findOrEmpty();
  74. if ($bind->isEmpty()) {
  75. $bindState = 0;
  76. } else {
  77. $bindState = $bind['status'] + 1;
  78. }
  79. $platform[$val['sign']]['status'] = $bindState;
  80. }
  81. return $platform;
  82. }
  83. }