4934 lines
190 KiB
PHP
4934 lines
190 KiB
PHP
<?php
|
||
|
||
|
||
namespace App\Http\Controllers\Admin;
|
||
|
||
use App\Models\Live\Article;
|
||
use App\Models\Course\Course;
|
||
use App\Models\Live\Opus;
|
||
use App\Utils\Messenger as Messengers;
|
||
use App\Jobs\AuditViewerShare;
|
||
use App\Models\CommunityGroupAdmin;
|
||
use App\Models\ApproveHistory;
|
||
use App\Models\CommunityStar;
|
||
use App\Models\Live\ActivityUser;
|
||
use App\Models\Live\Ballot;
|
||
use App\Models\Live\ViewerShareAudit;
|
||
use App\Models\Live\ViewerTaskScore;
|
||
use App\Utils\IP;
|
||
use App\Models\Live\TaskViewer;
|
||
use App\Jobs\AddCashToViewer;
|
||
use App\Exports\MessengerExport;
|
||
use Illuminate\Support\Facades\Log;
|
||
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||
//use App\Events\News;
|
||
use App\Jobs\CreateLiveMpqrcode;
|
||
use App\Models\Community;
|
||
use App\Models\CommunityGroupLink;
|
||
use App\Models\CommunityMember;
|
||
use App\Models\CommunityMoment;
|
||
use App\Models\Live\GiftOrder;
|
||
use App\Models\Live\Lottery;
|
||
use App\Models\Live\LotteryList;
|
||
use App\Models\Live\Messenger;
|
||
use App\Models\Live\Platfrom;
|
||
use App\Models\Live\Question;
|
||
use App\Models\Live\Record;
|
||
use App\Models\Live\Anchor;
|
||
use App\Models\Live\AnchorViewer;
|
||
use App\Models\Live\Asset;
|
||
use App\Models\Live\AssetLog;
|
||
use App\Models\Live\Comment;
|
||
use App\Models\Live\Feedback;
|
||
use App\Models\Live\Gift;
|
||
use App\Models\Live\Live;
|
||
use App\Models\Live\LiveChannel;
|
||
use App\Models\Live\LiveClass;
|
||
use App\Models\Live\LiveOrder;
|
||
use App\Models\Live\LiveViewer;
|
||
use App\Models\Live\Task;
|
||
use App\Models\Live\Video;
|
||
use App\Models\Live\Viewer;
|
||
use App\Models\Live\ViewerShare;
|
||
use App\Models\Live\ShareRole;
|
||
use App\Models\Live\ShareRoleViewer;
|
||
use App\Models\Live\Winner;
|
||
use App\Models\User;
|
||
use App\Models\ProfileMarriage;
|
||
use Illuminate\Broadcasting\Channel;
|
||
use Illuminate\Http\Request;
|
||
use App\Repositories\Eloquent\SmsRepository as Sms;
|
||
use App\Http\Controllers\Controller;
|
||
use App\Contracts\UserContract;
|
||
use Illuminate\Support\Facades\Redis;
|
||
use Illuminate\Support\Facades\DB;
|
||
use App\Jobs\TransferToAlipayAccount;
|
||
use EasyWeChat\Factory;
|
||
use EasyWeChat\Kernel\Messages\News;
|
||
use EasyWeChat\Kernel\Messages\NewsItem;
|
||
use EasyWeChat\Kernel\Messages\Text;
|
||
use EasyWeChat\Kernel\Messages\Image;
|
||
use EasyWeChat\Kernel\Messages\MiniProgramPage;
|
||
use App\Jobs\SendSpreaderNote;
|
||
use App\Jobs\SendTemplateMsg;
|
||
use Illuminate\View\View;
|
||
use App\Http\Response\ResponseJson;
|
||
use App\Models\ShareFund;
|
||
use App\Models\ConsultationRecords;
|
||
use App\Models\ShareFundLog;
|
||
use App\Facades\QrcodeRectService;
|
||
use EasyWeChat\Kernel\Messages\Raw;
|
||
use App\Models\Wechat;
|
||
use App\Models\SubscribeOfficialLog;
|
||
use App\Models\Live\LiveLog;
|
||
use App\Models\AnchorVideo;
|
||
use App\Models\AnchorArticle;
|
||
use App\Models\CommunityActivity;
|
||
use App\Models\Live\LiveBanner;
|
||
use App\Models\MerchantAccount;
|
||
use App\Models\Message;
|
||
use App\Models\Order;
|
||
use App\Models\TouristOrder;
|
||
use App\Models\TaggingTagGroup;
|
||
use App\Utils\Str;
|
||
|
||
class LiveController extends Controller
|
||
{
|
||
use ResponseJson;
|
||
//额外的分享奖励
|
||
const SHARE_EXTRA_CASH = 5;
|
||
|
||
protected $sms;
|
||
protected $userCon;
|
||
protected $viewer;
|
||
protected $app;
|
||
protected $config;
|
||
|
||
public function __construct(Sms $sms, UserContract $userCon)
|
||
{
|
||
$this->config = [
|
||
'app_id' => config('wechat.official_account.new.app_id'),
|
||
'secret' => config('wechat.official_account.new.secret'),
|
||
'token' => config('wechat.official_account.new.token'),
|
||
'aes_key' => config('wechat.official_account.new.aes_key')
|
||
];
|
||
|
||
$this->app = Factory::officialAccount($this->config);
|
||
$this->sms = $sms;
|
||
$this->userCon = $userCon;
|
||
}
|
||
|
||
/**添加H5直播 */
|
||
public function addLive(Request $request)
|
||
{
|
||
$user = auth()->user();
|
||
if (!$request->title || !$request->poster || !$request->start_time) {
|
||
|
||
// if (!$request->has('title') || !$request->has('poster') || !$request->has('url') || !$request->has('start_time') || !$request->has('class_id') || !$request->has('anchor_id')) {
|
||
|
||
return $this->failure('必选项不能为空');
|
||
}
|
||
|
||
if ($request->end_time <= $request->start_time) {
|
||
return $this->failure('结束时间必须大于开始时间');
|
||
}
|
||
if (!$request->anchor_id)
|
||
return $this->failure('请选择绑定老师');
|
||
try {
|
||
DB::beginTransaction();
|
||
$live = new Live();
|
||
$live->title = $request->title;
|
||
// $live->recommend_course_id = json_encode($request->recommend_course_id,JSON_UNESCAPED_UNICODE);
|
||
$live->sort = $request->sort;
|
||
$live->poster = $request->poster;
|
||
$live->share_poster = $request->share_poster;
|
||
$live->introduction = $request->introduction ?: '无';
|
||
$live->start_time = $request->start_time;
|
||
$live->end_time = $request->end_time;
|
||
$live->class_id = $request->class_id ?: 0;
|
||
$live->anchor_id = $request->anchor_id ?: 0;
|
||
$live->recommend = $request->recommend ?: 0;
|
||
$live->detail = $request->detail ?: '无';
|
||
$live->is_free = $request->is_free ?: 0;
|
||
$live->price = $request->price ?: 0.00;
|
||
$live->teaser = $request->teaser;
|
||
$prefix = config('app.env') == 'alpha' ? 'http://alpha.ufutx.net/h5/#/watchLive/' : env('APP_URL') . '/h5/#/watchLive/';
|
||
$live->url = $request->url ?: $prefix . $live->id;
|
||
$live->save();
|
||
$this->addLiveUser($request->anchor_id, $live->id);
|
||
//抽奖口令
|
||
if (!empty($request->command) && !empty($request->command[0]['command']) && !empty($request->command[0]['num'])) {
|
||
foreach ($request->command as $item) {
|
||
$new_lottery = new Lottery();
|
||
$new_lottery->live_id = $live->id;
|
||
$new_lottery->command = $item['command'];
|
||
$new_lottery->num = $item['num'];
|
||
$new_lottery->start_time = $live->start_time;
|
||
$new_lottery->end_time = $live->end_time;
|
||
$new_lottery->save();
|
||
}
|
||
}
|
||
|
||
if ($request->has('video') && $request->video) {
|
||
$video = new Video();
|
||
$video->live_id = $live->id;
|
||
$video->uri = $request->video;
|
||
$video->duration = 0;
|
||
$video->save();
|
||
}
|
||
|
||
if (empty($live->chat_room_id) || $live->chat_room_id == 0) {
|
||
$anchors = Anchor::with('viewer')->where('id', $live->anchor_id)
|
||
->first();
|
||
//网易账号
|
||
$user->createIMUser();
|
||
$chat_room = '';
|
||
if ($anchors->viewer) {
|
||
$chat_room = \CommonUtilsService::createChatRoom($anchors->viewer->user_id, $live->title);
|
||
} elseif ($anchors->viewerV2) {
|
||
$chat_room = \CommonUtilsService::createChatRoom($anchors->viewerV2->user_id, $live->title);
|
||
} elseif ($anchors->viewerV3) {
|
||
$chat_room = \CommonUtilsService::createChatRoom($anchors->viewerV3->user_id, $live->title);
|
||
}
|
||
|
||
if (empty($chat_room))
|
||
throw new \Exception("创建IM聊天室失败", 1);
|
||
$live->chat_room_id = $chat_room['roomid'];
|
||
$live->save();
|
||
}
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
}
|
||
|
||
public function addLiveUser($anchor_id, $live_id)
|
||
{
|
||
$live = Live::find($live_id);
|
||
$anchor = Anchor::where('id', $anchor_id)->first();
|
||
$viewer = Viewer::where('id', $anchor->viewer_id)->first();
|
||
if ($viewer && $viewer->user_id) {
|
||
$live->user_id = $viewer->user_id;
|
||
} elseif ($viewer && !$viewer->user_id) {
|
||
$user = User::where('mobile', $anchor->mobile)->first();
|
||
if ($user) {
|
||
$live->user_id = $user->id;
|
||
} else {
|
||
if (!$anchor->mobile)
|
||
$anchor->mobile = '188' . rand('00000000', '99999999');
|
||
$user = new User();
|
||
$user->name = $anchor->name;
|
||
$user->nickname = $anchor->name;
|
||
$user->mobile = $anchor->mobile;
|
||
$password = $anchor->mobile;
|
||
$user->email = $anchor->mobile . '@ufutx.com';
|
||
$user->is_new = 1;
|
||
$user->approve_time = 3;
|
||
$user->type = 'marriage';
|
||
$user->remark = '虚拟用户';
|
||
$user->password = $password ? bcrypt($password) : null;
|
||
$sex = Viewer::where('mobile', $anchor->mobile)->value('sex');
|
||
$user->sex = $sex ?? 0;
|
||
$user->save();
|
||
ProfileMarriage::create([
|
||
'user_id' => $user->id
|
||
]);
|
||
}
|
||
} else {
|
||
$user = User::withTrashed()->where('mobile', $anchor->mobile)->first();
|
||
if ($user && empty($user->deleted_at)) {
|
||
$live->user_id = $user->id;
|
||
} elseif ($user && !empty($user->deleted_at)) {
|
||
$user->deleted_at = null;
|
||
$user->save();
|
||
$live->user_id = $user->id;
|
||
} else {
|
||
$user = new User();
|
||
$user->name = $anchor->name;
|
||
$user->nickname = $anchor->name;
|
||
$user->mobile = $anchor->mobile;
|
||
$password = $anchor->mobile;
|
||
$user->email = $anchor->mobile . '@ufutx.com';
|
||
$user->is_new = 1;
|
||
$user->approve_time = 3;
|
||
$user->type = 'marriage';
|
||
$user->remark = '虚拟用户';
|
||
$user->password = $password ? bcrypt($password) : null;
|
||
$sex = Viewer::where('mobile', $anchor->mobile)->value('sex');
|
||
$user->sex = $sex ?? 0;
|
||
$user->save();
|
||
ProfileMarriage::create([
|
||
'user_id' => $user->id
|
||
]);
|
||
}
|
||
}
|
||
$live->save();
|
||
}
|
||
|
||
|
||
public function lives(Request $request)
|
||
{
|
||
try {
|
||
|
||
$lives = Live::with('video', 'lottery')->withCount('register', 'liveviewer');
|
||
$start = $request->start;
|
||
|
||
if ($start == 1) {
|
||
$lives = $lives->whereIn('status', [1, 3]); //1.直播中 3.暂停中
|
||
} elseif ($start == 2) {
|
||
$lives = $lives->where('status', 0); //未开始
|
||
} elseif ($start == 3) {
|
||
$lives = $lives->where('status', 2); //已结束
|
||
}
|
||
|
||
if ($request->has('class_id') && $request->class_id) {
|
||
$lives = $lives->where('class_id', $request->class_id);
|
||
}
|
||
|
||
if ($request->has('channel_id') && $request->channel_id) {
|
||
$lives = $lives->where('channel_id', $request->channel_id);
|
||
}
|
||
|
||
|
||
if ($request->has('recommend')) {
|
||
$lives = $lives->where('recommend', $request->recommend);
|
||
}
|
||
|
||
if ($request->has('anchor_id') && $request->anchor_id) {
|
||
$lives = $lives->where('anchor_id', $request->anchor_id);
|
||
}
|
||
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
if (is_numeric($request->keyword)) {
|
||
$lives = $lives->where('id', $request->keyword);
|
||
} else {
|
||
$lives = $lives->where('title', 'like', '%' . $request->keyword . '%');
|
||
}
|
||
}
|
||
$lives = $lives->where('id', '!=', 108)->orderBy('sort', 'desc')/*->orderByRaw(DB::raw('FIELD(status, 1,3,0,2) asc'))*/ ->orderBy('id', 'desc')->paginate();
|
||
foreach ($lives as $live) {
|
||
$live->pv = Redis::zscore('page_pv', $live->id);
|
||
$live->start_time = date('Y-m-d H:i', strtotime($live->start_time));
|
||
|
||
if ($live->times == 0) {
|
||
$live->times = Redis::zscore('page_pv', $live->id);
|
||
}
|
||
|
||
$live->recommend_course_id = json_decode($live->recommend_course_id, true);
|
||
$recommend_course_name = [];
|
||
if (!empty($live->recommend_course_id)) {
|
||
$recommend_course_name = Course::whereIn('id', $live->recommend_course_id)->pluck('title');
|
||
|
||
}
|
||
$live->recommend_course_name = $recommend_course_name;
|
||
|
||
|
||
$bind_mobile_count = 0;
|
||
$live->total_count = 0;
|
||
//绑定手机号人数
|
||
$bind_mobile_count = Viewer::where('mobile', '<>', '')->whereNoTNull('mobile')->where('live_id', $live->id)->count();
|
||
//没绑定手机号人数
|
||
$total_count = Viewer::where('live_id', $live->id)->count();
|
||
$live->bind_mobile_count = $bind_mobile_count;
|
||
$live->total_count = $total_count;
|
||
// return $recommend_course_name;
|
||
// $live->lottery_count = Record::select('viewer_id')->where('content', $live->command)->where('live_id', $live->id)->count();
|
||
// $command_arr = [];
|
||
// $new_arr = [];
|
||
// if(!empty($live->lottery)){
|
||
// foreach ($live->lottery as $item) {
|
||
// $new_arr['command'] = $item->command;
|
||
// $new_arr['num'] = $item->lottery->num;
|
||
// $command_arr[] = $new_arr;
|
||
// }
|
||
// }
|
||
// $live->command = $command_arr;
|
||
}
|
||
|
||
|
||
return $this->success('ok', $lives);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('获取直播首页数据失败,请稍后再试');
|
||
}
|
||
|
||
}
|
||
|
||
//直播推荐拖拽排序
|
||
public function livesOrderByDrag(Request $request)
|
||
{
|
||
$live_id = $request->live_id;
|
||
$other_live_id = $request->other_live_id;
|
||
$live = Live::find($live_id);
|
||
$other_live = Live::find($other_live_id);
|
||
if (empty($live)) {
|
||
return $this->failure('直播' . $live_id . '不存在');
|
||
}
|
||
if (empty($other_live)) {
|
||
return $this->failure('直播' . $other_live_id . '不存在');
|
||
}
|
||
$sort = $live->sort;
|
||
$other_sort = $other_live->sort;
|
||
|
||
|
||
if ($live->sort == $other_live->sort && $live->id < $other_live->id) {
|
||
$live->sort = $sort + 1;
|
||
} elseif ($live->sort == $other_live->sort && $live->id > $other_live->id) {
|
||
$other_live->sort = $other_sort + 1;
|
||
// dd($other_live->sort);
|
||
} elseif ($live->sort != $other_live->sort) {
|
||
$live->sort = $other_sort;
|
||
$other_live->sort = $sort;
|
||
}
|
||
|
||
$live->save();
|
||
$other_live->save();
|
||
return $this->success('ok', compact('live', 'other_live'));
|
||
}
|
||
|
||
public function live(Request $request, $live_id)
|
||
{
|
||
$viewer = Viewer::where('openid', $request->openid)->first();
|
||
|
||
//判断
|
||
$path = substr($request->path(), 0, 12);
|
||
$live = Live::with(['liveviewer', 'class:id,name', 'teacher', 'lottery'])->withCount('viewer', 'register')->find($live_id);
|
||
// return $this->success('ok', $live);
|
||
if (empty($live)) {
|
||
return $this->failure('直播不存在');
|
||
}
|
||
$id_arr = LiveViewer::where('live_id', $live_id)->pluck('viewer_id')->toArray();
|
||
// $live->viewer = Viewer::withCount('share')->whereIn('id', $id_arr)->paginate();
|
||
$live->viewer = Viewer::withCount('share')->where('live_id', $live_id)->paginate();
|
||
$live->pv = Redis::zscore('page_pv', $live_id);
|
||
$live->income = LiveOrder::where('live_id', $live_id)->where('pay_status', 1)->sum('price');
|
||
//如果是回放的话
|
||
if ($live->status == 2) {
|
||
$videos = Video::where('live_id', $live_id)->orderBy('created_at', 'desc')->get();
|
||
$new_videos = [];
|
||
$videoids = [];
|
||
foreach ($videos as &$video) {
|
||
|
||
//回放
|
||
if (substr($video->uri, 0, 4) != 'http') {
|
||
$new_videos[] = 'https://ufutx-image.oss-cn-shenzhen.aliyuncs.com/' . $video->uri;
|
||
} else {
|
||
$new_videos[] = $video->uri;
|
||
}
|
||
|
||
}
|
||
$live->video = $new_videos;
|
||
$live->videoid = $videoids;
|
||
}
|
||
|
||
$live->start_time = str_replace('-', '/', $live->start_time);
|
||
if (empty($live)) {
|
||
return $this->failure('直播数据不存在');
|
||
}
|
||
//如果是前端请求的话就获取拉流地址
|
||
if ($path == 'api/official') {
|
||
$aliyun = new Aliyun();
|
||
$live->playUrl = $aliyun->getPlayUrl($live->class_id, $live->id);
|
||
$live->mobilePlayUrl = $aliyun->getHlsPlayUrl($live->class_id, $live->id);
|
||
|
||
//统计页面pv
|
||
$this->addPv($live, $viewer);
|
||
} else if ($path == 'api/admin/li') {
|
||
$key = 'live_' . $live_id . 'pushurl';
|
||
$pushUrl = Redis::get($key);
|
||
if (!$pushUrl) {
|
||
$aliyun = new Aliyun();
|
||
$pushUrl = $aliyun->getPushUrl($live->class_id, $live->id);
|
||
Redis::setex($key, 30 * 60, $pushUrl);
|
||
}
|
||
$live->pushrul = $pushUrl;
|
||
|
||
//抽奖相关
|
||
if (!empty($live->lottery)) {
|
||
foreach ($live->lottery as $item) {
|
||
$item->lotteryer_count = LotteryList::where('lottery_id', $item->id)->count();
|
||
$winner_id = LotteryList::where('lottery_id', $item->id)->where('is_winner', 1)->pluck('viewer_id')->toArray();
|
||
$item->winner = Viewer::whereIn('id', $winner_id)->get();
|
||
}
|
||
}
|
||
|
||
//分享二维码
|
||
if (empty($live->share_qrcode)) {
|
||
$url = env('APP_URL') . '/h5/#/watchLive/' . $live_id . '?live_id=' . $live_id . '&type=live';
|
||
$result = $this->app->qrcode->forever($url);
|
||
$share_qrcode = $this->app->qrcode->url($result['ticket']);
|
||
Live::where('id', $live_id)->update(['share_qrcode' => $share_qrcode]);
|
||
$live->share_qrcode = $share_qrcode;
|
||
}
|
||
}
|
||
$live->viewer_count = $live->pv > $live->times ? $live->pv : $live->times;
|
||
$recommend_course_name = [];
|
||
if (!empty($live->recommend_course_id)) {
|
||
$live->recommend_course_id = json_decode($live->recommend_course_id, true);
|
||
$recommend_course_name[] = Course::whereIn('id', $live->recommend_course_id)->pluck('title');
|
||
}
|
||
$live->recommend_course_name = $recommend_course_name;
|
||
|
||
$bind_mobile_count = 0;
|
||
|
||
$live->total_count = 0;
|
||
$bind_mobile_count = Viewer::where('mobile', '<>', '')->whereNoTNull('mobile')->where('live_id', $live->id)->count();
|
||
$total_count = Viewer::where('live_id', $live->id)->count();
|
||
$live->bind_mobile_count = $bind_mobile_count;
|
||
$live->total_count = $total_count;
|
||
|
||
return $this->success('ok', $live);
|
||
}
|
||
|
||
public function viewersList(Request $request, $live_id)
|
||
{
|
||
$total = $request->all;
|
||
$keyword = $request->keyword;
|
||
$viewers = Viewer::where('live_id', $live_id);
|
||
if ($request->total == 'part') {
|
||
$viewers = $viewers->where('mobile', '<>', '')->whereNoTNull('mobile');
|
||
}
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$viewers = $viewers->where(function ($sql) use ($keyword) {
|
||
$sql->where('nickname', 'like', '%' . $keyword . '%')->orWhere('actual_name', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
|
||
$viewers = $viewers->select('avatar', 'mobile', 'sex', 'nickname', 'actual_name')->paginate();
|
||
return $this->success('ok', $viewers);
|
||
|
||
}
|
||
|
||
//增加观看历史、直播pv、主播热度
|
||
public function addPv($live, $viewer)
|
||
{
|
||
$key = $viewer->id . '_watch';
|
||
$len = Redis::llen($key);
|
||
if ($len) {
|
||
Redis::lrem($key, 1, $live->id);
|
||
Redis::lpush($key, $live->id);
|
||
redis::ltrim($key, 0, 149);
|
||
} else {
|
||
Redis::lpush($key, $live->id);
|
||
}
|
||
|
||
//增加页面跟主播的pv
|
||
Redis::zincrby('page_pv', 1, $live->id);
|
||
|
||
$anchor_id = $live->anchor_id;
|
||
if ($anchor_id) {
|
||
Redis::zincrby('anchor_red', 1, $anchor_id);
|
||
}
|
||
|
||
$count = LiveViewer::where('viewer_id', $viewer->id)->where('live_id', $live->id)->count();
|
||
if (!$count) {
|
||
$new_live_viewer = new LiveViewer();
|
||
$new_live_viewer->viewer_id = $viewer->id;
|
||
$new_live_viewer->live_id = $live->id;
|
||
$new_live_viewer->times = 1;
|
||
$new_live_viewer->save();
|
||
}
|
||
return true;
|
||
}
|
||
|
||
|
||
public function liveUpdate(Request $request, $live_id)
|
||
{
|
||
try {
|
||
$live = Live::find($live_id);
|
||
if (empty($live)) {
|
||
return $this->failure('直播数据不存在');
|
||
}
|
||
|
||
|
||
if ($request->has('title') && $request->title) {
|
||
$live->title = $request->title;
|
||
}
|
||
|
||
if ($request->has('recommend_course_id') && $request->recommend_course_id) {
|
||
$live->recommend_course_id = json_encode($request->recommend_course_id, JSON_UNESCAPED_UNICODE);
|
||
}
|
||
|
||
if ($request->has('sort') && $request->sort) {
|
||
$live->sort = $request->sort;
|
||
}
|
||
if ($request->has('recommend_community_id') && $request->recommend_community_id) {
|
||
$live->recommend_community_id = $request->recommend_community_id;
|
||
}
|
||
if ($request->has('poster') && $request->poster) {
|
||
$live->poster = $request->poster;
|
||
}
|
||
if ($request->has('share_poster') && $request->share_poster) {
|
||
$live->share_poster = $request->share_poster;
|
||
}
|
||
if ($request->has('url')) {
|
||
$live->url = $request->url;
|
||
}
|
||
if ($request->has('introduction') && $request->introduction) {
|
||
$live->introduction = $request->introduction;
|
||
}
|
||
if ($request->has('start_time') && $request->start_time) {
|
||
$live->start_time = $request->start_time;
|
||
}
|
||
if ($request->has('end_time') && $request->end_time) {
|
||
$live->end_time = $request->end_time;
|
||
}
|
||
if ($request->has('anchor_id') && $request->anchor_id) {
|
||
$live->anchor_id = $request->anchor_id;
|
||
|
||
}
|
||
if ($request->has('class_id') && $request->class_id) {
|
||
$live->class_id = $request->class_id;
|
||
}
|
||
if ($request->has('recommend')) {
|
||
$live->recommend = $request->recommend;
|
||
}
|
||
if ($request->has('detail') && $request->detail) {
|
||
$live->detail = $request->detail;
|
||
}
|
||
if ($request->has('is_show') && is_numeric($request->is_show)) {
|
||
$live->is_show = $request->is_show;
|
||
}
|
||
//收费
|
||
if ($request->has('is_free') && is_numeric($request->is_free)) {
|
||
$live->is_free = $request->is_free;
|
||
}
|
||
//收费价格
|
||
if ($request->has('price') && $request->price) {
|
||
$live->price = $request->is_free == 0 ? 0.00 : $request->price;
|
||
}
|
||
//预告
|
||
if ($request->has('teaser') && $request->teaser) {
|
||
$live->teaser = $request->teaser;
|
||
}
|
||
DB::beginTransaction();
|
||
//抽奖口令
|
||
if ($request->has('command') && $request->command) {
|
||
$command = $request->command;
|
||
if (empty($request->command) || empty($command[0]['command']) || empty($command[0]['num'])) {
|
||
Lottery::where('live_id', $live_id)->delete();
|
||
} elseif (is_array($request->command)) {
|
||
foreach ($request->command as $item) {
|
||
$lottery = Lottery::where('command', $item['command'])->where('live_id', $live_id)->first();
|
||
//不存在就新建
|
||
if (empty($lottery)) {
|
||
$new_lottery = new Lottery();
|
||
$new_lottery->live_id = $live_id;
|
||
$new_lottery->command = $item['command'];
|
||
$new_lottery->num = $item['num'];
|
||
$new_lottery->start_time = $live->start_time;
|
||
$new_lottery->end_time = $live->end_time;
|
||
$new_lottery->save();
|
||
} else {
|
||
//存在但是num不一样更新
|
||
if ($item['num'] != $lottery->num) {
|
||
$lottery->num = $item;
|
||
$lottery->save();
|
||
}
|
||
}
|
||
}
|
||
$command_arr = array_column($request->command, 'command');
|
||
Lottery::whereNotIn('command', $command_arr)->where('live_id', $live_id)->delete();
|
||
}
|
||
|
||
|
||
}
|
||
//如果手动添加了回放
|
||
$is_set = Video::where('uri', $request->video)->where('live_id', $live_id)->count();
|
||
if ($request->has('video') && empty($is_set)) {
|
||
Video::where('live_id', $live_id)->delete();
|
||
if (!empty($request->video)) {
|
||
$video = new Video();
|
||
$video->live_id = $live->id;
|
||
$video->uri = $request->video;
|
||
$video->duration = 0;
|
||
$video->save();
|
||
}
|
||
}
|
||
$live->command = '无';
|
||
$live->save();
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
|
||
} catch (\Exception $e) {
|
||
DB::rollBack();
|
||
return $this->failure('操作失败');
|
||
}
|
||
}
|
||
|
||
//展示/隐藏直播
|
||
public function liveShow(Request $request, $live_id)
|
||
{
|
||
$id_arr = explode(',', $request->id);
|
||
Live::whereIn('is_show', $id_arr)->update(['is_show', $request->is_show]);
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function liveDelete(Request $request, $live_id)
|
||
{
|
||
$live = Live::find($live_id);
|
||
if (empty($live)) {
|
||
return $this->failure('直播数据不存在');
|
||
}
|
||
Live::where('id', $live_id)->delete();
|
||
|
||
return $this->success('ok');
|
||
}
|
||
|
||
|
||
public function viewers(Request $request)
|
||
{
|
||
$viewers = Viewer::withCount([
|
||
'activityUser' => function ($query) {
|
||
$query->where('status', 1);
|
||
}
|
||
])/*->with('shareRoles')*/ ;
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$keyword = $request->keyword;
|
||
$viewers = $viewers->where(function ($sql) use ($keyword) {
|
||
$sql->where('nickname', 'like', '%' . $keyword . '%')
|
||
->orWhere('mobile', 'like', '%' . $keyword . '%')
|
||
->orWhere('id', $keyword);
|
||
});
|
||
// $viewers->where('nickname', 'like', '%'.$request->keyword.'%')->orWhere('mobile', '%'.$request->keyword.'%')->orWhere('id', $request->keyword);
|
||
|
||
}
|
||
if ($request->has('viewer_id') && $request->viewer_id) {
|
||
$viewers = $viewers->where('viewer_id', $request->viewer_id);
|
||
}
|
||
|
||
if ($request->has('is_follower') && $request->is_follower) {
|
||
$viewers = $viewers->whereHas('user')->where('is_follower', $request->is_follower);
|
||
}
|
||
if ($request->has('type') && $request->type) {
|
||
switch ($request->type) {
|
||
case 'time':
|
||
$viewer = $viewers->orderBy('created_at', 'desc');
|
||
break;
|
||
case 'share':
|
||
$viewer = $viewers->orderBy('times', 'desc');
|
||
break;
|
||
default:
|
||
$viewer = $viewers->orderBy('created_at', 'desc');
|
||
}
|
||
}
|
||
|
||
|
||
|
||
$viewers = $viewers->orderBy('become_follower_at', 'desc')->paginate();
|
||
|
||
//判断是否关注
|
||
foreach ($viewers as &$viewer) {
|
||
// dd($viewer->user_id);
|
||
// $viewer->is_subscribe = $this->subscribe($viewer->openid);
|
||
// $viewer->share_count = ViewerShare::where('sharer_id', $viewer->id)->where('type', 1)->count();
|
||
// $viewer->times = $viewer->shareviewer_count;
|
||
// $viewer->referrer = Viewer::select('id', 'nickname')->where('id', $viewer->viewer_id)->first();
|
||
$viewer->is_banned = $viewer->free_time > date('Y-m-d H:i:s') ? 1 : 0;
|
||
$real_approve_users = ApproveHistory::where('status', 1)->where('type', 'body')->where('from_user_id', $viewer->user_id);
|
||
if ($request->approve_from_platform) {
|
||
$real_approve_users = $real_approve_users->where('from_platform', $request->approve_from_platform);
|
||
}
|
||
$user_ids = $real_approve_users->pluck('user_id')->toArray();
|
||
$approve_count = User::whereIn('id', $user_ids)->where('is_real_approved', 1)->count();//专员真人认证数量
|
||
|
||
$viewer->approve_count = $approve_count;
|
||
// if($request->is_follower == 1){
|
||
// $viewer->activity_user_count = ActivityUser::where('follow_user_id', $viewer->user_id)->where('status', 1)->count();
|
||
// }
|
||
}
|
||
return $this->success('ok', $viewers);
|
||
}
|
||
|
||
public function viewer(Request $request, $viewer_id)
|
||
{
|
||
$viewer = Viewer::withCount('share')->with('asset:id,cash')->find($viewer_id);
|
||
if (empty($viewer)) {
|
||
return $this->failure('用户不存在');
|
||
}
|
||
$viewer->focus_count = AnchorViewer::where('viewer_id', $viewer_id)->where('focusing', 1)->count();
|
||
$viewer->share = Viewer::where('viewer_id', $viewer_id)->paginate();
|
||
|
||
//钱包余额
|
||
|
||
$asset = Asset::select('cash', 'share_cash')->where('viewer_id', $viewer_id)->first();
|
||
if ($asset) {
|
||
$score = $asset ? bcadd($asset->share_cash, $asset->cash, 2) : 0;
|
||
$viewer->score = $score;
|
||
|
||
}
|
||
|
||
foreach ($viewer->share as &$item) {
|
||
$item->is_subscribe = $this->subscribe($item->openid);
|
||
}
|
||
|
||
$path = substr($request->path(), 0, 12);
|
||
if ($path == 'api/official') {
|
||
$anchor = Anchor::where('viewer_id', $viewer_id)->first();
|
||
$viewer->is_teacher = empty($anchor) ? 0 : 1;
|
||
if ($viewer->is_teacher) {
|
||
$viewer->fans = AnchorViewer::where('anchor_id', $anchor->id)->where('focusing', 1)->count();
|
||
}
|
||
}
|
||
return $this->success('ok', $viewer);
|
||
}
|
||
|
||
//收益记录
|
||
public function gainLogs(Request $request, $viewer_id)
|
||
{
|
||
|
||
$logs = AssetLog::select('id', 'num', 'type', 'score', 'created_at')->where('viewer_id', $viewer_id)->where('is_hooked', 1)->where('type', '!=', 3)->orderBy('created_at', 'desc')->paginate();
|
||
return $this->success('ok', $logs);
|
||
|
||
}
|
||
|
||
|
||
public function updateViewer(Request $request, $viewer_id)
|
||
{
|
||
$viewer = Viewer::find($viewer_id);
|
||
if (empty($viewer)) {
|
||
return $this->failure('直播用户不存在');
|
||
}
|
||
|
||
if ($request->has('free_time') && $request->free_time) {
|
||
$viewer->free_time = $request->free_time;
|
||
}
|
||
$viewer->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function banLiveViewer(Request $request, $user_id)
|
||
{
|
||
$viewer = Viewer::where('user_id', $user_id)->first();
|
||
if (empty($viewer)) {
|
||
return $this->failure('直播用户不存在');
|
||
}
|
||
|
||
if ($request->has('free_time') && $request->free_time) {
|
||
$viewer->free_time = $request->free_time;
|
||
}
|
||
$viewer->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function unbanLiveViewer(Request $request, $user_id)
|
||
{
|
||
$viewer = Viewer::where('user_id', $user_id)->first();
|
||
if (empty($viewer)) {
|
||
return $this->failure('直播用户不存在');
|
||
}
|
||
$viewer->free_time = null;
|
||
$viewer->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
|
||
public function deleteViewer(Request $request, $viewer_id)
|
||
{
|
||
$viewer = Viewer::find($viewer_id);
|
||
if (empty($viewer)) {
|
||
return $this->failure('直播用户不存在');
|
||
}
|
||
DB::beginTransaction();
|
||
if (!Viewer::where('id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (Anchor::where('viewer_id', $viewer_id)->count('viewer_id') && !Anchor::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (AnchorViewer::where('viewer_id', $viewer_id)->count('viewer_id') && !AnchorViewer::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (ShareRoleViewer::where('viewer_id', $viewer_id)->count('viewer_id') && !ShareRoleViewer::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (LiveViewer::where('viewer_id', $viewer_id)->count('viewer_id') && !LiveViewer::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (TaskViewer::where('viewer_id', $viewer_id)->count('viewer_id') && !TaskViewer::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (AssetLog::where('viewer_id', $viewer_id)->count('viewer_id') && !AssetLog::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (Asset::where('viewer_id', $viewer_id)->count('viewer_id') && !Asset::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (ViewerShare::where('viewer_id', $viewer_id)->count('viewer_id') && !ViewerShare::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (ShareFundLog::where('viewer_id', $viewer_id)->count('viewer_id') && !ShareFundLog::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (Messenger::where('viewer_id', $viewer_id)->count('viewer_id') && !Messenger::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (Record::where('viewer_id', $viewer_id)->where('class', 'h5')->count('viewer_id') && !Record::where('viewer_id', $viewer_id)->where('class', 'h5')->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (Feedback::where('viewer_id', $viewer_id)->count('viewer_id') && !Feedback::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (GiftOrder::where('viewer_id', $viewer_id)->count('viewer_id') && !GiftOrder::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (LiveOrder::where('viewer_id', $viewer_id)->count('viewer_id') && !LiveOrder::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (Question::where('viewer_id', $viewer_id)->count('viewer_id') && !Question::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (CommunityGroupAdmin::where('viewer_id', $viewer_id)->count('viewer_id') && !CommunityGroupAdmin::where('viewer_id', $viewer_id)->delete()) {
|
||
DB::rollback();
|
||
return $this->failure('删除失败');
|
||
}
|
||
if (CommunityStar::where('from_id', $viewer_id)->count('from_id') && !CommunityStar::where('from_id', $viewer_id)->update(['from_id' => 0])) {
|
||
DB::rollback();
|
||
return $this->failure('更新失败');
|
||
}
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 新增分类
|
||
* @description 增加直播分类接口
|
||
* @method POST
|
||
* @url api/admin/live/class
|
||
* @param name 必选 string 名字
|
||
* @return {
|
||
"code": 0,
|
||
"message": "ok",
|
||
"data": []
|
||
}
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
|
||
public function addClass(Request $request)
|
||
{
|
||
if (!$request->has('name')) {
|
||
return $this->failure('必选项不能为空');
|
||
}
|
||
$isset = LiveClass::where('name', $request->name)->count();
|
||
if ($isset) {
|
||
return $this->failure('分类已存在');
|
||
}
|
||
$class = new LiveClass();
|
||
$class->name = $request->name;
|
||
$class->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 分类列表
|
||
* @description 分类列表接口
|
||
* @method GET
|
||
* @url api/admin/live/classes
|
||
* @param keyword 可选 string 关键字
|
||
* @return {
|
||
"code": 0,
|
||
"message": "ok",
|
||
"data": {
|
||
"current_page": 1,
|
||
"data": [
|
||
{
|
||
"id": 7,
|
||
"name": "婚恋辅导",
|
||
"sort": 0,
|
||
"created_at": "2020-04-08 16:26:21",
|
||
"updated_at": "2020-04-08 16:26:23",
|
||
"deleted_at": null
|
||
}
|
||
],
|
||
"first_page_url": "http://wlj.test/api/admin/live/classes?page=1",
|
||
"from": 1,
|
||
"last_page": 1,
|
||
"last_page_url": "http://wlj.test/api/admin/live/classes?page=1",
|
||
"next_page_url": null,
|
||
"path": "http://wlj.test/api/admin/live/classes",
|
||
"per_page": 15,
|
||
"prev_page_url": null,
|
||
"to": 7,
|
||
"total": 7
|
||
}
|
||
}
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
//分类列表
|
||
public function classes(Request $request)
|
||
{
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$classes = LiveClass::where('name', 'like', '%' . $request->keyword . '%')->orderBy('created_at', 'desc');
|
||
} else {
|
||
$classes = LiveClass::orderBy('created_at', 'desc');
|
||
}
|
||
$classes = $classes->paginate();
|
||
return $this->success('ok', $classes);
|
||
}
|
||
|
||
//其他页面请求分类列表
|
||
public function searchClasses(Request $request)
|
||
{
|
||
$classes = LiveClass::select('id', 'name');
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$classes = $classes->where('name', 'like', '%' . $request->keyword . '%')->orderBy('created_at', 'desc');
|
||
} else {
|
||
$classes = $classes->orderBy('created_at', 'desc');
|
||
}
|
||
$classes = $classes->get();
|
||
return $this->success('ok', $classes);
|
||
}
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 分类详情
|
||
* @description 分类详情接口
|
||
* @method GET
|
||
* @url api/admin/live/class/{class_id}
|
||
* @return {
|
||
"code": 0,
|
||
"message": "ok",
|
||
"data": {
|
||
"id": 1,
|
||
"name": "美年T LB",
|
||
"sort": 99,
|
||
"created_at": "2020-04-08 16:25:16",
|
||
"updated_at": "2020-04-08 16:25:17",
|
||
"deleted_at": null
|
||
}
|
||
}
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
//分类列表
|
||
public function class(Request $request, $class_id)
|
||
{
|
||
$class = LiveClass::find($class_id);
|
||
return $this->success('ok', $class);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 编辑分类
|
||
* @description 编辑直播分类接口
|
||
* @method PUT
|
||
* @url api/admin/live/class/{class_id}
|
||
* @return {
|
||
"code": 0,
|
||
"message": "ok",
|
||
"data": []
|
||
}
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
//编辑分类
|
||
public function classUpdate(Request $request, $class_id)
|
||
{
|
||
$class = LiveClass::find($class_id);
|
||
if ($request->has('name') && $request->name) {
|
||
$isset = LiveClass::where('name', $request->name)->count();
|
||
if ($isset) {
|
||
return $this->failure('分类名已存在');
|
||
}
|
||
$class->name = $request->name;
|
||
}
|
||
if ($request->has('sort') && $request->sort) {
|
||
$class->name = $request->sort;
|
||
}
|
||
if ($request->has('is_show') && is_numeric($request->is_show)) {
|
||
if ($request->is_show != $class->is_show) {
|
||
$class->is_show = $request->is_show;
|
||
}
|
||
}
|
||
$class->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播
|
||
* @title 删除分类
|
||
* @description 删除直播分类接口
|
||
* @method DELETE
|
||
* @url api/admin/live/class/{class_id}
|
||
* @return {
|
||
"code": 0,
|
||
"message": "ok",
|
||
"data": []
|
||
}
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
public function classDelete(Request $request, $class_id)
|
||
{
|
||
$class = LiveClass::find($class_id);
|
||
$class->delete();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
|
||
/**
|
||
* 频道
|
||
*/
|
||
public function addChannel(Request $request)
|
||
{
|
||
if (!$request->has('name') || !$request->has('icon') || !$request->has('sort') || !$request->has('type')) {
|
||
return $this->failure('必选项不能为空');
|
||
}
|
||
if (($request->type == 2 || $request->type == 3) && (!$request->has('price') || !$request->price)) {
|
||
return $this->failure('价格错误');
|
||
}
|
||
$channel = new LiveChannel();
|
||
$channel->name = $request->name;
|
||
$channel->sort = $request->sort;
|
||
$channel->icon = $request->icon;
|
||
$channel->type = $request->type;
|
||
$channel->price = $request->price;
|
||
$channel->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
|
||
|
||
//频道列表
|
||
public function channels(Request $request)
|
||
{
|
||
|
||
$classes = LiveClass::orderBy('sort', 'desc');
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$classes->where('title', 'like', '%' . $request->keyword . '%');
|
||
}
|
||
if ($request->has('type') && $request->type) {
|
||
$classes->where('type', $request->type);
|
||
}
|
||
if ($request->has('start_time') && $request->start_time && $request->has('end_time') && $request->end_time) {
|
||
$classes->whereBetween('created_at', [$request->start_time, $request->end_time]);
|
||
}
|
||
$classes = $classes->paginate();
|
||
return $this->success('ok', $classes);
|
||
}
|
||
//频道
|
||
public function channel(Request $request, $channel_id)
|
||
{
|
||
$class = LiveChannel::find($channel_id);
|
||
return $this->success('ok', $class);
|
||
}
|
||
|
||
//编辑分类
|
||
public function channelUpdate(Request $request, $channel_id)
|
||
{
|
||
$channel = LiveChannel::find($channel_id);
|
||
if ($request->has('name') && $request->name) {
|
||
$channel->name = $request->name;
|
||
}
|
||
if ($request->has('sort') && $request->sort) {
|
||
$channel->name = $request->sort;
|
||
}
|
||
if ($request->has('icon') && $request->icon) {
|
||
$channel->name = $request->icon;
|
||
}
|
||
$channel->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function channelDelete(Request $request, $channel_id)
|
||
{
|
||
$channel = LiveChannel::find($channel_id);
|
||
$channel->delete();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播
|
||
* @title 新增主播
|
||
* @description 增加主播分类接口
|
||
* @method POST
|
||
* @url api/admin/live/anchor
|
||
* @param viewer_id 必选 int 主播id
|
||
* @param introduction 必选 string 简介
|
||
* @param fans_group 可选 string 粉丝群
|
||
* @return {
|
||
"code": 0,
|
||
"message": "ok",
|
||
"data": []
|
||
}
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
/**
|
||
* 主播
|
||
*/
|
||
public function addAnchor(Request $request)
|
||
{
|
||
if (!$request->has('viewer_id')) {
|
||
return $this->failure('用户id不能为空');
|
||
}
|
||
$isset = Anchor::where('viewer_id', $request->viewer_id)->count();
|
||
if ($isset) {
|
||
return $this->failure('老师已存在');
|
||
}
|
||
|
||
try {
|
||
DB::beginTransaction();
|
||
$viewer = Viewer::find($request->viewer_id);
|
||
$anchor = new Anchor();
|
||
$anchor->viewer_id = $request->viewer_id;
|
||
$anchor->introduction = $request->introduction ?: '无';
|
||
$anchor->name = $request->name ?: $viewer->nickname;
|
||
$anchor->pic = $request->pic ?: $viewer->avatar;
|
||
$anchor->follow_user = auth()->id();
|
||
$anchor->status = 2;
|
||
$anchor->is_show = 0;
|
||
// $anchor->desc = '后台直接添加';
|
||
if ($request->fans_group) {
|
||
$anchor->fans_group = $request->fans_group;
|
||
}
|
||
$anchor->save();
|
||
|
||
$user_id = User::where('mobile', $viewer->mobile)->value('id');
|
||
if ($user_id) {
|
||
$community = new Community();
|
||
$community->user_id = $user_id;
|
||
$community->logo = $viewer->avatar;
|
||
$community->title = $viewer->nickname;
|
||
$community->intro = $viewer->introduction;
|
||
$community->save();
|
||
|
||
$community_link = new CommunityGroupLink();
|
||
$community_link->community_id = $community->id;
|
||
$community_link->group_id = 109;
|
||
$community_link->save();
|
||
|
||
$community_member = new CommunityMember();
|
||
$community_member->user_id = $user_id;
|
||
$community_member->community_id = $community->id;
|
||
$community_member->save();
|
||
|
||
}
|
||
\DB::commit();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
\DB::rollback();
|
||
return $this->success('添加失败');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播
|
||
* @title 主播列表
|
||
* @description 分类列表接口
|
||
* @method GET
|
||
* @url api/admin/live/classes
|
||
* @param keyword 可选 string 关键字
|
||
* @return {
|
||
"code": 0,
|
||
"message": "ok",
|
||
"data": {
|
||
"current_page": 1,
|
||
"data": [
|
||
{
|
||
"id": 1,
|
||
"viewer_id": 1,
|
||
"introduction": "对我个人而言,该不该吃狗 在面对这种问题时。",
|
||
"fans_group": "https://local-pictures.oss-cn-shenzhen.aliyuncs.com/202004/08/=17.png",
|
||
"created_at": "2020-04-08 18:32:35",
|
||
"updated_at": "2020-04-08 18:32:35",
|
||
"deleted_at": null,
|
||
"viewer": []
|
||
}
|
||
],
|
||
"first_page_url": "http://wlj.test/api/admin/live/classes?page=1",
|
||
"from": 1,
|
||
"last_page": 1,
|
||
"last_page_url": "http://wlj.test/api/admin/live/classes?page=1",
|
||
"next_page_url": null,
|
||
"path": "http://wlj.test/api/admin/live/classes",
|
||
"per_page": 15,
|
||
"prev_page_url": null,
|
||
"to": 7,
|
||
"total": 7
|
||
}
|
||
}
|
||
* @return_param viewer arr 用户
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
//主播列表
|
||
public function anchors(Request $request)
|
||
{
|
||
|
||
$keyword = $request->keyword;
|
||
$status = $request->input('status', 0);
|
||
$anchors = Anchor::with('viewer', 'operator', 'merchant:mobile,id')->withCount('articles', 'videos')->where('status', $status);
|
||
if ($keyword) {
|
||
$anchors = $anchors->where(function ($sql) use ($keyword) {
|
||
$sql->where('name', 'like', '%' . $keyword . '%')->orWhere('mobile', 'like', '%' . $keyword . '%')
|
||
->orWhereHas('merchant', function ($sql) use ($keyword) {
|
||
$sql->where('id', $keyword);
|
||
});
|
||
});
|
||
}
|
||
if ($request->has('is_rec') && $request->is_rec) {
|
||
$anchors = $anchors->where('is_rec', 1);
|
||
}
|
||
// $page = $request->page?:1;
|
||
// $limit = $request->limit?:15;
|
||
// $start = ($page - 1)*$limit;
|
||
// $total = $anchors->count();
|
||
// $last_page = ceil($total/$limit);
|
||
// $next_page = ($page+1) > $last_page ? $page : $page+1;
|
||
if ($request->has('nopage') && $request->nopage) {
|
||
$anchors = $anchors->orderBy('is_show_consulation', 'desc')->orderBy('id', 'desc')->get();
|
||
} else {
|
||
$anchors = $anchors->orderBy('is_show_consulation', 'desc')->orderBy('id', 'desc')->paginate();
|
||
}
|
||
|
||
|
||
foreach ($anchors as $anchor) {
|
||
$anchor->pv = Redis::zscore('anchor_red', $anchor->id);
|
||
$anchor->desc = $anchor->desc ? json_decode($anchor->desc, true) : [];
|
||
$anchor->teaching_user = $anchor->teaching_user ? json_decode($anchor->teaching_user, true) : [];
|
||
$anchor->cooperation_type = $anchor->cooperation_type ? json_decode($anchor->cooperation_type, true) : [];
|
||
$anchor->label = $anchor->label ? json_decode($anchor->label, true) : [];
|
||
if ($anchor->service_nature == 'person') {
|
||
$anchor->service_nature = '个人';
|
||
}
|
||
if ($anchor->service_nature == 'team') {
|
||
$anchor->service_nature = '团队';
|
||
}
|
||
|
||
$from_user_name = '未获取';
|
||
$from_user_name = Viewer::where('openid', $anchor->from_openid)->value('nickname');
|
||
if (empty($from_user_name)) {
|
||
if ($anchor->viewer_id) {
|
||
$viewer = Viewer::where('id', $anchor->viewer_id)->first();
|
||
if ($viewer && $viewer->viewer_id) {
|
||
$from_user_name = Viewer::where('id', $viewer->viewer_id)->value('nickname');
|
||
}
|
||
}
|
||
}
|
||
$anchor->from_user_name = $from_user_name;
|
||
if (empty($anchor->mobile) && $anchor->viewer_id) {
|
||
$anchor->mobile = Viewer::where('id', $anchor->viewer_id)->value('mobile');
|
||
}
|
||
|
||
}
|
||
return $this->success('ok', $anchors);
|
||
// $data = [
|
||
// 'data' => $anchors,
|
||
// 'first_page_url' => env('APP_URL')."/api/admin/live/anchors?page=1",
|
||
// 'from' => $start,
|
||
// 'last_page' => $last_page,
|
||
// 'last_page_url' => env('APP_URL')."/api/admin/live/anchors?page=".$last_page,
|
||
// 'next_page_url' => null,
|
||
// 'path' => env('APP_URL')."/api/admin/live/anchors",
|
||
// 'per_page' => $limit,
|
||
// 'prev_page_url' => null,
|
||
// 'to'=> $next_page,
|
||
// 'total' => $total,
|
||
// ];
|
||
// return $this->success('ok', $data);
|
||
}
|
||
|
||
//更改老师跟进状态
|
||
public function updateTeacherStatus(Request $request, $anchor_id)
|
||
{
|
||
try {
|
||
$user_id = auth()->id();
|
||
$user = User::find($user_id);
|
||
$nickname = $user->nickname ? $user->nickname : $user->name;
|
||
$avatar = $user->userAvatar($user_id);
|
||
$anchor = Anchor::find($anchor_id);
|
||
$max_sort = Anchor::max('sort');
|
||
if (empty($anchor))
|
||
return $this->failure('要跟进的老师不存在');
|
||
$descs = $request->descs;
|
||
if (empty($descs))
|
||
return $this->failure('请按要求填写对老师的跟进描述');
|
||
if (empty($anchor->desc)) {
|
||
$record = array(
|
||
array('沟通方式' => $descs[0], '跟进内容' => $descs[1], '达成结果' => $descs[2], '跟进人' => auth()->id(), '跟进时间' => date('Y-m-d H:i:s'), '跟进人头像' => $avatar, '跟进人昵称' => $nickname)
|
||
)
|
||
;
|
||
} else {
|
||
$desc = json_decode($anchor->desc);
|
||
$array = ['沟通方式' => $descs[0], '跟进内容' => $descs[1], '达成结果' => $descs[2], '跟进人' => auth()->id(), '跟进时间' => date('Y-m-d H:i:s'), '跟进人头像' => $avatar, '跟进人昵称' => $nickname];
|
||
array_push($desc, $array);
|
||
$record = $desc;
|
||
}
|
||
$status = $request->status;
|
||
if ($status == 2) {
|
||
$anchor->withdrawal_radio = 100;
|
||
// $anchor->sort = $max_sort + 1;
|
||
$anchor->is_show_consulation = 1;
|
||
}
|
||
$anchor->desc = json_encode($record, JSON_UNESCAPED_UNICODE);
|
||
$anchor->follow_user = $user_id;
|
||
$anchor->follow_time = date('Y-m-d H:i:s');
|
||
$anchor->status = $status;
|
||
$anchor->save();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('跟进失败,请联系开发人员');
|
||
}
|
||
|
||
}
|
||
|
||
//批量 隐藏/打开 老师
|
||
public function changeStatusBatch(Request $request)
|
||
{
|
||
$anchor_ids = $request->anchor_ids;
|
||
$is_show = $request->is_show ?? 0;
|
||
$type = $request->type ?? 'consulation';
|
||
if (empty($anchor_ids))
|
||
return $this->failure('请选择要修改的老师');
|
||
if ($type == 'live') {
|
||
Anchor::whereIn('id', $anchor_ids)->update(['is_show' => $is_show]);
|
||
}
|
||
if ($type == 'consulation') {
|
||
Anchor::whereIn('id', $anchor_ids)->update(['is_show_consulation' => $is_show]);
|
||
}
|
||
return $this->success('ok');
|
||
}
|
||
|
||
|
||
|
||
public function getPreviewQrcode($scene_str)
|
||
{
|
||
$pic_path = storage_path('qrcode/' . time() . 'preview.png');
|
||
//二维码图片
|
||
QrCode::format('png')->margin(1)->size(600)->generate($scene_str, $pic_path);
|
||
$pic = $this->uploadFile($pic_path);
|
||
return $pic;
|
||
}
|
||
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 主播详情
|
||
* @description 主播详情接口
|
||
* @method GET
|
||
* @url api/admin/live/anchor/{anchor_id}
|
||
* @return {
|
||
"code": 0,
|
||
"message": "ok",
|
||
"data": {
|
||
"id": 1,
|
||
"viewer_id": 8,
|
||
"introduction": "对我个人而言,该不该吃狗肉不仅仅是一个重大的事件,还可能会改变我的人生。 难的抉择下,本人思来想去,寝食难安。 每个人都不得不面对这些问题。 在面对这种问题时。",
|
||
"fans_group": "https://local-pictures.oss-cn-shenzhen.aliyuncs.com/202004/08/=17.png",
|
||
"created_at": "2020-04-08 18:32:35",
|
||
"updated_at": "2020-04-08 18:32:35",
|
||
"deleted_at": null,
|
||
"viewer_count": 1
|
||
}
|
||
}
|
||
* @return_param viewer arr 用户
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
//主播
|
||
public function anchor(Request $request, $anchor_id)
|
||
{
|
||
$lives = Live::with('video', 'lottery')->where('anchor_id', $anchor_id)->withCount('register', 'liveviewer');
|
||
$start = $request->start;
|
||
if ($start == 1) {
|
||
$lives = $lives->whereIn('status', [1, 3]); //1.直播中 3.暂停中
|
||
} elseif ($start == 2) {
|
||
$lives = $lives->where('status', 0); //未开始
|
||
} elseif ($start == 3) {
|
||
$lives = $lives->where('status', 2); //已结束
|
||
}
|
||
$lives = $lives->where('id', '!=', 108)->orderBy('sort', 'desc')/*->orderByRaw(DB::raw('FIELD(status, 1,3,0,2) asc'))*/ ->orderBy('id', 'desc')->get();
|
||
foreach ($lives as $live) {
|
||
$live->pv = Redis::zscore('page_pv', $live->id);
|
||
$live->start_time = date('Y-m-d H:i', strtotime($live->start_time));
|
||
|
||
if ($live->times == 0) {
|
||
$live->times = Redis::zscore('page_pv', $live->id);
|
||
}
|
||
}
|
||
|
||
$anchor = Anchor::withCount([
|
||
'focu' => function ($query) {
|
||
$query->where('focusing', 1);
|
||
}
|
||
])->with(['viewer:id,nickname,avatar,sex,mobile', 'live.video'])->find($anchor_id);
|
||
if (empty($anchor)) {
|
||
return $this->failure('老师不存在');
|
||
}
|
||
if ($anchor->focu_count) {
|
||
$anchor->focu_count = $anchor->focu_count < 10000 ? $anchor->focu_count : round($anchor->focu_count / 10000, 2) . '万';
|
||
} else {
|
||
$anchor->focu_count = 0;
|
||
}
|
||
|
||
// $videos = [];
|
||
// if(!empty($anchor->live)){
|
||
// foreach ($anchor->live as $live){
|
||
// if(!empty($live->video)){
|
||
// $videos[] = $live->video->uri;
|
||
// }
|
||
// }
|
||
// }
|
||
// $anchor->video = $videos;
|
||
// unset($anchor->live);
|
||
$anchor->is_focu = $anchor->focu_count ? 1 : 0;
|
||
$anchor->pv = Redis::zscore('anchor_red', $anchor_id);
|
||
$anchor->label = json_decode($anchor->label, true) ?? [];
|
||
$anchor->lives = $lives;
|
||
|
||
return $this->success('ok', $anchor);
|
||
}
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 编辑主播
|
||
* @description 编辑主播的接口
|
||
* @method PUT
|
||
* @url /api/official/live/anchor/{anchor_id}
|
||
* @param introduction 可选 string 简介
|
||
* @param fans_group 可选 string 粉丝群
|
||
* @return {
|
||
"code": 0,
|
||
"message": "ok",
|
||
"data": []
|
||
}
|
||
* @return_param groupid int 用户组id
|
||
* @return_param name string 用户昵称
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
//编辑主播
|
||
public function anchorUpdate(Request $request, $anchor_id)
|
||
{
|
||
$anchor = Anchor::find($anchor_id);
|
||
if (empty($anchor)) {
|
||
return $this->failure('数据不存在');
|
||
}
|
||
if ($request->has('introduction') && $request->introduction) {
|
||
$anchor->introduction = $request->introduction;
|
||
}
|
||
if ($request->has('fans_group') && $request->fans_group) {
|
||
$anchor->fans_group = $request->fans_group;
|
||
}
|
||
if ($request->has('name') && $request->name) {
|
||
$anchor->name = $request->name;
|
||
}
|
||
if ($request->has('pic') && $request->pic) {
|
||
$anchor->pic = $request->pic;
|
||
}
|
||
if ($request->has('designation') && $request->designation) {
|
||
$anchor->designation = $request->designation;
|
||
}
|
||
if ($request->has('sort') && $request->sort) {
|
||
$anchor->sort = $request->sort;
|
||
}
|
||
if ($request->has('price') && $request->price && is_numeric($request->price)) {
|
||
$anchor->price = $request->price;
|
||
}
|
||
if ($request->has('Years') && $request->Years && is_numeric($request->Years)) {
|
||
$anchor->Years = $request->Years;
|
||
}
|
||
if ($request->has('label') && $request->label) {
|
||
$anchor->label = json_encode($request->label);
|
||
}
|
||
if ($request->has('resume') && $request->resume) {
|
||
$anchor->resume = $request->resume;
|
||
}
|
||
if ($request->has('duration') && $request->duration) {
|
||
$anchor->duration = $request->duration;
|
||
}
|
||
if ($request->has('experience') && $request->experience) {
|
||
$anchor->experience = $request->experience;
|
||
}
|
||
if ($request->has('branch') && $request->branch && $anchor->branch != $request->branch) {
|
||
$anchor->branch = $request->branch;
|
||
}
|
||
if ($request->is_rec == 1) {
|
||
$anchor->is_rec = 1;
|
||
}
|
||
if ($request->is_rec == 2) {
|
||
$anchor->is_rec = 0;
|
||
}
|
||
if ($request->has('is_show') && $request->is_show == 1) {
|
||
$anchor->is_show = 0;
|
||
}
|
||
if ($request->has('is_show') && $request->is_show == 2) {
|
||
$anchor->is_show = 1;
|
||
}
|
||
if ($request->has('is_show_consulation') && $request->is_show_consulation == 1) {
|
||
$anchor->is_show_consulation = 0;
|
||
}
|
||
if ($request->has('is_show_consulation') && $request->is_show_consulation == 2) {
|
||
$anchor->is_show_consulation = 1;
|
||
}
|
||
if ($request->has('service_content') && $anchor->service_content != $request->service_content) {
|
||
$anchor->service_content = $request->service_content;
|
||
}
|
||
if ($request->withdrawal_radio && $anchor->withdrawal_radio != $request->withdrawal_radio) {
|
||
if (!is_numeric($request->withdrawal_radio) || $request->withdrawal_radio > 100 || $request->withdrawal_radio < 0) {
|
||
return $this->failure('请输入正确的提现比例');
|
||
}
|
||
$anchor->withdrawal_radio = $request->withdrawal_radio;
|
||
}
|
||
$anchor->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
//老师咨询记录
|
||
public function consulationRecords(Request $request)
|
||
{
|
||
$status = $request->input('status', 0);
|
||
$pay_status = $request->input('pay_status', 0);
|
||
$anchor_id = $request->anchor_id;
|
||
$keyword = $request->keyword;
|
||
$comment = $request->comment;
|
||
$records = ConsultationRecords::with('viewer', 'anchor', 'fromUser')->where('status', $status)->where('pay_status', $pay_status);
|
||
if ($anchor_id) {
|
||
$records = $records->where('anchor_id', $anchor_id);
|
||
}
|
||
if ($comment == 'comment') {
|
||
$records = $records->whereNotNull('comment')->where('comment', '<>', '');
|
||
}
|
||
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$records = $records->where(function ($sql) use ($keyword) {
|
||
$sql->where('name', 'like', '%' . $keyword . '%')->orWhere('phone', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$records = $records->orderBy('id', 'desc')->paginate();
|
||
return $this->success('ok', $records);
|
||
}
|
||
//老师咨询记录v2
|
||
public function consulationRecordsV2(Request $request)
|
||
{
|
||
$status = $request->input('status', 0);
|
||
$pay_status = $request->input('pay_status', 0);
|
||
$anchor_id = $request->anchor_id;
|
||
$keyword = $request->keyword;
|
||
$comment = $request->comment;
|
||
$records = ConsultationRecords::with('viewer', 'anchor', 'fromUser');
|
||
if ($anchor_id) {
|
||
$records = $records->where('anchor_id', $anchor_id);
|
||
}
|
||
|
||
if ($comment == 'comment') {
|
||
$records = $records->whereNotNull('comment')->where('comment', '<>', '');
|
||
}
|
||
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$records = $records->where(function ($sql) use ($keyword) {
|
||
$sql->where('name', 'like', '%' . $keyword . '%')->orWhere('phone', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$records = $records->orderBy('id', 'desc')->paginate();
|
||
return $this->success('ok', $records);
|
||
}
|
||
|
||
|
||
//老师咨询管理 视频管理
|
||
//上传老师视频
|
||
// public function addAnchorVideo(Request $request){
|
||
// $result = \AliyunService::getPlayInfo($request->aliyun_video_id);
|
||
// if (empty($result)) throw new \Exception("获取播放地址失败", 1);
|
||
// $viewer_id = $request->viewer_id;
|
||
// }
|
||
|
||
/** 单个老师的视频列表 */
|
||
public function anchorVideos(Request $request, $anchor_id)
|
||
{
|
||
try {
|
||
//视频列表
|
||
$videos = AnchorVideo::with('tagged')->where('anchor_id', $anchor_id);
|
||
$keyword = $request->input('keyword');
|
||
if ($keyword) {
|
||
$videos = $videos->where('title', 'like', '%' . trim($keyword) . '%');
|
||
}
|
||
$videos = $videos->orderBy('id', 'desc')->paginate();
|
||
foreach ($videos as $video) {
|
||
$video_tags = [];
|
||
foreach ($video->tags as $tag) {
|
||
$video_tags[] = $tag->name;
|
||
}
|
||
$video->video_tags = $video_tags;
|
||
unset($video->tagged);
|
||
}
|
||
return $this->success('ok', $videos);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('数据错误,请联系开发人员');
|
||
}
|
||
}
|
||
|
||
/** 单个老师的视频列表 */
|
||
public function anchorArticles(Request $request, $anchor_id)
|
||
{
|
||
try {
|
||
//文章列表
|
||
$articles = AnchorArticle::with('tagged')->where('anchor_id', $anchor_id);
|
||
$keyword = $request->input('keyword');
|
||
if ($keyword) {
|
||
$articles = $articles->where('title', 'like', '%' . trim($keyword) . '%');
|
||
}
|
||
$articles = $articles->orderBy('id', 'desc')->paginate();
|
||
foreach ($articles as $article) {
|
||
$article_tags = [];
|
||
foreach ($article->tags as $tag) {
|
||
$article_tags[] = $tag->name;
|
||
}
|
||
$article->article_tags = $article_tags;
|
||
unset($article->tagged);
|
||
}
|
||
return $this->success('ok', $articles);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('数据错误,请联系开发人员');
|
||
}
|
||
}
|
||
|
||
/** 设置资源推荐方式 */
|
||
public function setAnchorSources(Request $request)
|
||
{
|
||
try {
|
||
$is_love_show = $request->input('is_love_show');
|
||
$is_recommend = $request->input('is_recommend');
|
||
$belief_id = $request->input('belief_id');
|
||
$source = $this->getAnchorSource();
|
||
if (empty($source))
|
||
throw new \Exception('未找到对应资源');
|
||
if (is_numeric($is_love_show)) {
|
||
$source->is_love_show = $is_love_show;
|
||
}
|
||
if (is_numeric($is_recommend)) {
|
||
$source->is_recommend = $is_recommend;
|
||
}
|
||
if (is_numeric($belief_id)) {
|
||
$source->belief_id = $belief_id;
|
||
}
|
||
$source->save();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure("数据错误,请稍后再试");
|
||
}
|
||
|
||
}
|
||
|
||
public function getAnchorSource()
|
||
{
|
||
try {
|
||
//类型 video, article, course
|
||
$type_arr = ['video', 'article', 'course'];
|
||
$type = request()->input('type');
|
||
if (!in_array($type, $type_arr))
|
||
throw new \Exception('资源类型不符');
|
||
//资源id
|
||
$source_id = request()->input('source_id');
|
||
if (!is_numeric($source_id))
|
||
throw new \Exception('请求资源错误');
|
||
switch ($type) {
|
||
case 'video':
|
||
$source = AnchorVideo::find($source_id);
|
||
break;
|
||
case 'article':
|
||
$source = AnchorArticle::find($source_id);
|
||
break;
|
||
case 'course':
|
||
$source = Course::find($source_id);
|
||
break;
|
||
}
|
||
if (empty($source))
|
||
throw new \Exception('未找到对应资源');
|
||
return $source;
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return null;
|
||
}
|
||
|
||
}
|
||
|
||
/** 设置资源标签 */
|
||
public function tagAnchorSources(Request $request)
|
||
{
|
||
try {
|
||
$source = $this->getAnchorSource();
|
||
if (empty($source))
|
||
throw new \Exception('未找到对应资源');
|
||
$tag_arr = $request->input("tag_arr");
|
||
if (empty(count($tag_arr)))
|
||
return $this->failure("请填写标签");
|
||
$source->tag($tag_arr);
|
||
$group = TaggingTagGroup::firstOrCreate(['slug' => $request->type, 'name' => $request->type]);
|
||
$tags = \Conner\Tagging\Model\Tag::whereIn('name', $tag_arr)->get();
|
||
foreach ($tags as $tag) {
|
||
$tag->setGroup($group->name);
|
||
}
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('数据错误,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/** 删除资源标签 */
|
||
public function delTagAnchorSources(Request $request)
|
||
{
|
||
try {
|
||
$source = $this->getAnchorSource();
|
||
if (empty($source))
|
||
throw new \Exception('未找到对应资源');
|
||
$tag_arr = $request->input("tag_arr");
|
||
if (empty(count($tag_arr)))
|
||
return $this->failure("请填写标签");
|
||
$source->untag($tag_arr);
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('删除资源标签失败,请联系开发人员');
|
||
}
|
||
}
|
||
|
||
/** 老师资源标签列表 */
|
||
public function tags(Request $request)
|
||
{
|
||
try {
|
||
$type = $request->input('type');
|
||
$type_arr = ['video', 'article', 'course'];
|
||
if (!in_array($type, $type_arr))
|
||
throw new \Exception('资源类型不符');
|
||
$nopage = $request->input('nopage', 0);
|
||
$tags = \Conner\Tagging\Model\Tag::inGroup($type);
|
||
if ($nopage) {
|
||
$tags = $tags->get();
|
||
} else {
|
||
$tags = $tags->paginate();
|
||
}
|
||
return $this->success('ok', $tags);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('数据错误,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/** 老师资源标签删除 */
|
||
public function delTag(Request $request)
|
||
{
|
||
try {
|
||
$tag_arr = $request->input('tag_arr', []);
|
||
if (empty(count($tag_arr)))
|
||
return $this->failure('请选择标签');
|
||
if (in_array('', $tag_arr))
|
||
return $this->failure('标签为空');
|
||
$type = $request->input('type');
|
||
$type_arr = ['video', 'article', 'course'];
|
||
if (!in_array($type, $type_arr))
|
||
throw new \Exception('资源类型不符');
|
||
switch ($type) {
|
||
case 'video':
|
||
$source = AnchorVideo::withAllTags($tag_arr, $type)->first();
|
||
break;
|
||
case 'article':
|
||
$source = AnchorArticle::withAllTags($tag_arr, $type)->first();
|
||
break;
|
||
case 'article':
|
||
$source = Course::withAllTags($tag_arr, $type)->first();
|
||
break;
|
||
}
|
||
if ($source)
|
||
return $this->failure("删除标签失败,存在关联的资源");
|
||
//该标签是否有关联信息
|
||
collect($tag_arr)->map(function ($tag_str) use ($type) {
|
||
if (empty($tag_str))
|
||
throw new \Exception('数据错误,标签为空');
|
||
$tag = \Conner\Tagging\Model\Tag::where('name', $tag_str)->first();
|
||
if (empty($tag))
|
||
throw new \Exception('数据错误,标签不存在');
|
||
$tag->delete();
|
||
});
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('数据错误,请稍后再试');
|
||
}
|
||
}
|
||
|
||
//老师视频列表
|
||
public function anchorAllVideos(Request $request)
|
||
{
|
||
$keyword = $request->keyword;
|
||
$videos = AnchorVideo::with('anchor')->where('channel', '<>', 'admin')->orderBy('id', 'desc');
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$videos = $videos->where(function ($sql) use ($keyword) {
|
||
$sql->where('title', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$videos = $videos->paginate();
|
||
foreach ($videos as $video) {
|
||
if (!empty($video->file_path)) {
|
||
$video->file_path = 'love.ufutx.com/spiders/' . $video->file_path;
|
||
}
|
||
}
|
||
return $this->success('ok', $videos);
|
||
}
|
||
|
||
//老师文章列表
|
||
public function anchorAllArticles(Request $request)
|
||
{
|
||
$keyword = $request->keyword;
|
||
$articles = AnchorArticle::with('anchor')->orderBy('id', 'desc');
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$articles = $articles->where(function ($sql) use ($keyword) {
|
||
$sql->where('title', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$articles = $articles->paginate();
|
||
foreach ($articles as $article) {
|
||
if (!empty($article->file_path)) {
|
||
$article->file_path = 'love.ufutx.com/spiders/' . $article->file_path;
|
||
}
|
||
}
|
||
return $this->success('ok', $articles);
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 删除主播
|
||
* @description 删除主播的接口
|
||
* @method DELETE
|
||
* @url /api/official/live/anchor/{anchor_id}
|
||
* @return{
|
||
"code": 0,
|
||
"message": "ok",
|
||
"data": []
|
||
}
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
public function anchorDelete(Request $request, $anchor_id)
|
||
{
|
||
$anchor = Anchor::find($anchor_id);
|
||
$anchor->delete();
|
||
AnchorViewer::where('anchor_id', $anchor_id)->delete();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 新增礼物
|
||
* @description 增加礼物接口
|
||
* @method POST
|
||
* @url api/admin/live/gift
|
||
* @param name 必选 string 名称
|
||
* @param price 必选 float 价格
|
||
* @param icon 必选 string 图标
|
||
* @return { "code": 0, "message": "ok", "data": [] }
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
/**
|
||
* 礼物
|
||
*/
|
||
public function addGift(Request $request)
|
||
{
|
||
if (!$request->has('name')) {
|
||
return $this->failure('名称不能为空');
|
||
}
|
||
if (!$request->has('price')) {
|
||
return $this->failure('价格不能为空');
|
||
}
|
||
if (!$request->has('icon')) {
|
||
return $this->failure('icon不能为空');
|
||
}
|
||
|
||
|
||
$gift = new Gift();
|
||
$gift->name = $request->name;
|
||
$gift->price = $request->price;
|
||
$gift->icon = $request->icon;
|
||
$gift->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 礼物列表
|
||
* @description 礼物列表接口
|
||
* @method GET
|
||
* @url api/admin/live/gifts
|
||
* @param keyword 可选 string 关键字
|
||
* @return { "code": 0, "message": "ok", "data": { "current_page": 1, "data": [ { "id": 1, "name": 飞船, "price": 1.00, 'icon':'http:' "updated_at": "2020-04-08 18:32:35", "deleted_at": null,}],"first_page_url": "http://wlj.test/api/admin/live/classes?page=1","from": 1,"last_page": 1,"last_page_url": "http://wlj.test/api/admin/live/classes?page=1","next_page_url": null,"path": "http://wlj.test/api/admin/live/classes","per_page": 15,"prev_page_url": null,"to": 7,"total": 7}}
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
//主播列表
|
||
public function gifts(Request $request)
|
||
{
|
||
$gifts = Gift::orderBy('created_at', 'desc');
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$gifts = $gifts->where('name', 'like', '%' . $request->keyword . '%');
|
||
}
|
||
$gifts->paginate();
|
||
return $this->success('ok', $gifts);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 礼物详情
|
||
* @description 礼物详情接口
|
||
* @method GET
|
||
* @url api/admin/live/gift/{gift_id}
|
||
* @return { "code": 0, "message": "ok", "data":{ "id": 1, "name": 飞船, "price": 1.00, 'icon':'http:' "updated_at": "2020-04-08 18:32:35", "deleted_at": null,}
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
//主播
|
||
public function gift(Request $request, $gift_id)
|
||
{
|
||
$gift = Anchor::find($gift_id);
|
||
|
||
return $this->success('ok', $gift);
|
||
}
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 编辑礼物
|
||
* @description 编辑主播的接口
|
||
* @method PUT
|
||
* @url /api/official/live/gift/{gift_id}
|
||
* @param name 可选 string 名称
|
||
* @param price 可选 string 价格
|
||
* @param icon 可选 string 图标
|
||
* @return { "code": 0, "message": "ok", "data": [] }
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
//编辑主播
|
||
public function giftUpdate(Request $request, $gift_id)
|
||
{
|
||
$gift = Gift::find($gift_id);
|
||
if (empty($gift)) {
|
||
return $this->failure('数据不存在');
|
||
}
|
||
if ($request->has('name') && $request->name) {
|
||
$gift->name = $request->name;
|
||
}
|
||
if ($request->has('price') && $request->price) {
|
||
$gift->price = $request->price;
|
||
}
|
||
if ($request->has('icon') && $request->icon) {
|
||
$gift->icon = $request->icon;
|
||
}
|
||
$gift->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 删除礼物
|
||
* @description 删除礼物的接口
|
||
* @method DELETE
|
||
* @url /api/official/live/gift/{gift_id}
|
||
* @return { "code": 0, "message": "ok", "data": [] }
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
public function giftDelete(Request $request, $gift_id)
|
||
{
|
||
$gift = Anchor::find($gift_id);
|
||
$gift->delete();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
|
||
//操作直播部分开始
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 获取推流地址
|
||
* @description 获取推流地址的接口
|
||
* @method GET
|
||
* @url /api/official/live/getParams
|
||
* @return { "code": 0, "message": "ok", "push_url: "rtmp://live.ufutx.com/fulink/c_1_v_2?auth_key=1587194453-BcxzVp-0-c7c22cd6adf97debd3cdfb1856f57dd2"" }
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
public function getParams(Request $request, $live_id)
|
||
{
|
||
$live = Live::find($live_id);
|
||
// $service = $request->input('service');
|
||
|
||
$key = 'live_' . $live_id . 'pushurl';
|
||
$pushUrl = Redis::get($key);
|
||
if (!$pushUrl) {
|
||
$aliyun = new Aliyun();
|
||
$pushUrl = $aliyun->getPushUrl($live->class_id, $live->id);
|
||
Redis::setex($key, 30 * 60, $pushUrl);
|
||
}
|
||
|
||
$aliyun->resume($live->class_id, $live->id);
|
||
|
||
return $this->success('ok', $pushUrl);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 停止直播
|
||
* @description 停止直播的接口
|
||
* @method POST
|
||
* @url /api/admin/live/pasue/{live_id}
|
||
* @return { "code": 0, "message": "ok", "data": [] }
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
public function pause(Request $request, $live_id)
|
||
{
|
||
|
||
$live = Live::find($live_id);
|
||
// $service = $request->input('service');
|
||
$pushUrl = '';
|
||
$aliyun = new Aliyun();
|
||
$aliyun->pause($live->class_id, $live->id);
|
||
|
||
$live->status = 2;
|
||
$live->save();
|
||
return $this->success('ok');
|
||
}
|
||
//直播生成回放中 状态 status : 3
|
||
public function playBack(Request $request, $live_id)
|
||
{
|
||
$status = $request->status;
|
||
if (empty($status))
|
||
return $this->failure('请选择直播状态');
|
||
$live = Live::find($live_id);
|
||
if (empty($live))
|
||
return $this->failure('直播不存在');
|
||
$live->status = $status;
|
||
$live->save();
|
||
return $this->success('ok', $live);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 管理后台/直播/V2
|
||
* @title 恢复直播到未开始的状态
|
||
* @description 恢复直播到未开始的状态的接口
|
||
* @method POST
|
||
* @url /api/admin/live/resume/{live_id}
|
||
* @return { "code": 0, "message": "ok", "data": [] }
|
||
* @remark 这里是备注信息
|
||
* @number 99
|
||
*/
|
||
public function resume(Request $request, $live_id)
|
||
{
|
||
$live = Live::find($live_id);
|
||
$aliyun = new Aliyun();
|
||
$aliyun->resume($live->class_id, $live->id);
|
||
|
||
$live->status = 0;
|
||
$live->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
//录制回放回调
|
||
public function recordCallback(Request $request)
|
||
{
|
||
if (empty($request->all())) {
|
||
|
||
} else {
|
||
if (substr($request->uri, 0, 4) == 'http') {
|
||
$uri = str_replace('http', 'https', $request->uri);
|
||
}
|
||
|
||
$stream = $request->stream;
|
||
$arr = explode('_', $stream);
|
||
if ($arr[3] != 108) {
|
||
$video = new Video();
|
||
$video->live_id = $arr[3];
|
||
$video->uri = $uri;
|
||
$video->duration = $request->duration;
|
||
$video->start_time = $request->start_time;
|
||
$video->stop_time = $request->stop_time;
|
||
$video->save();
|
||
}
|
||
|
||
$live = Live::find($arr[3]);
|
||
if ($live->status == 3) {
|
||
$live->status = 2;
|
||
$live->save();
|
||
}
|
||
}
|
||
}
|
||
|
||
//直播录制状态回调设置
|
||
public function recordSetCallback(Request $request)
|
||
{
|
||
$aliyun = new Aliyun();
|
||
$result = $aliyun->statusCallback();
|
||
return $this->success('ok', $result);
|
||
}
|
||
|
||
//录制回放暂停回调
|
||
public function recordStatusCallback(Request $request)
|
||
{
|
||
if (empty($request->all())) {
|
||
|
||
} else {
|
||
|
||
$stream = $request->stream;
|
||
$arr = explode('_', $stream);
|
||
$live = Live::find($arr[3]);
|
||
$live->status = 2;
|
||
$live->save();
|
||
}
|
||
}
|
||
|
||
public function liveStatusCallback(Request $request)
|
||
{
|
||
$arr = explode('_', $request->id);
|
||
$live_id = $arr[3];
|
||
$live = Live::find($live_id);
|
||
if ($request->action == 'publish') {
|
||
//推流中
|
||
if ($live->status != 2) {
|
||
$live->status = 1;
|
||
$live->save();
|
||
$LiveLog = new LiveLog;
|
||
$LiveLog->live_id = $live_id;
|
||
$LiveLog->live_status = 1;
|
||
$LiveLog->publish = $request->action;
|
||
$LiveLog->save();
|
||
//发送开播提醒
|
||
$has_send = Redis::get($live_id . '_send');
|
||
if (!$has_send) {
|
||
Redis::setex($live_id . '_send', 60 * 60 * 12, 1);
|
||
// $this->sendStartLiveRemind($live);
|
||
}
|
||
}
|
||
} elseif ($request->action == 'publish_done') {
|
||
//推流结束,但直播没有结束
|
||
if ($live->status == 1) {
|
||
$live->status = 3;
|
||
$live->save();
|
||
$LiveLog = new LiveLog;
|
||
$LiveLog->live_id = $live_id;
|
||
$LiveLog->live_status = 3;
|
||
$LiveLog->publish = $request->action;
|
||
$LiveLog->save();
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
|
||
//发送开课提醒
|
||
public function sendStartLiveRemind($live)
|
||
{
|
||
$teacher = Anchor::where('id', $live->anchor_id)->value('name');
|
||
$followers = AnchorViewer::where('anchor_id', $live->anchor_id)->where('focusing', 1)->pluck('viewer_id')->toArray();
|
||
|
||
$data['touser'] = Viewer::whereIn('id', $followers)->pluck('openid')->toArray();
|
||
$data['template_id'] = 'BinirgWI3EAYs9jindxPBwUm-rAceTu9T4H02m-sq5g';
|
||
$data['url'] = env('APP_URL') . '/api/official/live/wechat/oauth?live_id=' . $live->id;
|
||
// $data['miniprogram'] = [
|
||
//// 'appid' => config('wechat.official_account.new.app_id'),
|
||
// 'appid' => 'wx36c72a00f1b2be64',
|
||
// 'pagepath' => '',
|
||
// ];
|
||
$data['data'] = [
|
||
'first' => $live->title . '已经开始直播了,可立即观看',
|
||
'keyword1' => $live->start_time,
|
||
'keyword2' => $teacher,
|
||
'reamrk' => '快去听课吧',
|
||
];
|
||
SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
||
}
|
||
|
||
|
||
|
||
|
||
public function checkoutVideo(Request $request, $live_id)
|
||
{
|
||
if (!$request->has('url') || !$request->url) {
|
||
return $this->failure('没有视频地址');
|
||
}
|
||
$live = Live::find($live_id);
|
||
if ($live->status != 2) {
|
||
return $this->failure('不是回放');
|
||
}
|
||
|
||
|
||
Video::where('live_id', $live_id)->delete();
|
||
$video = new Video();
|
||
$video->live_id = $live_id;
|
||
$video->uri = $request->url;
|
||
$video->duration = 0;
|
||
$video->save();
|
||
|
||
return $this->success('ok');
|
||
}
|
||
|
||
|
||
//点播回调设置
|
||
public function vodCallback(Request $request)
|
||
{
|
||
if (empty($request->all())) {
|
||
|
||
} else {
|
||
|
||
$aliyun = new Aliyun();
|
||
switch ($request->EventType) {
|
||
case 'AddLiveRecordVideoComplete':
|
||
$aliyun->AddLiveRecordVideoComplete($request->all());
|
||
break;
|
||
case 'StreamTranscodeComplete':
|
||
$aliyun->StreamTranscodeComplete($request->all());
|
||
break;
|
||
}
|
||
}
|
||
return $this->success('success');
|
||
}
|
||
|
||
public function rank(Request $request, $live_id)
|
||
{
|
||
//分页
|
||
$page = $request->page ?: 1;
|
||
$limit = $request->limit ?: 15;
|
||
$total = Redis::zcard($live_id . '_share_rank');
|
||
$last_page = 0;
|
||
if ($total) {
|
||
$max_page = ceil($total / $limit);
|
||
$last_page = ($page + 1) > $max_page ? $page : $page + 1;
|
||
$share_rank = Redis::zRevRangeByScore($live_id . '_share_rank', "+inf", "-inf");
|
||
return $this->success('ok', $share_rank);
|
||
$shares = Viewer::select('id', 'avatar', 'nickname', 'sex', 'openid', 'mobile', 'source', 'created_at')->whereIn('id', array_keys($share_rank))->get()->toArray();
|
||
foreach ($shares as $key => &$item) {
|
||
$item['share_count'] = $share_rank[$item['id']];
|
||
$item['is_subscribe'] = $this->subscribe($item['openid']);
|
||
}
|
||
array_multisort(array_column($shares, 'share_count'), SORT_DESC, $shares);
|
||
} else {
|
||
$shares = [];
|
||
}
|
||
|
||
$data = [
|
||
'data' => $shares,
|
||
'from' => $page,
|
||
'per_page' => $limit,
|
||
'last_page' => $last_page,
|
||
'total' => $total
|
||
];
|
||
return $this->success('ok', $data);
|
||
}
|
||
|
||
//打赏记录
|
||
public function rewards(Request $request, $live_id)
|
||
{
|
||
$logs = GiftOrder::with(['viewer', 'teacher']);
|
||
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$keyword = $request->keyword;
|
||
$logs = $logs->whereHas('viewer', function ($query) use ($keyword) {
|
||
$query->where('nickname', 'like', '%' . $keyword . '%')->orWhere('id', $keyword);
|
||
});
|
||
}
|
||
|
||
$logs = $logs->where('live_id', $live_id)->where('pay_status', 1)->orderBy('created_at', 'desc')->paginate();
|
||
return $this->success('ok', $logs);
|
||
}
|
||
|
||
public function userStat(Request $request)
|
||
{
|
||
if ($request->has('start_time') && $request->start_time && $request->has('end_time') && $request->end_time) {
|
||
$start_time = $request->start_time;
|
||
$end_time = $request->end_time;
|
||
} else {
|
||
$start_time = '2020-04-01 00:00:00';
|
||
$end_time = '2021-04-01 00:00:00';
|
||
}
|
||
|
||
$new_user_count = Viewer::whereBetween('created_at', [$start_time, $end_time])->count();
|
||
$live_count = LiveViewer::whereBetween('created_at', [$start_time, $end_time])->count();
|
||
$all_share_count = ViewerShare::whereBetween('created_at', [$start_time, $end_time])->count();
|
||
$new_share_count = ViewerShare::where('type', 1)->whereBetween('created_at', [$start_time, $end_time])->count();
|
||
$old_share_count = ViewerShare::where('type', 2)->whereBetween('created_at', [$start_time, $end_time])->count();
|
||
//奖金池
|
||
$fund_balance_amount = ShareFund::where('id', 1)->value('balance_amount');
|
||
|
||
|
||
return $this->success('ok', compact('new_user_count', 'live_count', 'all_share_count', 'new_share_count', 'old_share_count', 'fund_balance_amount'));
|
||
}
|
||
|
||
public function weekStat(Request $request)
|
||
{
|
||
$start_time = date('Y-m-d 00:00:00', strtotime('-2 monday', time()));
|
||
$end_time = date('Y-m-d 00:00:00', (time() - ((date('w', time()) == 0 ? 7 : date('w', time())) - 1) * 24 * 3600));
|
||
$lives = Live::select('id', 'title', 'start_time')->withCount('register', 'liveviewer', 'viewershare')->whereBetween('start_time', [$start_time, $end_time])->orderBy('start_time', 'desc')->get();
|
||
$data = [];
|
||
foreach ($lives as $live) {
|
||
$data['title_arr'][] = $live->title;
|
||
$data['day_arr'][] = substr($live->start_time, 5, 5);
|
||
$data['regist_count'][] = $live->register_count;
|
||
$data['share_count'][] = $live->viewershare_count;
|
||
$data['viewer_count'][] = $live->liveviewer_count;
|
||
|
||
}
|
||
|
||
|
||
// $day_arr = ['04-27', '04-28', '04-29', '04-30', '05-01', '05-02', '05-03'];
|
||
// $title_arr = ['test', '测试', 'test', 'test', 'test', 'test', 'test'];
|
||
|
||
|
||
return $this->success('ok', $data);
|
||
}
|
||
|
||
//直播反馈
|
||
public function feedbacks(Request $request)
|
||
{
|
||
if ($request->has('nickname') && $request->nickname) {
|
||
$nickname = $request->nickname;
|
||
$logs = Feedback::withCount('comment')->with([
|
||
'viewer' => function ($query) use ($nickname) {
|
||
$query->where('nickname', 'like', '%' . $nickname . '%');
|
||
}
|
||
]);
|
||
} else {
|
||
$logs = Feedback::withCount('comment')->with('viewer:id,nickname');
|
||
}
|
||
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$keyword = trim($request->keyword);
|
||
$logs = $logs->where(function ($sql) use ($keyword) {
|
||
$sql->where('content', 'like', '%' . $keyword . '%')
|
||
->orWhere('contact', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
|
||
if ($request->start_time && $request->start_time && $request->end_time && $request->end_time) {
|
||
$logs = $logs->whereBetween('created_at', [$request->start_time, $request->end_time]);
|
||
}
|
||
|
||
$logs = $logs->orderBy('created_at', 'desc')->paginate();
|
||
|
||
return $this->success('ok', $logs);
|
||
}
|
||
|
||
//直播反馈详情
|
||
public function feedback(Request $request, $feedback_id)
|
||
{
|
||
$feedback = Feedback::with(['viewer:id,avatar,nickname,mobile'])->where('id', $feedback_id)->first();
|
||
if (empty($feedback)) {
|
||
return $this->failure('反馈数据不存在');
|
||
}
|
||
return $this->success('ok', $feedback);
|
||
}
|
||
|
||
//新增反馈备注
|
||
public function addComment(Request $request, $feedback_id)
|
||
{
|
||
$comment = new Comment();
|
||
$comment->feedback_id = $feedback_id;
|
||
$comment->order_id = $request->order_id;
|
||
$comment->content = $request->input('content');
|
||
$comment->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
//备注列表
|
||
public function comments(Request $request, $feedback_id)
|
||
{
|
||
$comments = Comment::paginate();
|
||
if ($request->has('feedback_id') && $request->feedback_id) {
|
||
$comments = Comment::where('feedback_id', $feedback_id)->paginate();
|
||
}
|
||
if ($request->has('order_id') && $request->order_id) {
|
||
$comments = Comment::where('order_id', $feedback_id)->paginate();
|
||
}
|
||
return $this->success('ok', $comments);
|
||
}
|
||
|
||
//备注列表
|
||
public function comment(Request $request, $comment_id)
|
||
{
|
||
$comment = Comment::find($comment_id);
|
||
return $this->success('ok', $comment);
|
||
}
|
||
|
||
//备注更新
|
||
public function checkComment(Request $request, $comment_id)
|
||
{
|
||
$comment = Comment::find($comment_id);
|
||
if ($request->has('content') && $request->input('content')) {
|
||
$comment->content = $request->input('content');
|
||
}
|
||
$comment->save();
|
||
return $this->success('ok', $comment);
|
||
}
|
||
|
||
public function delComment(Request $request, $comment_id)
|
||
{
|
||
$comment = Comment::where('id', $comment_id)->delete();
|
||
|
||
return $this->success('ok');
|
||
}
|
||
|
||
|
||
//分享奖励配置
|
||
public function receiptConfig(Request $request)
|
||
{
|
||
$config = config('live.receipt');
|
||
return $this->success('ok', $config);
|
||
}
|
||
|
||
//更新分享奖励配置
|
||
public function checkreceiptConfig(Request $request)
|
||
{
|
||
if ($request->has('old') && $request->old) {
|
||
config(['live.receipt.old' => $request->old]);
|
||
}
|
||
if ($request->has('new') && $request->new) {
|
||
config(['live.receipt.new' => $request->new]);
|
||
}
|
||
return $this->success('ok');
|
||
}
|
||
|
||
|
||
//提现订单
|
||
public function withdrawLogs(Request $request)
|
||
{
|
||
|
||
$logs = AssetLog::select('id', 'viewer_id', 'num', 'created_at', 'cash_status', 'reason', 'is_audit')->with('viewer:id,nickname,alipay_account,actual_name,avatar,sex');
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$nickname = $request->keyword;
|
||
$logs = $logs->whereHas('viewer', function ($query) use ($nickname) {
|
||
$query->where('nickname', 'like', '%' . $nickname . '%');
|
||
});
|
||
}
|
||
|
||
if ($request->has('is_audit') && is_numeric($request->is_audit)) {
|
||
$logs = $logs->where('is_audit', $request->is_audit);
|
||
}
|
||
if ($request->has('cash_status') && is_numeric($request->cash_status)) {
|
||
$logs = $logs->where('cash_status', $request->cash_status);
|
||
}
|
||
$logs = $logs->where('account', 2)->orderBy('created_at', 'desc')->paginate();
|
||
|
||
foreach ($logs as &$log) {
|
||
if (!empty($log->reason)) {
|
||
switch ($log->reason) {
|
||
case 'PAYEE_NOT_EXIST':
|
||
$log->reason = '支付宝账户或者真实姓名有误';
|
||
break;
|
||
case 'INVALID_PARAMETER':
|
||
$log->reason = '缺少支付宝或者真实姓名';
|
||
break;
|
||
case 'PAYER_BALANCE_NOT_ENOUGH':
|
||
$log->reason = '账号余额不足';
|
||
break;
|
||
default:
|
||
$log->reason = $log->reason ?: '';
|
||
}
|
||
}
|
||
}
|
||
return $this->success('ok', $logs);
|
||
}
|
||
|
||
|
||
//审核提现订单
|
||
public function auditCash(Request $request)
|
||
{
|
||
if (!$request->has('id') || !$request->id) {
|
||
return $this->failure('请输入需要审核的记录id');
|
||
}
|
||
if (!$request->has('is_audit') || !$request->is_audit) {
|
||
return $this->failure('请输入需要更改的状态');
|
||
}
|
||
$id_arr = explode(',', $request->id);
|
||
|
||
|
||
$logs = AssetLog::with('viewer:id,alipay_account,actual_name')->whereIn('id', $id_arr)->get();
|
||
//提现到支付宝
|
||
if ($request->is_audit == 1) {
|
||
AssetLog::whereIn('id', $id_arr)->update(['is_audit' => $request->is_audit, 'cash_status' => 1]);
|
||
|
||
|
||
foreach ($logs as &$log) {
|
||
$out_biz_no = $log->out_biz_no;
|
||
$parames = [
|
||
'out_biz_no' => $out_biz_no,
|
||
'payee_type' => 'ALIPAY_LOGONID',
|
||
'payee_account' => $log->viewer->alipay_account,
|
||
'amount' => $log->num,
|
||
'payer_show_name' => '福恋智能',
|
||
'payee_real_name' => $log->viewer->actual_name,
|
||
'reamrk' => '直播账户余额提现'
|
||
];
|
||
TransferToAlipayAccount::dispatch($parames)->onQueue('love');
|
||
|
||
}
|
||
} else {
|
||
AssetLog::whereIn('id', $id_arr)->update(['is_audit' => $request->is_audit, 'reason' => $request->reason, 'cash_status' => 3]);
|
||
foreach ($logs as $log) {
|
||
AssetLog::where('id', $log->id)->increment('score', $log->num);
|
||
Asset::where('viewer_id', $log->viewer_id)->increment('cash', $log->num);
|
||
|
||
//模板消息-提现失败通知
|
||
$viewer = Viewer::select('openid', 'alipay_account')->where('id', $log->viewer_id)->first();
|
||
$account_type = $log->account == 2 ? '支付宝账户' . $viewer->alipay_account : '微信' . $viewer->nickname;
|
||
|
||
$data['touser'] = $viewer->openid;
|
||
$data['template_id'] = 'AqwVt0liVmQfzfnX3ZGvmVOdOh62nkCbhlOUI0NVQGs';
|
||
$data['url'] = env('APP_URL') . '/h5/#/myWallet';
|
||
$data['data'] = [
|
||
'first' => '您好,您的提现订单未通过审核',
|
||
'keyword1' => $log->num,
|
||
'keyword2' => '提现到' . $account_type,
|
||
'keyword3' => $request->reason,
|
||
'reamrk' => '请重试',
|
||
];
|
||
SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
||
}
|
||
|
||
}
|
||
return $this->success('ok');
|
||
}
|
||
|
||
|
||
//判断用户是否关注
|
||
public function subscribe($openid)
|
||
{
|
||
$app = Factory::officialAccount($this->config);
|
||
$wechatUser = $app->user->get($openid);
|
||
$result = !empty($wechatUser) && isset($wechatUser['subscribe']);
|
||
$is_subscribe = $result ? $wechatUser['subscribe'] : 0;
|
||
return $is_subscribe;
|
||
}
|
||
|
||
/**
|
||
* 分享角色列表
|
||
*/
|
||
public function shareRoles(Request $request, ShareRole $share_role)
|
||
{
|
||
try {
|
||
$share_roles = $share_role->all();
|
||
return $this->success('share_roles', $share_roles);
|
||
} catch (Exception $e) {
|
||
return $this->failure('角色列表拉取失败');
|
||
}
|
||
|
||
}
|
||
|
||
public function storeShareRole(Request $request, ShareRole $share_role)
|
||
{
|
||
try {
|
||
$name = $request->input('name');
|
||
if (empty($name)) {
|
||
return $this->failure('请输入角色名');
|
||
}
|
||
$count = $share_role->where([
|
||
'name' => $name,
|
||
])->first();
|
||
if ($count) {
|
||
return $this->failure("已存在该角色");
|
||
}
|
||
// $result = $share_role->create(['name'=>$name, 'type'=>$type]);
|
||
$share_role->name = $name;
|
||
$share_role->save();
|
||
return $this->success('角色创建成功', $share_role);
|
||
} catch (\Exception $e) {
|
||
\Log::error($e->getMessage());
|
||
return $this->failure('创建角色失败');
|
||
}
|
||
|
||
}
|
||
|
||
public function deleteShareRole(Request $request, ShareRole $share_role)
|
||
{
|
||
try {
|
||
$result = $share_role->delete();
|
||
return $result ? $this->success('角色删除成功') : $this->failure('角色删除失败');
|
||
} catch (\Exception $e) {
|
||
\Log::error($e->getMessage());
|
||
return $this->failure('角色删除失败');
|
||
}
|
||
}
|
||
|
||
public function updateShareRole(Request $request, ShareRole $share_role)
|
||
{
|
||
try {
|
||
$name = $request->input('name');
|
||
if (empty($name)) {
|
||
return $this->failure('请输入角色名');
|
||
}
|
||
$count = $share_role->where([
|
||
'name' => $name,
|
||
])->where('id', '<>', $share_role->id)->first();
|
||
if ($count) {
|
||
return $this->failure("已存在该角色");
|
||
}
|
||
$share_role->update(['name' => $name]);
|
||
return $this->success('角色修改成功');
|
||
} catch (\Exception $e) {
|
||
\Log::error($e->getMessage());
|
||
return $this->failure('角色修改失败');
|
||
}
|
||
}
|
||
|
||
public function shareRole(Request $request, ShareRole $share_role)
|
||
{
|
||
return $this->success('角色详情', $share_role);
|
||
}
|
||
|
||
/**
|
||
* 用户的分享角色
|
||
*/
|
||
public function viewerShareRole(Request $request, Viewer $viewer)
|
||
{
|
||
$share_role = $viewer->shareRoles;
|
||
return $this->success('用户的分享角色', $share_role);
|
||
}
|
||
|
||
/**
|
||
* 给用户分配角色
|
||
*/
|
||
public function distributeShareRole(Request $request, Viewer $viewer)
|
||
{
|
||
try {
|
||
$share_role = $viewer->shareRole();
|
||
$share_role_id = $request->input('share_role_id');
|
||
if (empty($share_role_id)) {
|
||
return $this->failure('请选择分配角色');
|
||
}
|
||
$re_share_role = ShareRole::find($share_role_id);
|
||
if (empty($re_share_role)) {
|
||
return $this->failure('分享角色不存在,请重新选择');
|
||
}
|
||
if ($share_role) {
|
||
if ($share_role->id != $share_role_id) {
|
||
$viewer->shareRoles()->attach($share_role_id, ['created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]);
|
||
$viewer->shareRoles()->detach($share_role->id);
|
||
}
|
||
} else {
|
||
$result = $viewer->shareRoles()->attach($share_role_id, ['created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]);
|
||
}
|
||
//短信通知
|
||
$mobile = $viewer->mobile;
|
||
if ($mobile) {
|
||
$role_name = $this->getRoleName($share_role_id);
|
||
$param['mobile'] = $mobile;
|
||
$param['message'] = ($viewer->nickname) . ",您好!经福恋平台审核,恭喜您正式成为【" . $role_name . "婚姻使者】,现在您可以开始祝福他人进入蒙福家庭的旅程了!";
|
||
SendSpreaderNote::dispatch($param)->onQueue('love');
|
||
}
|
||
return $this->success("角色分配成功");
|
||
} catch (\Exception $e) {
|
||
\Log::error($e->getMessage());
|
||
return $this->failure('角色分配失败');
|
||
}
|
||
|
||
}
|
||
|
||
public function getRoleName($share_role_id)
|
||
{
|
||
$role = ShareRole::find($share_role_id);
|
||
$name = mb_substr($role->name, 0, 2);
|
||
if ($name == '普通') {
|
||
$name = '';
|
||
}
|
||
return $name;
|
||
}
|
||
|
||
/**
|
||
* 移除角色
|
||
*/
|
||
public function deleteShareRoleViewer(Request $request, Viewer $viewer)
|
||
{
|
||
try {
|
||
$viewer->shareRoles()->detach();
|
||
return $this->success('角色移除成功');
|
||
} catch (\Exception $e) {
|
||
\Log::error($e->getMessage());
|
||
return $this->failure('角色分配失败');
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 含分享角色的用户
|
||
*/
|
||
public function shareRoleViewers(Request $request, Viewer $viewer)
|
||
{
|
||
try {
|
||
|
||
$keyword = $request->input('keyword');
|
||
// $viewer_ids = $viewer_share->where('sharer_id',$viewer->id)->where('type', 1)->pluck('viewer_id');
|
||
$lists = \DB::table('viewers')->leftJoin('live_share_role_viewers', 'viewers.id', '=', 'live_share_role_viewers.viewer_id')->select('viewers.id', 'viewers.viewer_id', 'viewers.nickname', 'viewers.avatar', 'viewers.sex', 'viewers.mobile', 'live_share_role_viewers.share_role_id')->where('live_share_role_viewers.share_role_id', '>', 0);
|
||
if (trim($keyword)) {
|
||
$lists = $lists->where('viewers.nickname', 'like', '%' . $keyword . '%');
|
||
}
|
||
$lists = $lists->orderBy('share_role_id', 'desc')->paginate();
|
||
// $viewers = $viewer->with('shareRoles')->whereHas('shareRoles', function($sql){
|
||
// $sql->where('name', 'like', '%推广员%');
|
||
// })->paginate();
|
||
|
||
foreach ($lists as $list) {
|
||
$list->share_count = ViewerShare::where('sharer_id', $list->id)->count();
|
||
$list->income = (AssetLog::where('viewer_id', $list->id)->where('type', 2)->sum('num'));
|
||
$list->role_name = ShareRole::where('id', $list->share_role_id)->value('name');
|
||
$list->role_date = ShareRoleViewer::where("viewer_id", $list->id)->where('share_role_id', $list->share_role_id)->value('created_at')->toDateTimeString();
|
||
$list->referrer = Viewer::select('id', 'nickname')->where('id', $list->viewer_id)->first();
|
||
}
|
||
return $this->success('ok', $lists);
|
||
} catch (\Exception $e) {
|
||
\Log::error($e->getMessage());
|
||
return $this->failure('用户列表获取失败');
|
||
}
|
||
|
||
}
|
||
|
||
//推广员详情
|
||
public function shareRoleViewer(Request $request, $viewer_id)
|
||
{
|
||
try {
|
||
$viewer = Viewer::with('shareRoles')->whereHas('shareRoles', function ($sql) {
|
||
$sql->where('name', 'like', '%推广员%');
|
||
})->where('id', $viewer_id)->first();
|
||
|
||
$viewer->share_count = ViewerShare::where('sharer_id', $viewer->id)->count();
|
||
$viewer->income = (AssetLog::where('viewer_id', $viewer->id)->where('type', 2)->sum('num'));
|
||
|
||
if (empty($viewer)) {
|
||
return $this->failure('推广员不存在');
|
||
}
|
||
return $this->success('ok', $viewer);
|
||
} catch (\Exception $e) {
|
||
return $this->failure('推广员详情获取失败');
|
||
}
|
||
}
|
||
|
||
//分享的用户
|
||
public function shareLists(Request $request, $viewer_id)
|
||
{
|
||
//手动分页
|
||
$page = $request->page ?: 1;
|
||
$limit = $request->limit ?: 15;
|
||
$start = ($page - 1) * $limit;
|
||
$total = ViewerShare::where('sharer_id', $viewer_id)->distinct()->count();
|
||
$last_page = ceil($total / $limit);
|
||
$next_page = ($page + 1) > $last_page ? $page : $page + 1;
|
||
|
||
$ids = ViewerShare::where('sharer_id', $viewer_id)->distinct()->orderBy('created_at', 'desc')->offset($start)->limit($limit)->pluck('viewer_id');
|
||
|
||
$viewers = Viewer::with('shareRoles')->whereIn('id', $ids)->get();
|
||
foreach ($viewers as $viewer) {
|
||
$viewer->share_count = ViewerShare::where('sharer_id', $viewer->id)->count();
|
||
$viewer->income = (AssetLog::where('viewer_id', $viewer->id)->where('type', 2)->sum('num'));
|
||
}
|
||
// if($request->has('keyword') && $request->keyword){
|
||
// $keyword = $request->keyword;
|
||
// $lists = ViewerShare::whereHas('share', function ($query) use ($keyword) {
|
||
// $query->where('nickname', 'like', "%".$keyword."%");
|
||
// });
|
||
// }else{
|
||
// $lists = ViewerShare::with('share:id,nickname,avatar');
|
||
// }
|
||
//
|
||
// if($request->type){
|
||
// $lists = $lists->where('type', $request->type);
|
||
// }
|
||
// $lists =$lists->where('sharer_id', $viewer_id)->distinct()->orderBy('created_at', 'desc')->paginate();
|
||
// foreach ($lists as $k => &$list){
|
||
// if($list->share){
|
||
// $list->nickname = $list->share->nickname;
|
||
// $list->avatar = $list->share->avatar;
|
||
// }
|
||
//
|
||
//
|
||
// }
|
||
$data = [
|
||
'data' => $viewers,
|
||
'first_page_url' => "http://alpha.ufutx.net/api/admin/live/share/role/viewers?page=1",
|
||
'from' => $page,
|
||
'last_page' => $last_page,
|
||
'last_page_url' => "http://alpha.ufutx.net/api/admin/live/share/role/viewers?page=1",
|
||
'next_page_url' => null,
|
||
'path' => "http://alpha.ufutx.net/api/admin/live/share/role/viewers",
|
||
'per_page' => 15,
|
||
'prev_page_url' => null,
|
||
'to' => $total,
|
||
'total' => $total,
|
||
];
|
||
return $this->success('ok', $data);
|
||
}
|
||
|
||
//收益记录
|
||
public function assetLog(Request $request, $viewer_id)
|
||
{
|
||
try {
|
||
$logs = AssetLog::with('sourcer:id,nickname')->whereIn('type', [2, 4])->where('viewer_id', $viewer_id)->paginate();
|
||
foreach ($logs as &$log) {
|
||
$log->num = $log->num;
|
||
}
|
||
return $this->success('ok', $logs);
|
||
} catch (\Exception $e) {
|
||
return $this->failure('收益列表获取失败');
|
||
}
|
||
}
|
||
|
||
//购买回放视频订单
|
||
public function liveOrders(Request $request, $live_id)
|
||
{
|
||
$orders = LiveOrder::withCount('comment')->where('live_id', $live_id);
|
||
if ($request->has('start_time') && $request->start_time && $request->has('end_time') && $request->end_time) {
|
||
$orders = $orders->whereBetween('created_at', [$request->start_time, $request->end_time]);
|
||
}
|
||
;
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$nickname = $request->keyword;
|
||
$orders = $orders->with([
|
||
'viewer' => function ($query) use ($nickname) {
|
||
$query->where('nickname', 'like', '%' . $nickname . '%');
|
||
}
|
||
]);
|
||
} else {
|
||
$orders = $orders->with('viewer');
|
||
}
|
||
;
|
||
$orders = $orders->orderBy('created_at', 'desc')->paginate();
|
||
return $this->success('ok', $orders);
|
||
}
|
||
|
||
|
||
//
|
||
public function records(Request $request, $live_id)
|
||
{
|
||
$records = Record::with('viewer:id,avatar,nickname,mobile')->select('id', 'content', 'viewer_id', 'pic', 'created_at', 'type', 'related_msg', 'is_show')->where('live_id', $live_id)->where('class', 'h5');
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$records = $records->where('content', 'like', '%' . $request->keyword . '%');
|
||
}
|
||
$records = $records->orderBy('created_at', 'desc')->paginate();
|
||
return $this->success('ok', $records);
|
||
}
|
||
|
||
public function deleteRecords(Request $request, $id)
|
||
{
|
||
$record = Record::find($id);
|
||
if (empty($record))
|
||
return $this->failure('该记录不存在');
|
||
$record->delete();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function updateRecordStatus(Request $request)
|
||
{
|
||
$ids = $request->id;
|
||
$is_show = $request->input('is_show', 0);
|
||
if (!empty($ids) && is_array($ids)) {
|
||
$records = Record::whereIn('id', $ids)->update(['is_show' => $is_show]);
|
||
return $this->success('ok');
|
||
}
|
||
return $this->failure('修改失败');
|
||
}
|
||
|
||
//申请福恋使者列表
|
||
public function messengerLogs(Request $request)
|
||
{
|
||
try {
|
||
$logs = Messenger::with('sharer:id,nickname,user_id', 'viewer')->whereHas('viewer');
|
||
if ($request->start_time && $request->end_time) {
|
||
$start_time = $request->start_time;
|
||
$end_time = $request->end_time;
|
||
$logs = $logs->withCount([
|
||
'messenger' => function ($query) use ($start_time, $end_time) {
|
||
$query->whereBetween('created_at', [$start_time, $end_time]);
|
||
}
|
||
]);
|
||
} else {
|
||
$logs = $logs->withCount('messenger');
|
||
}
|
||
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$keyword = $request->keyword;
|
||
$logs = $logs->where(function ($sql) use ($keyword) {
|
||
$sql->where('name', 'like', '%' . $keyword . '%')
|
||
->orWhere('mobile', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
|
||
if ($request->has('share_name') && $request->share_name) {
|
||
$keyword = $request->share_name;
|
||
$logs = $logs->whereHas('sharer', function ($query) use ($keyword) {
|
||
$query->where('nickname', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
|
||
if ($request->has('is_audit') && is_numeric($request->is_audit)) {
|
||
$logs = $logs->where('is_audit', $request->is_audit);
|
||
}
|
||
if ($request->has('sex') && is_numeric($request->sex)) {
|
||
$logs = $logs->where('sex', $request->sex);
|
||
}
|
||
if ($request->has('degree') && $request->degree) {
|
||
$logs = $logs->where('degree', 'like', '%' . $request->degree . '%');
|
||
}
|
||
if ($request->has('min_age') && is_numeric($request->min_age) & $request->has('max_age') && is_numeric($request->max_age)) {
|
||
$logs = $logs->whereBetween('age', [$request->min_age, $request->max_age]);
|
||
}
|
||
if ($request->has('marital_status') && is_numeric($request->marital_status)) {
|
||
$logs = $logs->where('marital_status', $request->marital_status);
|
||
}
|
||
if ($request->has('belief') && is_numeric($request->belief)) {
|
||
$logs = $logs->where('belief', $request->belief);
|
||
}
|
||
if ($request->has('resident_province') && $request->resident_province) {
|
||
$logs = $logs->where('resident_province', $request->resident_province);
|
||
}
|
||
if ($request->has('resident_city') && $request->resident_city) {
|
||
$logs = $logs->where('resident_city', $request->resident_city);
|
||
}
|
||
if ($request->has('work_province') && $request->work_province) {
|
||
$logs = $logs->where('work_province', $request->work_province);
|
||
}
|
||
if ($request->has('work_city') && $request->work_city) {
|
||
$logs = $logs->where('work_city', $request->work_city);
|
||
}
|
||
if ($request->has('work_city') && $request->work_city) {
|
||
$logs = $logs->where('work_city', $request->work_city);
|
||
}
|
||
|
||
//判断来源
|
||
if ($request->has('source') && $request->source) {
|
||
$logs = $logs->where('source', 'like', '%' . $request->source . '%');
|
||
}
|
||
|
||
//判断来源
|
||
if ($request->has('recruit_type') && $request->recruit_type) {
|
||
$logs = $logs->where('recruit_type', 'like', '%' . $request->recruit_type . '%');
|
||
}
|
||
|
||
// if($request->is_audit == 0){
|
||
$logs = $logs->orderBy('created_at', 'desc')->paginate();
|
||
//按福恋使者分享排序:会卡
|
||
// }else{
|
||
// $logs = $logs->orderBy('messenger_count', 'desc')->paginate();
|
||
// }
|
||
|
||
|
||
foreach ($logs as $log) {
|
||
// $log->all_score = AssetLog::where('viewer_id', $log->viewer_id)->whereIn('type', [2,4])->sum('num');
|
||
// $log->today_score = AssetLog::where('viewer_id', $log->viewer_id)->whereIn('type', [2,4])->where('created_at', date('Y-m-d H:i:s'))->sum('num');
|
||
// $log->viewer->share_count = Viewer::where('viewer_id', $log->viewer_id)->count();
|
||
// $log->viewer->messenger_count = $log->messenger_count;
|
||
|
||
$log->viewer->share_role = $log->viewer->shareRole();
|
||
$log->viewer->next_role = $this->getNextRole($log->viewer->messenger_count);
|
||
//是否可以升级
|
||
$can_upgrade = 0;
|
||
if ($log->viewer->share_role) {
|
||
$can_upgrade = $log->viewer->share_role->id < ($log->viewer->next_role)['id'] ? 1 : 0;
|
||
}
|
||
$log->viewer->can_upgrade = $can_upgrade;
|
||
unset($log->viewer->shareRoles);
|
||
}
|
||
return $this->success('ok', $logs);
|
||
} catch (\Exception $e) {
|
||
\Log::error($e->getMessage());
|
||
return $this->failure("系统错误");
|
||
}
|
||
}
|
||
|
||
//福恋使者详情
|
||
public function messenger(Request $request, $messenger_id)
|
||
{
|
||
$messenger = Messenger::with('sharer', 'viewer', 'live')->find($messenger_id);
|
||
if (empty($messenger)) {
|
||
return $this->failure('福恋使者不存在');
|
||
}
|
||
$messenger->share_role = $messenger->viewer->shareRole();
|
||
$messenger->viewer->messenger = Messenger::where('share_viewer_id', $messenger->viewer_id)->paginate();
|
||
$messenger->viewer->share = Viewer::where('viewer_id', $messenger->viewer_id)->paginate();
|
||
return $this->success('ok', $messenger);
|
||
}
|
||
|
||
//申请福恋使者列表excel
|
||
public function messengerExcel(Request $request)
|
||
{ {
|
||
$logs = Messenger::with('sharer', 'viewer');
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$keyword = $request->keyword;
|
||
$logs = $logs->where(function ($sql) use ($keyword) {
|
||
$sql->where('name', 'like', '%' . $keyword . '%')
|
||
->orWhere('mobile', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
|
||
if ($request->has('is_audit') && is_numeric($request->is_audit)) {
|
||
$logs = $logs->where('is_audit', $request->is_audit);
|
||
}
|
||
if ($request->has('degree') && is_numeric($request->degree)) {
|
||
$logs = $logs->where('degree', $request->degree);
|
||
}
|
||
if ($request->has('resident_province') && is_numeric($request->resident_province)) {
|
||
$logs = $logs->where('resident_province', $request->resident_province);
|
||
}
|
||
if ($request->has('resident_city') && is_numeric($request->resident_city)) {
|
||
$logs = $logs->where('resident_city', $request->resident_city);
|
||
}
|
||
if ($request->has('work_province') && is_numeric($request->work_province)) {
|
||
$logs = $logs->where('work_province', $request->work_province);
|
||
}
|
||
if ($request->has('work_city') && is_numeric($request->work_city)) {
|
||
$logs = $logs->where('work_city', $request->work_city);
|
||
}
|
||
$logs = $logs->orderBy('created_at', 'desc')->get();
|
||
if (empty($logs)) {
|
||
return true;
|
||
}
|
||
$new_data = [];
|
||
foreach ($logs as $k => $log) {
|
||
$new_data[$k]['id'] = $log->id;
|
||
$new_data[$k]['name'] = $log->name;
|
||
$new_data[$k]['avatar'] = $log->viewer->avatar;
|
||
$new_data[$k]['mobile'] = $log->mobile;
|
||
switch ($log->sex) {
|
||
case 1:
|
||
$sex = '男';
|
||
break;
|
||
case 2:
|
||
$sex = '女';
|
||
default:
|
||
$sex = '未知';
|
||
}
|
||
$new_data[$k]['sex'] = $sex;
|
||
$new_data[$k]['age'] = $log->age;
|
||
switch ($log->marital_status) {
|
||
case 0:
|
||
$marital_status = '单身';
|
||
break;
|
||
case 2:
|
||
$marital_status = '恋爱中';
|
||
break;
|
||
case 1:
|
||
$marital_status = '已婚';
|
||
break;
|
||
default:
|
||
$marital_status = '单身';
|
||
break;
|
||
}
|
||
$new_data[$k]['marital_status'] = $marital_status;
|
||
$new_data[$k]['belief'] = $log->belief ? '其他' : '基督教';
|
||
$new_data[$k]['resident_place'] = $log->resident_province . $log->resident_city;
|
||
$new_data[$k]['work_place'] = $log->work_province . $log->work_city;
|
||
$new_data[$k]['degree '] = $log->degree;
|
||
$sharer_name = '';
|
||
if (!empty($log->sharer)) {
|
||
$sharer_name = $log->sharer->nickname;
|
||
}
|
||
$new_data[$k]['sharer'] = $sharer_name;
|
||
$new_data[$k]['created_at'] = $log->created_at->toDateTimeString();
|
||
|
||
}
|
||
return \Excel::download(new MessengerExport($new_data), 'messengers.xlsx');
|
||
|
||
}
|
||
}
|
||
|
||
//更改使者申请字段
|
||
// public function updateMessenger(Request $request){
|
||
|
||
// try {
|
||
// $id_arr = explode(',', $request->id);
|
||
// if($request->has('is_audit') && $request->is_audit){
|
||
// Messenger::whereIn('id', $id_arr)->update(['is_audit'=>$request->is_audit, 'updated_at'=>date('Y-m-d H:i:s')]);
|
||
// }
|
||
// return $this->success('ok');
|
||
// } catch (\Exception $e) {
|
||
// \Log::error($e->getMessage());
|
||
// return $this->failure("系统错误");
|
||
// }
|
||
// }
|
||
|
||
//手动添加余额
|
||
public function addScoreToviewer(Request $request, $viewer_id)
|
||
{
|
||
if (!$request->has('cash') || !$request->cash) {
|
||
return $this->failure('请输入金额');
|
||
}
|
||
|
||
$admin = auth()->user();
|
||
// print_r($admin);die;
|
||
if (config('app.env') == 'production') {
|
||
if (!in_array($admin->id, [58701, 7808])) {
|
||
return $this->failure('您没有权限');
|
||
}
|
||
}
|
||
|
||
try {
|
||
DB::beginTransaction();
|
||
$viewer = Viewer::select('mobile', 'nickname')->where('id', $viewer_id)->first();
|
||
$asset = Asset::where('viewer_id', $viewer_id)->first();
|
||
if (empty($asset)) {
|
||
$asset = new Asset();
|
||
$asset->viewer_id = $viewer_id;
|
||
$asset->cash = 0.00;
|
||
$asset->share_cash = $request->cash;
|
||
$asset->save();
|
||
} else {
|
||
Asset::where('viewer_id', $viewer_id)->increment('share_cash', $request->cash);
|
||
}
|
||
$asset_log = new AssetLog();
|
||
$asset_log->viewer_id = $viewer_id;
|
||
$asset_log->num = $request->cash;
|
||
$asset_log->real_num = $request->cash;
|
||
$asset_log->type = self::SHARE_EXTRA_CASH;
|
||
$asset_log->log_id = $admin->id;
|
||
$asset_log->is_hooked = 1;
|
||
$asset_log->score = bcadd($asset->share_cash, $asset->cash, 2);
|
||
$asset_log->save();
|
||
if ($viewer->mobile) {
|
||
// $this->sms->sentMessage($viewer->mobile, '额外奖励:'.$viewer->nickname.',您好!经福恋平台审核,你邀请好友超过50人,获得额外'.($request->cash*100).'福气的奖励,感谢你的参与!');
|
||
$this->sms->sentMessage($viewer->mobile, $viewer->nickname . '您好,经福恋平台统计,您昨天为福恋做出杰出贡献,特别给予额外 ' . ($request->cash * 100) . ' 福气的奖励,感谢您以行动做出榜样!继续加油哦');
|
||
}
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
DB::rollback();
|
||
\Log::error($e->getMessage());
|
||
return $this->failure("系统错误");
|
||
}
|
||
|
||
}
|
||
|
||
//手动添加余额
|
||
public function addScoreFromSharefun(Request $request, $viewer_id)
|
||
{
|
||
|
||
$share_fund = ShareFund::find(1);
|
||
|
||
if (!$request->has('cash') || !$request->cash) {
|
||
return $this->failure('请输入金额');
|
||
}
|
||
|
||
if ($request->cash > $share_fund->balance_amount) {
|
||
return $this->failure('资金池资金不足');
|
||
}
|
||
$admin = auth()->user();
|
||
// if(config('app.env') == 'production'){
|
||
// if( !in_array($admin->id, [58701,7808])){
|
||
// return $this->failure('您没有权限');
|
||
// }
|
||
// }
|
||
|
||
try {
|
||
DB::beginTransaction();
|
||
$viewer = Viewer::select('mobile', 'nickname')->where('id', $viewer_id)->first();
|
||
$asset = Asset::where('viewer_id', $viewer_id)->first();
|
||
if (empty($asset)) {
|
||
$asset = new Asset();
|
||
$asset->viewer_id = $viewer_id;
|
||
$asset->cash = 0.00;
|
||
$asset->share_cash = $request->cash;
|
||
$asset->save();
|
||
} else {
|
||
Asset::where('viewer_id', $viewer_id)->increment('share_cash', $request->cash);
|
||
}
|
||
$asset_log = new AssetLog();
|
||
$asset_log->viewer_id = $viewer_id;
|
||
$asset_log->num = $request->cash;
|
||
$asset_log->real_num = $request->cash;
|
||
$asset_log->type = self::SHARE_EXTRA_CASH;
|
||
$asset_log->log_id = $admin->id;
|
||
$asset_log->is_hooked = 1;
|
||
$asset_log->score = bcadd($asset->share_cash, $asset->cash, 2);
|
||
$asset_log->admin_id = auth()->id();
|
||
$asset_log->save();
|
||
if ($viewer->mobile) {
|
||
// $this->sms->sentMessage($viewer->mobile, '额外奖励:'.$viewer->nickname.',您好!经福恋平台审核,你邀请好友超过50人,获得额外'.($request->cash*100).'福气的奖励,感谢你的参与!');
|
||
$this->sms->sentMessage($viewer->mobile, $viewer->nickname . '您好,经福恋平台统计,您昨天为福恋做出杰出贡献,特别给予额外 ' . ($request->cash * 100) . ' 福气的奖励,感谢您以行动做出榜样!继续加油哦');
|
||
}
|
||
|
||
//奖金池操作
|
||
$share_fund->balance_amount = bcsub($share_fund->balance_amount, $request->cash, 2);
|
||
$share_fund->withdraw_amount = bcadd($share_fund->withdraw_amount, $request->cash, 2);
|
||
$share_fund->save();
|
||
|
||
$share_fund_log = new ShareFundLog();
|
||
$share_fund_log->viewer_id = $viewer_id;
|
||
$share_fund_log->value = $request->cash;
|
||
$share_fund_log->type = 'loss';
|
||
$share_fund_log->balance_amount = bcsub($share_fund->balance_amount, $request->cash, 2);
|
||
$share_fund_log->save();
|
||
|
||
|
||
|
||
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
DB::rollback();
|
||
\Log::error($e->getMessage());
|
||
return $this->failure("系统错误");
|
||
}
|
||
|
||
}
|
||
|
||
public function updateWechatInfoByOpenid($app, $openid)
|
||
{
|
||
try {
|
||
$wechat_user = $app->user->get($openid);
|
||
$unionid = $wechat_user['unionid'] ?? null;
|
||
if (!empty($unionid)) {//已关注公众号
|
||
//通过unionid查找
|
||
$wechat = Wechat::with('user')->where('unionid', $unionid)->first();
|
||
if ($wechat && $wechat->user) {//已注册小程序
|
||
$wechat->official_openid = $openid;
|
||
$wechat->user->is_subscribe = $wechat_user['subscribe'];
|
||
$wechat->save();
|
||
$wechat->user->save();
|
||
} elseif ($wechat && empty($wechat->user)) {//未注册小程序
|
||
$wechat->official_openid = $openid;
|
||
$wechat->save();
|
||
} elseif (empty($wechat) && empty($wechat->user)) {//没有记录过微信信息
|
||
$viewer = Viewer::where('unionid', $unionid)->orWhere('openid', $openid)->first();
|
||
if ($viewer && $viewer->user_id) {
|
||
if ($viewer->user) {
|
||
$viewer->user->is_subscribe = $wechat_user['subscribe'];
|
||
$viewer->user->save();
|
||
}
|
||
if ($viewer->user && $viewer->user->wechat) {
|
||
$viewer->user->wechat->official_openid = $openid;
|
||
$viewer->user->wechat->unionid = $unionid;
|
||
$viewer->user->wechat->save();
|
||
}
|
||
}
|
||
}
|
||
$viewer = Viewer::where('openid', $openid)->first();
|
||
} else {//未关注公众号
|
||
//通过openid查询
|
||
$wechat = Wechat::with('user')->where('official_openid', $openid)->first();
|
||
if ($wechat && $wechat->user) {
|
||
$wechat->unionid = $unionid;
|
||
$wechat->user->is_subscribe = $wechat_user['subscribe'];
|
||
$wechat->save();
|
||
$wechat->user->save();
|
||
} elseif ($wechat && empty($wechat->user)) {
|
||
$wechat->unionid = $unionid;
|
||
$wechat->save();
|
||
} elseif (empty($wechat) && empty($wechat->user)) {
|
||
$viewer = Viewer::where('openid', $openid)->first();
|
||
if ($viewer && $viewer->user_id) {
|
||
if ($viewer->user) {
|
||
$viewer->user->is_subscribe = $wechat_user['subscribe'];
|
||
$viewer->user->save();
|
||
}
|
||
if ($viewer->user && $viewer->user->wechat) {
|
||
$viewer->user->wechat->official_openid = $openid;
|
||
$viewer->user->wechat->unionid = $unionid;
|
||
$viewer->user->wechat->save();
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public function subOperat($app, $openid, $event_key = null)
|
||
{
|
||
try {
|
||
//修改关注信息
|
||
$mini_program_id = config('wechat.mini_program.app_id');
|
||
$user = $app->user->get($openid);
|
||
// $nickname = $user['nickname']??'';
|
||
$url = env('APP_URL') . "/h5/#/recruitingTeacher?openid=&from_id=0&from_openid=&from_user_id=&from_platform=official&anchor_openid=";
|
||
// $text = "终于等到你!欢迎关注福恋智能服务号
|
||
//
|
||
//如果您是老师,请继续关注我们的福恋平台SaaS系统给您发来的有关订单管理的信息。
|
||
//<a href='".$url."'>进入SaaS系统</a>
|
||
//
|
||
//欢迎关注福恋智能,优秀单身、专业课程、趣味活动,助力单身进入婚恋,组建合一蒙福家庭。
|
||
//<a href='www.love.com' data-miniprogram-appid='".$mini_program_id."' data-miniprogram-path='pages/tabBar/welcome?from_plantform=official'>进入福恋小程序</a>";
|
||
if ($event_key == 'qrscene_saas_anchor') {
|
||
$text = "终于等到你!欢迎关注福恋智能服务号
|
||
|
||
请继续关注我们的福恋平台SaaS系统给您发来的有关订单管理的信息。
|
||
<a href='" . $url . "'>进入SaaS系统</a>";
|
||
} else {
|
||
$text = "欢迎关注福恋智能,优秀单身、专业课程、趣味活动,助力单身进入婚恋,组建合一蒙福家庭。
|
||
<a href='www.love.com' data-miniprogram-appid='" . $mini_program_id . "' data-miniprogram-path='pages/tabBar/welcome?from_plantform=official'>进入福恋小程序</a>";
|
||
}
|
||
return $text;
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public function server()
|
||
{
|
||
$app = $this->app;
|
||
$app->server->push(function ($message) use ($app) {
|
||
Log::info($message);
|
||
// $result = $app->material->list('image', 0, 10);
|
||
$msg_type = $message['MsgType'];
|
||
if ($msg_type != 'event') {
|
||
// $mediaId = 'XOQlsIN1Qsrn-CIdnUulsxYP-r_hAVnSBN0bu5o9oJCdV7NsFYm8JLW2IU1nJAL3';
|
||
$mediaId = "XOQlsIN1Qsrn-CIdnUulswzNPU2RL2lsUsfD7WSII16d7nOs4DzelAGSlcPnJGpA";
|
||
$image = new Image($mediaId);
|
||
$app->customer_service->message($image)->to($message['FromUserName'])->send();
|
||
} else {
|
||
//处理事件类型
|
||
$event = $message['Event'];
|
||
switch ($event) {//关注
|
||
case 'subscribe':
|
||
//修改微信信息
|
||
$this->updateWechatInfoByOpenid($app, $message['FromUserName']);
|
||
//增加关注记录
|
||
$this->addSubscribeLog($message['FromUserName'], $message['EventKey'], 1);
|
||
//发送小程序卡片
|
||
$result = $this->subOperat($app, $message['FromUserName'], $message['EventKey']);
|
||
if (empty($result))
|
||
throw new \Exception("发送小程序信息失败", 1);
|
||
$text = new Text($result);
|
||
$app->customer_service->message($text)->to($message['FromUserName'])->send();
|
||
// }
|
||
//已入驻商户发送消息
|
||
if ($this->is_recruit($message['FromUserName'])) {
|
||
$result = $this->subOperatV2($app, $message['FromUserName']);
|
||
if (empty($result))
|
||
throw new \Exception("发送小程序信息失败", 1);
|
||
$text = new Text($result);
|
||
$result = $app->customer_service->message($text)->to($message['FromUserName'])->send();
|
||
}
|
||
$news = $this->scanQrcode($message);
|
||
|
||
return $news;
|
||
break;
|
||
case 'unsubscribe': //取消关注
|
||
$this->updateWechatInfoByOpenid($app, $message['FromUserName']);
|
||
//增加关注记录
|
||
$this->addSubscribeLog($message['FromUserName'], $message['EventKey'], 0);
|
||
break;
|
||
case 'SCAN':
|
||
//如果带有福恋链接 发送小程序信息
|
||
if (count(explode(config('app.url'), $message['EventKey'])) > 1) {
|
||
|
||
if ($this->getOpenidUserinfoTypeSingle($message['FromUserName'])) {
|
||
$result = $this->subOperat($app, $message['FromUserName']);
|
||
if (empty($result))
|
||
throw new \Exception("发送小程序信息失败", 1);
|
||
$text = new Text($result);
|
||
$result = $app->customer_service->message($text)->to($message['FromUserName'])->send();
|
||
}
|
||
|
||
$news = $this->scanQrcode($message);
|
||
return $news;
|
||
} elseif ($message['EventKey'] == "buyVip") {
|
||
$items = [
|
||
new NewsItem([
|
||
'title' => "开通会员立享多项权益!",
|
||
'description' => "预估交友成功率提升100%",
|
||
'url' => config("app.url") . "/api/official/live/wechat/oauth?url=https%3A%2F%2Flove.ufutx.cn%2Fh5%2F%23%2FbuyVipPackage",
|
||
'image' => "https://image.fulllinkai.com/202412/06/77b0710a2a16d58856cf748f957048ca.png",
|
||
]),
|
||
];
|
||
$news = new News($items);
|
||
return $news;
|
||
}
|
||
break;
|
||
default:
|
||
# code...
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
return isset($news) ? $news : null;
|
||
});
|
||
$response = $app->server->serve();
|
||
return $response;
|
||
}
|
||
|
||
/**根据判断用户的类型,如果单身返回true */
|
||
public function getOpenidUserinfoTypeSingle($openid)
|
||
{
|
||
try {
|
||
$userinfo = Wechat::where(['openid' => $openid])
|
||
->orWhere('official_openid', $openid)
|
||
->with('user')
|
||
->first();
|
||
if ($userinfo) {
|
||
if ($userinfo->user) {
|
||
if ($userinfo->user->type == 'single') {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
} else {
|
||
return true;
|
||
}
|
||
} else {
|
||
return true;
|
||
}
|
||
return false;
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
public function addSubscribeLog($openid, $channel, $is_subscribed)
|
||
{
|
||
try {
|
||
$log = SubscribeOfficialLog::where('openid', $openid)->first();
|
||
if (empty($log)) {
|
||
$log = new SubscribeOfficialLog;
|
||
}
|
||
$log->openid = $openid;
|
||
$log->channel = $channel;
|
||
$log->is_subscribed = $is_subscribed;
|
||
$log->save();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
//扫描二维码事件
|
||
public function scanQrcode($message)
|
||
{
|
||
$openid = $message['FromUserName'];
|
||
$viewer = Viewer::where('openid', $openid)->first();
|
||
|
||
//处理参数
|
||
$EventKey = $message['EventKey'];
|
||
\Log::info('关注场景参数:' . $EventKey . ' openid=' . $message['FromUserName']);
|
||
//关注带过来的参数字符串会多一个‘qrscene’
|
||
$EventKey = substr($EventKey, 0, 7) == 'qrscene' ? substr($EventKey, 8) : $EventKey;
|
||
if (strpos($EventKey, 'watchLive')) {
|
||
|
||
//不存在用户
|
||
if (empty($viewer)) {
|
||
//注册之前先绑定用户关系
|
||
$url = Redis::get($openid . 'url');
|
||
if (!$url) {
|
||
Redis::setex($openid . 'url', 24 * 60 * 60, $EventKey);
|
||
}
|
||
}
|
||
|
||
//发送图文消息
|
||
$live_id = substr($EventKey, strripos($EventKey, "live_id=") + 8, 3);
|
||
$live = Live::select('id', 'poster', 'title', 'detail', 'share_poster')->where('id', $live_id)->first();
|
||
$param = substr($EventKey, strpos($EventKey, "?"));
|
||
|
||
$title = $live->title;
|
||
$description = $live->detail;
|
||
$image = $live->share_poster ?: $live->poster;
|
||
$jump_url = urlencode(env('APP_URL') . '/h5/#/watchLive/' . $live_id);
|
||
$url = env('APP_URL') . '/api/official/live/wechat/oauth' . $param . '&url=' . $jump_url;
|
||
$items = [
|
||
new NewsItem([
|
||
'title' => $title,
|
||
'description' => $description,
|
||
'url' => $url,
|
||
'image' => $image,
|
||
]),
|
||
];
|
||
$news = new News($items);
|
||
return $news;
|
||
} elseif (strpos($EventKey, 'information')) {
|
||
$content = "<a href='http://www.qq.com' data-miniprogram-appid='wxc41491431733671e' data-miniprogram-path='" . $EventKey . "'>点击跳小程序</a>";
|
||
$text = new Text($content);
|
||
$result = $this->app->customer_service->message($text)->to($openid)->send();
|
||
if ($result['errcode'] != 0) {
|
||
\Log::info('customer_service:' . json_encode($result));
|
||
}
|
||
} elseif (strpos($EventKey, 'courseDetail')) {
|
||
$course_id = substr($EventKey, strpos($EventKey, 'c_id=') + 5);
|
||
$course = Course::find($course_id);
|
||
//\Log::info('课程id:'.$course_id);
|
||
if (!$course)
|
||
return;
|
||
$jump_url = urlencode(env('APP_URL') . '/pu/#/courseDetail/' . $course_id);
|
||
$url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $course->merchant_id . '&url=' . $jump_url;
|
||
$items = [
|
||
new NewsItem([
|
||
'title' => $course->title,
|
||
// 'description' =>$this->getHtmlText($course->short_description),
|
||
'description' => str_replace(
|
||
array(
|
||
" ",
|
||
" ",
|
||
" ",
|
||
" ",
|
||
"‌",
|
||
"‍",
|
||
"“",
|
||
"”",
|
||
'·',
|
||
" ",
|
||
"\r\n",
|
||
"\r",
|
||
"\n"
|
||
),
|
||
'',
|
||
strip_tags(htmlspecialchars_decode($course->short_description))
|
||
),
|
||
'url' => $url,
|
||
'image' => $course->thumb,
|
||
]),
|
||
];
|
||
$news = new News($items);
|
||
return $news;
|
||
} elseif (strpos($EventKey, 'activitySignIn')) {
|
||
$qr_code_id = substr($EventKey, strpos($EventKey, 'qr_code_id=') + 11);
|
||
$qr_code = \App\Models\Server\QrCode::find($qr_code_id);
|
||
if (!$qr_code) {
|
||
return;
|
||
}
|
||
switch ($qr_code->type) {
|
||
case 'course':
|
||
$service = Course::where('id', $qr_code->type_id)->where('is_show', 1)
|
||
->first();
|
||
$description = str_replace(
|
||
array(
|
||
" ",
|
||
" ",
|
||
" ",
|
||
" ",
|
||
"‌",
|
||
"‍",
|
||
"“",
|
||
"”",
|
||
'·',
|
||
" ",
|
||
"\r\n",
|
||
"\r",
|
||
"\n"
|
||
),
|
||
'',
|
||
strip_tags(htmlspecialchars_decode($service->short_description))
|
||
);
|
||
$image = $service->thumb;
|
||
break;
|
||
case 'activity':
|
||
case 'service':
|
||
case 'community':
|
||
$service = CommunityActivity::where('id', $qr_code->type_id)->where('status', 1)
|
||
->first();
|
||
$description = $service->title;
|
||
$image = $service->pic;
|
||
break;
|
||
default:
|
||
$service = null;
|
||
}
|
||
if (!$service) {
|
||
return;
|
||
}
|
||
$jump_url = urlencode(env('APP_URL') . '/pu/#/activitySignIn/' . $qr_code->type_id . '?qr_code_id=' . $qr_code_id);
|
||
$url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $qr_code->merchant_id .
|
||
'&url=' . $jump_url . '&qr_code_id=' . $qr_code_id;
|
||
$items = [
|
||
new NewsItem([
|
||
'title' => $service->title,
|
||
// 'description' =>$this->getHtmlText($course->short_description),
|
||
'description' => $description,
|
||
'url' => $url,
|
||
'image' => $image,
|
||
]),
|
||
];
|
||
$news = new News($items);
|
||
return $news;
|
||
} elseif ($message['EventKey'] == "qrscene_buyVip") {
|
||
$items = [
|
||
new NewsItem([
|
||
'title' => "开通会员立享多项权益!",
|
||
'description' => "预估交友成功率提升100%",
|
||
'url' => "https://love.ufutx.com/api/official/live/wechat/oauth?url=https%3A%2F%2Flove.ufutx.com%2Fh5%2F%23%2FbuyVipPackage",
|
||
'image' => "https://image.fulllinkai.com/202412/06/77b0710a2a16d58856cf748f957048ca.png",
|
||
]),
|
||
];
|
||
$news = new News($items);
|
||
return $news;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 审核福恋使者
|
||
*/
|
||
public function checkMessenger(Request $request, Messenger $messenger)
|
||
{
|
||
try {
|
||
DB::beginTransaction();
|
||
$is_audit = $request->input('is_audit');
|
||
if (empty($is_audit)) {
|
||
return $this->failure('请选择审核状态');
|
||
}
|
||
if ($messenger->is_audit == 1) {
|
||
return $this->failure('该记录已审核');
|
||
}
|
||
switch ($is_audit) {
|
||
case 1:
|
||
$messenger->is_audit = $is_audit;
|
||
$messenger->reason = '';
|
||
$messenger->check_date = date('Y-m-d H:i:s');
|
||
$messenger->save();
|
||
//成为普通推广员 如果已有推广员,则不变
|
||
$result = ShareRoleViewer::where('viewer_id', $messenger->viewer_id)->exists();
|
||
if (!$result) {
|
||
ShareRoleViewer::create([
|
||
'viewer_id' => $messenger->viewer_id,
|
||
'share_role_id' => 1,
|
||
]);
|
||
//短信通知
|
||
$param['mobile'] = $messenger->mobile;
|
||
$param['message'] = ($messenger->name) . ",您好!经福恋平台审核,恭喜您正式成为【婚姻使者】,现在您可以开始祝福他人进入蒙福家庭的旅程了!【福恋】";
|
||
SendSpreaderNote::dispatch($param)->onQueue('love');
|
||
}
|
||
|
||
if ($messenger->share_viewer_id) {
|
||
$share_count = Messenger::where('share_viewer_id', $messenger->share_viewer_id)->count();
|
||
if (in_array($share_count, [5, 25, 125])) {
|
||
$nickname = Viewer::where('id', $messenger->share_viewer_id)->value('nickname');
|
||
|
||
}
|
||
}
|
||
|
||
if (!empty($messenger->task_id)) {
|
||
$task = Task::find($messenger->task_id);
|
||
// $adddata['cash'] = $cash/100;
|
||
// $adddata['viewer_id'] = $messenger->share_viewer_id;
|
||
// $adddata['type'] = 'share_cash';
|
||
// $adddata['source_id'] = $messenger->viewer_id;
|
||
// AddCashToViewer::dispatch($adddata)->onQueue('love');
|
||
|
||
//任务奖励先存起来
|
||
if ($task->type == '婚姻使者') {
|
||
$viewer_task_score = ViewerTaskScore::where('viewer_id', $messenger->share_viewer_id)->where('task_id', $messenger->task_id)->first();
|
||
if (!empty($viewer_task_score)) {
|
||
$viewer_task_score->increment('all_score', $task->new_score);
|
||
$viewer_task_score->increment('score', $task->new_score);
|
||
} else {
|
||
$viewer_task_score = new ViewerTaskScore();
|
||
$viewer_task_score->viewer_id = $messenger->share_viewer_id;
|
||
$viewer_task_score->task_id = $messenger->task_id;
|
||
$viewer_task_score->all_score = $task->new_score;
|
||
$viewer_task_score->score = $task->new_score;
|
||
$viewer_task_score->save();
|
||
|
||
}
|
||
}
|
||
|
||
$task_viewer = new Taskviewer();
|
||
$task_viewer->viewer_id = $messenger->share_viewer_id;
|
||
$task_viewer->other_viewer_id = $messenger->viewer_id;
|
||
$task_viewer->task_id = $messenger->task_id;
|
||
$task_viewer->save();
|
||
} else {
|
||
//生成冻结金额7元
|
||
// $this->shareMessengerCashV2($messenger);
|
||
//生成1元金额
|
||
// $this->shareMessengerCash($messenger, 'no_blocked');
|
||
}
|
||
break;
|
||
case 2:
|
||
$reason = $request->input('reason');
|
||
if (empty($reason)) {
|
||
return $this->failure('请输入拒绝理由');
|
||
}
|
||
$messenger->reason = $reason;
|
||
$messenger->is_audit = $is_audit;
|
||
$messenger->check_date = date('Y-m-d H:i:s');
|
||
$messenger->save();
|
||
//通知 todo
|
||
// $param['mobile'] = $messenger->mobile;
|
||
// $param['message'] = ($messenger->name).",您好!经福恋平台审核,你的申请福恋【婚姻使者】失败,请分享七位以上好友再申请!【福恋】";
|
||
// SendSpreaderNote::dispatch($param)->onQueue('love');
|
||
// //短信通知分享人
|
||
// $sharer = $messenger->sharer;
|
||
// if ($sharer) {
|
||
// $param['mobile'] = $sharer->mobile;
|
||
// $param['message'] = $sharer->nickname.",您好!经福恋平台审核,".$messenger->name."申请【婚姻使者】失败,Ta需要分享七位以上好友再申请!【福恋】";
|
||
// SendSpreaderNote::dispatch($param)->onQueue('love');
|
||
// }
|
||
if (!empty($messenger->task_id)) {
|
||
$task = Task::find($request->task_id);
|
||
$task->increment('the_rest');
|
||
}
|
||
break;
|
||
}
|
||
DB::commit();
|
||
return $this->success('审核成功');
|
||
} catch (\Exception $e) {
|
||
DB::rollback();
|
||
\Log::error($e->getMessage());
|
||
return $this->failure('审核失败, 联系开发人员');
|
||
}
|
||
|
||
}
|
||
|
||
public function sendTest()
|
||
{
|
||
$arr = CommunityMoment::with('community')->get();
|
||
return $this->success($arr);
|
||
$app = $this->app;
|
||
$made = $app->material->list('image', 0, 1);
|
||
return $this->success('ok', $made);
|
||
// $result = $app->qrcode->temporary('uncle', 30 * 24 * 3600);
|
||
// $url = $app->qrcode->url($result['ticket']);
|
||
// return $this->success('ok', $url);
|
||
}
|
||
/**
|
||
* 分享福恋使者收益
|
||
*/
|
||
public function shareMessengerCash($messenger, $type = 'blocked')
|
||
{
|
||
$sharer = $messenger->sharer;
|
||
if (empty($sharer)) {
|
||
return;
|
||
}
|
||
|
||
//生成冻结金额
|
||
$asset = $sharer->asset;
|
||
if (empty($asset)) {
|
||
$asset = $sharer->asset()->create();
|
||
}
|
||
$assetLog = $sharer->assetLog()->where('type', 4)->where('log_id', $messenger->viewer_id)->first();
|
||
if ($assetLog) {
|
||
return;
|
||
}
|
||
$num = 1;
|
||
switch ($type) {
|
||
case 'blocked':
|
||
$asset->increment('blocked_cash', $num);
|
||
$score = bcadd($asset->share_cash, $asset->cash, 2);
|
||
//生成冻结记录
|
||
$sharer->assetLog()->create([
|
||
'num' => $num,
|
||
'real_num' => 0,
|
||
'type' => 4,
|
||
'log_id' => $messenger->viewer_id,
|
||
'is_hooked' => 0,
|
||
'score' => $score
|
||
]);
|
||
break;
|
||
case 'no_blocked':
|
||
$asset->increment('share_cash', $num);
|
||
$score = bcadd($asset->share_cash, $asset->cash, 2);
|
||
//生成冻结记录
|
||
$sharer->assetLog()->create([
|
||
'num' => $num,
|
||
'real_num' => $num,
|
||
'type' => 4,
|
||
'log_id' => $messenger->viewer_id,
|
||
'is_hooked' => 1,
|
||
'score' => $score
|
||
]);
|
||
break;
|
||
}
|
||
//短信通知分享人
|
||
// $param['mobile'] = $sharer->mobile;
|
||
// $param['message'] = $sharer->nickname.",您好!经福恋平台审核,".$messenger->name."通过【婚姻使者】申请,获得700福气的奖励,感谢你的推荐!【福恋】";
|
||
// SendSpreaderNote::dispatch($param)->onQueue('love');
|
||
return;
|
||
}
|
||
|
||
//添加直播渠道
|
||
public function addPlatfrom(Request $request)
|
||
{
|
||
if (!$request->has('code') || !$request->code) {
|
||
return $this->failure('请输入渠道简写');
|
||
}
|
||
$is_set = Platfrom::where('code', $request->code)->count();
|
||
if ($is_set) {
|
||
return $this->failure('渠道已存在');
|
||
}
|
||
if (!$request->has('name') || !$request->name) {
|
||
return $this->failure('请输入渠道名称');
|
||
}
|
||
$platfrom = new Platfrom();
|
||
$platfrom->code = $request->code;
|
||
$platfrom->name = $request->name;
|
||
$platfrom->save();
|
||
|
||
$app = $this->app;
|
||
$result = $app->qrcode->forever($request->code);
|
||
$url = $app->qrcode->url($result['ticket']);
|
||
Redis::set($request->code . '_qrcode', $url);
|
||
return $this->success('ok');
|
||
}
|
||
|
||
//直播渠道列表
|
||
public function platfroms(Request $request)
|
||
{
|
||
$platfroms = Platfrom::withcount('viewer');
|
||
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$platfroms = $platfroms->where('name', 'like', '%' . $request->keyword . '%');
|
||
}
|
||
|
||
if ($request->has('start_time') && $request->start_time && $request->has('end_time') && $request->end_time) {
|
||
$platfroms = $platfroms->where('created_at', 'between', [$request->start_time, $request->end_time]);
|
||
}
|
||
|
||
$platfroms = $platfroms->orderBy('created_at', 'desc')->paginate();
|
||
foreach ($platfroms as $item) {
|
||
$item->qrcode = Redis::get($item->code . '_qrcode');
|
||
}
|
||
return $this->success('ok', $platfroms);
|
||
}
|
||
|
||
//直播渠道详情
|
||
public function platfrom(Request $request, $id)
|
||
{
|
||
$platfrom = Platfrom::withcount('viewer')->where('id', $id)->first();
|
||
if (empty($platfrom)) {
|
||
return $this->failure('渠道不存在');
|
||
}
|
||
$platfrom->qrcode = Redis::get($platfrom->code . '_qrcode');
|
||
$platfrom->viewer = Viewer::where('source', $platfrom->code)->paginate();
|
||
return $this->success('ok', $platfrom);
|
||
}
|
||
|
||
//更新渠道
|
||
public function updatePlatfrom(Request $request, $id)
|
||
{
|
||
$platfrom = Platfrom::find($id);
|
||
if (empty($platfrom)) {
|
||
return $this->failure('渠道不存在');
|
||
}
|
||
if ($request->code && $request->has('code')) {
|
||
$platfrom->code = $request->code;
|
||
$app = $this->app;
|
||
$result = $app->qrcode->forever($request->code);
|
||
$url = $app->qrcode->url($result['ticket']);
|
||
Redis::set($request->code . '_qrcode', $url);
|
||
}
|
||
if ($request->name && $request->has('name')) {
|
||
$platfrom->name = $request->name;
|
||
}
|
||
$platfrom->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
//删除渠道
|
||
public function delPlatfrom(Request $request, $id)
|
||
{
|
||
$platfrom = Platfrom::find($id);
|
||
if (empty($platfrom)) {
|
||
return $this->failure('渠道不存在');
|
||
}
|
||
$platfrom = Platfrom::where('id', $id)->delete();
|
||
Redis::del($request->code . '_qrcode');
|
||
return $this->success('ok');
|
||
}
|
||
|
||
//问卷调查
|
||
public function questions(Request $request)
|
||
{
|
||
$questions = Question::with('live', 'viewer');
|
||
|
||
if ($request->has('viewer') && $request->viewer) {
|
||
$nickname = $request->viewer;
|
||
$questions = $questions->whereHas('viewer', function ($query) use ($nickname) {
|
||
$query->where('nickname', 'like', "%" . $nickname . "%");
|
||
});
|
||
}
|
||
|
||
if ($request->has('live') && $request->live) {
|
||
$title = $request->live;
|
||
$questions = $questions->whereHas('viewer', function ($query) use ($title) {
|
||
$query->where('title', 'like', "%" . $title . "%");
|
||
});
|
||
}
|
||
|
||
if ($request->has('keyword') && $request->keyword) {
|
||
$keyword = $request->keyword;
|
||
$questions = $questions->where(function ($sql) use ($keyword) {
|
||
$sql->where('harvest', 'like', '%' . $keyword . '%')
|
||
->orWhere('defect', 'like', '%' . $keyword . '%')
|
||
->orWhere('defect', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
|
||
if ($request->has('star') && $request->star) {
|
||
$questions->where('star', $request->star);
|
||
}
|
||
|
||
if ($request->has('live_id') && $request->live_id) {
|
||
$questions->where('live_id', $request->live_id);
|
||
}
|
||
$questions = $questions->orderBy('created_at', 'desc')->paginate();
|
||
return $this->success('ok', $questions);
|
||
}
|
||
|
||
//设置福恋使者视频以及轮播图
|
||
public function messengerSetting(Request $request)
|
||
{
|
||
// if(!$request->has('banner') || !$request->banner){
|
||
// return $this->failure('请上传轮播图');
|
||
// }
|
||
if (!$request->has('video') || !$request->video) {
|
||
return $this->failure('请上传视频');
|
||
}
|
||
$messenger_config = [
|
||
'banner' => $request->banner,
|
||
'video' => $request->video,
|
||
'question' => $request->question,
|
||
];
|
||
Redis::set('messenger_config', json_encode($messenger_config));
|
||
return $this->success('ok', $messenger_config);
|
||
}
|
||
|
||
//福恋使者页面配置
|
||
public function getMessengerSetting(Request $request)
|
||
{
|
||
$config = Redis::get('messenger_config');
|
||
return $this->success('ok', json_decode($config));
|
||
}
|
||
|
||
//推广奖励任务设置
|
||
public function addTask(Request $request)
|
||
{
|
||
|
||
if (!$request->has('text') || !$request->text) {
|
||
return $this->failure('请输入推广文案');
|
||
}
|
||
if (!$request->has('end_time') || !$request->end_time) {
|
||
return $this->failure('请输入结束时间');
|
||
}
|
||
// if(!$request->has('title') || !$request->title){
|
||
// return $this->failure('请输入标题');
|
||
// }
|
||
// if(!$request->has('pic') || !$request->pic){
|
||
// return $this->failure('请输入海报');
|
||
// }
|
||
// if(!$request->has('url') || !$request->url){
|
||
// return $this->failure('请输入链接');
|
||
// }
|
||
$task = new Task();
|
||
$task->text = $request->text;
|
||
$task->new_score = $request->new_score ? $request->new_score / 100 : 0;
|
||
$task->old_score = $request->old_score ? $request->old_score / 100 : 0;
|
||
$task->start_time = $request->start_time ?: date('Y-d-d H:i:s');
|
||
$task->end_time = $request->end_time;
|
||
$task->title = $request->title;
|
||
$task->pic = $request->pic;
|
||
$task->num = $request->num;
|
||
$task->the_rest = $request->num;
|
||
$task->url = $request->url;
|
||
$task->type = $request->type;
|
||
$task->live_id = $request->live_id ?: 0;
|
||
$task->save();
|
||
|
||
return $this->success('ok');
|
||
}
|
||
|
||
//任务列表
|
||
public function tasks(Request $request)
|
||
{
|
||
$task = Task::with('live');
|
||
|
||
if ($request->has('type') && is_numeric($request->type)) {
|
||
switch ($request->type) {
|
||
//仅限新用户
|
||
case 1:
|
||
$task = $task->where('new_score', '!=', 0)->where('old_score', 0);
|
||
break;
|
||
//仅限老用户
|
||
case 2:
|
||
$task = $task->where('old_score', '!=', 0)->where('new_score', 0);
|
||
break;
|
||
default:
|
||
}
|
||
}
|
||
|
||
if ($request->has('status') && is_numeric($request->status)) {
|
||
switch ($request->status) {
|
||
//未开始
|
||
case 0:
|
||
$task = $task->where('start_time', '>', date('Y-m-d H:i:s'));
|
||
break;
|
||
//进行中
|
||
case 1:
|
||
$task = $task->where('end_time', '>', date('Y-m-d H:i:s'))->where('start_time', '<', date('Y-m-d H:i:s'));
|
||
break;
|
||
//已结束
|
||
case 2:
|
||
$task = $task->where('end_time', '<', date('Y-m-d H:i:s'));
|
||
break;
|
||
default:
|
||
}
|
||
}
|
||
|
||
if ($request->has('live_id') && is_numeric($request->live_id)) {
|
||
$task = $task->where('live_id', $request->live_id);
|
||
}
|
||
|
||
if ($request->has('keyword') && is_numeric($request->keyword)) {
|
||
$keyword = $request->keysword;
|
||
$task = $task->where('text', 'like', '%' . $keyword . '%')->orWhereHas(function ($query) use ($keyword) {
|
||
$query->where('title', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$task = $task->orderByRaw(DB::raw('FIELD(is_top, 1,0) asc'))->orderByRaw('created_at desc')->paginate();
|
||
foreach ($task as $val) {
|
||
$val->new_score = $val->new_score * 100;
|
||
}
|
||
|
||
return $this->success('ok', $task);
|
||
}
|
||
|
||
public function task(Request $request, $task_id)
|
||
{
|
||
$task = Task::with(['live', 'viewer', 'viewer.referrer', 'star', 'star.viewer'])->where('id', $task_id)->first();
|
||
$finished_task_count = TaskViewer::where('task_id', $task_id)->count();
|
||
|
||
$task->loss_cash = $finished_task_count * $task->new_score * 100;
|
||
if (!empty($task->live)) {
|
||
$task->url = env('APP_URL') . '/h5/#/watchLive/' . $task->live->id;
|
||
$task->title = $task->live->title;
|
||
$task->pic = $task->live->poster;
|
||
}
|
||
if ($request->keyword) {
|
||
$task->finisher = $task->finisher()->where('nickname', 'like', '%' . $request->keyword . '%')->paginate();
|
||
} else {
|
||
$task->finisher = $task->finisher()->paginate();
|
||
}
|
||
$task->new_score = $task->new_score * 100;
|
||
foreach ($task->finisher as $val) {
|
||
if (!empty($val)) {
|
||
$viewertask_score = ViewerTaskScore::where('viewer_id', $val->id)->where('task_id', $task_id)->first();
|
||
$val->cash = !empty($viewertask_score) ? $viewertask_score->score * 100 : 0;
|
||
$val->all_cash = !empty($viewertask_score) ? $viewertask_score->all_score * 100 : 0;
|
||
$val->viewer = Viewer::find($val->pivot->other_viewer_id);
|
||
$asset_log = AssetLog::where('viewer_id', $val->id)->where('type', 5)->orderBy('id', 'desc')->first();
|
||
$val->has_been_reward = !empty($asset_log) ?: false;
|
||
$val->add_time = !empty($asset_log) ? $asset_log->created_at->toDateTimeString() : '';
|
||
$val->admin = !empty($asset_log) ? User::find($asset_log->admin_id) : '';
|
||
}
|
||
}
|
||
return $this->success('ok', $task);
|
||
}
|
||
|
||
//从任务金额里面添加福气
|
||
public function addScoreFromTask(Request $request)
|
||
{
|
||
$admin = auth()->user();
|
||
// print_r($admin);die;
|
||
if (config('app.env') == 'production') {
|
||
if (!in_array($admin->id, [58701, 7808])) {
|
||
return $this->failure('您没有权限');
|
||
}
|
||
}
|
||
|
||
try {
|
||
DB::beginTransaction();
|
||
$cash = Asset::where('id', $request->viewer_id)->value('cash');
|
||
$viewer_task_score = ViewerTaskScore::where('viewer_id', $request->viewer_id)->where('task_id', $request->task_id)->first();
|
||
if ($request->score && ($request->score / 100) > $viewer_task_score->score) {
|
||
return $this->failure('福气不足');
|
||
}
|
||
|
||
$viewer_task_score->increment('used_score', $request->score / 100);
|
||
$viewer_task_score->decrement('score', $request->score / 100);
|
||
|
||
$log = new AssetLog;
|
||
$log->viewer_id = $request->viewer_id;
|
||
$log->num = $request->score / 100;
|
||
$log->type = 2;
|
||
$log->is_hooked = 0;
|
||
$log->score = bcadd($request->score / 100, $cash, 2);
|
||
$log->save();
|
||
|
||
// Asset::where('viewer_id', $request->viewer_id)->increment('cash', $request->score/100);
|
||
//生成福气
|
||
DB::commit();
|
||
return $this->success('ok', $viewer_task_score->score);
|
||
} catch (\Exception $e) {
|
||
DB::rollback();
|
||
\Log::error($e->getMessage());
|
||
return $this->failure("系统错误");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
//筛选完成分享人
|
||
public function searchFinisher(Request $request)
|
||
{
|
||
$viewer_id = TaskViewer::where('task_id', $request->task_id);
|
||
if ($request->keyword) {
|
||
$keyword = $request->keyword;
|
||
$viewer_id = $viewer_id->whereHas('viewer', function ($query) use ($keyword) {
|
||
$query->where('nickname', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$viewer_id = $viewer_id->pluck('viewer_id')->toArray();
|
||
$viewers = Viewer::whereIn('id', $viewer_id)->get();
|
||
$new_score = Task::where('id', $request->task_id)->value('new_score');
|
||
foreach ($viewers as $viewer) {
|
||
$viewertask_score = ViewerTaskScore::where('viewer_id', $viewer->id)->where('task_id', $request->task_id)->first();
|
||
$viewer->cash = !empty($viewertask_score) ? $viewertask_score->score * 100 : 0;
|
||
$viewer->all_cash = !empty($viewertask_score) ? $viewertask_score->all_score * 100 : 0;
|
||
$asset_log = AssetLog::where('viewer_id', $viewer->id)->where('type', 5)->orderBy('id', 'desc')->first();
|
||
$viewer->has_been_reward = !empty($asset_log) ?: false;
|
||
$viewer->add_time = !empty($asset_log) ? $asset_log->created_at->toDateTimeString() : '';
|
||
$viewer->admin = !empty($asset_log) ? User::find($asset_log->admin_id) : '';
|
||
}
|
||
|
||
return $this->success('ok', $viewers);
|
||
}
|
||
|
||
public function updateTask(Request $request, $task_id)
|
||
{
|
||
$task = Task::find($task_id);
|
||
if (empty($task)) {
|
||
return $this->failure('任务不存在');
|
||
}
|
||
|
||
if ($request->has('live_id') && $request->live_id) {
|
||
$task->live_id = $request->live_id;
|
||
}
|
||
if ($request->has('text') && $request->text) {
|
||
$task->text = $request->text;
|
||
}
|
||
if ($request->has('start_time') && $request->start_time) {
|
||
$task->start_time = $request->start_time;
|
||
}
|
||
if ($request->has('end_time') && $request->end_time) {
|
||
$task->end_time = $request->end_time;
|
||
}
|
||
if ($request->has('new_score') && $request->new_score) {
|
||
$task->new_score = $request->new_score / 100;
|
||
}
|
||
if ($request->has('old_score') && $request->old_score) {
|
||
$task->old_score = $request->old_score;
|
||
}
|
||
if ($request->has('pic') && $request->pic) {
|
||
$task->pic = $request->pic;
|
||
}
|
||
if ($request->has('title') && $request->title) {
|
||
$task->title = $request->title;
|
||
}
|
||
if ($request->has('url') && $request->url) {
|
||
$task->url = $request->url;
|
||
}
|
||
if ($request->has('num') && $request->num) {
|
||
$task->num = $request->num;
|
||
$task->the_rest = $request->num;
|
||
}
|
||
if ($request->has('is_top') && is_numeric($request->is_top)) {
|
||
$task->is_top = $request->is_top;
|
||
}
|
||
$task->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function delTask(Request $request, $task_id)
|
||
{
|
||
$task = Task::find($task_id);
|
||
if (empty($task)) {
|
||
return $this->failure('任务不存在');
|
||
}
|
||
$task->delete();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function finisher(Request $request, $task_id)
|
||
{
|
||
$task = Task::with('finisher')->find($task_id);
|
||
$finisher = $task->finisher;
|
||
switch ($task->type) {
|
||
|
||
}
|
||
}
|
||
|
||
/**
|
||
* [MessengerShares description]
|
||
* @param Request $request [description]
|
||
*/
|
||
public function messengerShares(Request $request)
|
||
{
|
||
$sharers = \DB::table('messengers as m')->groupby('share_viewer_id')->whereNotNull('share_viewer_id')->select('share_viewer_id', \DB::raw('count(*) as num'))->orderBy('num', 'desc')->paginate();
|
||
foreach ($sharers as $sharer) {
|
||
$sharer->viewer = Viewer::where('id', $sharer->share_viewer_id)->select('id', 'nickname', 'avatar', 'mobile')->first();
|
||
//是否是福恋使者
|
||
$sharer->is_messenger = Messenger::where('viewer_id', $sharer->share_viewer_id)->where('is_audit', 1)->first() ? 1 : 0;
|
||
//当前推广等级
|
||
$sharer->sharer_role = $sharer->viewer ? ($sharer->viewer->shareRole() ? $sharer->viewer->shareRole()->name : null) : null;
|
||
//下一个升级等级
|
||
$sharer->next_role = $this->getNextRole($sharer->num);
|
||
unset($sharer->viewer->shareRoles);
|
||
}
|
||
return $this->success('ok', $sharers);
|
||
}
|
||
|
||
public function getNextRole($num)
|
||
{
|
||
$role = ['id' => 1, 'name' => '普通推广员'];
|
||
if ($num >= 5 && $num < 25) {
|
||
$role = ['id' => 2, 'name' => '铜牌推广员'];
|
||
} elseif ($num >= 25 && $num < 125) {
|
||
$role = ['id' => 3, 'name' => '银牌推广员'];
|
||
} elseif ($num >= 125) {
|
||
$role = ['id' => 4, 'name' => '金牌推广员'];
|
||
}
|
||
return $role;
|
||
}
|
||
|
||
/**
|
||
* 升级婚恋使者等级
|
||
* @param Request $request [description]
|
||
* @param [type] $messenger_id [description]
|
||
* @return [type] [description]
|
||
*/
|
||
public function upgradeMessengerRole(Request $request, $messenger_id)
|
||
{
|
||
try {
|
||
$messenger = Messenger::find($messenger_id);
|
||
if (empty($messenger))
|
||
return $this->failure('婚恋使者不存在');
|
||
//分享人数
|
||
$count = Messenger::where('share_viewer_id', $messenger->viewer_id)->where('is_audit', 1)->count();
|
||
//下一个等级
|
||
$role = $this->getNextRole($count);
|
||
//当前等级
|
||
$share_role = ShareRoleViewer::where('viewer_id', $messenger->viewer_id)->first();
|
||
$share_role_id = $share_role ? $share_role->share_role_id : 0;
|
||
if ($role['id'] <= $share_role_id) {
|
||
return $this->failure('升级后的等级低于当前等级');
|
||
}
|
||
if (empty($share_role)) {
|
||
$share_role = new ShareRoleViewer;
|
||
$share_role->viewer_id = $request->viewer_id;
|
||
$share_role->share_role_id = $role['id'];
|
||
}
|
||
$share_role->share_role_id = $role['id'];
|
||
$share_role->save();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('升级失败');
|
||
}
|
||
|
||
}
|
||
|
||
//抽奖用户名单
|
||
public function lotteryList(Request $request, $lottery_id)
|
||
{
|
||
$viewerids = LotteryList::where('lottery_id', $lottery_id)->pluck('viewer_id')->toArray();
|
||
$viewer = Viewer::whereIn('id', $viewerids)->distinct()->get();
|
||
return $this->success('ok', $viewer);
|
||
}
|
||
|
||
|
||
public function addWinnerToLive(Request $request)
|
||
{
|
||
|
||
$viewer_ids = $request->viewer_id;
|
||
if (is_array($viewer_ids)) {
|
||
LotteryList::whereIn('viewer_id', $viewer_ids)->where('lottery_id', $request->lottery_id)->update(['is_winner' => 1]);
|
||
}
|
||
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function shareFundLog(Request $request)
|
||
{
|
||
$log = shareFundLog::with(['viewer', 'otherViewer']);
|
||
|
||
if ($request->keyword) {
|
||
$keyword = $request->keyword;
|
||
$log = $log->whereHas('viewer', function ($query) use ($keyword) {
|
||
$query->where('nickname', 'like', '%' . $keyword . '%');
|
||
})
|
||
->orWhereHas('otherViewer', function ($query) use ($keyword) {
|
||
$query->where('nickname', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
|
||
|
||
if (in_array($request->type, ['gain', 'loss'])) {
|
||
$log = $log->where('type', $request->type);
|
||
}
|
||
|
||
if (is_numeric($request->status)) {
|
||
$log = $log->where('status', $request->status);
|
||
}
|
||
|
||
$log = $log->orderBy('id', 'desc')->paginate();
|
||
|
||
return $this->success('ok', $log);
|
||
}
|
||
|
||
// public function getMiniQrcode(Request $request){
|
||
// $qrcode = QrcodeRectService::getServiceMiniQrcode($request->path);
|
||
// return $this->success('ok', $qrcode);
|
||
// }
|
||
|
||
public function viewerShareAudit(Request $request)
|
||
{
|
||
$log = ViewerShareAudit::with('viewer', 'otherViewer', 'task');
|
||
if ($request->keyword) {
|
||
$keyword = $request->keyword;
|
||
$log = $log->whereHas('viewer', function ($query) use ($keyword) {
|
||
$query->where('nickanme', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
|
||
$log = $log->where('is_audit', 0)->orderBy('id', 'desc')->paginate();
|
||
return $this->success('ok', $log);
|
||
}
|
||
|
||
public function auditShare(Request $request)
|
||
{
|
||
ViewerShareAudit::where('viewer_id', $request->viewer_id)->update(['is_audit' => $request->is_audit]);
|
||
if ($request->is_audit == 1) {
|
||
$data = ['viewer_id' => $request->viewer_id];
|
||
AuditViewerShare::dispatch($data)->onQueue('love');
|
||
}
|
||
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function setFollower(Request $request)
|
||
{
|
||
$viewer = Viewer::find($request->viewer_id);
|
||
Viewer::where('id', $request->viewer_id)->update(['is_follower' => $request->is_follower, 'become_follower_at' => date('Y-m-d H:i:s')]);
|
||
if ($request->is_follower == 0 && $viewer->user_id) {
|
||
ActivityUser::where('follow_user_id', $viewer->user_id)->where('status', 2)->update(['follow_user_id' => 0, 'status' => 0]);
|
||
}
|
||
return $this->success('ok');
|
||
}
|
||
|
||
//活跃用户列表
|
||
public function activityUsers(Request $request)
|
||
{
|
||
$users = ActivityUser::with([
|
||
'user',
|
||
'followUser',
|
||
'remark' => function ($query) {
|
||
$query->orderBy('id', 'desc');
|
||
}
|
||
]);
|
||
if (is_numeric($request->status)) {
|
||
$users = $users->where('status', $request->status);
|
||
}
|
||
|
||
if (is_numeric($request->follow_user_id)) {
|
||
$users = $users->where('follow_user_id', $request->follow_user_id);
|
||
}
|
||
if ($request->keyword) {
|
||
$keyword = $request->keyword;
|
||
$users = $users->whereHas('user', function ($query) use ($keyword) {
|
||
$query->where('name', 'like', '%' . $keyword . "%")
|
||
->orWhere('nickname', 'like', '%' . $keyword . '%')
|
||
->orWhere('mobile', 'like', '%' . $keyword . '%');
|
||
})
|
||
->orWhereHas('followUser', function ($query) use ($keyword) {
|
||
$query->where('name', 'like', '%' . $keyword . "%")
|
||
->orWhere('nickname', 'like', '%' . $keyword . '%')
|
||
->orWhere('mobile', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$users = $users->orderBy('updated_at', 'desc')->paginate();
|
||
return $this->success('ok', $users);
|
||
}
|
||
|
||
|
||
//作品列表
|
||
public function opuses(Request $request)
|
||
{
|
||
$opuses = Opus::with('viewer')->withCount('ballot');
|
||
if (is_numeric($request->is_audit)) {
|
||
$opuses = $opuses->where('is_audit', $request->is_audit);
|
||
}
|
||
if ($request->keyword) {
|
||
$keyword = $request->keyword;
|
||
$opuses = $opuses->where(function ($query) use ($keyword) {
|
||
$query->where('content', 'like', '%' . $keyword . '%')
|
||
->orWhere('explan', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
if ($request->viewer_id) {
|
||
$opuses = $opuses->where('viewer_id', $request->viewer_id);
|
||
}
|
||
|
||
switch ($request->type) {
|
||
case 'rank':
|
||
$opuses = $opuses->orderBy('ballot_count', 'desc');
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
$opuses = $opuses->orderBy('id', 'desc')->paginate();
|
||
foreach ($opuses as $val) {
|
||
$rank = Opus::where('ballot_count', '>', $val->ballot_count)->count();
|
||
$val->rank = $rank + 1;
|
||
}
|
||
return $this->success('ok', $opuses);
|
||
}
|
||
|
||
//作品征集详情
|
||
public function opus(Request $request, $opus_id)
|
||
{
|
||
$opus = Opus::with('viewer')->where('id', $opus_id)->first();
|
||
if (empty($opus)) {
|
||
return $this->failure('作品不存在');
|
||
}
|
||
$rank = Opus::where('ballot_count', '>', $opus->ballot_count)->count();
|
||
$opus->rank = $rank + 1;
|
||
return $this->success('ok', $opus);
|
||
}
|
||
|
||
//投票列表
|
||
public function ballots(Request $request)
|
||
{
|
||
$ballots = Ballot::with(['viewer', 'opus']);
|
||
if ($request->viewer_id) {
|
||
$ballots = $ballots->where('viewer_id', $request->viewer_id);
|
||
}
|
||
|
||
if ($request->opus_id) {
|
||
$ballots = $ballots->where('opus_id', $request->opus_id);
|
||
}
|
||
|
||
if ($request->keyword) {
|
||
$keyword = $request->keyword;
|
||
$ballots = $ballots->whereHas('viewer', function ($query) use ($keyword) {
|
||
$query->where('nickname', 'like', '%' . $keyword . "%");
|
||
});
|
||
}
|
||
$ballots = $ballots->orderBy('id', 'desc')->paginate();
|
||
return $this->success('ok', $ballots);
|
||
}
|
||
|
||
//审核作品
|
||
public function auditOpus(Request $request, $opus_id)
|
||
{
|
||
$last_number = Opus::orderBy('number', 'desc')->value('number');
|
||
$opus = Opus::find($opus_id);
|
||
$opus->is_audit = $request->is_audit;
|
||
$opus->number = $last_number + 1;
|
||
$opus->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
//文章列表
|
||
public function articles(Request $request)
|
||
{
|
||
$articles = Article::has('user')->with('user')->withCount('messenger');
|
||
if ($request->keyword) {
|
||
$keyword = $request->keyword;
|
||
$articles = $articles->whereHas('user', function ($query) use ($keyword) {
|
||
$query->where('name', 'like', '%' . $keyword . '%')
|
||
->orWhere('id', $keyword)
|
||
->orWhere('mobile', 'like', '%' . $keyword . '%')
|
||
->orWhere('nickname', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
if ($request->title) {
|
||
$title = $request->title;
|
||
$articles = $articles->where(function ($query) use ($title) {
|
||
$query->where('title', 'like', '%' . $title . '%')->orWhere('content', 'like', '%' . $title . '%');
|
||
});
|
||
}
|
||
if ($request->input('content')) {
|
||
$articles = $articles->where('content', 'like', '%' . $request->input('content') . '%');
|
||
}
|
||
if (is_numeric($request->is_audit)) {
|
||
$articles = $articles->where('is_audit', $request->is_audit);
|
||
}
|
||
if (is_numeric($request->is_hot)) {
|
||
$articles = $articles->where('is_hot', $request->is_hot);
|
||
}
|
||
if (is_numeric($request->user_id)) {
|
||
$articles = $articles->where('user_id', $request->user_id);
|
||
}
|
||
if ($request->end_time && $request->start_time) {
|
||
$articles = $articles->whereBetween('created_at', [$request->start_time, $request->end_time]);
|
||
}
|
||
if ($request->pv) {
|
||
$articles = $articles->where('pv', $request->pv);
|
||
}
|
||
if (is_numeric($request->is_original)) {
|
||
$articles = $articles->where('is_original', $request->is_original);
|
||
}
|
||
if ($request->source) {
|
||
$articles = $articles->where('source', $request->source);
|
||
}
|
||
if ($request->article_count) {
|
||
$user_ids = Article::where('is_audit', 1)->groupBy('user_id')->havingRaw('COUNT(id) = ?', [$request->article_count])->pluck('user_id')->toArray();
|
||
$articles = $articles->whereIn('user_id', $user_ids);
|
||
}
|
||
if (is_numeric($request->is_messenger)) {
|
||
switch ($request->is_messenger) {
|
||
case 1:
|
||
$articles = $articles->has('messenger');
|
||
break;
|
||
case 2:
|
||
$articles = $articles->doesntHave('messenger');
|
||
break;
|
||
}
|
||
}
|
||
$articles = $articles->orderBy('id', 'desc')->paginate();
|
||
foreach ($articles as $article) {
|
||
//注册人数
|
||
$article_url = env('APP_URL') . '/h5/#/articleDetail/' . $article->id;
|
||
$article->register_count = Viewer::where('record_url', 'like', '%' . $article_url . '%')->count();
|
||
//点赞数
|
||
$article->like_count = $article->likers()->get()->count() ?: 0;
|
||
//评论数
|
||
$article->comment_count = $article->comments()->count();
|
||
//收藏数
|
||
$article->favorite_count = $article->favoriters()->count() ?: 0;
|
||
//直播用户
|
||
$article->viewer = Viewer::where('user_id', $article->user->id)->first();
|
||
//作者发表文章数
|
||
$article->article_count = Article::where('user_id', $article->user->id)->where('is_audit', 1)->count();
|
||
}
|
||
return $this->success('ok', $articles);
|
||
}
|
||
|
||
//文章详情
|
||
public function article(Request $request, $article_id)
|
||
{
|
||
$article = Article::with('user')->find($article_id);
|
||
return $this->success('ok', $article);
|
||
}
|
||
|
||
//审核文章
|
||
public function articleAudit(Request $request, $article_id)
|
||
{
|
||
$article = Article::with('user')->find($article_id);
|
||
$article->is_audit = $request->is_audit;
|
||
if ($request->reason) {
|
||
$article->reason = $request->reason;
|
||
}
|
||
$article->audit_at = date('Y-m-d H:i:s');
|
||
$article->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
//修改文章
|
||
public function articleUpdate(Request $request, $article_id)
|
||
{
|
||
$article = Article::find($article_id);
|
||
if (is_numeric($request->is_hot)) {
|
||
if ($article->is_audit && $article->is_audit) {
|
||
$article->is_hot = $request->is_hot;
|
||
}
|
||
if ($article->is_audit == 0) {
|
||
$article->is_hot = 0;
|
||
}
|
||
|
||
}
|
||
if ($request->title) {
|
||
$article->title = $request->title;
|
||
}
|
||
if ($request->input('content')) {
|
||
$article->content = $request->input('content');
|
||
}
|
||
if ($request->pic) {
|
||
$article->pic = $request->pic;
|
||
}
|
||
if ($request->has('share_pic')) {
|
||
$article->share_pic = $request->share_pic;
|
||
}
|
||
$article->save();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function articleDel(Request $request, $article_id)
|
||
{
|
||
Article::where('id', $article_id)->delete();
|
||
return $this->success('ok');
|
||
|
||
}
|
||
|
||
//设置首页banner
|
||
public function setHomeBanner(Request $request)
|
||
{
|
||
if (empty($request->banner)) {
|
||
return $this->failure('请上传图片');
|
||
}
|
||
$banner = json_encode($request->banner);
|
||
Redis::set('home_banner', $banner);
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function homeBanner(Request $request)
|
||
{
|
||
$banner = Redis::get('home_banner');
|
||
$banner = json_decode($banner);
|
||
return $this->success('ok', $banner);
|
||
}
|
||
|
||
//咨询师列表
|
||
public function communityActivities(Request $request)
|
||
{
|
||
try {
|
||
$keyword = $request->keyword;
|
||
$status = $request->status;
|
||
$activities = CommunityActivity::with('banners:class_id,icon')->where('type', 'fulllink');
|
||
// if($status!=2){
|
||
// $activities = $activities->where('status',$status);
|
||
// }
|
||
$activities = $activities->orderBy('id', 'desc')->orderBy('sort', 'desc');
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$activities = $activities->where(function ($sql) use ($keyword) {
|
||
$sql->where('title', 'like', '%' . $keyword . '%');
|
||
$sql->where('id', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$activities = $activities->paginate();
|
||
foreach ($activities as $activity) {
|
||
if (!empty($activity) && !empty($activity->banners))
|
||
$activity->banners->icon = json_decode($activity->banners->icon, true);
|
||
}
|
||
return $this->success('ok', $activities);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
|
||
}
|
||
|
||
//创建咨询师
|
||
public function createConsulator(Request $request)
|
||
{
|
||
try {
|
||
$banners = $request->banners;
|
||
$anchor_id = $request->anchor_id;
|
||
if (!$anchor_id)
|
||
return $this->failure('请选择对应老师');
|
||
$price = $request->price ? $request->price : 0;
|
||
if (!is_numeric($price) || $price < 0)
|
||
return $this->failure('请正确输入价格');
|
||
$title = $request->title;
|
||
$pic = $request->pic;
|
||
$Subtitle = $request->Subtitle;
|
||
$pay_type = $request->pay_type ? $request->pay_type : 'wechat';
|
||
$describe = $request->describe;
|
||
$sku = json_encode($request->sku);
|
||
$sort = $request->input('sort', 0);
|
||
$status = $request->input('status', 0);
|
||
|
||
$consulator = new CommunityActivity();
|
||
$consulator->price = $price;
|
||
$consulator->title = $title;
|
||
$consulator->anchor_id = $anchor_id;
|
||
$consulator->Subtitle = $Subtitle;
|
||
$consulator->pay_type = $pay_type;
|
||
$consulator->describe = $describe;
|
||
$consulator->sort = $sort;
|
||
$consulator->sku = $sku;
|
||
$consulator->type = 'fulllink';
|
||
$consulator->status = $status;
|
||
$consulator->pic = $pic;
|
||
$consulator->class = 'many';
|
||
DB::beginTransaction();
|
||
$consulator->save();
|
||
LiveBanner::create([
|
||
'icon' => json_encode($banners),
|
||
'class' => 'community',
|
||
'status' => 1,
|
||
'sort' => 0,
|
||
'class_id' => $consulator->id,
|
||
]);
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
|
||
}
|
||
|
||
//老师列表
|
||
public function anchorList(Request $request)
|
||
{
|
||
$anchor = Anchor::where('is_show_consulation', 1)->select('id', 'is_show_consulation', 'name')->get();
|
||
return $this->success('ok', $anchor);
|
||
}
|
||
|
||
//编辑咨询师
|
||
public function updateConsulator(Request $request, $id)
|
||
{
|
||
try {
|
||
$consulator = CommunityActivity::find($id);
|
||
$price = $request->input('price', 0);
|
||
if (!is_numeric($price) || $price < 0)
|
||
return $this->failure('请正确输入价格');
|
||
if (is_numeric($request->price) && $request->price != $consulator->price) {
|
||
$consulator->price = $request->price;
|
||
}
|
||
if ($request->title && $request->title != $consulator->title) {
|
||
$consulator->title = $request->title;
|
||
}
|
||
if ($request->Subtitle && $request->Subtitle != $consulator->Subtitle) {
|
||
$consulator->Subtitle = $request->Subtitle;
|
||
}
|
||
if ($request->pay_type && $request->pay_type != $consulator->pay_type) {
|
||
$consulator->pay_type = $request->pay_type;
|
||
}
|
||
if ($request->describe && $request->describe != $consulator->describe) {
|
||
$consulator->describe = $request->describe;
|
||
}
|
||
if ($request->pic && $request->pic != $consulator->pic) {
|
||
$consulator->pic = $request->pic;
|
||
}
|
||
$consulator->sku = json_encode($request->sku);
|
||
if ($request->anchor_id && $request->anchor_id != $consulator->anchor_id) {
|
||
$consulator->anchor_id = $request->anchor_id;
|
||
}
|
||
$status = $request->input('status', 0);
|
||
$consulator->status = $status;
|
||
$sort = $request->input('sort', 0);
|
||
$consulator->sort = $sort;
|
||
DB::beginTransaction();
|
||
if ($request->banners) {
|
||
LiveBanner::updateOrCreate(['class' => 'community', 'class_id' => $consulator->id], ['icon' => json_encode($request->banners)]);
|
||
}
|
||
$consulator->save();
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
|
||
}
|
||
|
||
//咨询师详情
|
||
public function communityActivity(Request $request, $id)
|
||
{
|
||
try {
|
||
$activity = CommunityActivity::with('banners:class_id,icon')->where('id', $id)->first();
|
||
$qr_code = $this->qrcodeWithScene(env('APP_URL') . '/pu/#/courseDetail/24');
|
||
$activity->banners->icon = json_decode($activity->banners->icon, true);
|
||
$activity->sku = json_decode($activity->sku, true);
|
||
$activity->qr_code = $qr_code;
|
||
return $this->success('ok', $activity);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
}
|
||
|
||
//移除咨询师
|
||
public function remmoveCommunityActivity(Request $request, $id)
|
||
{
|
||
try {
|
||
$activity = CommunityActivity::find($id);
|
||
if (!$activity)
|
||
return $this->failure('要移除的id不存在');
|
||
DB::beginTransaction();
|
||
$activity->delete();
|
||
TouristOrder::where('type', 'community')->where('type_id', $id)->delete();
|
||
DB::commit();
|
||
} catch (\Exception $e) {
|
||
DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
|
||
}
|
||
//报名成员
|
||
public function joinMembers(Request $request)
|
||
{
|
||
try {
|
||
$consulator_id = $request->consulator_id;
|
||
$keyword = $request->keyword;
|
||
$pay_status = $request->input('pay_status', 0);
|
||
$members = TouristOrder::with('viewer', 'fromUser')->where('type', 'community')->where('type_id', $consulator_id)->orderBy('id', 'desc');
|
||
if ($pay_status != 2) {
|
||
$members = $members->where('pay_status', $pay_status);
|
||
}
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$members = $members->where(function ($sql) use ($keyword) {
|
||
$sql->where('name', 'like', '%' . $keyword . '%')->orWhere('mobile', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$members = $members->paginate();
|
||
return $this->success('ok', $members);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
|
||
}
|
||
|
||
//删除报名成员
|
||
public function removeCommunityMember(Request $request, $id)
|
||
{
|
||
try {
|
||
$order = TouristOrder::find($id);
|
||
if (!$order)
|
||
return $this->failure('要删除的id不存在');
|
||
$order->delete();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
}
|
||
|
||
}
|