Modules_Api_Controllers_PublishController.proxy.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <?php
  2. namespace Modules\Api\Controllers;
  3. use App\Constants\AdConstrant;
  4. use App\Constants\CommentConstant;
  5. use App\Constants\CommonConstant;
  6. use App\Model\AdModel;
  7. use App\Model\UserAgentIncomeModel;
  8. use App\Repositories\AdRepository;
  9. use App\Repositories\CommissionRulesRepository;
  10. use App\Repositories\ConfigRepoistory;
  11. use App\Repositories\Criterias\FanGroupCriteria;
  12. use App\Repositories\Criterias\OrderLimitCriteria;
  13. use App\Repositories\Criterias\RebateOrderCriteria;
  14. use App\Repositories\FanGroupRepository;
  15. use App\Repositories\RebateOrderRepository;
  16. use App\Repositories\Service\CommonService;
  17. use App\Repositories\Service\QueueService;
  18. use App\Repositories\Service\UserSingInService;
  19. use App\Repositories\TaskAwarkLogRepository;
  20. use App\Repositories\UserLevelRelationRepository;
  21. use App\Repositories\UserRebateLevelRepoistory;
  22. use App\Repositories\UserRepository;
  23. use App\Repositories\UserTaskRepoistory;
  24. use App\Repositories\Utils\M3u8CacheRepository;
  25. use Carbon\Carbon;
  26. use Hyperf\Validation\Contract\ValidatorFactoryInterface;
  27. use Modules\Api\Responses\RebateOrderPageResponse;
  28. use Modules\Api\Services\VideoService;
  29. class PublishController extends BaseController
  30. {
  31. use \Hyperf\Di\Aop\ProxyTrait;
  32. use \Hyperf\Di\Aop\PropertyHandlerTrait;
  33. function __construct()
  34. {
  35. if (method_exists(parent::class, '__construct')) {
  36. parent::__construct(...func_get_args());
  37. }
  38. $this->__handlePropertyHandler(__CLASS__);
  39. }
  40. public function home()
  41. {
  42. $userId = $this->getUserId();
  43. //可提现余额
  44. $res['balance'] = make(UserRepository::class)->findBy('code', $userId, ['balance'])->balance;
  45. //连续签到次数
  46. $res['last_count'] = make(UserSingInService::class)->getContinuousSignCount($userId);
  47. //总业绩
  48. $res['total_perf'] = make(RebateOrderRepository::class)->sumUserTotalPerf($userId);
  49. //邀请人数
  50. $res['invite_people'] = make(UserLevelRelationRepository::class)->getCountNum(['relation_uid' => $userId]);
  51. //任务列表
  52. $res['task'] = make(UserTaskRepoistory::class)->findAllBy('task_type', 1, ['title', 'subtitle', 'jump_link', 'reward_type']);
  53. //今日是否签到
  54. $res['is_sign'] = make(UserSingInService::class)->checkSign($userId, date('Y-m'));
  55. $taskLogRepo = make(TaskAwarkLogRepository::class);
  56. $where['uid'] = $userId;
  57. foreach ($res['task'] as &$task) {
  58. $task['is_ok'] = 1;
  59. switch ($task['reward_type']) {
  60. case 1:
  61. $where['reward_way'] = 2;
  62. break;
  63. case 2:
  64. $where['date'] = date('Y-m-d');
  65. $where['reward_way'] = 3;
  66. break;
  67. case 3:
  68. $where['reward_way'] = 4;
  69. break;
  70. case 4:
  71. $where['date'] = date('Y-m-d');
  72. $where['reward_way'] = 5;
  73. break;
  74. case 5:
  75. $where['reward_way'] = 6;
  76. break;
  77. case 6:
  78. $where['reward_way'] = 7;
  79. break;
  80. case 9:
  81. $where['reward_way'] = 9;
  82. break;
  83. }
  84. $awarkLogInfo = $taskLogRepo->findUserRewardWay($where);
  85. if (!empty($awarkLogInfo)) {
  86. $task['is_ok'] = 2;
  87. }
  88. unset($task['reward_type']);
  89. }
  90. //签到奖励
  91. $res['sign_in_reward'] = make(ConfigRepoistory::class)->get('sign_in_reward', 'rule');
  92. //广告
  93. $adPosition = AdConstrant::VIDEO_FIND;
  94. $videoService = make(VideoService::class);
  95. $adList = $videoService->getAdList($adPosition);
  96. $adList1 = $videoService->getAdList(AdConstrant::DISCOVER_HOME1);
  97. $adList2 = $videoService->getAdList(AdConstrant::DISCOVER_HOME2);
  98. // $adList3 = $videoService->getAdList(AdConstrant::DISCOVER_HOME3);
  99. $ad = null;
  100. $ads1 = $ads2 = $ads3 = null;
  101. if (!empty($adList[0])) {
  102. $link = M3u8CacheRepository::getLinkUrl($adList[0]['link'], ['user_code' => $userId]);
  103. $ad = ['title' => $adList[0]['title'], 'cover' => !empty($adList[0]['cover']) ? M3u8CacheRepository::getImageUrl($adList[0]['cover']) : '', 'link' => $link, 'scheme' => $adList[0]['scheme']];
  104. }
  105. if (!empty($adList1)) {
  106. $ads1 = [];
  107. foreach ($adList1 as $v) {
  108. $link = M3u8CacheRepository::getLinkUrl($v['link'], ['user_code' => $userId]);
  109. $ads1[] = ['title' => $v['title'], 'cover' => !empty($v['cover']) ? M3u8CacheRepository::getImageUrl($v['cover']) : '', 'link' => $link, 'scheme' => $v['scheme']];
  110. }
  111. }
  112. if (!empty($adList2)) {
  113. $ads2 = [];
  114. foreach ($adList2 as $v) {
  115. $link = M3u8CacheRepository::getLinkUrl($v['link'], ['user_code' => $userId]);
  116. $ads2[] = ['title' => $v['title'], 'cover' => !empty($v['cover']) ? M3u8CacheRepository::getImageUrl($v['cover']) : '', 'link' => $link, 'scheme' => $v['scheme']];
  117. }
  118. }
  119. $res['ad'] = $ad;
  120. $res['ads1'] = $ads1;
  121. $res['ads1_seconds'] = 5;
  122. // 自动播放秒数
  123. $res['ads2'] = $ads2;
  124. $res['ads2_seconds'] = 5;
  125. // 自动播放秒数
  126. return json_success($res);
  127. }
  128. /**
  129. * 签到
  130. *
  131. * @return mixed
  132. */
  133. public function singIn()
  134. {
  135. $userId = $this->getUserId();
  136. $singInSer = make(UserSingInService::class);
  137. //获取今天是否签到
  138. $inCheckSign = $singInSer->checkSign($userId, date('Y-m'));
  139. if ($inCheckSign) {
  140. return json_fail('今日已签到,请勿重复签到!');
  141. }
  142. //签到
  143. $singInSer->doSigns($userId);
  144. //异步调度
  145. $result = make(QueueService::class)->sendSignInRewardsJob(['user_id' => $userId]);
  146. if (!$result) {
  147. return json_fail('签到失败!');
  148. }
  149. $res['last_count'] = make(UserSingInService::class)->getContinuousSignCount($userId);
  150. return json_success($res);
  151. }
  152. /**
  153. * 代理明细数据
  154. *
  155. * @return mixed
  156. */
  157. public function nationalAgentInfo()
  158. {
  159. $userId = $this->getUserId();
  160. //总业绩
  161. $res['total_perf'] = make(RebateOrderRepository::class)->sumUserTotalPerf($userId);
  162. //返佣等级
  163. $userLevel = make(UserRepository::class)->findBy('code', $userId, ['vip_level']);
  164. $res['rebate_level'] = $userLevel->vip_level;
  165. //返佣比例
  166. $res['rebate_ratio'] = make(CommissionRulesRepository::class)->getLevelMaxRebateRatio($userLevel->vip_level, $res['total_perf']);
  167. //业绩贡献数据
  168. $res['user_devote_rerf'] = make(RebateOrderRepository::class)->userGradeRerf($userId);
  169. //全民收益榜
  170. $res['earnings_list'] = [];
  171. $lists = UserAgentIncomeModel::query()->orderBy('perf_total', 'DESC')->get(['avatar', 'agent_name', 'perf_total']);
  172. if ($lists->count()) {
  173. $lists = $lists->toArray();
  174. foreach ($lists as &$v) {
  175. $v['avatar'] = M3u8CacheRepository::getImageUrl($v['avatar']);
  176. }
  177. $res['earnings_list'] = $lists;
  178. }
  179. return json_success($res);
  180. }
  181. /**
  182. * 佣金收益明细
  183. *
  184. * @return mixed|RebateOrderPageResponse
  185. */
  186. public function incomeDetailList()
  187. {
  188. $inputData = $this->getJsonData();
  189. $userId = $this->getUserId();
  190. $rules = ['page' => 'nullable|integer', 'page_size' => 'nullable|integer'];
  191. $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
  192. if ($validator->fails()) {
  193. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  194. return json_fail($validator->errors()->first());
  195. }
  196. $orders = [['id', 'DESC']];
  197. $pageSize = $inputData['page_size'] ?? CommentConstant::PAGE_SIZE;
  198. if ($pageSize > 100) {
  199. $pageSize = CommentConstant::PAGE_SIZE;
  200. }
  201. $page = format_page($inputData['page']);
  202. $pageSize = intval($pageSize);
  203. if ($pageSize <= 0) {
  204. $pageSize = CommonConstant::PAGE_SIZE;
  205. }
  206. $inputData['user_id'] = $userId;
  207. $field = ['rebate_amount', 'rebate_level', 'quilt_uid'];
  208. $lists = make(RebateOrderRepository::class)->pushCriteria(new RebateOrderCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, $field, $page);
  209. return new RebateOrderPageResponse($lists);
  210. }
  211. /**
  212. * 限时任务
  213. *
  214. * @return mixed
  215. */
  216. public function timeTask()
  217. {
  218. $date = Carbon::now()->toDayDateTimeString();
  219. $userId = $this->getUserId();
  220. //广告
  221. $adPosition = AdConstrant::DISCOVER_TASK;
  222. $videoService = make(VideoService::class);
  223. $adList = $videoService->getAdList($adPosition);
  224. $adList1 = $videoService->getAdList(AdConstrant::TASK_BANNER1);
  225. $ad = null;
  226. $ads1 = null;
  227. if (!empty($adList[0])) {
  228. $link = M3u8CacheRepository::getLinkUrl($adList[0]['link'], ['user_code' => $userId]);
  229. $ad = ['title' => $adList[0]['title'], 'cover' => !empty($adList[0]['cover']) ? M3u8CacheRepository::getImageUrl($adList[0]['cover']) : '', 'link' => $link, 'scheme' => $adList[0]['scheme']];
  230. }
  231. if (!empty($adList1)) {
  232. $ads1 = [];
  233. foreach ($adList1 as $v) {
  234. $link = M3u8CacheRepository::getLinkUrl($v['link'], ['user_code' => $userId]);
  235. $ads1[] = ['title' => $v['title'], 'cover' => !empty($v['cover']) ? M3u8CacheRepository::getImageUrl($v['cover']) : '', 'link' => $link, 'scheme' => $v['scheme']];
  236. }
  237. }
  238. $res['ad'] = $ad;
  239. $res['ads1'] = $ads1;
  240. $res['ads1_seconds'] = 5;
  241. // 自动播放秒数.
  242. //获取推广总人数
  243. $spreadNumber = make(UserLevelRelationRepository::class)->getCountNum(['relation_uid' => $userId, 'relation_level' => 1]);
  244. $taskInfo = make(UserTaskRepoistory::class)->findBy('reward_type', 7);
  245. $taskCondition = json_decode($taskInfo->task_condition, true);
  246. $reward = json_decode($taskInfo->reward, true);
  247. $subtitle = explode(',', $taskInfo->subtitle);
  248. $res['end_time'] = $taskCondition['end_time'];
  249. $endTime = strtotime($taskCondition['end_time']);
  250. $todyDate = strtotime(date('Y-m-d'));
  251. $res['last_time'] = round(($endTime - $todyDate) / 3600 / 24);
  252. // 防止填写错误 数据修正
  253. if ($res['last_time'] < 0) {
  254. $res['last_time'] = 0;
  255. }
  256. $res['task_list'] = [];
  257. foreach ($taskCondition['condition'] as $k => $val) {
  258. $res['task_list'][$k]['title'] = $taskInfo->title;
  259. $res['task_list'][$k]['subtitle'] = $subtitle[$k];
  260. $res['task_list'][$k]['condition'] = $val;
  261. //任务条件
  262. $res['task_list'][$k]['reward'] = $reward[$k];
  263. if ($spreadNumber >= $val) {
  264. $res['task_list'][$k]['fulfill_number'] = $val;
  265. $res['task_list'][$k]['is_ok'] = 1;
  266. } else {
  267. $res['task_list'][$k]['fulfill_number'] = $spreadNumber;
  268. $res['task_list'][$k]['is_ok'] = 2;
  269. }
  270. }
  271. return json_success($res);
  272. }
  273. /**
  274. * 收益排行榜
  275. *
  276. * @return mixed
  277. */
  278. public function incomeList()
  279. {
  280. $inputData = $this->getJsonData();
  281. $rules = ['income_type' => 'nullable|in:1,2,3'];
  282. $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
  283. if ($validator->fails()) {
  284. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  285. return json_fail($validator->errors()->first());
  286. }
  287. $res = make(UserRebateLevelRepoistory::class)->getUserIncomeList($inputData['income_type']);
  288. return json_success($res);
  289. }
  290. /**
  291. * 我的收益
  292. *
  293. * @return mixed
  294. */
  295. public function myIncome()
  296. {
  297. $res = make(UserRebateLevelRepoistory::class)->userIncome($this->getUserId());
  298. return json_success($res);
  299. }
  300. /**
  301. * 粉丝群列表
  302. *
  303. * @return mixed
  304. */
  305. public function fanGroupLists()
  306. {
  307. $inputData = $this->getJsonData();
  308. $rules = ['page' => 'nullable|integer', 'page_size' => 'nullable|integer'];
  309. $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
  310. if ($validator->fails()) {
  311. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  312. return json_fail($validator->errors()->first());
  313. }
  314. $orders = [['sort', 'DESC']];
  315. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  316. if ($pageSize > 100) {
  317. $pageSize = CommonConstant::PAGE_SIZE;
  318. }
  319. $page = format_page($inputData['page']);
  320. $pageSize = intval($pageSize);
  321. if ($pageSize <= 0) {
  322. $pageSize = CommonConstant::PAGE_SIZE;
  323. }
  324. $inputData['status'] = 1;
  325. $field = ['log', 'title', 'link'];
  326. $res = make(FanGroupRepository::class)->pushCriteria(new FanGroupCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, $field, $page);
  327. foreach ($res->items() as &$val) {
  328. $val->log = M3u8CacheRepository::getImageUrl($val->log);
  329. }
  330. return json_success($res);
  331. }
  332. }