679 lines
31 KiB
PHP
679 lines
31 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Server\Admin;
|
||
|
||
use App\Models\App\Comment;
|
||
use App\Models\Liker;
|
||
use App\Models\MerchantTags;
|
||
use Illuminate\Http\JsonResponse;
|
||
use Illuminate\Http\Request;
|
||
use App\Http\Controllers\Controller;
|
||
use App\Jobs\UploadUrl;
|
||
use App\Models\CommunityActivity;
|
||
use App\Models\ConfigAdvertise;
|
||
use App\Models\ConsultAccount;
|
||
use App\Models\Consultation;
|
||
use App\Models\Course\Course;
|
||
use App\Models\Live\Anchor;
|
||
use App\Models\User;
|
||
use App\Models\MerchantShop;
|
||
use App\Models\MerchantUsers;
|
||
use App\Models\Server\MerchantAccount;
|
||
use App\Models\Server\MerchantInformation as MInformation;
|
||
use App\Models\MerchantInformation;
|
||
use App\Models\Server\MEarning;
|
||
use App\Models\Server\MerchantUser;
|
||
use App\Models\Server\TouristOrder;
|
||
use Illuminate\Support\Facades\Cache;
|
||
use Illuminate\Support\Facades\Redis;
|
||
use App\Jobs\SynchronizationWeChat;
|
||
use App\Models\PayLog;
|
||
use PhpParser\Node\Stmt\TryCatch;
|
||
|
||
ini_set('max_execution_time', '3000');
|
||
|
||
class InformationController extends Controller
|
||
{
|
||
//资源控制器(服务商视频、文章)
|
||
|
||
/**
|
||
* 商户-发表更新动态
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function ReleaseNews(Request $request)
|
||
{
|
||
try {
|
||
$id = $request->id;
|
||
$title = $request->title;
|
||
$subTitle = $request->subTitle;
|
||
$content = $request->input('content');
|
||
$pic = $request->pic;
|
||
$reward_status = $request->reward_status;
|
||
$audio_url = $request->audio_url;
|
||
$audio_title = $request->audio_title;
|
||
$type = $request->type;
|
||
$tag_id = $request->tag_id;
|
||
if ($id) {
|
||
$information = MInformation::where('id', $id)->first();
|
||
if (!$information) return $this->failure('未查询到改数据');
|
||
} else {
|
||
$merchant_id = MerchantAccount::where('id', $request->account_id)->value('id');
|
||
if (!$merchant_id) return $this->failure('商户信息有误');
|
||
$information = new MInformation();
|
||
//保存后删除草稿箱内容
|
||
if (Cache::has('drafts_information_merchant_id_' . $request->account_id)) Cache::forget('drafts_information_merchant_id_' . $request->account_id);
|
||
}
|
||
|
||
if (isset($merchant_id)) {
|
||
$information->merchant_id = $merchant_id;
|
||
}
|
||
if ($title)
|
||
$information->title = $title;
|
||
if ($audio_url)
|
||
$information->audio_url = $audio_url;
|
||
if ($audio_title)
|
||
$information->audio_title = $audio_title;
|
||
if ($type)
|
||
$information->type = $type;
|
||
if ($subTitle)
|
||
$information->subTitle = $subTitle;
|
||
if ($content)
|
||
$information->content = $content;
|
||
if ($pic)
|
||
$information->pic = $pic;
|
||
if ($request->has('reward_status'))
|
||
$information->reward_status = intval($reward_status);
|
||
if ($request->has('is_top'))
|
||
$information->is_top = $request->is_top;
|
||
if ($request->has('top_time'))
|
||
$information->top_time = $request->top_time;
|
||
if ($request->has('status'))
|
||
$information->status = $request->status;
|
||
if ($request->has('type') && $request->type == '') {
|
||
$information->audio_url = null;
|
||
$information->audio_title = null;
|
||
$information->type = null;
|
||
}
|
||
if ($tag_id) {
|
||
$tag = MerchantTags::where('id', $tag_id)->where('mch_id', $request->account_id)->where('type', 'information')->first();
|
||
if ($tag) {
|
||
$information->tag_id = $tag_id;
|
||
} else {
|
||
$information->tag_id = 0;
|
||
}
|
||
} else {
|
||
$information->tag_id = $information->tag_id?:0;
|
||
}
|
||
$information->save();
|
||
if (!$id)
|
||
Redis::zscore('information', $information->id) ?? 0;
|
||
// //配置购买链接
|
||
if ($request->config == 'in') {
|
||
ConfigAdvertise::updateOrCreate(['type' => 'information', 'type_id' => $information->id], ['pic' => $request->c_pic, 'title' => $request->c_title, 'sub_title' => $request->c_sub_title, 'links' => '', 'choose_type' => $request->c_type, 'choose_type_id' => $request->c_id, 'class' => 'in']);
|
||
}
|
||
if ($request->config == 'out') {
|
||
ConfigAdvertise::updateOrCreate(['type' => 'information', 'type_id' => $information->id], ['pic' => $request->c_pic, 'title' => $request->c_title, 'sub_title' => $request->c_sub_title, 'links' => $request->links, 'choose_type' => $request->c_type, 'choose_type_id' => $request->c_id, 'class' => 'out']);
|
||
}
|
||
if ($request->config == 'cancel') {
|
||
ConfigAdvertise::where('type', 'information')->where('type_id', $information->id)->delete();
|
||
}
|
||
$key = 'infor_and_video_list_page_1' . $request->account_id;
|
||
Cache::forget($key);
|
||
return $this->success('ok', ['id' => $information->id]);
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
public function uploadUrl(Request $request)
|
||
{
|
||
try {
|
||
$content = $request->input('content');
|
||
$imgSrcArr = $this->getImgs($content);
|
||
if (empty($imgSrcArr)) return $this->success('ok', ['status' => 2]);//无图
|
||
UploadUrl::dispatch($content, $imgSrcArr)->onQueue('love');
|
||
return $this->success('ok', ['status' => 0]);
|
||
} catch (\Exception $e) {
|
||
return $this->success('fail', ['status' => 1]);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* $content 文章内容
|
||
* $order 要获取哪张图片,ALL所有图片,0第一张图片
|
||
**/
|
||
public function getImgs($content, $order = 'ALL')
|
||
{
|
||
try {
|
||
$imgSrcArr = [];
|
||
$pattern = '/src="(.*?)"/';
|
||
preg_match_all($pattern, $content, $match);
|
||
if (isset($match[1]) && !empty($match[1])) {
|
||
foreach ($match[1] as $key => $src) {
|
||
if (strstr($src, 'ufutx') || strstr($src, 'aliyuncs.com') || strstr($src, 'fulllinkai')) continue;
|
||
$imgSrcArr[] = $src;
|
||
}
|
||
}
|
||
return $imgSrcArr;
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取同步状态和数据
|
||
* *
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function picTransferStatusV2(Request $request)
|
||
{
|
||
try {
|
||
$content = $request->input('content');
|
||
$content = substr($content, 50, 30);
|
||
$result = PayLog::where('type', 'copy_wechat')->where('trade_no', $content)->first();
|
||
if ($result) {
|
||
$data['status'] = 1;
|
||
$data['content'] = $result->remark;
|
||
PayLog::where('type', 'copy_wechat')->delete();
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['content'] = null;
|
||
}
|
||
return $this->success('ok', $data);
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 商户-动态列表
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function informations(Request $request)
|
||
{
|
||
try {
|
||
$keyword = $request->keyword;
|
||
$status = $request->status ?? 2;
|
||
$merchant = MerchantAccount::where('id', $request->account_id)->first();
|
||
if (!$merchant) return $this->failure('未获取到商户信息!');
|
||
$result = MInformation::where('merchant_id', $merchant->id);
|
||
if ($status != 2)
|
||
$result = $result->where('status', $status);
|
||
$result = $result->where(function ($query) use ($keyword) {
|
||
$query->where('title', 'like', '%' . $keyword . '%')
|
||
->orWhere('id', 'like', '%' . $keyword . '%');
|
||
})->orderBy('is_top', 'desc')->orderBy('top_time', 'desc')->orderBy('id', 'desc')->paginate();
|
||
foreach ($result as $key => $value) {
|
||
$value->pv = Redis::zscore('information', $value->id) ?: 0;
|
||
if (!$value->pv) $value->pv = 0;
|
||
$comment_count = Comment::where('commentable_type', 'App\Models\MerchantInformation')->where('commentable_id', $value->id)->count();
|
||
$value->comment_count = $comment_count;
|
||
$like_count = Liker::where('like_type', 'App\Models\MerchantInformation')->where('like_id', $value->id)->count();
|
||
$value->like_count = $like_count;
|
||
if ($value->reward_status == 1) {
|
||
$reward_money = TouristOrder::where('type', 'reward_info')->where('type_id', $value->id)->whereIn('pay_status', [1, 4])->sum('price');
|
||
$value->reward_money = $reward_money;
|
||
} else {
|
||
$value->reward_money = 0;
|
||
}
|
||
}
|
||
return $this->success('ok', $result);
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 商户-动态详情
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function information_detail(Request $request)
|
||
{
|
||
try {
|
||
$id = $request->id;
|
||
$serve_tab = $request->serve_tab;
|
||
$serve_tab = $request->serve_tab;
|
||
$merchant_id = $request->account_id;
|
||
$result = MerchantInformation::where('id', $id)->first();
|
||
if ($result->merchant_id != $request->account_id) {
|
||
return $this->failure('文章不属于档登陆用户');
|
||
}
|
||
$anchor_openid = Anchor::where('m_id', $result->id)->value('openid');
|
||
$jump_url = urlencode(env('APP_URL') . '/pu/#/dynamicParticulars/' . $id);
|
||
$url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $merchant_id . '&anchor_openid=' . $anchor_openid . '&serve_tab=' . $serve_tab . '&serve_tab=' . $serve_tab . '&url=' . $jump_url;
|
||
// $qr_code = $this->getPreviewQrcode($url);
|
||
$qr_code = Redis::get('InforDetail_S' . $id);
|
||
if (!$qr_code) {
|
||
$qr_code = $this->getPreviewQrcode($url);
|
||
Redis::setex('InforDetail_S' . $id, 60 * 60 * 24 * 30, $qr_code);
|
||
$qr_code = Redis::get('InforDetail_S' . $id);
|
||
}
|
||
$result->qr_codes = $qr_code;
|
||
// $result->share_url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $merchant_id . '&anchor_openid=' . $anchor_openid . '&serve_tab=' . $serve_tab . '&url=' . $jump_url;
|
||
$result->share_url = env('APP_URL') . '/pu/#/dynamicParticulars/' . $id."?merchant_id=".$merchant_id;
|
||
if ($result)
|
||
$result->pv = Redis::zscore('information', $id) ?: 0;
|
||
|
||
$config = ConfigAdvertise::where('type', 'information')->where('type_id', $id)->first();
|
||
if ($config) {
|
||
if ($config && $config->choose_type == 'course' && $config->class == 'in') {
|
||
$config->price = Course::where('id', $config->choose_type_id)->value('charge');
|
||
$config->links = env('APP_URL') . '/pu/#/courseDetail/' . $config->choose_type_id;
|
||
}
|
||
if ($config && $config->choose_type == 'activity' && $config->class == 'in') {
|
||
$config->price = CommunityActivity::where('id', $config->choose_type_id)->value('price');
|
||
$config->links = env('APP_URL') . '/pu/#/activityDetails/' . $config->choose_type_id;
|
||
}
|
||
if ($config && $config->choose_type == 'service' && $config->class == 'in') {
|
||
$config->price = CommunityActivity::where('id', $config->choose_type_id)->value('price');
|
||
|
||
$config->links = env('APP_URL') . '/pu/#/serveDetails/' . $config->choose_type_id;
|
||
}
|
||
if ($config && $config->choose_type == 'shop' && $config->class == 'in') {
|
||
$config->price = MerchantShop::where('id', $config->choose_type_id)->value('price');
|
||
$config->links = env('APP_URL') . '/pu/#/mallDetail/' . $config->choose_type_id;
|
||
}
|
||
if ($config && $config->choose_type == 'consult' && $config->class == 'in') {
|
||
$config->price = Consultation::where('id', $config->choose_type_id)->value('price');
|
||
$config->links = env('APP_URL') . '/pu/#/consultingDetail/' . $config->choose_type_id;
|
||
}
|
||
}
|
||
$result->config = $config;
|
||
// 评论数
|
||
$result->comment_num = $result->totalCommentsCount();
|
||
// 点赞数
|
||
$result->liker_num = $result->likers()->count();
|
||
return $this->success('ok', $result);
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 商户-删除动态
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function information(Request $request)
|
||
{
|
||
try {
|
||
$id = $request->id;
|
||
$result = MInformation::where('id', $id)->delete();
|
||
if (!$result) return $this->failure('该记录不存在或已删除');
|
||
return $this->success('ok', $result);
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 咨讯(文章)评论列表
|
||
* @param $comment_id
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function commentList($comment_id)
|
||
{
|
||
try {
|
||
$information = MerchantInformation::where('id', $comment_id)->first();
|
||
$comments = $information->comments()->select('id', 'commentable_id', 'commented_id', 'reply_id', 'comment', 'created_at')->where('reply_id', 0)->orderBy('id', 'desc')->paginate();
|
||
foreach ($comments as $key => $value) {
|
||
# code...
|
||
$merchant_user = MerchantUsers::select('nickname', 'pic')->where('id', $value->commented_id)->first();
|
||
$value->nickname = $merchant_user->nickname ?? '匿名用户';
|
||
$value->pic = $merchant_user->pic ?? User::DefaultAvatar;
|
||
$reply = $information->comments()->select('id', 'commentable_id', 'commented_id', 'reply_id', 'comment', 'created_at')->where('reply_id', $value->id)->orderBy('id', 'desc')->get();
|
||
foreach ($reply as $k => $v) {
|
||
$merchant_user = MerchantUsers::select('nickname', 'pic')->where('id', $v->commented_id)->first();
|
||
$v->nickname = $merchant_user->nickname ?? '匿名用户';
|
||
$v->pic = $merchant_user->pic ?? User::DefaultAvatar;
|
||
}
|
||
$value->reply = $reply;
|
||
}
|
||
return $this->success('ok', $comments);
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 删除评论
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function delComment(Request $request)
|
||
{
|
||
try {
|
||
$comment_id = $request->comment_id;
|
||
$information_id = $request->information_id;
|
||
$information = MerchantInformation::select('id', 'title', 'merchant_id')->where('id', $information_id)->first();
|
||
$information->comments()->where(function ($sql) use ($comment_id) {
|
||
$sql->where('id', $comment_id)
|
||
->orWhere('reply_id', $comment_id);
|
||
})->delete();
|
||
return $this->success('ok');
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 咨讯(文章)点赞列表
|
||
* *
|
||
* @param $id
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function likes($id)
|
||
{
|
||
try {
|
||
$Information = MerchantInformation::select('id', 'title', 'pic')->where('id', $id)->first();
|
||
$comments = $Information->likers()->select('id', 'likedable_id', 'created_at')->orderBy('id', 'desc')->paginate();
|
||
foreach ($comments as $key => $value) {
|
||
$user = MerchantUser::select('id', 'nickname', 'pic')->where('id', $value->likedable_id)->first();
|
||
$value->nickname = $user->nickname ?? '匿名用户';
|
||
$value->pic = $user->pic ?? User::DefaultAvatar;
|
||
}
|
||
return $this->success('ok', $comments);
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 商户所有收费内容
|
||
* *
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function merchantsCharge(Request $request)
|
||
{
|
||
try {
|
||
$merchant_id = $request->account_id;
|
||
$merchant = MerchantAccount::find($merchant_id);
|
||
$type = $request->type;
|
||
$data = [];
|
||
//活动 服务
|
||
$anchor = Anchor::where('m_id', $merchant->id)->first();
|
||
if ($anchor) {
|
||
$activities = CommunityActivity::where('anchor_id', $anchor->id)->where('type', 'business')->where('status', 1)->where('class', 'one')->select('id', 'merchant_id', 'anchor_id', 'price', 'title', 'Subtitle', 'pic')->get();
|
||
$services = CommunityActivity::where('anchor_id', $anchor->id)->where('type', 'business')->where('status', 1)->where('class', 'many')->select('id', 'merchant_id', 'anchor_id', 'price', 'title', 'Subtitle', 'pic')->get();
|
||
} else {
|
||
$activities = CommunityActivity::where('merchant_id', $merchant_id)->where('type', 'business')->where('status', 1)->where('class', 'one')->select('id', 'merchant_id', 'anchor_id', 'price', 'title', 'Subtitle', 'pic')->get();
|
||
$services = CommunityActivity::where('merchant_id', $merchant_id)->where('type', 'business')->where('status', 1)->where('class', 'one')->select('id', 'merchant_id', 'anchor_id', 'price', 'title', 'Subtitle', 'pic')->get();
|
||
}
|
||
$courses = Course::where('merchant_id', $merchant_id)->where('type', 'business')->where('is_show', 1)->select('id', 'user_id', 'title', 'thumb', 'charge', 'merchant_id')->get();
|
||
$consult_ids = ConsultAccount::where('merchant_id', $merchant_id)->pluck('id')->toArray();
|
||
$consults = Consultation::whereIn('consult_account_id', $consult_ids)->where('status', 1)->select('id', 'title', 'price', 'pic')->get();
|
||
$shops = MerchantShop::where('merchant_id', $merchant_id)->where('is_show', 1)->select('id', 'title', 'price', 'icon', 'sub_title')->get();
|
||
$data['course'] = $courses;
|
||
$data['consult'] = $consults;
|
||
$data['activity'] = $activities;
|
||
$data['service'] = $services;
|
||
$data['shop'] = $shops;
|
||
if ($type == 'course') {
|
||
return $this->success('ok', $courses);
|
||
} elseif ($type == 'consult') {
|
||
return $this->success('ok', $consults);
|
||
} elseif ($type == 'activity') {
|
||
return $this->success('ok', $activities);
|
||
} elseif ($type == 'service') {
|
||
return $this->success('ok', $services);
|
||
} elseif ($type == 'shop') {
|
||
return $this->success('ok', $shops);
|
||
} else {
|
||
return $this->success('ok', $data);
|
||
}
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 移动端文章详情
|
||
* *
|
||
* @param Request $request
|
||
* @param $infor_id
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function phoneInforDetail(Request $request, $infor_id)
|
||
{
|
||
try {
|
||
$serve_tab = $request->serve_tab;
|
||
$result = MerchantInformation::withTrashed()->where('id', $infor_id)/*->where('status',1)*/ ->first();
|
||
if ($result)
|
||
$result->pv = Redis::zincrby('information', 1, $infor_id);
|
||
$price = '';
|
||
$config = ConfigAdvertise::where('type', 'information')->where('type_id', $infor_id)->first();
|
||
if ($config) {
|
||
if ($config && $config->choose_type == 'course' && $config->class == 'in') {
|
||
$price = Course::where('id', $config->choose_type_id)->value('charge');
|
||
$config->links = env('APP_URL') . '/pu_m/#/courseDetail/' . $config->choose_type_id;
|
||
}
|
||
if ($config && $config->choose_type == 'activity' && $config->class == 'in') {
|
||
$price = CommunityActivity::where('id', $config->choose_type_id)->value('price');
|
||
$config->links = env('APP_URL') . '/pu_m/#/activityDetail/' . $config->choose_type_id;
|
||
}
|
||
if ($config && $config->choose_type == 'service' && $config->class == 'in') {
|
||
$price = CommunityActivity::where('id', $config->choose_type_id)->value('price');
|
||
$config->links = env('APP_URL') . '/pu_m/#/serveDetail/' . $config->choose_type_id;
|
||
}
|
||
if ($config && $config->choose_type == 'shop' && $config->class == 'in') {
|
||
$price = MerchantShop::where('id', $config->choose_type_id)->value('price');
|
||
$config->links = env('APP_URL') . '/pu_m/#/mallDetail/' . $config->choose_type_id;
|
||
}
|
||
if ($config && $config->choose_type == 'consult' && $config->class == 'in') {
|
||
$price = Consultation::where('id', $config->choose_type_id)->value('price');
|
||
$config->links = env('APP_URL') . '/pu_m/#/consultingDetail/' . $config->choose_type_id;
|
||
}
|
||
$config->price = $price;
|
||
}
|
||
$reward_count = TouristOrder::where('type', 'reward_info')->where('type_id', $infor_id)->whereIn('pay_status', [1, 4])->get()->count();
|
||
$result->reward_count = $reward_count;
|
||
$result->config = $config;
|
||
$jump_url = urlencode(env('APP_URL') . '/pu/#/dynamicParticulars/' . $infor_id);
|
||
$url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $result->merchant_id . '&serve_tab=' . $serve_tab . '&anchor_openid=&url=' . $jump_url;
|
||
$qr_code = Redis::get('InforDetail_S' . $infor_id);
|
||
if (!$qr_code) {
|
||
$qr_code = $this->getPreviewQrcode($url);
|
||
Redis::setex('InforDetail_S' . $infor_id, 60 * 60 * 24 * 30, $qr_code);
|
||
$qr_code = Redis::get('InforDetail_S' . $infor_id);
|
||
}
|
||
$result->share_qr_code = $qr_code;
|
||
//打赏人头像
|
||
$avatar = [];
|
||
$orders = TouristOrder::where('type', 'reward_info')->where('type_id', $infor_id)->whereIn('pay_status', [1, 4])->orderBy('id', 'desc')->limit(3)->get();
|
||
foreach ($orders as $key => $order) {
|
||
$avatar[$key] = MerchantUser::where('id', $order->account_id)->value('pic') ?? User::DefaultAvatar;
|
||
if (empty($avatar[$key])) $avatar[$key] = User::DefaultAvatar;
|
||
}
|
||
$result->avatar = $avatar;
|
||
//订单数
|
||
$result->consume_user_count = TouristOrder::where('type', 'reward_info')->where('type_id', $infor_id)->whereIn('pay_status', [1, 4])->count();
|
||
//消费人数
|
||
$result->consume_order_count = TouristOrder::where('type', 'reward_info')->where('type_id', $infor_id)->whereIn('pay_status', [1, 4])->groupBy('open_id')->get()->count();
|
||
//总收入
|
||
$result->income_amount = TouristOrder::where('type', 'reward_info')->where('type_id', $infor_id)->whereIn('pay_status', [1, 4])->sum('price');
|
||
//商家分成
|
||
$order_ids = TouristOrder::where('type', 'reward_info')->where('type_id', $infor_id)->whereIn('pay_status', [1, 4])->pluck('id')->toArray();
|
||
$result->merchant_income_value = MEarning::whereIn('m_order_id', $order_ids)->where('m_user_id', 0)->sum('value');
|
||
// 评论数
|
||
$result->comment_num = $result->totalCommentsCount();
|
||
// 点赞数
|
||
$result->liker_num = $result->likers()->count();
|
||
//下架或删除状态 0下架 1正常上架 2已删除
|
||
$publish_state = 0;
|
||
if ($result->deleted_at) {
|
||
$publish_state = 2;
|
||
} elseif ($result->status == 1) {
|
||
$publish_state = 1;
|
||
} else {
|
||
$publish_state = 0;
|
||
}
|
||
$result->publish_state = $publish_state;
|
||
return $this->success('ok', $result);
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 移动端打赏用户列表
|
||
* *
|
||
* @param Request $request
|
||
* @param $infor_id
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function phoneRewardUsers(Request $request, $infor_id)
|
||
{
|
||
try {
|
||
$keyword = $request->keyword;
|
||
$orders = TouristOrder::with('merUser')->select('id', 'price', 'account_id', 'created_at')
|
||
->where('type', 'reward_info')
|
||
->where('type_id', $infor_id)
|
||
->whereIn('pay_status', [1, 4]);
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$orders = $orders->whereHas('merUser', function ($sql) use ($keyword) {
|
||
$sql->where('nickname', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$orders = $orders->orderBy('id', 'desc')->paginate();
|
||
$title = MInformation::where('id', $infor_id)->value('title');
|
||
foreach ($orders as $key => $order) {
|
||
$order->avatar = $order->mUser ? $order->mUser->pic : User::DefaultAvatar;
|
||
if (empty($order->avatar)) $order->avatar = User::DefaultAvatar;
|
||
$order->name = $order->mUser ? $order->mUser->nickname : '匿名用户';
|
||
$order->text = $order->created_at . '赞赏了《' . $title . '》';
|
||
unset($order->mUser);
|
||
}
|
||
return $this->success('ok', $orders);
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 移动端文章打赏列表
|
||
* *
|
||
* @param Request $request
|
||
* @param $infor_id
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function phoneRewardList(Request $request, $infor_id)
|
||
{
|
||
try {
|
||
$keyword = $request->keyword;
|
||
$merchant_id = $request->account_id;
|
||
$result = TouristOrder::select('id', 'price', 'type_id', 'pay_type', 'comment', 'account_id', 'created_at')
|
||
->where('merchant_id', $merchant_id)
|
||
->whereIn('pay_status', [1, 4])
|
||
->where('type', 'reward_info')
|
||
->where('type_id', $infor_id)
|
||
->orderBy('id', 'desc');
|
||
|
||
if ($keyword) {
|
||
$result = $result->whereHas('user', function ($query) use ($keyword) {
|
||
$query->where('nickname', 'like', '%' . $keyword . '%');
|
||
})
|
||
->orWhereHas('information', function ($query) use ($keyword, $merchant_id) {
|
||
$query->where('merchant_id', $merchant_id);
|
||
$query->where('title', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$result = $result->orderBy('id', 'desc')->paginate();
|
||
foreach ($result as $key => $value) {
|
||
$value->name = $value->user->nickname ?? '匿名用户';
|
||
$value->title = $value->information->title ?? '';
|
||
$value->pic = $value->information->pic ?? '';
|
||
$value->mobile = $value->user->mobile ?? '匿名用户';
|
||
$value->pv = Redis::zscore('information', $infor_id);
|
||
unset($value->user);
|
||
unset($value->information);
|
||
}
|
||
return $this->success('ok', $result);
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 同步微信公众号内容
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function synchronization(Request $request)
|
||
{
|
||
try {
|
||
$result = stripos($request->url, 'mp.weixin.qq.com');
|
||
if ($result === false)
|
||
return $this->success('fail', ['status' => 1, 'msg' => '请提供正确的公众号文章链接']);
|
||
$url = $request->url . '?f=json';
|
||
$result = PayLog::where('trade_no', $url)->first();
|
||
if ($result)
|
||
return $this->success('ok', ['status' => 0]);
|
||
Redis::setex($request->url, 60, 1);
|
||
$result = file_get_contents($url);
|
||
$result = json_decode($result, true);
|
||
$content_noencode = $result['content_noencode'];
|
||
$PayLog = new PayLog();
|
||
$PayLog->type = 'syn-waiting';
|
||
$PayLog->trade_no = 'test';
|
||
$PayLog->remark = $request->url;
|
||
$PayLog->save();
|
||
preg_match_all('/data-src="(.*?)"/', $content_noencode, $matchSrc);
|
||
SynchronizationWeChat::dispatch($matchSrc, $content_noencode, $url)->onQueue('love');
|
||
return $this->success('ok', ['status' => 0]);
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 获取同步状态和数据
|
||
* *
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function synchronizationData(Request $request)
|
||
{
|
||
try {
|
||
$url = $request->url . '?f=json';
|
||
$result = PayLog::where('trade_no', $url)->first();
|
||
if ($result) {
|
||
$data['status'] = 2;
|
||
$data['content'] = $result->remark;
|
||
} else {
|
||
$status = Redis::get($request->url);
|
||
if (!$status) {
|
||
return $this->success('ok', ['status' => 1, 'content' => null, 'msg' => '服务器休息,请稍后再试。']);
|
||
}
|
||
$data['status'] = 0;
|
||
$data['content'] = null;
|
||
}
|
||
return $this->success('ok', $data);
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
}
|