567 lines
19 KiB
PHP
567 lines
19 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Server\Admin;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\GoodMatch;
|
|
use App\Models\Matchmaker;
|
|
use App\Models\MatchmakerClient;
|
|
use App\Models\AppointmentHistory;
|
|
use App\Models\ClientComment;
|
|
use App\Models\Wechat;
|
|
use App\Models\User;
|
|
use App\Models\ProfileCourtship;
|
|
use App\Models\UserProfile;
|
|
use App\Models\Admin;
|
|
use \Exception;
|
|
use App\Models\AppointmentPlan;
|
|
class GoodMatchController extends Controller
|
|
{
|
|
/**
|
|
* 红娘列表
|
|
* @param Request $request [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function matchmakers(Request $request)
|
|
{
|
|
//类型
|
|
$status = $request->input('status',1);
|
|
$makers = Matchmaker::withCount('client', 'comment');
|
|
if($status != 2){
|
|
$makers = $makers->where('status', $status);
|
|
}
|
|
|
|
$makers = $makers->orderBy('id', 'desc');
|
|
$keyword = $request->input('keyword');
|
|
if ($keyword) {
|
|
$keyword = trim($keyword);
|
|
$makers = $makers->whereHas('user', function($sql) use($keyword){
|
|
$sql->where('name', 'like', '%'.$keyword.'%');
|
|
});
|
|
}
|
|
$nopage = $request->input('nopage',0);
|
|
if ($nopage) {
|
|
$makers = $makers->get();
|
|
foreach ($makers as $maker) {
|
|
$name = User::where('id', $maker->user_id)->value('name');
|
|
$maker->name = $name;
|
|
}
|
|
}else{
|
|
$makers = $makers->paginate();
|
|
foreach ($makers as $maker) {
|
|
$user = User::where('id', $maker->user_id)->first();
|
|
if (empty($user)) {
|
|
continue;
|
|
}
|
|
$maker->name = $user->name;
|
|
$wechat = Wechat::where('user_id', $maker->user_id)->select('avatar', 'avatar2')->first();
|
|
if (empty($wechat)) {
|
|
if ($user->sex == 1) {
|
|
$avatar = 'http://images.ufutx.com/201811/12/0e8b72aae6fa640d9e73ed312edeebf3.png';
|
|
}else {
|
|
$avatar = 'http://images.ufutx.com/201811/12/dddd79aa2c2fc6a6f35e641f6b8fb8f5.png';
|
|
}
|
|
}else{
|
|
$avatar = $wechat->avatar2?$wechat->avatar2:$wechat->avatar;
|
|
}
|
|
$maker->avatar = $avatar;
|
|
$client_user_ids = MatchmakerClient::where('user_id', $maker->user_id)->pluck('client_user_id');
|
|
//服务项目数
|
|
$service_count = AppointmentHistory::whereIn('user_id', $client_user_ids)->count();
|
|
$maker->service_count = $service_count;
|
|
//服务金额
|
|
$service_sum = AppointmentHistory::whereIn('user_id', $client_user_ids)->sum('price');
|
|
$maker->service_sum = $service_sum;
|
|
//佳偶认证
|
|
$good_match_count = GoodMatch::whereIn('user_id', $client_user_ids)->count();
|
|
$maker->good_match_count = $good_match_count;
|
|
}
|
|
|
|
}
|
|
return $this->success('ok', $makers);
|
|
}
|
|
|
|
/**
|
|
* 審核紅娘
|
|
* @param Request $request [description]
|
|
* @param [type] $user_id [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function checkMatchmaker(Request $request, $id)
|
|
{
|
|
$maker = Matchmaker::findOrFail($id);
|
|
$status = $request->input('status');
|
|
$maker->status = $status;
|
|
$maker->save();
|
|
//TODO 通知
|
|
return $this->success('ok');
|
|
}
|
|
/**
|
|
* 红娘客户
|
|
* @param Request $request [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function matchmakerClients(Request $request, $maker_user_id=null)
|
|
{
|
|
if ($maker_user_id) {
|
|
$user_id = $maker_user_id;
|
|
}else{
|
|
$user = Auth()->user();
|
|
$user_id = $user->id;
|
|
}
|
|
$client_user_ids = MatchmakerClient::where('user_id', $user_id)->pluck('client_user_id');
|
|
$users = UserProfile::whereIn('id', $client_user_ids)->orderBy('id',"desc");
|
|
$type = $request->input('type', '');
|
|
//单身、介绍人
|
|
if ($type) {
|
|
$users = $users->where('type', $type);
|
|
}
|
|
//男女
|
|
$sex = $request->input('sex', 0);
|
|
if ($sex) {
|
|
$users = $users->where('sex', $sex);
|
|
}
|
|
//是否是会员
|
|
$is_vip = $request->input('is_vip');
|
|
if ($is_vip) {
|
|
$users = $users->where(function($sql){
|
|
$sql->where('rank_id', '<>', 0)
|
|
->orWhere('temp_member', 1);
|
|
});
|
|
}
|
|
//是否是佳偶
|
|
$is_match = $request->input('is_match');
|
|
if ($is_match) {
|
|
$users = $users->whereHas('goodMatch', function($sql) {
|
|
$sql->where('status', 1);
|
|
});
|
|
}
|
|
//跟进红娘
|
|
// $has_maker = $request->input('has_maker');
|
|
// if ($has_maker) {
|
|
// $users = $users->whereHas('matchmakerClient', function($sql) {
|
|
// $sql->where('status', 1);
|
|
// });
|
|
// }else{
|
|
// $client_user_ids = MatchmakerClient::where('status',1)->pluck('client_user_id');
|
|
// $users = $users->whereNotIn('id', $client_user_ids);
|
|
// }
|
|
//实名认证
|
|
$is_approved = $request->input('is_approved');
|
|
if ($is_approved) {
|
|
$users = $users->where('is_approved',1);
|
|
}
|
|
|
|
$keyword = $request->input('keyword', '');
|
|
if ($keyword) {
|
|
$keyword = trim($keyword);
|
|
$users = $users->where(function($sql)use($keyword){
|
|
$sql->where('name', 'like', '%'.$keyword.'%')
|
|
->orWhere('mobile', 'like', '%'.$keyword.'%')
|
|
->orWhere('industry', 'like', '%'.$keyword.'%')
|
|
->orWhere('industry_sub', 'like', '%'.$keyword.'%')
|
|
->orWhere('province', 'like', '%'.$keyword.'%')
|
|
->orWhere('city', 'like', '%'.$keyword.'%')
|
|
->orWhere('graduate_school', 'like', '%'.$keyword.'%')
|
|
->orWhere('belief', 'like', '%'.$keyword.'%')
|
|
->orWhere('introduction', 'like', '%'.$keyword.'%')
|
|
->orWhere('ideal_mate', 'like', '%'.$keyword.'%')
|
|
->orWhere('company', 'like', '%'.$keyword.'%');
|
|
});
|
|
|
|
}
|
|
|
|
$nopage = $request->input('nopage', 0);
|
|
if ($nopage) {
|
|
$users = $users->select('id', 'name', 'mobile')->get();
|
|
return $this->success('ok', $users);
|
|
}
|
|
$users = $users->paginate();
|
|
foreach ($users as $user) {
|
|
$wechat = Wechat::where('user_id', $user->id)->select('avatar', 'avatar2', 'openid')->first();
|
|
if (empty($wechat)) {
|
|
if ($user->sex == 1) {
|
|
$avatar = 'http://images.ufutx.com/201811/12/0e8b72aae6fa640d9e73ed312edeebf3.png';
|
|
}else {
|
|
$avatar = 'http://images.ufutx.com/201811/12/dddd79aa2c2fc6a6f35e641f6b8fb8f5.png';
|
|
}
|
|
}else{
|
|
$avatar = $wechat->avatar2?$wechat->avatar2:$wechat->avatar;
|
|
}
|
|
$user->avatar = $avatar;
|
|
$user->rank = $this->memberType($user->rank_id, $user->temp_member);
|
|
//佳偶认证
|
|
$count = GoodMatch::where('user_id', $user->id)->where('status', 1)->count();
|
|
$user->is_good_match = $count?1:0;
|
|
//地址
|
|
$province = '';
|
|
$city = '';
|
|
if ($user->type == 'single') {
|
|
$profile = ProfileCourtship::where('user_id', $user->id)->first();
|
|
if (!empty($profile)) {
|
|
$province = $profile->province;
|
|
$city = $profile->city;
|
|
}
|
|
}
|
|
$user->province = $province;
|
|
$user->city = $city;
|
|
//邀请注册人数
|
|
$openid = $wechat?$wechat->openid:'无';
|
|
$invite_num = User::where('from_openid', $openid)->count();
|
|
$user->invite_num = $invite_num;
|
|
}
|
|
return $this->success('ok', $users);
|
|
}
|
|
|
|
/**
|
|
* 红娘跟进服务
|
|
*/
|
|
public function matchmakerServices(Request $request)
|
|
{
|
|
$user = auth()->user();
|
|
$admin_type = $request->session()->get('admin_type');
|
|
if ($admin_type == 'admin') {
|
|
$client_user_ids = MatchmakerClient::pluck('client_user_id');
|
|
}else{
|
|
//客户id
|
|
$client_user_ids = MatchmakerClient::where('user_id', $user->id)->pluck('client_user_id');
|
|
}
|
|
|
|
//客户买的服务
|
|
$histories = AppointmentHistory::with('user')->whereIn('user_id', $client_user_ids)->paginate();
|
|
return $this->success('ok', $histories);
|
|
}
|
|
|
|
/**
|
|
* 用户的约见记录
|
|
*/
|
|
public function userAppointmentPlans(Request $request, User $user)
|
|
{
|
|
$histories = AppointmentPlan::with('user', 'otherUser')->where('user_id', $user->id)->paginate();
|
|
return $this->success('ok', $histories);
|
|
}
|
|
|
|
/**
|
|
* 处理用户的约见记录
|
|
*/
|
|
public function dealUserAppointmentPlan(Request $request, AppointmentPlan $appointment_plan)
|
|
{
|
|
$appointment_plan->status = 1;
|
|
$appointment_plan->save();
|
|
return $this->success('ok');
|
|
}
|
|
|
|
/**
|
|
* 红娘某个客户备注列表
|
|
* @param request $request [description]
|
|
* @param [type] $client_user_id [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function comments(request $request, $user_id)
|
|
{
|
|
$comments = ClientComment::where('user_id', $user_id)->with('makerUser');
|
|
$admin_type = $request->session()->get('admin_type');
|
|
if ($admin_type == 'paas_admin') {
|
|
$paas_obj = $request->session()->get('paas_obj');
|
|
$admin_user_ids = Admin::where('type', $paas_obj->name)->pluck('user_id');
|
|
$comments = $comments->whereIn('maker_user_id', $admin_user_ids);
|
|
}
|
|
$comments = $comments->orderBy('id', 'desc')->paginate();
|
|
foreach ($comments as $comment) {
|
|
$comment->pics = json_decode($comment->pics, true)?json_decode($comment->pics, true):[];
|
|
$comment->type = $this->commentType($comment->type);
|
|
}
|
|
return $this->success('ok', $comments);
|
|
}
|
|
|
|
public function commentType($type)
|
|
{
|
|
$result = '';
|
|
if ($type == 'mobile') {
|
|
$result = '电话访问';
|
|
}elseif ($type == 'active') {
|
|
$result = '见面服务';
|
|
}elseif ($result == 'passive') {
|
|
return $result = '托管服务';
|
|
}
|
|
return $result;
|
|
}
|
|
/**
|
|
* 添加备注
|
|
* @param Request $request [description]
|
|
* @param [type] $client_user_id [description]
|
|
*/
|
|
public function addComment(Request $request, $user_id)
|
|
{
|
|
$merchant_id = $request->account_id;
|
|
$admin_id = $request->merchant_admin_id;
|
|
$admin_user_id = $this->getMakerUserId($admin_id,$merchant_id);
|
|
$type = $request->input('type');
|
|
if (empty($type)) {
|
|
$type = 'mobile';
|
|
}
|
|
$pics = $request->input('pics', '');
|
|
$comment = $request->input('comment');
|
|
try {
|
|
User::where('id', $user_id)->increment('tag_num');
|
|
// UserProfile::where('id', $user_id)->increment('tag_num', 1);
|
|
ClientComment::create([
|
|
'user_id'=>$user_id,
|
|
'maker_user_id'=>$admin_user_id,
|
|
'type'=>$type,
|
|
'pics'=>!empty($request->pics) ? json_encode($request->pics):null,
|
|
'comment'=>$comment,
|
|
]);
|
|
return $this->success('ok');
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|
}
|
|
}
|
|
|
|
public function updateComment(Request $request, $comment_id)
|
|
{
|
|
$comment = ClientComment::findORfail($comment_id);
|
|
if ($request->has('type') && $request->type != $comment->type) {
|
|
$comment->type = $request->type;
|
|
}
|
|
if ($request->has('pics') && json_encode($request->pics) != $comment->pics) {
|
|
$comment->pics = json_encode($request->pics);
|
|
}
|
|
if ($request->has('comment') && $request->comment != $comment->comment) {
|
|
$comment->comment = $request->comment;
|
|
}
|
|
$comment->save();
|
|
return $this->success('ok');
|
|
}
|
|
/**
|
|
* 备注详情
|
|
* @param Request $request [description]
|
|
* @param [type] $remark_id [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function comment(Request $request, $comment_id)
|
|
{
|
|
$comment = ClientComment::findORfail($comment_id);
|
|
$comment->pics = json_decode($comment->pics, true)?json_decode($comment->pics, true):[];
|
|
return $this->success('ok', $comment);
|
|
}
|
|
|
|
/**
|
|
* 取消佳偶
|
|
*/
|
|
public function deleteGoodsMatch(Request $request, $user_id)
|
|
{
|
|
$goods_match = GoodMatch::where('user_id', $user_id)->first();
|
|
$goods_match->delete();
|
|
return $this->success('ok');
|
|
}
|
|
|
|
/**
|
|
* 审核佳偶
|
|
* @param Request $request [description]
|
|
* @param [type] $user_id [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function checkGoodMatch(Request $request, $user_id)
|
|
{
|
|
$good_match = GoodMatch::where('user_id', $user_id)->first();
|
|
$status = $request->input('status');
|
|
$good_match->status = $status;
|
|
$good_match->save();
|
|
//TODO 通知
|
|
return $this->success('ok');
|
|
}
|
|
|
|
/**
|
|
* 设置管理员
|
|
* @param Request $request [description]
|
|
* @param [type] $user_id [description]
|
|
*/
|
|
public function setAdmin(Request $request, $user_id)
|
|
{
|
|
$user = User::findOrFail($user_id);
|
|
$is_admin = $request->input('is_admin', 0);
|
|
$admin_type = $request->session()->get('admin_type');
|
|
if ($admin_type == 'paas_admin') {
|
|
$paas_obj = $request->session()->get('paas_obj');
|
|
if ($is_admin) {
|
|
Admin::firstOrCreate(['user_id'=>$user_id, 'type'=>$paas_obj->name]);
|
|
}else{
|
|
Admin::where('user_id', $user_id)->where("type", $paas_obj->name)->delete();
|
|
}
|
|
}elseif ($admin_type == 'admin') {
|
|
$admin = Admin::where('user_id', $user_id)->where("type", 'SUPER')->first();
|
|
if ($is_admin) {
|
|
Admin::firstOrCreate(['user_id'=>$user_id, 'type'=>'SUPER']);
|
|
}else{
|
|
Admin::where('user_id', $user_id)->where("type", 'SUPER')->delete();
|
|
$user->is_admin = $is_admin;
|
|
}
|
|
$user->password = $user->password?:bcrypt($user->mobile);
|
|
$user->save();
|
|
}
|
|
return $this->success('ok');
|
|
}
|
|
|
|
/**
|
|
* 设置红娘与客服
|
|
* @param Request $request [description]
|
|
* @param [type] $user_id [description]
|
|
* @param [type] $client_user_id [description]
|
|
*/
|
|
public function setMatchmakerClient(Request $request, $match_id, $client_user_id)
|
|
{
|
|
// $client = MatchmakerClient::where('client_user_id', $client_user_id)->whereHas('clientUser', function($sql){
|
|
// $sql->where('id', '>', 0);
|
|
// })->first();
|
|
// if ($client) {
|
|
// return $this->failure('该用户已有红娘跟进');
|
|
// }
|
|
$maker = Matchmaker::find($match_id);
|
|
$client = MatchmakerClient::firstOrCreate(['client_user_id'=>$client_user_id]);
|
|
$client->user_id = $maker->user_id;
|
|
$client->status = 1;
|
|
$client->save();
|
|
// MatchmakerClient::create([
|
|
// 'user_id'=>$maker->user_id,
|
|
// 'client_user_id'=>$client_user_id,
|
|
// 'status'=>1
|
|
// ]);
|
|
return $this->success('ok');
|
|
}
|
|
|
|
public function goodMatches(Request $request)
|
|
{
|
|
$status = $request->input('status', 1);
|
|
if($status == 2){
|
|
$match_user_ids = GoodMatch::pluck('user_id');
|
|
}else {
|
|
$match_user_ids = GoodMatch::where('status', $status)->pluck('user_id');
|
|
}
|
|
$users = UserProfile::whereIn('id', $match_user_ids)->orderBy('id',"desc");
|
|
$type = $request->input('type', '');
|
|
//单身、介绍人
|
|
if ($type) {
|
|
$users = $users->where('type', $type);
|
|
}
|
|
//男女
|
|
$sex = $request->input('sex', 0);
|
|
if ($sex) {
|
|
$users = $users->where('sex', $sex);
|
|
}
|
|
//是否是会员
|
|
$is_vip = $request->input('is_vip');
|
|
if ($is_vip) {
|
|
$users = $users->where(function($sql){
|
|
$sql->where('rank_id', '<>', 0)
|
|
->orWhere('temp_member', 1);
|
|
});
|
|
}
|
|
//跟进红娘
|
|
$has_maker = $request->input('has_maker');
|
|
if ($has_maker) {
|
|
$users = $users->whereHas('matchmakerClient', function($sql) {
|
|
$sql->where('status', 1);
|
|
});
|
|
}
|
|
//实名认证
|
|
$is_approved = $request->input('is_approved');
|
|
if ($is_approved) {
|
|
$users = $users->where('is_approved',1);
|
|
}
|
|
|
|
$keyword = $request->input('keyword', '');
|
|
if ($keyword) {
|
|
$keyword = trim($keyword);
|
|
$users = $users->where(function($sql)use($keyword){
|
|
$sql->where('name', 'like', '%'.$keyword.'%')
|
|
->orWhere('mobile', 'like', '%'.$keyword.'%')
|
|
->orWhere('industry', 'like', '%'.$keyword.'%')
|
|
->orWhere('industry_sub', 'like', '%'.$keyword.'%')
|
|
->orWhere('province', 'like', '%'.$keyword.'%')
|
|
->orWhere('city', 'like', '%'.$keyword.'%')
|
|
->orWhere('graduate_school', 'like', '%'.$keyword.'%')
|
|
->orWhere('belief', 'like', '%'.$keyword.'%')
|
|
->orWhere('introduction', 'like', '%'.$keyword.'%')
|
|
->orWhere('ideal_mate', 'like', '%'.$keyword.'%')
|
|
->orWhere('company', 'like', '%'.$keyword.'%');
|
|
});
|
|
|
|
}
|
|
|
|
$nopage = $request->input('nopage', 0);
|
|
if ($nopage) {
|
|
$users = $users->select('id', 'name', 'mobile')->get();
|
|
return $this->success('ok', $users);
|
|
}
|
|
$users = $users->paginate();
|
|
foreach ($users as $user) {
|
|
$wechat = Wechat::where('user_id', $user->id)->select('avatar', 'avatar2')->first();
|
|
if (empty($wechat)) {
|
|
if ($user->sex == 1) {
|
|
$avatar = 'http://images.ufutx.com/201811/12/0e8b72aae6fa640d9e73ed312edeebf3.png';
|
|
}else {
|
|
$avatar = 'http://images.ufutx.com/201811/12/dddd79aa2c2fc6a6f35e641f6b8fb8f5.png';
|
|
}
|
|
}else{
|
|
$avatar = $wechat->avatar2?$wechat->avatar2:$wechat->avatar;
|
|
}
|
|
$user->avatar = $avatar;
|
|
$user->rank = $this->memberType($user->rank_id, $user->temp_member);
|
|
//佳偶认证
|
|
$count = GoodMatch::where('user_id', $user->id)->where('status', 1)->count();
|
|
$user->is_good_match = $count?1:0;
|
|
//地址
|
|
$province = '';
|
|
$city = '';
|
|
if ($user->type == 'single') {
|
|
$profile = ProfileCourtship::where('user_id', $user->id)->first();
|
|
if (!empty($profile)) {
|
|
$province = $profile->province;
|
|
$city = $profile->city;
|
|
}
|
|
}
|
|
$user->province = $province;
|
|
$user->city = $city;
|
|
}
|
|
return $this->success('ok', $users);
|
|
}
|
|
|
|
/**
|
|
* 备注列表
|
|
*/
|
|
public function usersComments(Request $request, ClientComment $comment)
|
|
{
|
|
$comments = $comment->with('user', 'makerUser')->orderBy('id', 'desc');
|
|
$keyword = $request->input("keyword");
|
|
if ($keyword) {
|
|
$keyword = trim($keyword);
|
|
$comments = $comments->whereHas('user', function($sql) use($keyword){
|
|
$sql->where('name', 'like', '%'.$keyword.'%')
|
|
->orWhere('mobile', 'like', '%'.$keyword.'%');
|
|
});
|
|
}
|
|
$comments = $comments->paginate();
|
|
return $this->success('ok', $comments);
|
|
}
|
|
|
|
/**
|
|
* 新增红娘
|
|
* @param Request $request [description]
|
|
* @param User $user [description]
|
|
* @param Matchmaker $matchmaker [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function matchmakerUser(Request $request, User $user, Matchmaker $matchmaker)
|
|
{
|
|
$matchmaker = $matchmaker->create([
|
|
'user_id'=>$user->id,
|
|
'status'=>1
|
|
]);
|
|
return $this->success('ok', $matchmaker);
|
|
}
|
|
|
|
}
|