| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- <?php
- namespace Modules\Api\Controllers;
- use App\Constants\AdConstrant;
- use App\Constants\CommentConstant;
- use App\Constants\CommonConstant;
- use App\Model\AdModel;
- use App\Model\UserAgentIncomeModel;
- use App\Repositories\AdRepository;
- use App\Repositories\CommissionRulesRepository;
- use App\Repositories\ConfigRepoistory;
- use App\Repositories\Criterias\FanGroupCriteria;
- use App\Repositories\Criterias\OrderLimitCriteria;
- use App\Repositories\Criterias\RebateOrderCriteria;
- use App\Repositories\FanGroupRepository;
- use App\Repositories\RebateOrderRepository;
- use App\Repositories\Service\CommonService;
- use App\Repositories\Service\QueueService;
- use App\Repositories\Service\UserSingInService;
- use App\Repositories\TaskAwarkLogRepository;
- use App\Repositories\UserLevelRelationRepository;
- use App\Repositories\UserRebateLevelRepoistory;
- use App\Repositories\UserRepository;
- use App\Repositories\UserTaskRepoistory;
- use App\Repositories\Utils\M3u8CacheRepository;
- use Carbon\Carbon;
- use Hyperf\Validation\Contract\ValidatorFactoryInterface;
- use Modules\Api\Responses\RebateOrderPageResponse;
- use Modules\Api\Services\VideoService;
- class PublishController extends BaseController
- {
- public function home()
- {
- $userId = $this->getUserId();
- //可提现余额
- $res['balance'] = make(UserRepository::class)->findBy('code', $userId, ['balance'])->balance;
- //连续签到次数
- $res['last_count'] = make(UserSingInService::class)->getContinuousSignCount($userId);
- //总业绩
- $res['total_perf'] = make(RebateOrderRepository::class)->sumUserTotalPerf($userId);
- //邀请人数
- $res['invite_people'] = make(UserLevelRelationRepository::class)->getCountNum(['relation_uid' => $userId]);
- //任务列表
- $res['task'] = make(UserTaskRepoistory::class)->findAllBy('task_type', 1, ['title', 'subtitle', 'jump_link', 'reward_type']);
- //今日是否签到
- $res['is_sign'] = make(UserSingInService::class)->checkSign($userId, date('Y-m'));
- $taskLogRepo = make(TaskAwarkLogRepository::class);
- $where['uid'] = $userId;
- foreach ($res['task'] as &$task) {
- $task['is_ok'] = 1;
- switch ($task['reward_type']) {
- case 1:
- $where['reward_way'] = 2;
- break;
- case 2:
- $where['date'] = date('Y-m-d');
- $where['reward_way'] = 3;
- break;
- case 3:
- $where['reward_way'] = 4;
- break;
- case 4:
- $where['date'] = date('Y-m-d');
- $where['reward_way'] = 5;
- break;
- case 5:
- $where['reward_way'] = 6;
- break;
- case 6:
- $where['reward_way'] = 7;
- break;
- case 9:
- $where['reward_way'] = 9;
- break;
- }
- $awarkLogInfo = $taskLogRepo->findUserRewardWay($where);
- if (!empty($awarkLogInfo)) {
- $task['is_ok'] = 2;
- }
- unset($task['reward_type']);
- }
- //签到奖励
- $res['sign_in_reward'] = make(ConfigRepoistory::class)->get('sign_in_reward', 'rule');
- //广告
- $adPosition = AdConstrant::VIDEO_FIND;
- $videoService = make(VideoService::class);
- $adList = $videoService->getAdList($adPosition);
- $adList1 = $videoService->getAdList(AdConstrant::DISCOVER_HOME1);
- $adList2 = $videoService->getAdList(AdConstrant::DISCOVER_HOME2);
- // $adList3 = $videoService->getAdList(AdConstrant::DISCOVER_HOME3);
- $ad = null;
- $ads1 = $ads2 = $ads3 = null;
- if (!empty($adList[0])) {
- $link = M3u8CacheRepository::getLinkUrl($adList[0]['link'], ['user_code' => $userId]);
- $ad = [
- 'title' => $adList[0]['title'],
- 'cover' => !empty($adList[0]['cover']) ? M3u8CacheRepository::getImageUrl($adList[0]['cover']) : '',
- 'link' => $link,
- 'scheme' => $adList[0]['scheme'],
- ];
- }
- if (!empty($adList1)) {
- $ads1 = [];
- foreach ($adList1 as $v) {
- $link = M3u8CacheRepository::getLinkUrl($v['link'], ['user_code' => $userId]);
- $ads1[] = [
- 'title' => $v['title'],
- 'cover' => !empty($v['cover']) ? M3u8CacheRepository::getImageUrl($v['cover']) : '',
- 'link' => $link,
- 'scheme' => $v['scheme'],
- ];
- }
- }
- if (!empty($adList2)) {
- $ads2 = [];
- foreach ($adList2 as $v) {
- $link = M3u8CacheRepository::getLinkUrl($v['link'], ['user_code' => $userId]);
- $ads2[] = [
- 'title' => $v['title'],
- 'cover' => !empty($v['cover']) ? M3u8CacheRepository::getImageUrl($v['cover']) : '',
- 'link' => $link,
- 'scheme' => $v['scheme'],
- ];
- }
- }
- $res['ad'] = $ad;
- $res['ads1'] = $ads1;
- $res['ads1_seconds'] = 5; // 自动播放秒数
- $res['ads2'] = $ads2;
- $res['ads2_seconds'] = 5; // 自动播放秒数
- return json_success($res);
- }
- /**
- * 签到
- *
- * @return mixed
- */
- public function singIn()
- {
- $userId = $this->getUserId();
- $singInSer = make(UserSingInService::class);
- //获取今天是否签到
- $inCheckSign = $singInSer->checkSign($userId, date('Y-m'));
- if ($inCheckSign) {
- return json_fail('今日已签到,请勿重复签到!');
- }
- //签到
- $singInSer->doSigns($userId);
- //异步调度
- $result = make(QueueService::class)->sendSignInRewardsJob(['user_id' => $userId]);
- if (!$result) {
- return json_fail('签到失败!');
- }
- $res['last_count'] = make(UserSingInService::class)->getContinuousSignCount($userId);
- return json_success($res);
- }
- /**
- * 代理明细数据
- *
- * @return mixed
- */
- public function nationalAgentInfo()
- {
- $userId = $this->getUserId();
- //总业绩
- $res['total_perf'] = make(RebateOrderRepository::class)->sumUserTotalPerf($userId);
- //返佣等级
- $userLevel = make(UserRepository::class)->findBy('code', $userId, ['vip_level']);
- $res['rebate_level'] = $userLevel->vip_level;
- //返佣比例
- $res['rebate_ratio'] = make(CommissionRulesRepository::class)->getLevelMaxRebateRatio($userLevel->vip_level, $res['total_perf']);
- //业绩贡献数据
- $res['user_devote_rerf'] = make(RebateOrderRepository::class)->userGradeRerf($userId);
- //全民收益榜
- $res['earnings_list'] = [];
- $lists = UserAgentIncomeModel::query()->orderBy('perf_total', 'DESC')->get(['avatar', 'agent_name', 'perf_total']);
- if ($lists->count()) {
- $lists = $lists->toArray();
- foreach ($lists as &$v) {
- $v['avatar'] = M3u8CacheRepository::getImageUrl($v['avatar']);
- }
- $res['earnings_list'] = $lists;
- }
- return json_success($res);
- }
- /**
- * 佣金收益明细
- *
- * @return mixed|RebateOrderPageResponse
- */
- public function incomeDetailList()
- {
- $inputData = $this->getJsonData();
- $userId = $this->getUserId();
- $rules = [
- 'page' => 'nullable|integer',
- 'page_size' => 'nullable|integer',
- ];
- $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $orders = [
- ['id', 'DESC'],
- ];
- $pageSize = $inputData['page_size'] ?? CommentConstant::PAGE_SIZE;
- if ($pageSize > 100) {
- $pageSize = CommentConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page']);
- $pageSize = intval($pageSize);
- if ($pageSize <= 0) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $inputData['user_id'] = $userId;
- $field = ['rebate_amount', 'rebate_level', 'quilt_uid'];
- $lists = make(RebateOrderRepository::class)->pushCriteria(new RebateOrderCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, $field, $page);
- return new RebateOrderPageResponse($lists);
- }
- /**
- * 限时任务
- *
- * @return mixed
- */
- public function timeTask()
- {
- $date = Carbon::now()->toDayDateTimeString();
- $userId = $this->getUserId();
- //广告
- $adPosition = AdConstrant::DISCOVER_TASK;
- $videoService = make(VideoService::class);
- $adList = $videoService->getAdList($adPosition);
- $adList1 = $videoService->getAdList(AdConstrant::TASK_BANNER1);
- $ad = null;
- $ads1 = null;
- if (!empty($adList[0])) {
- $link = M3u8CacheRepository::getLinkUrl($adList[0]['link'], ['user_code' => $userId]);
- $ad = [
- 'title' => $adList[0]['title'],
- 'cover' => !empty($adList[0]['cover']) ? M3u8CacheRepository::getImageUrl($adList[0]['cover']) : '',
- 'link' => $link,
- 'scheme' => $adList[0]['scheme'],
- ];
- }
- if (!empty($adList1)) {
- $ads1 = [];
- foreach ($adList1 as $v) {
- $link = M3u8CacheRepository::getLinkUrl($v['link'], ['user_code' => $userId]);
- $ads1[] = [
- 'title' => $v['title'],
- 'cover' => !empty($v['cover']) ? M3u8CacheRepository::getImageUrl($v['cover']) : '',
- 'link' => $link,
- 'scheme' => $v['scheme'],
- ];
- }
- }
- $res['ad'] = $ad;
- $res['ads1'] = $ads1;
- $res['ads1_seconds'] = 5; // 自动播放秒数.
- //获取推广总人数
- $spreadNumber = make(UserLevelRelationRepository::class)->getCountNum(['relation_uid' => $userId, 'relation_level' => 1]);
- $taskInfo = make(UserTaskRepoistory::class)->findBy('reward_type', 7);
- $taskCondition = json_decode($taskInfo->task_condition, true);
- $reward = json_decode($taskInfo->reward, true);
- $subtitle = explode(',', $taskInfo->subtitle);
- $res['end_time'] = $taskCondition['end_time'];
- $endTime = strtotime($taskCondition['end_time']);
- $todyDate = strtotime(date('Y-m-d'));
- $res['last_time'] = round(($endTime - $todyDate) / 3600 / 24);
- // 防止填写错误 数据修正
- if ($res['last_time'] < 0) {
- $res['last_time'] = 0;
- }
- $res['task_list'] = [];
- foreach ($taskCondition['condition'] as $k => $val) {
- $res['task_list'][$k]['title'] = $taskInfo->title;
- $res['task_list'][$k]['subtitle'] = $subtitle[$k];
- $res['task_list'][$k]['condition'] = $val;//任务条件
- $res['task_list'][$k]['reward'] = $reward[$k];
- if ($spreadNumber >= $val) {
- $res['task_list'][$k]['fulfill_number'] = $val;
- $res['task_list'][$k]['is_ok'] = 1;
- } else {
- $res['task_list'][$k]['fulfill_number'] = $spreadNumber;
- $res['task_list'][$k]['is_ok'] = 2;
- }
- }
- return json_success($res);
- }
- /**
- * 收益排行榜
- *
- * @return mixed
- */
- public function incomeList()
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'income_type' => 'nullable|in:1,2,3'
- ];
- $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $res = make(UserRebateLevelRepoistory::class)->getUserIncomeList($inputData['income_type']);
- return json_success($res);
- }
- /**
- * 我的收益
- *
- * @return mixed
- */
- public function myIncome()
- {
- $res = make(UserRebateLevelRepoistory::class)->userIncome($this->getUserId());
- return json_success($res);
- }
- /**
- * 粉丝群列表
- *
- * @return mixed
- */
- public function fanGroupLists()
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'page' => 'nullable|integer',
- 'page_size' => 'nullable|integer',
- ];
- $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $orders = [
- ['sort', 'DESC'],
- ];
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 100) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page']);
- $pageSize = intval($pageSize);
- if ($pageSize <= 0) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $inputData['status'] = 1;
- $field = ['log', 'title', 'link'];
- $res = make(FanGroupRepository::class)->pushCriteria(new FanGroupCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, $field, $page);
- foreach ($res->items() as &$val) {
- $val->log = M3u8CacheRepository::getImageUrl($val->log);
- }
- return json_success($res);
- }
- }
|