671 lines
29 KiB
PHP
671 lines
29 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Server\H5;
|
|
|
|
use App\Models\Server\MerchantUser;
|
|
use App\Models\Server\MerchantUserPhoto;
|
|
use App\Models\Server\MerchantUserProfile;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\MerchantUsers;
|
|
use App\Models\IdentityAuthorization;
|
|
use App\Models\ProfileCourtship;
|
|
use App\Models\User;
|
|
use Illuminate\Container\Container as App;
|
|
use App\Repositories\Eloquent\SmsRepository as Sms;
|
|
use App\Models\UnionUser;
|
|
use App\Models\ProfilePhoto;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
class MakeFriendsController extends Controller
|
|
{
|
|
/**
|
|
* 增加用户信息
|
|
* @param Request $Request
|
|
* @return JsonResponse|string
|
|
*/
|
|
public function addUser(Request $request)
|
|
{
|
|
try {
|
|
$merchant_user_id = $request->merchant_user_id;
|
|
$merchant_id = $request->merchant_id;
|
|
$mobile = $request->mobile;
|
|
if(!$mobile){
|
|
return $this->failure('手机号不能为空');
|
|
}
|
|
$merchant_user = MerchantUsers::where('id', $merchant_user_id)->first();
|
|
if ($merchant_user) {
|
|
$exist = IdentityAuthorization::where('m_user_id', $merchant_user->id)->where('m_id', $merchant_id)->exists();
|
|
if ($exist) return $this->failure('该用户已添加');
|
|
}
|
|
$nickname = $request->nickname;
|
|
$pic = $request->pic;
|
|
$sex = $request->sex;
|
|
$province = $request->province;
|
|
$city = $request->city;
|
|
$birthday = $request->birthday;
|
|
$belief = $request->belief;
|
|
$state = $request->state;
|
|
$ideal_mate = $request->ideal_mate;
|
|
$stature = $request->stature;
|
|
$weight = $request->weight;
|
|
$resident_province = $request->resident_province;
|
|
$resident_city = $request->resident_city;
|
|
$income = $request->income;
|
|
$degree = $request->degree;
|
|
$industry_sub = $request->industry_sub;
|
|
$industry = $request->industry;
|
|
$age = $this->getAge($birthday);
|
|
$introduction = $request->introduction;
|
|
$interest_hobby = $request->interest_hobby;
|
|
$mate_conditon = $request->mate_conditon;
|
|
$rand_str = $this->randString(8);
|
|
$photos = $request->photos;
|
|
|
|
\DB::beginTransaction();
|
|
if (!$merchant_user) {
|
|
$merchant_user = new MerchantUsers();
|
|
$merchant_user->mobile = $mobile;
|
|
$merchant_user->rand_str = $rand_str;
|
|
$merchant_user->nickname = $nickname;
|
|
$merchant_user->sex = $sex;
|
|
$merchant_user->city = $city;
|
|
$merchant_user->pic = $pic;
|
|
} else {
|
|
$merchant_user->nickname = $nickname;
|
|
$merchant_user->sex = $sex;
|
|
$merchant_user->city = $city;
|
|
$merchant_user->pic = $pic;
|
|
}
|
|
$UnionUser = UnionUser::where('mobile', $mobile)->first();
|
|
if (!$UnionUser) {
|
|
$UnionUser = new UnionUser;
|
|
$UnionUser->mobile = $mobile;
|
|
$UnionUser->source = 'SPA';
|
|
$UnionUser->save();
|
|
}
|
|
$user = User::where('mobile', $mobile)->first();
|
|
if (!$user) {
|
|
$user = new User();
|
|
$user->regist_channel = 'sass';
|
|
$user->hidden_profile = 'ALLSEX';
|
|
$user->can_be_found = 0;
|
|
}
|
|
$user->industry_sub = $industry_sub;
|
|
$user->industry = $industry;
|
|
$user->nickname = $nickname;
|
|
$user->uuid = $UnionUser->id;
|
|
$user->sex = $sex;
|
|
$user->age = $age;
|
|
$user->photo = $pic;
|
|
$user->mobile = $mobile;
|
|
$user->belief = $belief;
|
|
$user->save();
|
|
$merchant_user->uuid = $UnionUser->id;
|
|
$merchant_user->user_id = $user->id;
|
|
$merchant_user->save();
|
|
$IdentityAuthorization = new IdentityAuthorization();
|
|
$IdentityAuthorization->m_user_id = $merchant_user->id;
|
|
$IdentityAuthorization->m_id = $merchant_id;
|
|
$IdentityAuthorization->from_openid = $request->from_openid ?: null;
|
|
$IdentityAuthorization->save();
|
|
$profile = ProfileCourtship::where('user_id', $user->id)->first();
|
|
if (!$profile) {
|
|
$profile = new ProfileCourtship();
|
|
$profile->user_id = $user->id;
|
|
}
|
|
$profile->belief = $belief;
|
|
$profile->birthday = $birthday;
|
|
$profile->sex = $sex;
|
|
$profile->age = $age;
|
|
$profile->city = $city;
|
|
$profile->ideal_mate = $ideal_mate;
|
|
$profile->degree = $degree;
|
|
$profile->province = $province;
|
|
$profile->income = $income;
|
|
$profile->resident_province = $resident_province;
|
|
$profile->resident_city = $resident_city;
|
|
$profile->introduction = $introduction;
|
|
$profile->state = $state;
|
|
$profile->stature = $stature;
|
|
$profile->weight = $weight;
|
|
$profile->interest_hobby = $interest_hobby;
|
|
$profile->mate_conditon = json_encode($mate_conditon);
|
|
$profile->save();
|
|
if (count($photos)) {
|
|
foreach ($photos as $photo) {
|
|
if (empty($photo)) {
|
|
continue;
|
|
}
|
|
$photo_obj = new ProfilePhoto();
|
|
$photo_obj->photo = $photo;
|
|
$photo_obj->user_id = $user->id;
|
|
$photo_obj->dateline = date('Y-m-d');
|
|
$photo_obj->save();
|
|
}
|
|
}
|
|
\DB::commit();
|
|
return $this->success('ok', ['status' => 1]);
|
|
} catch (\Exception $e) {
|
|
//回滚事务
|
|
\DB::rollback();
|
|
$this->getError($e);
|
|
return $this->failure($e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 更新用户信息
|
|
* @param Request $Request
|
|
* @return JsonResponse|string
|
|
*/
|
|
public function updateUser(Request $request)
|
|
{
|
|
try {
|
|
$id = $request->merchant_user_id;
|
|
$merchant_user = MerchantUsers::where('id', $id)->first();
|
|
if (!$merchant_user) return $this->failure('该用户不存在');
|
|
|
|
$nickname = $request->nickname;
|
|
$pic = $request->pic;
|
|
$sex = $request->sex;
|
|
$province = $request->province;
|
|
$city = $request->city;
|
|
$birthday = $request->birthday;
|
|
$belief = $request->belief;
|
|
$state = $request->state;
|
|
$stature = $request->stature;
|
|
$weight = $request->weight;
|
|
$ideal_mate = $request->ideal_mate;
|
|
$resident_city = $request->resident_city;
|
|
$industry_sub = $request->industry_sub;
|
|
$industry = $request->industry;
|
|
$resident_province = $request->resident_province;
|
|
$income = $request->income;
|
|
$degree = $request->degree;
|
|
$introduction = $request->introduction;
|
|
$interest_hobby = $request->interest_hobby;
|
|
$mate_conditon = $request->mate_conditon;
|
|
$photos = $request->photos;
|
|
|
|
\DB::beginTransaction();
|
|
if ($merchant_user->user_id) {
|
|
$user = User::where('id', $merchant_user->user_id)->first();
|
|
} else {
|
|
$user = User::where('mobile', $request->mobile)->first();
|
|
if ($merchant_user->user_id != $user->id) {
|
|
$merchant_user->user_id = $user->id;
|
|
}
|
|
|
|
}
|
|
$profile = ProfileCourtship::where('user_id', $user->id)->first();
|
|
|
|
if ($nickname) {
|
|
$user->nickname = $nickname;
|
|
$merchant_user->nickname = $nickname;
|
|
}
|
|
if ($pic) {
|
|
$user->photo = $pic;
|
|
$merchant_user->pic = $pic;
|
|
}
|
|
if ($sex) {
|
|
$user->sex = $sex;
|
|
$merchant_user->sex = $sex;
|
|
$profile->sex = $sex;
|
|
}
|
|
if ($city) {
|
|
$merchant_user->city = $city;
|
|
$profile->city = $city;
|
|
}
|
|
if ($mate_conditon) {
|
|
$profile->mate_conditon = json_encode($mate_conditon);
|
|
}
|
|
if ($birthday) {
|
|
$profile->birthday = $birthday;
|
|
$age = $this->getAge($birthday);
|
|
$profile->age = $age;
|
|
$user->age = $age;
|
|
}
|
|
if ($photos) {
|
|
ProfilePhoto::where('user_id', $user->id)->delete();
|
|
foreach ($photos as $photo) {
|
|
if (empty($photo)) {
|
|
continue;
|
|
}
|
|
$photo_obj = new ProfilePhoto();
|
|
$photo_obj->photo = $photo;
|
|
$photo_obj->user_id = $user->id;
|
|
$photo_obj->dateline = date('Y-m-d');
|
|
$photo_obj->save();
|
|
}
|
|
}
|
|
$IdentityAuthorization = IdentityAuthorization::where('m_user_id', $merchant_user->id)->exists();
|
|
if (!$IdentityAuthorization) {
|
|
$IdentityAuthorization = new IdentityAuthorization();
|
|
$IdentityAuthorization->m_user_id = $merchant_user->id;
|
|
$IdentityAuthorization->m_id = $request->merchant_id;
|
|
$IdentityAuthorization->from_openid = $request->from_openid ?: null;
|
|
$IdentityAuthorization->save();
|
|
}
|
|
$user->industry_sub = $industry_sub ?? $user->industry_sub;
|
|
$user->industry = $industry ?? $user->industry;
|
|
$profile->province = $province ?? $profile->province;
|
|
$profile->belief = $belief ?? $profile->belief;
|
|
$profile->state = $state ?? $profile->state;
|
|
$profile->degree = $degree ?? $profile->degree;
|
|
$profile->ideal_mate = $ideal_mate ?? $profile->ideal_mate;
|
|
$profile->stature = $stature ?? $profile->stature;
|
|
$profile->weight = $weight ?? $profile->weight;
|
|
$profile->resident_province = $resident_province ?? $profile->resident_province;
|
|
$profile->resident_city = $resident_city ?? $profile->resident_city;
|
|
$profile->income = $income ?? $profile->income;
|
|
$profile->introduction = $introduction ?? $profile->introduction;
|
|
$profile->interest_hobby = $interest_hobby ?? $profile->interest_hobby;
|
|
$user->save();
|
|
$merchant_user->save();
|
|
$profile->save();
|
|
\DB::commit();
|
|
return $this->success('ok', ['status' => 1]);
|
|
}catch (\Exception $e){
|
|
\DB::rollback();
|
|
$this->getError($e);
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 用户详情
|
|
* @param Request $request
|
|
* @return JsonResponse|string
|
|
*/
|
|
public function userInfo(Request $request)
|
|
{
|
|
try {
|
|
$id = $request->id ?? $request->merchant_user_id;
|
|
$m_id = $request->merchant_id;
|
|
$key = 'MakeFriend_S';
|
|
if ($m_id == 491) {
|
|
Redis::zincrby($key, 1, $id);
|
|
}else {
|
|
Redis::zincrby($key, 1, $m_id.'-'.$id);
|
|
}
|
|
$merchant_user = MerchantUsers::select('id', 'user_id', 'pic','mobile', 'nickname', 'created_at')->where('id', $id)
|
|
->first();
|
|
$profile = MerchantUserProfile::firstOrCreate(['m_id'=>$m_id, 'user_id' => $id]);
|
|
$merchant_user->info = $profile;
|
|
$merchant_user->info->industry_sub = $profile->industry_sub;
|
|
$merchant_user->info->mobile = substr_replace($merchant_user->mobile, '****', 3, 4);
|
|
$merchant_user->info->industry = $profile->industry;
|
|
$merchant_user->info->age = $this->getAge($profile->birthday);
|
|
$merchant_user->info->mate_conditon = json_decode($profile->mate_conditon);
|
|
// 生活照
|
|
$merchant_user->photos = MerchantUserPhoto::where(['m_id'=>$m_id, 'user_id'=>$id])->pluck('photo');
|
|
$merchant_user->pv = Redis::zscore($key, $id) ? Redis::zscore($key, $id) : 0;
|
|
return $this->success('ok', $merchant_user);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 根据手机号查询是否是福恋用户
|
|
* @param Request $request
|
|
* @return JsonResponse|string
|
|
*/
|
|
public function chack_user(Request $request)
|
|
{
|
|
try {
|
|
//检查验证码
|
|
$sms = new Sms(new App);
|
|
$result = $sms->check($request->mobile, $request->code);
|
|
if ($result) {
|
|
switch ($result) {
|
|
case '请填写验证码':
|
|
return $this->resp($result, ['status' => 7, 'message' => '请填写验证码']);
|
|
break;
|
|
case '验证码有误':
|
|
return $this->resp($result, ['status' => 8, 'message' => '验证码有误']);
|
|
break;
|
|
case '验证码过期':
|
|
return $this->resp($result, ['status' => 9, 'message' => '验证码过期']);
|
|
break;
|
|
case '验证码已使用':
|
|
return $this->resp($result, ['status' => 10, 'message' => '验证码已使用']);
|
|
break;
|
|
default:
|
|
# code...
|
|
break;
|
|
}
|
|
}
|
|
$mobile = $request->mobile;
|
|
$user = User::select('id', 'photo as pic', 'nickname', 'industry_sub', 'industry', 'hidden_profile', 'created_at')
|
|
->where('mobile', $mobile)
|
|
->first();
|
|
if (!$user) return $this->resp('fail', ['status' => 1]);
|
|
$merchant_user_mobile = MerchantUser::where('mobile', $mobile)
|
|
->first();
|
|
if($merchant_user_mobile){
|
|
return $this->failure('手机号已被另一帐号绑定');
|
|
}
|
|
$merchant_user_id = $request->merchant_user_id;
|
|
$merchant_user = MerchantUser::where('id', $merchant_user_id)
|
|
->first();
|
|
$merchant_user->mobile = $mobile;
|
|
$merchant_user->user_id = $user->id;
|
|
$merchant_user->save();
|
|
$user->info = $user->sass_profileCourtship;
|
|
$user->info->industry_sub = $user->industry_sub;
|
|
$user->info->industry = $user->industry;
|
|
$user->info->mobile = $mobile;
|
|
$user->info->age = $this->getAge($user->sass_profileCourtship->birthday);
|
|
$user->info->mate_conditon = json_decode($user->info->mate_conditon);
|
|
$user->photos = ProfilePhoto::where('user_id', $user->id)->pluck('photo');
|
|
unset($user->sass_profileCourtship);
|
|
return $this->success('ok', $user);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 用户列表
|
|
* @param Request $Request
|
|
* @return JsonResponse|string
|
|
*/
|
|
public function userList(Request $request)
|
|
{
|
|
try {
|
|
$m_id = $request->merchant_id;
|
|
$ids = IdentityAuthorization::where('m_id', $m_id)->orderBy('id', 'desc')->pluck('m_user_id');
|
|
$fix_id = [];
|
|
//资料完整分大于60 才在saas h5单身广场列表
|
|
foreach ($ids as $key => $id) {
|
|
// $score = $this->completeInfoScore($id);
|
|
$score = $this->completeInfoScoreV2($id, $m_id);
|
|
if ($score >= 60) {
|
|
$fix_id [] = $id;
|
|
}
|
|
}
|
|
$users = MerchantUsers::select('id', 'user_id', 'pic', 'nickname', 'created_at')->whereIn('id', $fix_id)->paginate();
|
|
foreach ($users as $value) {
|
|
$profile = MerchantUserProfile::where(['m_id'=>$m_id, 'user_id'=>$value->id])->first();
|
|
$value->info = $profile;
|
|
$value->info->mobile = substr_replace($value->mobile, '****', 3, 4);
|
|
$value->info->age = $this->getAge($profile->birthday);
|
|
$value->info->mate_conditon = json_decode($profile->mate_conditon);
|
|
$value->photos = MerchantUserPhoto::where(['m_id'=>$m_id, 'user_id'=>$value->id])->pluck('photo');
|
|
}
|
|
return $this->success('ok', $users);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|
}
|
|
}
|
|
|
|
public function completeInfoScoreV2($user_id, $m_id)
|
|
{
|
|
try {
|
|
$total_score = 0;
|
|
$user = MerchantUsers::find($user_id);
|
|
$profile = MerchantUserProfile::where(['m_id'=>$m_id, 'user_id'=>$user_id])->first();
|
|
if (!$user || !$profile) return $total_score;
|
|
$keys = ['belief', 'birthday', 'degree', 'ideal_mate', 'income', 'industry', 'industry_sub', 'interest_hobby', 'introduction', 'province', 'city', 'mate_conditon',
|
|
'state', 'stature', 'weight', 'sex'];
|
|
foreach ($keys as $key) {
|
|
if ($profile->$key) $total_score += 5;
|
|
}
|
|
$photos = MerchantUserPhoto::where(['m_id'=>$m_id, 'user_id'=>$user_id])->first();
|
|
if ($photos) $total_score += 5;//生活照
|
|
return $total_score;
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 计算信息完整度
|
|
* @param $m_user_id
|
|
*/
|
|
public function completeInfoScore($m_user_id)
|
|
{
|
|
try {
|
|
$user = MerchantUsers::find($m_user_id);
|
|
if (!$user) {
|
|
return 0;
|
|
}
|
|
$total_score = 0;
|
|
if (!$user || !$user->user || !$user->user->sass_profileCourtship) return $total_score;
|
|
$photos = ProfilePhoto::where('user_id', $user->user_id)->first();
|
|
if ($user->user->sass_profileCourtship->belief) $total_score += 5;
|
|
if ($user->user->sass_profileCourtship->birthday) $total_score += 5;
|
|
// if($user->user->sass_profileCourtship->city) $totle_score += 5;
|
|
if ($user->user->sass_profileCourtship->degree) $total_score += 5;
|
|
if ($user->user->sass_profileCourtship->ideal_mate) $total_score += 5;
|
|
if ($user->user->sass_profileCourtship->income) $total_score += 5;
|
|
if ($user->user->industry) $total_score += 5;
|
|
if ($user->user->industry_sub) $total_score += 5;
|
|
if ($user->user->sass_profileCourtship->interest_hobby) $total_score += 5;
|
|
if ($user->user->sass_profileCourtship->introduction) $total_score += 5;
|
|
if ($photos) $total_score += 5;//生活照
|
|
if ($user->user->sass_profileCourtship->province) $total_score += 5;
|
|
if ($user->user->sass_profileCourtship->mate_conditon) $total_score += 25;
|
|
if ($user->user->sass_profileCourtship->state) $total_score += 5;
|
|
if ($user->user->sass_profileCourtship->stature) $total_score += 5;
|
|
if ($user->user->sass_profileCourtship->weight) $total_score += 5;
|
|
if ($user->user->sass_profileCourtship->sex) $total_score += 5;
|
|
return $total_score;
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 用户头像
|
|
* @param Request $Request
|
|
* @return JsonResponse|string
|
|
*/
|
|
public function userPhotos(Request $request)
|
|
{
|
|
try{
|
|
$m_id = $request->merchant_id;
|
|
$num = $request->num ?? 4;
|
|
$ids = IdentityAuthorization::where('m_id', $m_id)->orderBy('id', 'desc')->pluck('m_user_id');
|
|
$fix_id = [];
|
|
//资料完整分大于60 才在saas h5单身广场列表
|
|
foreach ($ids as $key => $id) {
|
|
$score = $this->completeInfoScore($id);
|
|
if ($score >= 60) {
|
|
$fix_id [] = $id;
|
|
}
|
|
}
|
|
$users = MerchantUsers::select('id', 'user_id', 'pic', 'nickname', 'created_at')->whereIn('id', $fix_id)->orderByRaw("RAND()")->limit(4)->get();
|
|
foreach ($users as $key => $value) {
|
|
if (!$value->user) {
|
|
$value->info = [];
|
|
unset($value->user);
|
|
continue;
|
|
}
|
|
if (!$value->pic) {
|
|
$value->pic = $value->user->photo ?: $value->user->circle_avatar;
|
|
}
|
|
$value->m_user_id = $value->id;
|
|
unset($value->user);
|
|
}
|
|
return $this->success('ok', $users);
|
|
// $result = IdentityAuthorization::select('m_user_id')->where('m_id',$m_id)->orderByRaw("RAND()")->limit( $num)->get();
|
|
// foreach ($result as $key => $value) {
|
|
// $value->pic = $value->merchant_user->pic??User::DefaultAvatar;
|
|
// unset($value->merchant_user);
|
|
// }
|
|
// return $this->success('ok',$result);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 授权同步用户数据
|
|
* @param Request $Request
|
|
* @return JsonResponse|string
|
|
*/
|
|
public function SynchronousData(Request $request)
|
|
{
|
|
try {
|
|
$m_id = $request->merchant_id;
|
|
$merchant_user_id = $request->merchant_user_id;
|
|
$result = IdentityAuthorization::where('m_user_id', $merchant_user_id)->where('m_id', $m_id)->exists();
|
|
if ($result)
|
|
return $this->failure('您已经授权过此商家了');
|
|
$obj = new IdentityAuthorization();
|
|
$obj->m_user_id = $merchant_user_id;
|
|
$obj->m_id = $m_id;
|
|
$obj->save();
|
|
// $merchant_user = MerchantUsers::select('id', 'user_id', 'pic', 'nickname', 'created_at')->where('id', $merchant_user_id)->first();
|
|
// $merchant_user->info = $merchant_user->user->sass_profileCourtship;
|
|
// $merchant_user->info->industry_sub = $merchant_user->user->industry_sub;
|
|
// $merchant_user->info->industry = $merchant_user->user->industry;
|
|
// $merchant_user->info->mobile = $merchant_user->user->mobile;
|
|
// $merchant_user->info->age = $this->getAge($merchant_user->user->sass_profileCourtship->birthday);
|
|
// $merchant_user->info->mate_conditon = json_decode($merchant_user->info->mate_conditon);
|
|
// // 生活照
|
|
// $merchant_user->photos = ProfilePhoto::where('user_id', $merchant_user->user->id)->pluck('photo');
|
|
// unset($merchant_user->user);
|
|
return $this->success('ok');
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 用户资料
|
|
* @param Request $request
|
|
*/
|
|
public function userProfile(Request $request)
|
|
{
|
|
$m_id = $request->merchant_id;
|
|
$merchant_user_id = $request->merchant_user_id;
|
|
$user = MerchantUser::find($merchant_user_id);
|
|
$profile = MerchantUserProfile::firstOrCreate(["m_id"=>$m_id, 'user_id'=>$merchant_user_id]);
|
|
$profile = MerchantUserProfile::find($profile->id);
|
|
$profile->pic = $user->pic;
|
|
$profile->nickname = $user->nickname;
|
|
$profile->mobile = $user->mobile;
|
|
$photos = MerchantUserPhoto::where(["m_id"=>$m_id, 'user_id'=>$merchant_user_id])->get();
|
|
$photo_arr = [];
|
|
foreach ($photos as $photo) {
|
|
$photo_arr[] = $photo->photo;
|
|
}
|
|
$profile->photos = $photo_arr;
|
|
$profile->mate_conditon = json_decode($profile->mate_conditon);
|
|
return $this->success('ok', $profile);
|
|
}
|
|
|
|
public function updateUserProfile(Request $request)
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
$m_id = $request->merchant_id;
|
|
$merchant_user_id = $request->merchant_user_id;
|
|
$user = MerchantUser::find($merchant_user_id);
|
|
$profile = MerchantUserProfile::where(["m_id"=>$m_id, 'user_id'=>$merchant_user_id])->first();
|
|
if ($request->input('pic') && $user->pic != $request->pic) {
|
|
$user->pic = $request->pic;
|
|
}
|
|
if ($request->input('nickname') && $user->nickname != $request->nickname) {
|
|
$user->nickname = $request->nickname;
|
|
}
|
|
if ($request->input('mobile') && $user->mobile != $request->mobile) {
|
|
$user->mobile = $request->mobile;
|
|
$user_exists = MerchantUser::where('mobile', $request->mobile)->where('id', '<>', $user->id)->first();
|
|
if ($user_exists) {
|
|
$user_exists->update(['mobile'=>null]);
|
|
}
|
|
}
|
|
if ($request->input('birthday') && $profile->birthday != $request->birthday) {
|
|
$profile->birthday = $request->birthday;
|
|
}
|
|
if ($request->input('sex') && $profile->sex != $request->sex) {
|
|
$profile->sex = $request->sex;
|
|
$user->sex = $request->sex;
|
|
}
|
|
if ($request->input('province') && $profile->province != $request->province) {
|
|
$profile->province = $request->province;
|
|
}
|
|
if ($request->input('city') && $profile->city != $request->city) {
|
|
$profile->city = $request->city;
|
|
}
|
|
if ($request->input('state') && $profile->state != $request->state) {
|
|
$profile->state = $request->state;
|
|
}
|
|
if ($request->input('belief') && $profile->belief != $request->belief) {
|
|
$profile->belief = $request->belief;
|
|
}
|
|
if ($request->input('stature') && $profile->stature != $request->stature) {
|
|
$profile->stature = $request->stature;
|
|
}
|
|
if ($request->input('weight') && $profile->weight != $request->weight) {
|
|
$profile->weight = $request->weight;
|
|
}
|
|
if ($request->input('resident_province') && $profile->resident_province != $request->resident_province) {
|
|
$profile->resident_province = $request->resident_province;
|
|
}
|
|
if ($request->input('resident_city') && $profile->resident_city != $request->resident_city) {
|
|
$profile->resident_city = $request->resident_city;
|
|
}
|
|
if ($request->input('degree') && $profile->degree != $request->degree) {
|
|
$profile->degree = $request->degree;
|
|
}
|
|
if ($request->input('industry') && $profile->industry != $request->industry) {
|
|
$profile->industry = $request->industry;
|
|
}
|
|
if ($request->input('industry_sub') && $profile->industry_sub != $request->industry_sub) {
|
|
$profile->industry_sub = $request->industry_sub;
|
|
}
|
|
if ($request->input('income') && $profile->income != $request->income) {
|
|
$profile->income = $request->income;
|
|
}
|
|
if ($request->input('introduction') && $profile->introduction != $request->introduction) {
|
|
$profile->introduction = $request->introduction;
|
|
}
|
|
if ($request->input('interest_hobby') && $profile->interest_hobby != $request->interest_hobby) {
|
|
$profile->interest_hobby = $request->interest_hobby;
|
|
}
|
|
if ($request->input('mate_conditon') && json_encode($profile->mate_conditon) != $request->mate_conditon) {
|
|
$profile->mate_conditon = json_encode($request->mate_conditon);
|
|
}
|
|
if ($request->input('ideal_mate') && $profile->ideal_mate != $request->ideal_mate) {
|
|
$profile->ideal_mate = $request->ideal_mate;
|
|
//最后一项填完加入交友管理
|
|
IdentityAuthorization::firstOrCreate(['m_id'=>$m_id, 'm_user_id'=>$merchant_user_id]);
|
|
}
|
|
|
|
//图片
|
|
$photos = $request->input('photos',[]);
|
|
if (count($photos)) {
|
|
MerchantUserPhoto::where(['m_id'=>$m_id, 'user_id'=>$merchant_user_id])->delete();
|
|
foreach ($photos as $photo) {
|
|
MerchantUserPhoto::firstOrCreate(['m_id'=>$m_id, 'user_id'=>$merchant_user_id, 'photo'=>$photo]);
|
|
}
|
|
}
|
|
$user->save();
|
|
$profile->save();
|
|
DB::commit();
|
|
return $this->success('ok');
|
|
}catch (\Exception $e) {
|
|
DB::rollBack();
|
|
$this->getError($e);
|
|
return $this->failure();
|
|
}
|
|
}
|
|
|
|
}
|