1160 lines
52 KiB
PHP
1160 lines
52 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
namespace App\Http\Controllers\Server\Admin;
|
|||
|
|
|
|||
|
|
use App\Exports\TouristOrdersExport;
|
|||
|
|
use App\Facades\QrcodeRectService;
|
|||
|
|
use App\Models\Admin;
|
|||
|
|
use App\Models\AdminLog;
|
|||
|
|
use App\Models\CloseProfileHistory;
|
|||
|
|
use App\Models\MatchmakerClient;
|
|||
|
|
use App\Models\Paas;
|
|||
|
|
use App\Models\Platform;
|
|||
|
|
use App\Models\ProfileCourtship;
|
|||
|
|
use App\Models\ProfileMarriage;
|
|||
|
|
use App\Models\Rank;
|
|||
|
|
use App\Models\RankHistory;
|
|||
|
|
use App\Models\Salary;
|
|||
|
|
use App\Models\Server\IdentityAuthorization;
|
|||
|
|
use App\Models\Server\MerchantEvaluate;
|
|||
|
|
use App\Models\Server\MerchantUserProfile;
|
|||
|
|
use App\Models\Wechat;
|
|||
|
|
use Illuminate\Http\JsonResponse;
|
|||
|
|
use Illuminate\Http\Request;
|
|||
|
|
use App\Http\Controllers\Controller;
|
|||
|
|
use App\Models\AccessRecord;
|
|||
|
|
use App\Models\AnchorVideo;
|
|||
|
|
use App\Models\App\Comment;
|
|||
|
|
use App\Models\CommunityActivity;
|
|||
|
|
use App\Models\ConsultAccount;
|
|||
|
|
use App\Models\Consultation;
|
|||
|
|
use App\Models\ConsultationRecords;
|
|||
|
|
use App\Models\Course\Course;
|
|||
|
|
use App\Models\Liker;
|
|||
|
|
use App\Models\Live\Anchor;
|
|||
|
|
use App\Models\Live\Viewer;
|
|||
|
|
use App\Models\MEarningwithdraws;
|
|||
|
|
use App\Models\MerchantShop;
|
|||
|
|
use App\Models\QATest;
|
|||
|
|
use App\Models\Server\MEarning;
|
|||
|
|
use App\Models\Server\MerchantAccount;
|
|||
|
|
use App\Models\Server\MerchantInformation;
|
|||
|
|
use App\Models\Server\MerchantUser;
|
|||
|
|
use App\Models\Server\SaasNotice;
|
|||
|
|
use App\Models\Server\TouristOrder;
|
|||
|
|
use App\Models\TemplateMsgLog;
|
|||
|
|
use App\Models\User;
|
|||
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|||
|
|
use Illuminate\Support\Facades\Cache;
|
|||
|
|
use Illuminate\Support\Facades\DB;
|
|||
|
|
use Illuminate\Support\Facades\Redis;
|
|||
|
|
|
|||
|
|
class UserController extends Controller
|
|||
|
|
{
|
|||
|
|
/**
|
|||
|
|
* 用户控制器
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function users(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$account_id = $request->account_id;
|
|||
|
|
$keyword = $request->keyword;
|
|||
|
|
$serve_tab = $request->serve_tab;
|
|||
|
|
$account = MerchantAccount::where('id', $account_id)->first();
|
|||
|
|
if (!$account) return $this->fail('请重新登录', 2);
|
|||
|
|
// $qr_code = MerchantAccount::where('openid',$open_id)->value('qr_code');
|
|||
|
|
$url = urlencode(env('APP_URL') . '/pu/#/');
|
|||
|
|
$path = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $account_id .
|
|||
|
|
'&serve_tab=' . $serve_tab . '&url=' . $url;
|
|||
|
|
$short_url = \CommonUtilsService::shortUrl($path);
|
|||
|
|
$short_url = $short_url['url'];
|
|||
|
|
|
|||
|
|
$qr_code = Redis::get('HomePage_S' . $account_id);
|
|||
|
|
if (!$qr_code) {
|
|||
|
|
$qr_code = $this->getPreviewQrcode($path);
|
|||
|
|
Redis::setex('HomePage_S' . $account_id, 60 * 60 * 24 * 30, $qr_code);
|
|||
|
|
$qr_code = Redis::get('HomePage_S' . $account_id);
|
|||
|
|
}
|
|||
|
|
$ids = AccessRecord::where(function ($query) use ($account) {
|
|||
|
|
if ($account->openid && $account->openid != 'null') {
|
|||
|
|
$query->where('from_openid', $account->openid)
|
|||
|
|
->orWhere('account_id', $account->id);
|
|||
|
|
} else {
|
|||
|
|
$query->where('account_id', $account->id);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
})->groupby('open_id')->pluck('id');
|
|||
|
|
if ($request->is_consume == 1) {
|
|||
|
|
$ids = TouristOrder::where('merchant_id', $account_id)->whereIn('pay_status', [1, 4])
|
|||
|
|
->where('price', '>', 0)->pluck('account_id');
|
|||
|
|
}
|
|||
|
|
$users = AccessRecord::wherein('id', $ids);
|
|||
|
|
if ($request->is_consume == 1) {
|
|||
|
|
$open_ids = TouristOrder::where('merchant_id', $account_id)
|
|||
|
|
->where('price', '>=', 0)->whereIn('pay_status', [1, 4])
|
|||
|
|
->pluck('open_id')
|
|||
|
|
->toArray();
|
|||
|
|
$open_ids = array_unique($open_ids);
|
|||
|
|
$users = AccessRecord::whereIn('open_id', $open_ids)->where('account_id', $account_id);
|
|||
|
|
}
|
|||
|
|
if ($keyword) {
|
|||
|
|
$users = $users->whereHas('mUser', function ($sql) use ($keyword) {
|
|||
|
|
$sql->where('nickname', 'like', '%' . $keyword . '%')
|
|||
|
|
->orWhere('mobile','like', '%' . $keyword . '%');
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
$users = $users->orderBy('id', 'desc')->paginate();
|
|||
|
|
|
|||
|
|
foreach ($users as $key => $value) {
|
|||
|
|
$is_consume = 0; //是否是付费用户
|
|||
|
|
$consume_money = 0; //消费金额
|
|||
|
|
$line_consume_money = 0; //推荐消费金额
|
|||
|
|
$agent = '一级代理';
|
|||
|
|
// $user_id = $this->getUseridByOpenid($value->open_id);
|
|||
|
|
// if($user_id){
|
|||
|
|
// $love_user = User::find($user_id);
|
|||
|
|
// $value->love_user = $love_user;
|
|||
|
|
// if($love_user){
|
|||
|
|
// if($love_user->from_user_id){
|
|||
|
|
// $recommend_user = User::find($love_user->from_user_id);
|
|||
|
|
// if($recommend_user) {
|
|||
|
|
// $value->recommand_pic = $recommend_user->photo ?? User::DefaultAvatar;
|
|||
|
|
// $value->recommand_name = $recommend_user->name ?? '匿名用户';
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// if($love_user->from_openid){
|
|||
|
|
// if(!$value->recommand_pic && !$value->recommand_name ){
|
|||
|
|
// $wechat = Wechat::where('openid',$love_user->from_openid)->first();
|
|||
|
|
// if($wechat){
|
|||
|
|
// $value->recommand_pic = $wechat->avatar ?? User::DefaultAvatar;
|
|||
|
|
// $value->recommand_name = $wechat->nickname ?? '匿名用户';
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// if($love_user->from_official_openid){
|
|||
|
|
// if(!$value->recommand_pic && !$value->recommand_name ){
|
|||
|
|
// $viewer = Viewer::where('openid',$love_user->from_openid)->first();
|
|||
|
|
// if($viewer){
|
|||
|
|
// $value->recommand_pic = $viewer->avatar ?? User::DefaultAvatar;
|
|||
|
|
// $value->recommand_name = $viewer->nickname ?? '匿名用户';
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// if(!$value->recommand_pic && !$value->recommand_name ){
|
|||
|
|
// $value->recommand_pic = User::DefaultAvatar;
|
|||
|
|
// $value->recommand_name = '匿名用户';
|
|||
|
|
// }
|
|||
|
|
// }else{
|
|||
|
|
// $value->recommand_pic = User::DefaultAvatar;
|
|||
|
|
// $value->recommand_name = '匿名用户';
|
|||
|
|
// }
|
|||
|
|
// $value->user_id = $user_id;
|
|||
|
|
// }else{
|
|||
|
|
// $value->recommand_pic = User::DefaultAvatar;
|
|||
|
|
// $value->recommand_name = '匿名用户';
|
|||
|
|
// $value->user_id = null;
|
|||
|
|
// }
|
|||
|
|
//首邀人
|
|||
|
|
if ($value->recommender) {
|
|||
|
|
$from_user = MerchantUser::where('openid', $value->recommender)->first();
|
|||
|
|
$value->recommand_pic = $from_user->pic ?? User::DefaultAvatar;
|
|||
|
|
$value->recommand_name = $from_user->nickname ?? '无';
|
|||
|
|
$value->recommand_openid = $from_user->openid ?? null;
|
|||
|
|
} else {
|
|||
|
|
$value->recommand_pic = User::DefaultAvatar;
|
|||
|
|
$value->recommand_name = '无';
|
|||
|
|
$value->recommand_openid = null;
|
|||
|
|
}
|
|||
|
|
$user = MerchantUser::where('openid', $value->open_id)->first();
|
|||
|
|
if ($user) {
|
|||
|
|
$value->avatar = $user->pic ?? User::DefaultAvatar;
|
|||
|
|
$value->nickname = $user->nickname ?? '匿名用户';
|
|||
|
|
$consume_money = TouristOrder::where(function ($query) use ($value) {
|
|||
|
|
$query->where('account_id', $value->id)
|
|||
|
|
->orWhere('open_id', $value->open_id);
|
|||
|
|
})
|
|||
|
|
->where('merchant_id', $account_id)->whereIn('pay_status', [1, 4])
|
|||
|
|
->sum('price');
|
|||
|
|
if ($user->openid) {
|
|||
|
|
$line_consume_money = TouristOrder::where('from_openid', $user->openid)
|
|||
|
|
->where('merchant_id', $account_id)->whereIn('pay_status', [1, 4])
|
|||
|
|
->sum('price');
|
|||
|
|
}
|
|||
|
|
$is_consume = $consume_money > 0 ? 1 : 0;
|
|||
|
|
$agent = $line_consume_money > 10000? '二级代理':'一级代理';
|
|||
|
|
$value->merchant_user_id = $user->id;
|
|||
|
|
} else {
|
|||
|
|
$value->avatar = $value->viewer->avatar ?? User::DefaultAvatar;
|
|||
|
|
$value->nickname = $value->viewer->nickname ?? '匿名用户';
|
|||
|
|
$value->merchant_user_id = null;
|
|||
|
|
}
|
|||
|
|
$value->is_consume = $is_consume;
|
|||
|
|
$value->consume_money = $consume_money;
|
|||
|
|
$value->line_consume_money = $line_consume_money;
|
|||
|
|
$value->agent = $agent;
|
|||
|
|
unset($value->viewer);
|
|||
|
|
$score = Redis::zscore('access_count' . $value->id, $account_id);
|
|||
|
|
$value->record_count = $score ?: 1;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return $this->success('ok', compact('short_url', 'qr_code', 'users'));
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure($e->getMessage());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 邀请的用户列表
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function invitationUsers(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_id = $request->account_id;
|
|||
|
|
$openid = $request->input('openid');
|
|||
|
|
if (empty($openid)) return $this->failure('openid不能为空');
|
|||
|
|
$list = AccessRecord::with('mUser')
|
|||
|
|
->where('recommender',$openid)
|
|||
|
|
->where('account_id',$merchant_id)
|
|||
|
|
->orderBy('id','desc')
|
|||
|
|
->paginate(10);
|
|||
|
|
foreach ($list as $item){
|
|||
|
|
if($item->mUser){
|
|||
|
|
$item->mUser->pic = $item->mUser->pic ?: User::DefaultAvatar;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return $this->success('ok',$list);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure($e->getMessage());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 数据分析
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function dataAnalysis(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$openid = $request->openid;
|
|||
|
|
$course_id = $request->course_id;//课程id
|
|||
|
|
$community_id = $request->community_id;//社群id
|
|||
|
|
$consulation_id = $request->consulation_id;
|
|||
|
|
$shop_id = $request->shop_id;
|
|||
|
|
$type = $request->type;
|
|||
|
|
|
|||
|
|
$end_time = date('Y-m-d 23:59:59');
|
|||
|
|
$start_time = date('Y-m-d H:i:s', strtotime('-7 days', strtotime($end_time)));
|
|||
|
|
$data = [];
|
|||
|
|
$watch_user_count = 0;//访问人数
|
|||
|
|
$consume_user_count = 0;//消费人数
|
|||
|
|
$consume_cash_amount = 0;//支付金额
|
|||
|
|
if ($type == 'course') {
|
|||
|
|
$consume_user_count = TouristOrder::where('type', 'course')->where('type_id', $course_id)->whereIn('pay_status', [1, 4])->count();
|
|||
|
|
$consume_cash_amount = TouristOrder::where('type', 'course')->where('type_id', $course_id)->whereIn('pay_status', [1, 4])->sum('price');
|
|||
|
|
$watch_user_count = Redis::zscore('coursepv', $course_id) ?: 0;
|
|||
|
|
} elseif ($type == 'activity') {
|
|||
|
|
$consume_user_count = TouristOrder::where('type', 'community')->where('type_id', $community_id)->whereIn('pay_status', [1, 4])->count();
|
|||
|
|
$consume_cash_amount = TouristOrder::where('type', 'community')->where('type_id', $community_id)->whereIn('pay_status', [1, 4])->sum('price');
|
|||
|
|
$watch_user_count = CommunityActivity::where('id', $community_id)->value('pv') ?: 0;
|
|||
|
|
} elseif ($type == 'consulation') {
|
|||
|
|
$consume_user_count = ConsultationRecords::where('consulation_id', $consulation_id)->where('pay_status', 1)->count();
|
|||
|
|
$consume_cash_amount = ConsultationRecords::where('consulation_id', $consulation_id)->where('pay_status', 1)->sum('price');
|
|||
|
|
$watch_user_count = Redis::zscore('consulation', $consulation_id) ?: 0;
|
|||
|
|
} elseif ($type == 'shop') {
|
|||
|
|
$consume_user_count = TouristOrder::where('type', 'shop')->where('type_id', $shop_id)->whereIn('pay_status', [1, 4])->count();
|
|||
|
|
$consume_cash_amount = TouristOrder::where('type', 'shop')->where('type_id', $shop_id)->whereIn('pay_status', [1, 4])->sum('price');
|
|||
|
|
$watch_user_count = Redis::zscore('shop', $shop_id) ?: 0;
|
|||
|
|
}
|
|||
|
|
$data['consume_user_count'] = $consume_user_count;
|
|||
|
|
$data['consume_cash_amount'] = $consume_cash_amount;
|
|||
|
|
$data['watch_user_count'] = $watch_user_count;
|
|||
|
|
return $this->success('ok', $data);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 批量操作
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function operateBatch(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$ids = $request->ids;
|
|||
|
|
$merchant_id = $request->account_id;
|
|||
|
|
if (!$ids) return $this->failure('请先选择要操作的内容');
|
|||
|
|
$type = $request->type;
|
|||
|
|
$operation = $request->operation;//删除:delete 上下架:hidden
|
|||
|
|
$is_show = $request->is_show ?? 0;
|
|||
|
|
if ($type == 'course' && $operation == 'delete') {
|
|||
|
|
Course::whereIn('id', $ids)->delete();
|
|||
|
|
}
|
|||
|
|
if ($type == 'course' && $operation == 'hidden') {
|
|||
|
|
if ($is_show == 0) {
|
|||
|
|
$is_show = -1;
|
|||
|
|
}
|
|||
|
|
Course::whereIn('id', $ids)->update(['is_show' => $is_show]);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ($type == 'activity' && $operation == 'delete') {//status
|
|||
|
|
CommunityActivity::whereIn('id', $ids)->delete();
|
|||
|
|
}
|
|||
|
|
if ($type == 'activity' && $operation == 'hidden') {//status
|
|||
|
|
CommunityActivity::whereIn('id', $ids)->update(['status' => $is_show]);
|
|||
|
|
}
|
|||
|
|
if ($type == 'moment' && $operation == 'delete') {
|
|||
|
|
MerchantInformation::whereIn('id', $ids)->delete();
|
|||
|
|
}
|
|||
|
|
if ($type == 'moment' && $operation == 'hidden') {
|
|||
|
|
MerchantInformation::whereIn('id', $ids)->update(['status' => $is_show]);
|
|||
|
|
}
|
|||
|
|
if ($type == 'consulation' && $operation == 'delete') {
|
|||
|
|
Consultation::whereIn('id', $ids)->delete();
|
|||
|
|
}
|
|||
|
|
if ($type == 'consulation' && $operation == 'hidden') {
|
|||
|
|
Consultation::whereIn('id', $ids)->update(['status' => $is_show]);
|
|||
|
|
}
|
|||
|
|
if ($type == 'qa_test' && $operation == 'hidden') {
|
|||
|
|
QATest::whereIn('id', $ids)->update(['status' => $is_show]);
|
|||
|
|
}
|
|||
|
|
if ($type == 'qa_test' && $operation == 'delete') {
|
|||
|
|
QATest::whereIn('id', $ids)->delete();
|
|||
|
|
}
|
|||
|
|
if ($type == 'shop' && $operation == 'hidden') {
|
|||
|
|
MerchantShop::whereIn('id', $ids)->update(['is_show' => $is_show]);
|
|||
|
|
}
|
|||
|
|
if ($type == 'shop' && $operation == 'delete') {
|
|||
|
|
MerchantShop::whereIn('id', $ids)->delete();
|
|||
|
|
}
|
|||
|
|
if ($type == 'video' && $operation == 'hidden') {
|
|||
|
|
AnchorVideo::whereIn('id', $ids)->update(['status' => $is_show]);
|
|||
|
|
}
|
|||
|
|
if ($type == 'video' && $operation == 'delete') {
|
|||
|
|
AnchorVideo::whereIn('id', $ids)->delete();
|
|||
|
|
}
|
|||
|
|
if ($type == 'evaluate' && $operation == 'hidden') {
|
|||
|
|
MerchantEvaluate::whereIn('id', $ids)->where('merchant_id', $merchant_id)
|
|||
|
|
->update(['status' => $is_show]);
|
|||
|
|
}
|
|||
|
|
if ($type == 'evaluate' && $operation == 'delete') {
|
|||
|
|
MerchantEvaluate::whereIn('id', $ids)->where('merchant_id', $merchant_id)
|
|||
|
|
->delete();
|
|||
|
|
}
|
|||
|
|
return $this->success('ok');
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 商户选中模板
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function chooseTemplate(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$account_id = $request->account_id;
|
|||
|
|
$choose_tarbar = $request->choose_tarbar;
|
|||
|
|
$template_position = $request->template_position;//个人中心
|
|||
|
|
$account = MerchantAccount::find($account_id);
|
|||
|
|
if (!$account) return $this->failure('商户信息有误');
|
|||
|
|
|
|||
|
|
if ($choose_tarbar && $account->choose_tarbar != json_encode($choose_tarbar)) {
|
|||
|
|
$account->choose_tarbar = json_encode($choose_tarbar);
|
|||
|
|
}
|
|||
|
|
if ($template_position && $account->template_position != json_encode($template_position)) {
|
|||
|
|
$account->template_position = json_encode($template_position);
|
|||
|
|
}
|
|||
|
|
$account->save();
|
|||
|
|
MerchantAccount::syncRedisMerchant($account_id);
|
|||
|
|
return $this->success('ok');
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//手机移动端后台部分
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 用户列表
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function mUsers(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_id = $request->account_id;
|
|||
|
|
$openid = MerchantAccount::where('id', $request->account_id)->value('openid') ?? 'bussiness';
|
|||
|
|
$keyword = $request->keyword;
|
|||
|
|
$users = AccessRecord::with('viewer:nickname,openid,avatar')->where(function ($query) use ($request, $openid) {
|
|||
|
|
if ($openid && $openid != 'null') {
|
|||
|
|
$query->where('from_openid', $openid)
|
|||
|
|
->orWhere('account_id', $request->account_id);
|
|||
|
|
} else {
|
|||
|
|
$query->where('account_id', $request->account_id);
|
|||
|
|
}
|
|||
|
|
})->groupBy('open_id');
|
|||
|
|
if ($keyword) {
|
|||
|
|
$keyword = trim($keyword);
|
|||
|
|
$users = $users->whereHas('viewer', function ($sql) use ($keyword) {
|
|||
|
|
$sql->where('nickname', 'like', '%' . $keyword . '%');
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
$users = $users->orderBy('last_time', 'desc')->paginate();
|
|||
|
|
foreach ($users as $key => $user) {
|
|||
|
|
$is_hide = 1;
|
|||
|
|
$preview_count = Redis::zscore('access_count' . $user->id, $user->account_id) ?: 1;
|
|||
|
|
$text = $user->created_at . '成功注册,访问了平台' . $preview_count . '次,最新访问时间:' . $user->last_time;
|
|||
|
|
$user->text = $text;
|
|||
|
|
// $user->avatar = $user->viewer ? $user->viewer->avatar : User::DefaultAvatar;
|
|||
|
|
// $user->nickname = $user->viewer ? $user->viewer->nickname : '匿名用户';
|
|||
|
|
// $nickname = $user->mUser ? $user->mUser->nickname : '未授权';
|
|||
|
|
$user->avatar = $user->mUser ? $user->mUser->pic : User::DefaultAvatar;
|
|||
|
|
$user->nickname = $user->mUser ? $user->mUser->nickname : '匿名用户';
|
|||
|
|
if (strpos($user->nickname, '用户') !== false) $is_hide = 0;
|
|||
|
|
$user->is_hide = $is_hide;
|
|||
|
|
unset($user->viewer);
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $users);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 商户所有服务
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function merchantServices(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_id = $request->account_id;
|
|||
|
|
$data = [];
|
|||
|
|
$information_arr = [];
|
|||
|
|
$service_arr = [];
|
|||
|
|
$activity_arr = [];
|
|||
|
|
$shop_arr = [];
|
|||
|
|
$consult_arr = [];
|
|||
|
|
$test_arr = [];
|
|||
|
|
$course_arr = [];
|
|||
|
|
$video_arr = [];
|
|||
|
|
|
|||
|
|
//资讯动态
|
|||
|
|
$infors = MerchantInformation::where('merchant_id', $merchant_id)->orderBy('id', 'desc')->get();
|
|||
|
|
foreach ($infors as $key => $info) {
|
|||
|
|
$time = date("Y-m-d H:i:s", strtotime($info->created_at));
|
|||
|
|
$pv = Redis::zscore('information', $info->id) ?: 0;
|
|||
|
|
$information_arr[$key] = ['id' => $info->id, 'type' => 'information', 'pv' => $pv, 'title' => $info->title, 'pic' => $info->pic, 'created_at' => $time, 'status' => $info->status];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$services = CommunityActivity::where('merchant_id', $merchant_id)->where('class', 'many')->where('type', 'business')->get();
|
|||
|
|
$activities = CommunityActivity::where('merchant_id', $merchant_id)->where('class', 'one')->where('type', 'business')->get();
|
|||
|
|
|
|||
|
|
foreach ($services as $key => $service) {
|
|||
|
|
$time = date("Y-m-d H:i:s", strtotime($service->created_at));
|
|||
|
|
$service_arr[$key] = ['id' => $service->id, 'type' => 'service', 'pv' => $service->pv, 'title' => $service->title, 'pic' => $service->pic, 'created_at' => $time, 'status' => $service->status];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
foreach ($activities as $key => $activity) {
|
|||
|
|
$time = date("Y-m-d H:i:s", strtotime($activity->created_at));
|
|||
|
|
$activity_arr[$key] = ['id' => $activity->id, 'type' => 'activity', 'pv' => $activity->pv, 'title' => $activity->title, 'pic' => $activity->pic, 'created_at' => $time, 'status' => $activity->status];
|
|||
|
|
}
|
|||
|
|
//商城商品
|
|||
|
|
$shops = MerchantShop::where('merchant_id', $merchant_id)->get();
|
|||
|
|
foreach ($shops as $key => $shop) {
|
|||
|
|
$time = date("Y-m-d H:i:s", strtotime($shop->created_at));
|
|||
|
|
$pv = Redis::zscore('shop', $shop->id) ?: 0;
|
|||
|
|
$shop_arr[$key] = ['id' => $shop->id, 'type' => 'shop', 'pv' => $pv, 'title' => $shop->title, 'pic' => $shop->icon, 'created_at' => $time, 'status' => $shop->is_show];
|
|||
|
|
}
|
|||
|
|
//语音咨询
|
|||
|
|
$consult_account_ids = ConsultAccount::where('merchant_id', $merchant_id)->pluck('id')->toArray();
|
|||
|
|
$consulations = Consultation::whereIn('consult_account_id', $consult_account_ids)->get();
|
|||
|
|
foreach ($consulations as $key => $consulation) {
|
|||
|
|
$time = date("Y-m-d H:i:s", strtotime($consulation->created_at));
|
|||
|
|
$pv = Redis::zscore('consulation', $consulation->id) ?: 0;
|
|||
|
|
$consult_arr[$key] = ['id' => $consulation->id, 'type' => 'consult', 'pv' => $pv, 'title' => $consulation->title, 'pic' => $consulation->pic, 'created_at' => $time, 'status' => $consulation->is_show];
|
|||
|
|
}
|
|||
|
|
//问答测试
|
|||
|
|
$tests = QATest::where('merchant_id', $merchant_id)->get();
|
|||
|
|
foreach ($tests as $key => $test) {
|
|||
|
|
$time = date("Y-m-d H:i:s", strtotime($test->created_at));
|
|||
|
|
$pv = Redis::zscore('testpv', $test->id) ?: 0;
|
|||
|
|
$test_arr[$key] = ['id' => $test->id, 'type' => 'test', 'pv' => $pv, 'title' => $test->title, 'pic' => $test->pic, 'created_at' => $time, 'status' => $test->status];
|
|||
|
|
}
|
|||
|
|
//课程
|
|||
|
|
$courses = Course::where('merchant_id', $merchant_id)->where('type', 'business')->get();
|
|||
|
|
foreach ($courses as $key => $course) {
|
|||
|
|
$status = $course->is_show == 1 ? 1 : 0;
|
|||
|
|
$time = date("Y-m-d H:i:s", strtotime($course->created_at));
|
|||
|
|
$pv = Redis::zscore('coursepv', $course->id) ?: 0;
|
|||
|
|
$course_arr[$key] = ['id' => $course->id, 'type' => 'course', 'pv' => $pv, 'title' => $course->title, 'pic' => $course->thumb, 'created_at' => $time, 'status' => $status];
|
|||
|
|
}
|
|||
|
|
//短视频
|
|||
|
|
$videos = AnchorVideo::where('m_id', $merchant_id)->get();
|
|||
|
|
foreach ($videos as $key => $video) {
|
|||
|
|
$time = date("Y-m-d H:i:s", strtotime($video->created_at));
|
|||
|
|
$pv = Redis::zscore('short_videopv', $video->id) ?: 0;
|
|||
|
|
$video_arr[$key] = ['id' => $video->id, 'type' => 'video', 'pv' => $pv, 'title' => $video->title, 'pic' => $video->cover, 'created_at' => $time, 'status' => $video->status];
|
|||
|
|
}
|
|||
|
|
$data = array_merge($information_arr, $video_arr, $service_arr, $activity_arr, $consult_arr, $test_arr, $course_arr, $shop_arr);
|
|||
|
|
$time_key = array_column($data, 'created_at');
|
|||
|
|
array_multisort($time_key, SORT_DESC, $data);
|
|||
|
|
//手动分页
|
|||
|
|
$page = $request->page ?? 1;
|
|||
|
|
$perPage = 15;
|
|||
|
|
$offset = ($page * $perPage) - $perPage;
|
|||
|
|
$result = new LengthAwarePaginator(array_slice($data, $offset, $perPage), count($data), $perPage, $page, ['path' => $request->url(), 'query' => $request->query()]);
|
|||
|
|
return $this->success('ok', $result);
|
|||
|
|
} 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 = MerchantInformation::where('merchant_id', $merchant->id)->select('id', 'title', 'pic', 'status');
|
|||
|
|
// 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;
|
|||
|
|
$value->type = 'information';
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $result);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 商品列表
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function platShops(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$keyword = $request->keyword;
|
|||
|
|
$merchant_id = $request->account_id;
|
|||
|
|
$shops = MerchantShop::where('merchant_id', $merchant_id)->select('id', 'title', 'icon', 'is_show');
|
|||
|
|
if ($keyword) {
|
|||
|
|
$shops = $shops->where('title', 'like', '%' . $keyword . '%');
|
|||
|
|
}
|
|||
|
|
$shops = $shops->orderBy('is_show','desc')->orderBy('is_top', 'desc')->orderBy('top_time', 'desc')
|
|||
|
|
->orderBy('id', 'desc')->paginate();
|
|||
|
|
foreach ($shops as $key => $shop) {
|
|||
|
|
$shop->pv = Redis::zscore('shop', $shop->id) ?: 0;
|
|||
|
|
$shop->type = 'shop';
|
|||
|
|
$shop->pic = $shop->icon;
|
|||
|
|
$shop->status = $shop->is_show;
|
|||
|
|
unset($shop->icon);
|
|||
|
|
unset($shop->is_show);
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $shops);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取问答测试列表
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function QA_testList(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_id = $request->account_id;
|
|||
|
|
$result = QATest::select('id', 'title', 'pic', 'status')
|
|||
|
|
->where('merchant_id', $merchant_id);
|
|||
|
|
$result = $result->orderBy('is_top', 'desc')
|
|||
|
|
->orderBy('top_time', 'desc')
|
|||
|
|
->orderBy('id', 'desc')
|
|||
|
|
->paginate();
|
|||
|
|
foreach ($result as $key => $value) {
|
|||
|
|
$value->type = 'test';
|
|||
|
|
$value->pv = Redis::zscore('testpv', $value->id) ?? 0;
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $result);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 我的课程列表
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function myCouseList(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$open_id = MerchantAccount::where('id', $request->account_id)->value('openid') ?? 'default';
|
|||
|
|
$courses = Course::select('id', 'thumb', 'title', 'is_show')/*->where('type','business')*/
|
|||
|
|
;
|
|||
|
|
//if ($request->account_id != 88) {
|
|||
|
|
$courses = $courses->where('type', 'business');
|
|||
|
|
//}
|
|||
|
|
$courses = $courses->Where('merchant_id', $request->account_id);
|
|||
|
|
$courses = $courses->orderBy('is_show', 'desc')->orderBy('is_top', 'desc')->orderBy('top_time', 'desc')
|
|||
|
|
->orderBy('id', 'desc')->paginate();
|
|||
|
|
foreach ($courses as $key => $course) {
|
|||
|
|
$course->type = 'course';
|
|||
|
|
$course->pv = Redis::zscore('coursepv', $course->id) ?? 0;
|
|||
|
|
$course->pic = $course->thumb;
|
|||
|
|
$course->status = $course->is_show == 1 ? 1 : 0;
|
|||
|
|
unset($course->thumb);
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $courses);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('获取列表失败');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 咨询服务列表
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function consultServices(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_id = $request->account_id;
|
|||
|
|
$nopage = $request->nopage;
|
|||
|
|
//商户名下的老师id
|
|||
|
|
$account_ids = ConsultAccount::where('merchant_id', $merchant_id)->pluck('id')->toArray();
|
|||
|
|
$consults = Consultation::whereIn('consult_account_id', $account_ids)->select('id', 'title', 'pic', 'status');
|
|||
|
|
|
|||
|
|
if ($nopage){
|
|||
|
|
$consults = $consults->orderBy('is_top', 'desc')->orderBy('top_time', 'desc')->orderBy('id', 'desc')->get();
|
|||
|
|
}else{
|
|||
|
|
$consults = $consults->orderBy('is_top', 'desc')->orderBy('top_time', 'desc')->orderBy('id', 'desc')->paginate();
|
|||
|
|
}
|
|||
|
|
foreach ($consults as $key => $consult) {
|
|||
|
|
$consult->type = 'consult';
|
|||
|
|
$consult->pv = Redis::zscore('consulation', $consult->id) ?: 0;
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $consults);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 通用删除
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function deleteServices(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$type_arr = ['shop', 'service', 'activity', 'video', 'information', 'course', 'consult', 'test'];
|
|||
|
|
if (!in_array($request->type, $type_arr)) return $this->failure('要删除的类型不存在');
|
|||
|
|
$type_id = $request->type_id;
|
|||
|
|
switch ($request->type) {
|
|||
|
|
case 'shop':
|
|||
|
|
MerchantShop::where('id', $type_id)->where('merchant_id', $request->account_id)->delete();
|
|||
|
|
break;
|
|||
|
|
case 'service':
|
|||
|
|
CommunityActivity::where('id', $type_id)->where('merchant_id', $request->account_id)->delete();
|
|||
|
|
break;
|
|||
|
|
case 'activity':
|
|||
|
|
CommunityActivity::where('id', $type_id)->where('merchant_id', $request->account_id)->delete();
|
|||
|
|
break;
|
|||
|
|
case 'video':
|
|||
|
|
AnchorVideo::where('id', $type_id)->where('m_id', $request->account_id)->delete();
|
|||
|
|
break;
|
|||
|
|
case 'information':
|
|||
|
|
MerchantInformation::where('id', $type_id)->where('merchant_id', $request->account_id)->delete();
|
|||
|
|
break;
|
|||
|
|
case 'course':
|
|||
|
|
Course::where('id', $type_id)->where('merchant_id', $request->account_id)->delete();
|
|||
|
|
break;
|
|||
|
|
case 'test':
|
|||
|
|
QATest::where('id', $type_id)->where('merchant_id', $request->account_id)->delete();
|
|||
|
|
break;
|
|||
|
|
case 'consult':
|
|||
|
|
Consultation::where('id', $type_id)->delete();
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
return $this->success('ok');
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('删除失败,稍后再试');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public function phoneNotices(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$type = $request->type ?? 'system';
|
|||
|
|
$notices = SaasNotice::where('m_id', $request->account_id)->where('type', '<>', 'analyse');
|
|||
|
|
if ($type == 'system') {//系统通知
|
|||
|
|
$notices = $notices->where('type', '<>', 'order');
|
|||
|
|
} else {//订单通知
|
|||
|
|
$notices = $notices->where('type', 'order');
|
|||
|
|
}
|
|||
|
|
$notices = $notices->orderBy('id', 'desc')->paginate();
|
|||
|
|
foreach ($notices as $key => $notice) {
|
|||
|
|
$time = date('Y-m-d H:i', strtotime($notice->created_at));
|
|||
|
|
$notice->consume_time = $time;
|
|||
|
|
unset($notice->created_at, $notice->updated_at);
|
|||
|
|
switch ($notice->type) {
|
|||
|
|
case 'like'://点赞
|
|||
|
|
$notice->title = '收到一条点赞';
|
|||
|
|
$like = Liker::withTrashed()->where('id', $notice->type_id)->first();
|
|||
|
|
if (empty($like)) break;
|
|||
|
|
if (strstr($like->like_type, 'Information')) $like_type = 'information';
|
|||
|
|
if (strstr($like->like_type, 'Video')) $like_type = 'video';
|
|||
|
|
$notice->jump_type = $like_type;
|
|||
|
|
$notice->jump_type_id = $like->like_id;
|
|||
|
|
break;
|
|||
|
|
case 'comment'://评论
|
|||
|
|
$notice->title = '收到新的评论';
|
|||
|
|
$comment = Comment::withTrashed()->where('id', $notice->type_id)->first();
|
|||
|
|
if (empty($comment)) break;
|
|||
|
|
if (strstr($comment->commentable_type, 'Information')) $like_type = 'information';
|
|||
|
|
if (strstr($comment->commentable_type, 'Video')) $like_type = 'video';
|
|||
|
|
$notice->jump_type = $like_type;
|
|||
|
|
$notice->jump_type_id = $comment->commentable_id;
|
|||
|
|
break;
|
|||
|
|
case 'withdraw'://提现
|
|||
|
|
$withdraw = MEarningwithdraws::where('id', $notice->type_id)->first();
|
|||
|
|
if (strstr($notice->content, '已成功提现')) {
|
|||
|
|
$notice->title = '提现' . $withdraw->real_value . '元到账';
|
|||
|
|
} else {
|
|||
|
|
$notice->title = '提现' . $withdraw->real_value . '元失败';
|
|||
|
|
}
|
|||
|
|
$notice->jump_type = 'withdraw';
|
|||
|
|
$notice->jump_type_id = 0;
|
|||
|
|
break;
|
|||
|
|
case 'm_invite'://邀请入驻
|
|||
|
|
$notice->title = '邀请入驻成功';
|
|||
|
|
$notice->jump_type = 'm_invite';
|
|||
|
|
$notice->jump_type_id = 0;
|
|||
|
|
break;
|
|||
|
|
case 'recruiting'://商户入驻
|
|||
|
|
$notice->title = '你已入驻成功';
|
|||
|
|
$notice->jump_type = 'recruiting';
|
|||
|
|
$notice->jump_type_id = 0;
|
|||
|
|
break;
|
|||
|
|
case 'order'://购买服务
|
|||
|
|
$title = '新订单通知';
|
|||
|
|
$order = TouristOrder::where('id', $notice->type_id)->first();
|
|||
|
|
if (empty($order)) break;
|
|||
|
|
$notice->title = $title;
|
|||
|
|
$notice->jump_type = 'order';
|
|||
|
|
$notice->jump_type_id = $order->id;
|
|||
|
|
break;
|
|||
|
|
case 're_order'://打赏文章 活动
|
|||
|
|
$order = TouristOrder::where('id', $notice->type_id)->first();
|
|||
|
|
if (empty($order)) break;
|
|||
|
|
if ($order->type == 'reward_info') $jump_type = 'information';
|
|||
|
|
if ($order->type == 'reward_activity') $jump_type = 'activity';
|
|||
|
|
$notice->title = '收到打赏通知';
|
|||
|
|
$notice->jump_type = $jump_type;
|
|||
|
|
$notice->jump_type_id = $order->type_id;
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
# code...
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $notices);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 读取通知
|
|||
|
|
* @param $id
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function readNotice($id)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
SaasNotice::where('id', $id)->update(['is_read' => 1]);
|
|||
|
|
return $this->success('ok');
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 查看报名人信息
|
|||
|
|
*/
|
|||
|
|
public function getOrderUser(Request $request){
|
|||
|
|
try {
|
|||
|
|
$order_id = $request->order_id;
|
|||
|
|
$order = TouristOrder::where('id', $order_id)
|
|||
|
|
->where('merchant_id',$request->account_id)
|
|||
|
|
->first();
|
|||
|
|
if ($order) {
|
|||
|
|
$data = $this->getOrderUserInfo($order);
|
|||
|
|
if($data){
|
|||
|
|
$data->merchant_user_id = $order->account_id;
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
return $this->failure('订单不存在');
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $data);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 查看用户隐藏手机号增加记录
|
|||
|
|
* **/
|
|||
|
|
public function getUserMobile(Request $request){
|
|||
|
|
$user_id = $request->user_id;
|
|||
|
|
$merchant_id = $request->account_id;
|
|||
|
|
if($merchant_id != 491){
|
|||
|
|
return $this->failure('暂无权限');
|
|||
|
|
}
|
|||
|
|
$admin_id = $request->merchant_admin_id ?? $request->account_id;
|
|||
|
|
$param = ['user_id'=> $user_id,'operator'=>$request->account_id.'_'.$request->merchant_admin_id,'platform'=>'saas'];
|
|||
|
|
$log = [
|
|||
|
|
'path'=> $request->path(),
|
|||
|
|
'method'=>$request->method(),
|
|||
|
|
'user_id'=>$admin_id,
|
|||
|
|
'param'=>json_encode($param),
|
|||
|
|
'model'=>'User',
|
|||
|
|
'model_id'=>$user_id,
|
|||
|
|
'created_at'=>date('Y-m-d H:i:s'),
|
|||
|
|
'updated_at'=>date('Y-m-d H:i:s'),
|
|||
|
|
];
|
|||
|
|
$mobile = User::where('id',$user_id)->value('mobile');
|
|||
|
|
AdminLog::insert($log);
|
|||
|
|
return $this->success('ok',['mobile'=>$mobile]);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 用户详情
|
|||
|
|
* @param Request $request 参数
|
|||
|
|
* @param integer $id 用户id
|
|||
|
|
*/
|
|||
|
|
public function user(Request $request, $user_id)
|
|||
|
|
{
|
|||
|
|
//用户主账号信息
|
|||
|
|
$user = User::with('areaUser','areaUser.classArea','bannedHistory','systemBlacklist','wrongInfo','clientComments:user_id,pics,comment,created_at,type')->where('id', $user_id)->first();
|
|||
|
|
if (empty($user)) return $this->failure('用户不存在');
|
|||
|
|
|
|||
|
|
//管理员账号id
|
|||
|
|
$admin_user_id = auth()->id();
|
|||
|
|
|
|||
|
|
//判断账号权限
|
|||
|
|
// $is_promote = RoleUser::where('user_id', $admin_user_id)->where('role_id', 6)->count();
|
|||
|
|
// $platfroms = Platform::where('paas_id', 33)->pluck('app_id')->toArray();
|
|||
|
|
// if($is_promote && !in_array($user->from_platform, $platfroms)) return $this->failure('没有权限访问该用户');
|
|||
|
|
|
|||
|
|
// $admin_type = $request->session()->get('admin_type');
|
|||
|
|
// if ($admin_type == 'paas_admin') {
|
|||
|
|
// $paas_obj = $request->session()->get('paas_obj');
|
|||
|
|
// $paas_user_ids = $this->userCon->paasUserIds($paas_obj->name)->toArray();
|
|||
|
|
// if (!in_array($user_id, $paas_user_ids)) {
|
|||
|
|
// return $this->failure('没有权限访问该用户');
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
$photos = [];
|
|||
|
|
$graduate_photos = [];
|
|||
|
|
$identification_photos = [];
|
|||
|
|
$other_photos = [];
|
|||
|
|
$wechat_qrcode = [];
|
|||
|
|
$sex = 0;
|
|||
|
|
if ($user->type == 'single') {
|
|||
|
|
$profile = ProfileCourtship::firstOrCreate(['user_id' => $user->id]);
|
|||
|
|
if ($profile) {
|
|||
|
|
$photos = json_decode($profile->photos, true)?json_decode($profile->photos, true):[];
|
|||
|
|
$graduate_photos = json_decode($profile->graduate_photos, true)?json_decode($profile->graduate_photos, true):[];
|
|||
|
|
$identification_photos = json_decode($profile->identification_photos, true)?json_decode($profile->identification_photos, true):[];
|
|||
|
|
$other_photos = json_decode($profile->other_photos, true)?json_decode($profile->other_photos, true):[];
|
|||
|
|
$wechat_qrcode = json_decode($profile->wechat_qrcode, true)?json_decode($profile->wechat_qrcode, true):[];
|
|||
|
|
$profile->interest_label = json_decode($profile->interest_label);
|
|||
|
|
$profile->photos = $photos;
|
|||
|
|
$profile->graduate_photos = $graduate_photos;
|
|||
|
|
$profile->identification_photos = $identification_photos;
|
|||
|
|
$profile->other_photos = $other_photos;
|
|||
|
|
$profile->wechat_qrcode = $wechat_qrcode;
|
|||
|
|
$sex = $profile->sex;
|
|||
|
|
$salary = Salary::where('id', $profile->salary_id)->value('text');
|
|||
|
|
$profile->salary = $salary;
|
|||
|
|
}
|
|||
|
|
}else{
|
|||
|
|
$profile = ProfileMarriage::firstOrCreate(['user_id' => $user->id]);
|
|||
|
|
if ($profile) {
|
|||
|
|
$sex = $profile->sex;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$user->profile = $profile;
|
|||
|
|
if($user->clientComments){
|
|||
|
|
foreach ($user->clientComments as $key => $value) {
|
|||
|
|
if($value->pics == '[]'){
|
|||
|
|
$value->comment_type = 'write';
|
|||
|
|
}else{
|
|||
|
|
$value->comment_type = 'auto';
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$wechat = Wechat::where('user_id', $user_id)->select('user_id', 'avatar', 'gender','avatar2')->first();
|
|||
|
|
$avatar = '';
|
|||
|
|
if (!empty($wechat)) {
|
|||
|
|
$avatar = $wechat->avatar2?:$wechat->avatar;
|
|||
|
|
}
|
|||
|
|
$user->avatar = $user->userAvatar();
|
|||
|
|
if (empty($sex) && $wechat) {
|
|||
|
|
$sex = $wechat->gender;
|
|||
|
|
}
|
|||
|
|
$user->sex = $user->sex?:$sex;
|
|||
|
|
|
|||
|
|
//福分
|
|||
|
|
$score = $this->getAccountScore($user->id);
|
|||
|
|
$user->score = $score;
|
|||
|
|
|
|||
|
|
//测试结果
|
|||
|
|
//$result = $this->testResult($user_id);
|
|||
|
|
//$love_languages = $result['love_languages'];
|
|||
|
|
//$love_characters = $result['love_characters'];
|
|||
|
|
//$character = $result['character'];
|
|||
|
|
//$user->love_languages = $love_languages;
|
|||
|
|
//$user->love_characters = $love_characters;
|
|||
|
|
//$user->character = $character;
|
|||
|
|
//用户等级
|
|||
|
|
$rank_name = Rank::where('id', $user->rank_id)->value('name');
|
|||
|
|
$user->rank_name = $rank_name;
|
|||
|
|
//会员期限
|
|||
|
|
$rank_history = RankHistory::where('user_id', $user_id)->where('rank_id', $user->rank_id)->whereNotNull('deadline')->orderBy('deadline', 'desc')->first();
|
|||
|
|
if (empty($rank_history)) {
|
|||
|
|
$deadline = '';
|
|||
|
|
}else{
|
|||
|
|
$deadline = $rank_history->deadline;
|
|||
|
|
}
|
|||
|
|
$from_user_name = null;
|
|||
|
|
if (!empty($user->from_user_id)) {
|
|||
|
|
$from_user_name = User::where('id',$user->from_user_id)->value('name');
|
|||
|
|
if (empty($from_user_name)) {
|
|||
|
|
$from_user_name = User::where('id',$user->from_user_id)->value('nickname');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$user->from_user_name = $from_user_name;
|
|||
|
|
$user->deadline =$deadline;
|
|||
|
|
|
|||
|
|
//我的类型
|
|||
|
|
$admin_type = $request->session()->get('admin_type');
|
|||
|
|
if ($admin_type == 'admin' || $admin_type == 'paas_admin') {
|
|||
|
|
$user_is_admin = 1;
|
|||
|
|
}else{
|
|||
|
|
$user_is_admin = 0;
|
|||
|
|
}
|
|||
|
|
$admin = Admin::where('user_id', $user_id)->first();
|
|||
|
|
if (empty($admin)) {
|
|||
|
|
$user->is_admin = 0;
|
|||
|
|
}else{
|
|||
|
|
$user->is_admin = 1;
|
|||
|
|
}
|
|||
|
|
$user->user_is_admin = $user_is_admin;
|
|||
|
|
//分配的红娘
|
|||
|
|
$maker_user_id = MatchmakerClient::where('client_user_id', $user_id)->value('user_id');
|
|||
|
|
$maker_name = '';
|
|||
|
|
if ($maker_user_id) {
|
|||
|
|
$maker_name = User::where('id', $maker_user_id)->value('name');
|
|||
|
|
}
|
|||
|
|
$user->maker_name = $maker_name;
|
|||
|
|
//生活照
|
|||
|
|
//$lifePhotos = $this->userCon->lifePhotos($user_id);
|
|||
|
|
//$user->lifePhotos = $lifePhotos->count()?$lifePhotos:[];
|
|||
|
|
//openid
|
|||
|
|
$user->openid = Wechat::where('user_id', $user->id)->value('openid');
|
|||
|
|
//隐藏手机号
|
|||
|
|
//$result = $this->userCon->hideMobile($request, $user_id);
|
|||
|
|
//$user->mobile = $result?'******':$user->mobile;
|
|||
|
|
//是否完成资料
|
|||
|
|
//$is_completed = $this->userCon->isCompleteProfile($user->id);
|
|||
|
|
//$user->is_completed = $is_completed;
|
|||
|
|
//手机归属地
|
|||
|
|
$user->home_location = $user->homeLocation();
|
|||
|
|
//最近所在位置
|
|||
|
|
$user->post_location = $user->positionGetAddress($user->location_longitude, $user->location_latitude);
|
|||
|
|
$user->identification_photos = !empty($user->identification_photos) ? array_values(json_decode($user->identification_photos)):[];
|
|||
|
|
//推荐平台
|
|||
|
|
$paas_id = Platform::where('app_id', $user->from_platform)->value('paas_id');
|
|||
|
|
if ($paas_id) {
|
|||
|
|
$from_paas = Paas::where('id', $paas_id)->value('name');
|
|||
|
|
}else{
|
|||
|
|
$from_paas = '';
|
|||
|
|
}
|
|||
|
|
$user->from_paas = $from_paas;
|
|||
|
|
$user->industry_arr = [$user->industry, $user->industry_sub];
|
|||
|
|
// if($is_promote){
|
|||
|
|
// $user->mobile = substr_replace($user->mobile,'****',3,4);
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
$card_num = $user->card_num;
|
|||
|
|
if ($admin_user_id != 616) {
|
|||
|
|
if(!empty($card_num)){
|
|||
|
|
$card_num = substr_replace($card_num, '********',-8,8);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$user->new_card_num = $card_num;
|
|||
|
|
//最近访问
|
|||
|
|
$user->last_visit = Cache::get(User::RDLASTTIMEKEY.$user->id)?:$user->last_visit;
|
|||
|
|
$user->regist_channel = DB::table('user_register_channels')->where('user_id', $user_id)->value('channel');
|
|||
|
|
$user->has_mobile = $user->mobile === NULL? 0 : 1;
|
|||
|
|
//加字段 判断用户权限是否被禁用
|
|||
|
|
$user->ban_moment = 0; //发动态
|
|||
|
|
$user->ban_moment_date = '';
|
|||
|
|
$user->ban_friend = 0; //加好友
|
|||
|
|
$user->ban_friend_date = '';
|
|||
|
|
$user->ban_chat = 0; //聊天
|
|||
|
|
$user->ban_chat_date = '';
|
|||
|
|
$user->ban_user = 0; //系统黑名单
|
|||
|
|
$user->ban_user_date = '';
|
|||
|
|
$user->ban_live = 0; //直播间聊天
|
|||
|
|
$user->ban_live_date = '';
|
|||
|
|
$date = date('Y-m-d H:i:s');
|
|||
|
|
if (!empty($user->bannedHistory)) {
|
|||
|
|
foreach ($user->bannedHistory as $history) {
|
|||
|
|
if ($history->type == 'moment' && $history->start_time <= $date && $history->end_time >= $date) {
|
|||
|
|
$user->ban_moment = 1;
|
|||
|
|
$user->ban_moment_date = $history->end_time;
|
|||
|
|
}
|
|||
|
|
if ($history->type == 'chat' && $history->start_time <= $date && $history->end_time >= $date) {
|
|||
|
|
$user->ban_chat = 1;
|
|||
|
|
$user->ban_chat_date = $history->end_time;
|
|||
|
|
}
|
|||
|
|
if ($history->type == 'friend' && $history->start_time <= $date && $history->end_time >= $date) {
|
|||
|
|
$user->ban_friend = 1;
|
|||
|
|
$user->ban_friend_date = $history->end_time;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//是否禁止直播间聊天
|
|||
|
|
if ($user->viewer && $user->viewer->free_time >= $date) {
|
|||
|
|
$user->ban_live = 1; //直播间聊天
|
|||
|
|
$user->ban_live_date = $user->viewer->free_time;
|
|||
|
|
}
|
|||
|
|
//是否被封账号
|
|||
|
|
if (!empty($user->systemBlacklist) && $user->systemBlacklist->start_time <= $date
|
|||
|
|
&& $user->systemBlacklist->end_time >= $date) {
|
|||
|
|
$user->ban_user = 1;
|
|||
|
|
$user->ban_user_date = $user->systemBlacklist->end_time;
|
|||
|
|
}
|
|||
|
|
$user->mobile = '';
|
|||
|
|
$user->is_account_wall = $user->userInfo ? $user->userInfo->is_account_wall : 0;
|
|||
|
|
$user->is_closed = 0;
|
|||
|
|
unset($user->userInfo);
|
|||
|
|
$qrcode_user = DB::table('user_share_qrcode')->where('user_id',$user_id)->where('type','<>',3)->first();//判断是否有新的分享
|
|||
|
|
if (empty($qrcode_user)){ //没有的话 后台生成
|
|||
|
|
$qrcode_path = QrcodeRectService::getQrcodeToMini($user_id);
|
|||
|
|
// dd($qrcode_path);
|
|||
|
|
$param = ['page'=>'pages/home/information?id='.$user_id,'from_user_id'=>$user->id];
|
|||
|
|
$param = json_encode($param);
|
|||
|
|
$data = [
|
|||
|
|
'user_id' => $user_id,
|
|||
|
|
'qrcode_path' => $qrcode_path,
|
|||
|
|
'type' => 4,
|
|||
|
|
'param' => $param,
|
|||
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|||
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|||
|
|
];
|
|||
|
|
$user->my_qrcode = $qrcode_path;
|
|||
|
|
DB::table('user_share_qrcode')->insert($data);
|
|||
|
|
|
|||
|
|
}else{
|
|||
|
|
$user->my_qrcode = $qrcode_user->qrcode_path;
|
|||
|
|
}
|
|||
|
|
$user->emotional_state = $user->userInfo ? $user->userInfo->emotional_state : 'unknow';
|
|||
|
|
$user->profile->age = $user->profile ? \CommonUtilsService::getAge($user->profile->birthday) : '未填写';
|
|||
|
|
//关闭资料提示
|
|||
|
|
$close_log = CloseProfileHistory::where('user_id', $user_id)->orderBy('id', 'desc')->first();
|
|||
|
|
$user->hidden_operator = $close_log?$close_log->operator:0;
|
|||
|
|
$m_user_id = $this->matchMerchantUser($user_id);
|
|||
|
|
$m_ids = IdentityAuthorization::where('m_user_id',$m_user_id)->pluck('m_id')->toArray();
|
|||
|
|
$merchant_name = Anchor::whereIn('m_id',$m_ids)->pluck('name')->toArray();
|
|||
|
|
$user->merchant_name = $merchant_name;
|
|||
|
|
return $this->success('ok', $user);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public function syncProfileCourtships(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$from_user_id = $request->input('from_user_id');
|
|||
|
|
$to_account_id = $request->input('to_account_id');
|
|||
|
|
$to_user_id = $request->input('to_user_id');
|
|||
|
|
$profile = ProfileCourtship::where('user_id',$from_user_id)->first();
|
|||
|
|
if(!$profile){
|
|||
|
|
return $this->failure("{$from_user_id}福恋小程序用户资料未找到");
|
|||
|
|
}
|
|||
|
|
$from_user = User::where('id',$from_user_id)->first();
|
|||
|
|
DB::beginTransaction();
|
|||
|
|
$data = [];
|
|||
|
|
if($to_user_id){
|
|||
|
|
$data = $profile->toArray();
|
|||
|
|
unset($data['id']);
|
|||
|
|
unset($data['user_id']);
|
|||
|
|
unset($data['created_at']);
|
|||
|
|
unset($data['updated_at']);
|
|||
|
|
unset($data['deleted_at']);
|
|||
|
|
$res = ProfileCourtship::where('user_id',$to_user_id)->update($data);
|
|||
|
|
User::where('id',$to_user_id)->update(['name'=>$from_user->name,'sex'=>$from_user->sex]);
|
|||
|
|
}else{
|
|||
|
|
// sass绑定福恋id
|
|||
|
|
$res = MerchantUser::where('id', $to_account_id)->update(['user_id'=>$from_user_id]);
|
|||
|
|
}
|
|||
|
|
DB::commit();
|
|||
|
|
// if(!$res){
|
|||
|
|
// return $this->failure('同步失败',$data);
|
|||
|
|
// }
|
|||
|
|
return $this->success('ok',$data);
|
|||
|
|
} catch (\Exception $e){
|
|||
|
|
DB::rollBack();
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure($e->getMessage());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|