534 lines
25 KiB
PHP
534 lines
25 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Server\Admin;
|
||
|
|
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Models\ClientComment;
|
||
|
|
use App\Models\Live\Anchor;
|
||
|
|
use App\Models\Portrait;
|
||
|
|
use App\Models\PortraitAdvance;
|
||
|
|
use App\Models\ProfileCourtship;
|
||
|
|
use App\Models\Server\MatchLog;
|
||
|
|
use App\Models\Server\MerchantAccount;
|
||
|
|
use App\Models\Server\MerchantAdmins;
|
||
|
|
use App\Models\Server\MerchantMembers;
|
||
|
|
use App\Models\Server\MerchantUser;
|
||
|
|
use App\Models\Server\MOrderFollow;
|
||
|
|
use App\Models\Server\TouristOrder;
|
||
|
|
use App\Models\User;
|
||
|
|
use App\Models\UserInfo;
|
||
|
|
use App\Server\ServiceRole;
|
||
|
|
use App\Server\ServiceRoleOrder;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
|
||
|
|
class PersonPortraitController extends Controller
|
||
|
|
{
|
||
|
|
//填充用户画像内容
|
||
|
|
public function fullPortrait(Request $request,$m_user_id){
|
||
|
|
try {
|
||
|
|
$merchant_id = $request->account_id;
|
||
|
|
$admin_id = $request->merchant_admin_id;
|
||
|
|
if($admin_id) {
|
||
|
|
$admin = MerchantAdmins::find($admin_id);
|
||
|
|
}else{
|
||
|
|
$admin = MerchantAccount::find($merchant_id);
|
||
|
|
}
|
||
|
|
$admin_user_id = User::where('mobile',$admin->mobile)->value('id') ?? 0;
|
||
|
|
$merchant_user = MerchantUser::find($m_user_id);
|
||
|
|
if(empty($merchant_user)) return $this->failure('该用户不存在');
|
||
|
|
$interest_label = $request->interest;
|
||
|
|
$marry_in = $request->marry_in;
|
||
|
|
$character = $request->character;
|
||
|
|
$family_members = $request->family_members;
|
||
|
|
$state = $request->state;
|
||
|
|
$economic_situation_work = $request->economic_situation_work;
|
||
|
|
$economic_situation_job = $request->economic_situation_job;
|
||
|
|
$economic_situation_salary = $request->economic_situation_salary;
|
||
|
|
$house_array = ['has_house'=>$request->has_house,'house_location'=>$request->house_location];
|
||
|
|
$raw_family = $request->raw_family;
|
||
|
|
$work_requirement = $request->work_requirement;
|
||
|
|
$body_requirement = $request->body_requirement;
|
||
|
|
$child_array = ['single_accept'=>$request->single_accept,'divorce_accept'=>$request->divorce_accept,'child_accept'=>$request->child_accept];
|
||
|
|
$area_requirement = $request->area_requirement;
|
||
|
|
$economic_requirement = $request->economic_requirement;
|
||
|
|
$belief_requirement = $request->belief_requirement;
|
||
|
|
$family_requirement = $request->family_requirement;
|
||
|
|
$accept_age = null;
|
||
|
|
if($request->min_age || $request->max_age){
|
||
|
|
$accept_age = $request->min_age.'-'.$request->max_age;
|
||
|
|
}
|
||
|
|
Portrait::updateOrCreate(['m_user_id'=>$m_user_id],[
|
||
|
|
'interest_label'=>$interest_label,
|
||
|
|
'marry_in'=>$marry_in,
|
||
|
|
'character'=>$character,
|
||
|
|
'family_members'=>$family_members,
|
||
|
|
'state'=>$state,
|
||
|
|
'economic_situation_work'=>$economic_situation_work,
|
||
|
|
'economic_situation_job'=>$economic_situation_job,
|
||
|
|
'economic_situation_salary'=>$economic_situation_salary,
|
||
|
|
'economic_situation_house'=>json_encode($house_array),
|
||
|
|
'raw_family'=>$raw_family,
|
||
|
|
'work_requirement'=>$work_requirement,
|
||
|
|
'body_requirement'=>$body_requirement,
|
||
|
|
'child_requirement'=>json_encode($child_array),
|
||
|
|
'area_requirement'=>$area_requirement,
|
||
|
|
'belief_requirement'=>$belief_requirement,
|
||
|
|
'family_requirement'=>$family_requirement,
|
||
|
|
'age_requirement'=>$accept_age,
|
||
|
|
'economic_requirement'=>$economic_requirement,
|
||
|
|
'admin_id'=>$admin_user_id
|
||
|
|
]);
|
||
|
|
return $this->success('ok');
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//填充用户画像内容v2
|
||
|
|
public function fullPortraitV2(Request $request,$m_user_id){
|
||
|
|
try {
|
||
|
|
$merchant_id = $request->account_id;
|
||
|
|
$admin_id = $request->merchant_admin_id;
|
||
|
|
if($admin_id) {
|
||
|
|
$admin = MerchantAdmins::find($admin_id);
|
||
|
|
}else{
|
||
|
|
$admin = MerchantAccount::find($merchant_id);
|
||
|
|
}
|
||
|
|
$admin_user_id = User::where('mobile',$admin->mobile)->value('id') ?? 0;
|
||
|
|
$merchant_user = MerchantUser::find($m_user_id);
|
||
|
|
if(empty($merchant_user)) return $this->failure('该用户不存在');
|
||
|
|
$name = $request->name;//姓名
|
||
|
|
$sex = $request->sex;//性别
|
||
|
|
$age = $request->age;//年龄
|
||
|
|
$stature = $request->stature;//身高
|
||
|
|
$economic_situation_work = $request->economic_situation_work;//职业
|
||
|
|
$economic_situation_salary = $request->economic_situation_salary;//年收入
|
||
|
|
$live_in = $request->live_in;//常居地
|
||
|
|
$house_array = ['has_house'=>1,'house_location'=>$request->house_location];//房车情况
|
||
|
|
$interest_label = $request->interest_label;//兴趣爱好
|
||
|
|
$raw_family = $request->interest_label;//原生家庭 成长经历
|
||
|
|
$character = $request->character;//性格特点
|
||
|
|
$advantage = $request->advantage;//我的择偶优势
|
||
|
|
$taboo = $request->taboo;//择偶禁忌
|
||
|
|
$promote_point = $request->promote_point;//有待提升的点
|
||
|
|
$daily_travel = $request->daily_travel;//一日之旅
|
||
|
|
$friend_trouble = $request->friend_trouble;//目前的脱单困扰
|
||
|
|
$advice = $request->advice;//想法/建议
|
||
|
|
$emotion_requirement = $request->emotion_requirement;//择偶.情感需求
|
||
|
|
$car_describe = $request->car_describe;//车子
|
||
|
|
|
||
|
|
// $growth_experience = $request->growth_experience;
|
||
|
|
$growth_experience_child = $request->growth_experience_child;
|
||
|
|
$growth_experience_young = $request->growth_experience_young;
|
||
|
|
$growth_experience_teen = $request->growth_experience_teen;
|
||
|
|
$growth_experience_work = $request->growth_experience_work;
|
||
|
|
$growth_experience_emo = $request->growth_experience_emo;
|
||
|
|
$chating_model = $request->chating_model;
|
||
|
|
$conflict_model = $request->conflict_model;
|
||
|
|
$sense_worth = $request->sense_worth;
|
||
|
|
$key_point = $request->key_point;
|
||
|
|
$demand_target = $request->demand_target;
|
||
|
|
$confidence = $request->confidence;
|
||
|
|
$service_target = $request->service_target;
|
||
|
|
DB::beginTransaction();
|
||
|
|
$result = Portrait::updateOrCreate(['m_user_id'=>$m_user_id],[
|
||
|
|
'name'=>$name,
|
||
|
|
'sex'=>$sex,
|
||
|
|
'age'=>$age,
|
||
|
|
'stature'=>$stature,
|
||
|
|
'economic_situation_work'=>$economic_situation_work,
|
||
|
|
'economic_situation_salary'=>$economic_situation_salary,
|
||
|
|
'live_in'=>$live_in,
|
||
|
|
'economic_situation_house'=>json_encode($house_array),
|
||
|
|
'interest_label'=>$interest_label,
|
||
|
|
'raw_family'=>$raw_family,
|
||
|
|
'character'=>$character,
|
||
|
|
'advantage'=>$advantage,
|
||
|
|
'taboo'=>$taboo,
|
||
|
|
'promote_point'=>$promote_point,
|
||
|
|
'daily_travel'=>$daily_travel,
|
||
|
|
'friend_trouble'=>$friend_trouble,
|
||
|
|
'advice'=>$advice,
|
||
|
|
'emotion_requirement'=>$emotion_requirement,
|
||
|
|
'car_describe'=>$car_describe,
|
||
|
|
'admin_id'=>$admin_user_id
|
||
|
|
]);
|
||
|
|
PortraitAdvance::updateOrCreate(['portrait_id'=>$result->id],[
|
||
|
|
'growth_experience_child'=>json_encode($growth_experience_child),
|
||
|
|
'growth_experience_young'=>json_encode($growth_experience_young),
|
||
|
|
'growth_experience_teen'=>json_encode($growth_experience_teen),
|
||
|
|
'growth_experience_work'=>json_encode($growth_experience_work),
|
||
|
|
'growth_experience_emo'=>json_encode($growth_experience_emo),
|
||
|
|
'chating_model'=>json_encode($chating_model),
|
||
|
|
'conflict_model'=>json_encode($conflict_model),
|
||
|
|
'sense_worth'=>$sense_worth,
|
||
|
|
'demand_target'=>$demand_target,
|
||
|
|
'key_point'=>$key_point,
|
||
|
|
'confidence'=>$confidence,
|
||
|
|
'service_target'=>$service_target,
|
||
|
|
]);
|
||
|
|
DB::commit();
|
||
|
|
return $this->success('ok');
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
DB::rollBack();
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//获取用户画像详情
|
||
|
|
public function userProtrait(Request $request,$m_user_id){
|
||
|
|
try {
|
||
|
|
$user = MerchantUser::where('id',$m_user_id)->first();
|
||
|
|
if(empty($user)) return $this->failure('该用户不存在');
|
||
|
|
$portrait = Portrait::where('m_user_id',$m_user_id)->first();
|
||
|
|
if(!$portrait){
|
||
|
|
return $this->success('ok',compact('portrait'));
|
||
|
|
}
|
||
|
|
$portrait->child_requirement = json_decode($portrait->child_requirement,true);
|
||
|
|
$portrait->economic_situation_house = json_decode($portrait->economic_situation_house,true);
|
||
|
|
$portrait->belief = '未获取';
|
||
|
|
$portrait->interest_hobby = '未获取';
|
||
|
|
$mate_conditon = '未获取';
|
||
|
|
$age = '未获取';
|
||
|
|
$user_id = $this->matchFulinkUser($m_user_id);
|
||
|
|
if($user_id){
|
||
|
|
$profile = ProfileCourtship::firstOrCreate(['user_id'=>$user_id]);
|
||
|
|
$portrait->belief = $profile->belief;
|
||
|
|
$portrait->interest_hobby = $profile->interest_hobby;
|
||
|
|
$mate_conditon = $profile->mate_conditon;
|
||
|
|
if($mate_conditon){
|
||
|
|
$mate_conditon = json_decode($mate_conditon,true);
|
||
|
|
if(array_key_exists('age',$mate_conditon)){
|
||
|
|
$age = $mate_conditon['age'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$portrait->age = $age;
|
||
|
|
return $this->success('ok',compact('portrait'));
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//获取用户画像详情
|
||
|
|
public function userProtraitV2(Request $request,$m_user_id){
|
||
|
|
try {
|
||
|
|
$user = MerchantUser::where('id',$m_user_id)->first();
|
||
|
|
if(empty($user)) return $this->failure('该用户不存在');
|
||
|
|
$portrait = Portrait::with('advance')->where('m_user_id',$m_user_id)->first();
|
||
|
|
if(!$portrait){
|
||
|
|
return $this->success('ok',compact('portrait'));
|
||
|
|
}
|
||
|
|
$portrait->economic_situation_house = json_decode($portrait->economic_situation_house,true);
|
||
|
|
if($portrait->advance){
|
||
|
|
$portrait->advance->growth_experience_child = json_decode($portrait->advance->growth_experience_child,true);
|
||
|
|
$portrait->advance->growth_experience_young = json_decode($portrait->advance->growth_experience_young,true);
|
||
|
|
$portrait->advance->growth_experience_teen = json_decode($portrait->advance->growth_experience_teen,true);
|
||
|
|
$portrait->advance->growth_experience_work = json_decode($portrait->advance->growth_experience_work,true);
|
||
|
|
$portrait->advance->growth_experience_emo = json_decode($portrait->advance->growth_experience_emo,true);
|
||
|
|
$portrait->advance->chating_model = json_decode($portrait->advance->chating_model,true);
|
||
|
|
$portrait->advance->conflict_model = json_decode($portrait->advance->conflict_model,true);
|
||
|
|
}
|
||
|
|
return $this->success('ok',compact('portrait'));
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//牵线服务匹配
|
||
|
|
public function serviceMatchUser(Request $request,$order_id){
|
||
|
|
try {
|
||
|
|
$order = TouristOrder::find($order_id);
|
||
|
|
if(!$order || !in_array($order->pay_status,[1,4])) return $this->failure('牵线订单不存在或未支付');
|
||
|
|
$receive_user_id = $request->user_id;
|
||
|
|
$match_user = User::find($receive_user_id);
|
||
|
|
$send_user = $this->getOrderUserInfo($order);
|
||
|
|
if($send_user){
|
||
|
|
$send_user_id = $send_user->id;
|
||
|
|
}else{
|
||
|
|
return $this->failure('订单用户未找到');
|
||
|
|
}
|
||
|
|
if(!$match_user) return $this->failure('匹配用户不存在');
|
||
|
|
$pattern = $request->pattern;
|
||
|
|
$status = $request->status;
|
||
|
|
if(!isset($status)){
|
||
|
|
return $this->failure('匹配状态为必填值');
|
||
|
|
}
|
||
|
|
$admin_id = $request->merchant_admin_id??0;
|
||
|
|
DB::beginTransaction();
|
||
|
|
MatchLog::create([
|
||
|
|
'm_order_id'=> $order_id,
|
||
|
|
'receive_user_id'=>$receive_user_id,
|
||
|
|
'send_user_id' => $send_user_id,
|
||
|
|
'pattern'=>$pattern,
|
||
|
|
'status'=>$status,
|
||
|
|
'admin_id'=>$admin_id,
|
||
|
|
'is_positive' => 1,
|
||
|
|
|
||
|
|
]);
|
||
|
|
MatchLog::create([
|
||
|
|
'm_order_id'=> $order_id,
|
||
|
|
'receive_user_id'=>$receive_user_id,
|
||
|
|
'send_user_id' => $send_user_id,
|
||
|
|
'pattern'=>$pattern,
|
||
|
|
'status'=>$status,
|
||
|
|
'admin_id'=>$admin_id,
|
||
|
|
'is_positive' => 0,
|
||
|
|
]);
|
||
|
|
$maker_user_id = 0;//福恋操作人id
|
||
|
|
$admin = !empty($admin_id) ? MerchantAdmins::find($admin_id) : MerchantAccount::find($request->account_id);
|
||
|
|
$maker_user = User::where('mobile',$admin->mobile)->first();
|
||
|
|
$maker_user_id = $maker_user ? $maker_user->id : 0;
|
||
|
|
$admin_nickname = $maker_user ? $maker_user->nickname : '';
|
||
|
|
$text = '管理员 '.$admin_nickname.' 通过牵线服务【'.$order->desc.'】为他匹配了'.$match_user->nickname;
|
||
|
|
//同步一条该订单用户的用户备注
|
||
|
|
$match_user_id = $this->matchFulinkUser($order->account_id);
|
||
|
|
if($match_user_id){
|
||
|
|
$this->createClientComment($match_user_id,$maker_user_id,$text);
|
||
|
|
}
|
||
|
|
|
||
|
|
DB::commit();
|
||
|
|
return $this->success('ok');
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息,请稍后再试');
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
//牵线服务-匹配记录
|
||
|
|
public function recommendLog(Request $request,$order_id){
|
||
|
|
$merchant_id = $request->account_id;
|
||
|
|
$keyword = trim($request->keyword);
|
||
|
|
$logs = MatchLog::with('user:id,nickname,app_avatar,photo,circle_avatar,nickname,mobile,name')
|
||
|
|
->where('is_positive',1)
|
||
|
|
->where('m_order_id',$order_id)
|
||
|
|
->orderBy('id','desc');
|
||
|
|
if($keyword){
|
||
|
|
$logs = $logs->whereHas('user',function($sql) use($keyword){
|
||
|
|
$sql->where('mobile','like',"%$keyword%")
|
||
|
|
->orWhere('name','like',"%$keyword%")
|
||
|
|
->orWhere('nickname','like',"%$keyword%");
|
||
|
|
});
|
||
|
|
}
|
||
|
|
$logs = $logs->paginate();
|
||
|
|
foreach ($logs as $key => $value) {
|
||
|
|
if($value->admin_id == 0){
|
||
|
|
$anchor = Anchor::where('m_id',$merchant_id)->first();
|
||
|
|
$user['pic'] = !empty($anchor) ? $anchor->pic : User::DefaultAvatar;
|
||
|
|
$user['name'] = !empty($anchor) ? $anchor->name : '未获取';
|
||
|
|
}else{
|
||
|
|
$member = MerchantMembers::where('mch_id',$merchant_id)->where('admin_id',$value->admin_id)->first();
|
||
|
|
$user['pic'] = !empty($member) ? $member->avatar : User::DefaultAvatar;
|
||
|
|
$user['name'] = !empty($member) ? $member->name : '未获取';
|
||
|
|
}
|
||
|
|
$value->operator = $user;
|
||
|
|
}
|
||
|
|
return $this->success('ok',$logs);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 修改匹配服务记录(同步生成用户备注)
|
||
|
|
public function updateMatchLogs(Request $request,$id){
|
||
|
|
try {
|
||
|
|
$log = MatchLog::where('id',$id)->first();
|
||
|
|
if(!$log) return $this->failure('匹配记录不存在');
|
||
|
|
$desc = TouristOrder::where('id',$log->m_order_id)->value('desc');
|
||
|
|
$admin_id = $request->merchant_admin_id;
|
||
|
|
if($admin_id){
|
||
|
|
$nickname = MerchantMembers::where('mch_id',$request->account_id)->where('admin_id',$admin_id)->value('name');
|
||
|
|
}else{
|
||
|
|
$nickname = Anchor::where('m_id',$request->account_id)->value('name');
|
||
|
|
}
|
||
|
|
$match_user = User::where('id',$log->user_id)->value('nickname');
|
||
|
|
$pattern = $request->pattern;
|
||
|
|
$status = $request->status;
|
||
|
|
$text = '';
|
||
|
|
$way = $pattern == 1 ? '平台推荐':'用户自选';
|
||
|
|
if($status == 0){
|
||
|
|
$result = '失败';
|
||
|
|
}elseif($status == 1){
|
||
|
|
$result = '成功';
|
||
|
|
}elseif($status == 2){
|
||
|
|
$result = '沟通中';
|
||
|
|
}
|
||
|
|
DB::beginTransaction();
|
||
|
|
if($pattern != $log->pattern){
|
||
|
|
$text = $text.'管理员:'.$nickname.'将匹配服务【'.$desc.'】匹配模式更改为'.$way. ' 匹配用户'.$match_user;
|
||
|
|
$log->pattern = $pattern;
|
||
|
|
}
|
||
|
|
if($status != $log->status){
|
||
|
|
$text = $text.' 管理员:'.$nickname.'将匹配服务【'.$desc.'】匹配结果更改为'.$result . ' 匹配用户'.$match_user;
|
||
|
|
$log->status = $status;
|
||
|
|
}
|
||
|
|
$log->save();
|
||
|
|
$user_id = $this->matchFulinkUser($log->order->account_id);
|
||
|
|
if($user_id){
|
||
|
|
$maker_user_id = 0;//福恋操作人id
|
||
|
|
$admin = !empty($admin_id) ? MerchantAdmins::find($admin_id) : MerchantAccount::find($request->account_id);
|
||
|
|
$maker_user_id = User::where('mobile',$admin->mobile)->value('id');
|
||
|
|
$maker_user_id = $maker_user_id ?? 0;
|
||
|
|
if($text){
|
||
|
|
$this->createClientComment($user_id,$maker_user_id,$text);
|
||
|
|
}
|
||
|
|
if($status == 1){//匹配成功后:用户状态修改为恋爱中
|
||
|
|
UserInfo::updateOrCreate(['user_id'=>$user_id],['emotional_state'=>'loving']);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
DB::commit();
|
||
|
|
return $this->success('ok');
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
DB::rollBack();
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//修改匹配订单开始状态
|
||
|
|
public function updateMatchOrder(Request $request,$order_id){
|
||
|
|
try {
|
||
|
|
$is_start = $request->is_start ?? 1;
|
||
|
|
$admin_id = $request->merchant_admin_id??0;
|
||
|
|
DB::beginTransaction();
|
||
|
|
MOrderFollow::updateOrCreate(['order_id'=>$order_id,'result'=>'订单状态修改'],
|
||
|
|
['is_start'=>$is_start,'merchant_id'=>$request->account_id,'admin_id'=>$admin_id]);
|
||
|
|
if($admin_id){
|
||
|
|
$admin = MerchantAdmins::find($admin_id);
|
||
|
|
$nickname = MerchantMembers::where(['mch_id'=>$request->account_id,'admin_id'=>$admin_id])->value('name');
|
||
|
|
}else{
|
||
|
|
$nickname = Anchor::where('m_id',$request->account_id)->value('name');
|
||
|
|
}
|
||
|
|
$maker_user_id = 0;//福恋操作人id
|
||
|
|
$admin = !empty($admin_id) ? MerchantAdmins::find($admin_id) : MerchantAccount::find($request->account_id);
|
||
|
|
$maker_user_id = User::where('mobile',$admin->mobile)->value('id');
|
||
|
|
$maker_user_id = $maker_user_id ?? 0;
|
||
|
|
$order = TouristOrder::where('id',$order_id)->first();
|
||
|
|
$user_id = $this->matchFulinkUser($order->account_id);
|
||
|
|
if($is_start == 0){
|
||
|
|
$status = '未开始';
|
||
|
|
}elseif($is_start == 1){
|
||
|
|
$status = '已开始';
|
||
|
|
}else{
|
||
|
|
$status = '已结束';
|
||
|
|
}
|
||
|
|
$comment = '管理员'.$nickname.'将匹配服务订单【'.$order->desc.'】状态修改为:'.$status;
|
||
|
|
$this->createClientComment($user_id,$maker_user_id,$comment);
|
||
|
|
DB::commit();
|
||
|
|
return $this->success('ok');
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
DB::rollBack();
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function createClientComment($user_id,$admin_id,$comment){
|
||
|
|
if(!$user_id) return;
|
||
|
|
ClientComment::create([
|
||
|
|
'user_id'=>$user_id,
|
||
|
|
'maker_user_id'=>$admin_id,
|
||
|
|
'type'=>'mobile',
|
||
|
|
'comment'=>$comment,
|
||
|
|
'pics'=>null,
|
||
|
|
]);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
//搜索匹配用户
|
||
|
|
public function searchAdminUser(Request $request){
|
||
|
|
$keyword = trim($request->keyword);
|
||
|
|
if(!$keyword)
|
||
|
|
return $this->failure('请输入搜索关键词');
|
||
|
|
$users = User::where(function($sql) use($keyword){
|
||
|
|
$sql->where('name', 'like', '%'.$keyword.'%')
|
||
|
|
->orWhere('id', $keyword)
|
||
|
|
->orWhere('mobile', 'like', '%'.$keyword.'%')
|
||
|
|
->orWhere('nickname', 'like', '%'.$keyword.'%');
|
||
|
|
});
|
||
|
|
$users = $users->orderBy('id','desc')->paginate();
|
||
|
|
return $this->success('ok',$users);
|
||
|
|
}
|
||
|
|
|
||
|
|
//增加服务人员
|
||
|
|
public function addServiceRole(Request $request,$order_id){
|
||
|
|
try {
|
||
|
|
$order = TouristOrder::find($order_id);
|
||
|
|
if(!$order) return $this->failure('订单不存在');
|
||
|
|
$role_id = $request->role_id;
|
||
|
|
$role_name = ServiceRole::where('id',$role_id)->value('name');
|
||
|
|
$admin_id = $request->merchant_admin_id??0;
|
||
|
|
$exists = ServiceRoleOrder::where(['role_id'=>$role_id,'m_order_id'=>$order_id,'admin_id'=>$admin_id])->first();
|
||
|
|
if($exists) return $this->failure('您已经是该订单的'.$role_name.',请勿重复加入');
|
||
|
|
$user_id = $this->matchFulinkUser($order->account_id);
|
||
|
|
$maker_user_id = 0;
|
||
|
|
$nickname = '未获取';
|
||
|
|
if($admin_id){
|
||
|
|
$admin = MerchantAdmins::find($admin_id);
|
||
|
|
$nickname = User::where('mobile',$admin->mobile)->value('nickname');
|
||
|
|
}else{
|
||
|
|
$nickname = Anchor::where('m_id',$request->account_id)->value('name');
|
||
|
|
}
|
||
|
|
$text = $nickname.'作为【'.$role_name.'】参与服务';
|
||
|
|
DB::beginTransaction();
|
||
|
|
ServiceRoleOrder::create([
|
||
|
|
'role_id'=>$role_id,
|
||
|
|
'm_order_id'=>$order_id,
|
||
|
|
'admin_id'=>$admin_id,
|
||
|
|
]);
|
||
|
|
$this->createClientComment($user_id,$maker_user_id,$text);
|
||
|
|
MOrderFollow::create([
|
||
|
|
'order_id'=>$order_id,
|
||
|
|
'merchant_id'=>$request->account_id,
|
||
|
|
'admin_id'=>$request->merchant_admin_id,
|
||
|
|
'content'=>$text,
|
||
|
|
]);
|
||
|
|
DB::commit();
|
||
|
|
return $this->success('ok');
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
DB::rollBack();
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
//服务人员列表
|
||
|
|
public function serviceRoles(Request $request,$order_id){
|
||
|
|
$m_id = $request->account_id;
|
||
|
|
$order = TouristOrder::find($order_id);
|
||
|
|
if(!$order) return $this->failure('订单不存在');
|
||
|
|
$roles = ServiceRole::select('id','name')->get();
|
||
|
|
$result = ServiceRoleOrder::with('role:id,name')->where('m_order_id',$order_id)->whereHas('role',function($sql){
|
||
|
|
$sql->orderBy('role_id','desc')->orderBy('id','desc');
|
||
|
|
})->get();
|
||
|
|
foreach ($result as $key => $value) {
|
||
|
|
if($value->admin_id){
|
||
|
|
$value->role->nickname = MerchantMembers::where(['mch_id'=>$m_id,'admin_id'=>$value->admin_id])->value('name');
|
||
|
|
}else{
|
||
|
|
$value->role->nickname = Anchor::where('m_id',$m_id)->value('name');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return $this->success('ok',compact('result','roles'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function addTest(Request $request){
|
||
|
|
$insert[0]['name']='客服';
|
||
|
|
$insert[0]['status']=1;
|
||
|
|
$insert[0]['created_at']=date('Y-m-d H:i:s');
|
||
|
|
$insert[0]['updated_at']=date('Y-m-d H:i:s');
|
||
|
|
$insert[1]['name']='情感顾问';
|
||
|
|
$insert[1]['status']=1;
|
||
|
|
$insert[1]['created_at']=date('Y-m-d H:i:s');
|
||
|
|
$insert[1]['updated_at']=date('Y-m-d H:i:s');
|
||
|
|
$insert[2]['name']='咨询老师';
|
||
|
|
$insert[2]['status']=1;
|
||
|
|
$insert[2]['created_at']=date('Y-m-d H:i:s');
|
||
|
|
$insert[2]['updated_at']=date('Y-m-d H:i:s');
|
||
|
|
ServiceRole::insert($insert);
|
||
|
|
}
|
||
|
|
}
|