PublishController.php 14 KB

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