1599 lines
68 KiB
PHP
1599 lines
68 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Server\H5;
|
||
|
||
use App\Contracts\UserContract;
|
||
use App\Facades\CommonUtilsService;
|
||
use App\Jobs\SyncOrderRemark;
|
||
use App\Model\Server\TencentFaceidLog;
|
||
use App\Models\AccessRecord;
|
||
use App\Models\Appointment;
|
||
use App\Models\LinkingBlacklist;
|
||
use App\Models\MerchantUserImage;
|
||
use App\Models\SaasAppointment;
|
||
use App\Models\SaasMemberVipSpreadCarrier;
|
||
use App\Models\Server\AllianceMerchant;
|
||
use App\Models\Server\MerchantEvaluate;
|
||
use App\Models\Server\MerchantMembers;
|
||
use App\Models\Server\SaasAppointmentMember;
|
||
use App\Models\Server\SaasMemberBuyInfo;
|
||
use App\Models\Server\SaasMemberLevel;
|
||
use App\Models\SystemBlacklist;
|
||
use App\Models\UserInfo;
|
||
use App\Services\SaasVipService;
|
||
use Illuminate\Http\JsonResponse;
|
||
use Illuminate\Http\Request;
|
||
use App\Http\Controllers\Controller;
|
||
use App\Jobs\NewMerchantDefaultService;
|
||
use App\Models\CommunityActivity;
|
||
use App\Models\ConsultAccount;
|
||
use App\Models\Consultation;
|
||
use Illuminate\Support\Carbon;
|
||
use Illuminate\Support\Facades\Cache;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Illuminate\Support\Facades\Log;
|
||
use Illuminate\Support\Facades\Redis;
|
||
use App\Models\ConsultationRecords;
|
||
use App\Models\Course\Course;
|
||
use App\Models\Live\Anchor;
|
||
use Illuminate\Container\Container as App;
|
||
use App\Repositories\Eloquent\SmsRepository as Sms;
|
||
use App\Models\MEarningRules;
|
||
use App\Utils\Messenger as Messengers;
|
||
use App\Models\Message;
|
||
use App\Models\MerchantShop;
|
||
use App\Models\CoinLog;
|
||
use App\Models\Address;
|
||
use App\Models\QATest;
|
||
use App\Models\QATestRecord;
|
||
use App\Models\Server\MerchantAccount;
|
||
use App\Models\Server\MerchantUser;
|
||
use App\Models\Server\TouristOrder;
|
||
use App\Models\User;
|
||
use App\Models\Live\Viewer;
|
||
use App\Jobs\SendTemplateMsg;
|
||
use App\Jobs\StoreApproveWorthShare;
|
||
use App\Models\AnchorVideo;
|
||
use App\Models\ApproveHistory;
|
||
use App\Models\College;
|
||
use App\Models\IdentityAuthorization;
|
||
use App\Models\MEarning;
|
||
use App\Models\ProfileCourtship;
|
||
use App\Models\Server\MEarningAccount;
|
||
use App\Models\Server\MerchantInformation;
|
||
use App\Models\Wechat;
|
||
use App\Services\YDService;
|
||
use EasyWeChat\Factory;
|
||
use TencentCloud\Common\Credential;
|
||
use TencentCloud\Common\Exception\TencentCloudSDKException;
|
||
use TencentCloud\Common\Profile\ClientProfile;
|
||
use TencentCloud\Common\Profile\HttpProfile;
|
||
use TencentCloud\Faceid\V20180301\FaceidClient;
|
||
use TencentCloud\Faceid\V20180301\Models\GetEidResultRequest;
|
||
use TencentCloud\Faceid\V20180301\Models\GetEidTokenRequest;
|
||
|
||
class UserController extends Controller
|
||
{
|
||
protected $app;
|
||
protected $config;
|
||
protected $userCon;
|
||
public function __construct(UserContract $userCon){
|
||
$this->config = [
|
||
'app_id' => config('wechat.official_account.new.app_id'),
|
||
'secret' => config('wechat.official_account.new.secret'),
|
||
'token' => config('wechat.official_account.new.token'),
|
||
'aes_key' => config('wechat.official_account.new.aes_key')
|
||
];
|
||
$this->app = Factory::officialAccount($this->config);
|
||
$this->userCon = $userCon;
|
||
}
|
||
/**
|
||
* 个人中心-商户
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function BusinessInfo(Request $request)
|
||
{
|
||
try {
|
||
$Account = MerchantAccount::where('id', $request->merchant_id)->first();
|
||
if (!$Account) return $this->failure('未获取到商户信息!');
|
||
$anchor = Anchor::where('m_id', $Account->id)->first();
|
||
$member = array();
|
||
$info = [];
|
||
if ($anchor) {
|
||
$info['name'] = $anchor['name'];
|
||
$info['avatar'] = $anchor['pic'];
|
||
$info['designation'] = $anchor['designation'];
|
||
$info['introduction'] = $anchor['introduction'];
|
||
$info['type'] = $anchor->service_nature;
|
||
// $merchant = MerchantAccount::where('openid',$anchor_openid)->first();
|
||
if ($anchor->service_nature == 'team') {
|
||
$member = MerchantMembers::where('status',1)->where('mch_id',$request->merchant_id)
|
||
->get();
|
||
}
|
||
if ($anchor->service_nature == 'alliance') {
|
||
$alliance_merchant_count = AllianceMerchant::where('alliance_id',$request->merchant_id)
|
||
->where('audit_type',2)
|
||
->count();
|
||
if($alliance_merchant_count >= 1){
|
||
$info['has_alliance_member'] =1;
|
||
}else{
|
||
$info['has_alliance_member'] =0;
|
||
}
|
||
}
|
||
$info['qr_code'] = $Account['qr_code'];
|
||
$info['share_icon'] = $Account['share_icon'];
|
||
$info['share_title'] = $Account['share_title'];
|
||
$info['share_subtitle'] = $Account['share_subtitle'];
|
||
}
|
||
$data['member'] = $member;
|
||
$data['tabBarList'] = json_decode($Account->choose_tarbar, true) ?? [];
|
||
$data['info'] = $info;
|
||
$location_latitude = $Account->info ? $Account->info->location_latitude : null;
|
||
$location_longitude = $Account->info ? $Account->info->location_longitude : null;
|
||
$address = $Account->info ? $Account->info->address : null;
|
||
$data['location_longitude'] = $location_longitude;
|
||
$data['location_latitude'] = $location_latitude;
|
||
$data['address'] = $address;
|
||
return $this->success('ok', $data);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 分享联系我们
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function connectUs(Request $request)
|
||
{
|
||
// DB::enableQueryLog();
|
||
try {
|
||
$data = MerchantAccount::getRedisMerchant($request->merchant_id);
|
||
// $data = MerchantAccount::where('id', $request->merchant_id)->select('id', 'share_icon', 'mobile', 'share_subtitle', 'share_title', 'qr_code')->first();
|
||
if (!$data) return $this->failure('未获取到商户信息!');
|
||
$anchor = Anchor::where('m_id', $data->id)->first();
|
||
$data->name = $anchor->name ?? '匿名用户';
|
||
$data->make_friends = $data->info->make_friends ?? 0;
|
||
$data->avatar = $anchor->pic ? $anchor->pic : User::DefaultAvatar;
|
||
$data->designation = $anchor->designation ?? '暂无头衔';
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
$merchant_user = MerchantUser::where('id', $request->merchant_user_id)->first();
|
||
if (empty($merchant_user)) return $this->success('ok', $data);
|
||
if ($wechatUser) {
|
||
$openid = $wechatUser->getId();
|
||
} else {
|
||
$openid = $merchant_user->openid;
|
||
}
|
||
unset($data->info);
|
||
$data->openid = $openid;
|
||
if($merchant_user && empty($merchant_user->nickname)){
|
||
$rand_str = $this->randString(8);
|
||
$nickname = '用户'.$rand_str;
|
||
$merchant_user->nickname = $nickname;
|
||
$merchant_user->save();
|
||
}
|
||
$data->nickname = $merchant_user->nickname;
|
||
// Log::info(DB::getQueryLog());
|
||
|
||
return $this->success('ok', $data);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 服务 订单栏 是否展示
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function showInfo(Request $request)
|
||
{
|
||
try {
|
||
$merchant_id = $request->merchant_id;
|
||
$account = MerchantAccount::where('id', $merchant_id)->first();
|
||
if (!$account) return $this->failure('未获取到商户信息!');
|
||
$anchor = Anchor::where('m_id', $account->id)->first();
|
||
$show_order = [];
|
||
$show_service = [];
|
||
//是否有测试
|
||
// $is_show_test = QATest::where('merchant_id',$request->merchant_id)->where('status',1)->count();
|
||
$is_show_test = QATestRecord::where('merchant_id', $merchant_id)
|
||
->where('merchant_user_id', $request->merchant_user_id)
|
||
->count();
|
||
if ($anchor) {
|
||
//所有服务id
|
||
$service_ids = CommunityActivity::where('anchor_id', $anchor->id)
|
||
->where('type', 'business')->where('class', 'many')
|
||
->pluck('id')->toArray();
|
||
//所有活动id
|
||
$activity_ids = CommunityActivity::where('anchor_id', $anchor->id)
|
||
->where('type', 'business')->where('class', 'one')
|
||
->pluck('id')->toArray();
|
||
} else {
|
||
//所有服务id
|
||
$service_ids = CommunityActivity::where('merchant_id', $merchant_id)
|
||
->where('type', 'business')->where('class', 'many')
|
||
->pluck('id')->toArray();
|
||
//所有活动id
|
||
$activity_ids = CommunityActivity::where('merchant_id', $merchant_id)
|
||
->where('type', 'business')->where('class', 'one')
|
||
->pluck('id')->toArray();
|
||
}
|
||
|
||
//是否有订单
|
||
$is_show_service = TouristOrder::whereIn('pay_status', [1, 4])
|
||
->where('merchant_id', $request->merchant_id)
|
||
->where('type', 'community')->whereIn('type_id', $service_ids)
|
||
->where('account_id', $request->merchant_user_id)
|
||
->count();
|
||
$is_show_activity = TouristOrder::whereIn('pay_status', [1, 4])
|
||
->where('merchant_id', $request->merchant_id)
|
||
->where('type', 'community')
|
||
->whereIn('type_id', $activity_ids)
|
||
->where('account_id', $request->merchant_user_id)
|
||
->count();
|
||
$is_show_course = TouristOrder::whereIn('pay_status', [1, 4])
|
||
->where('merchant_id', $request->merchant_id)
|
||
->where('type', 'course')
|
||
->where('account_id', $request->merchant_user_id)
|
||
->count();
|
||
$is_show_consult = ConsultationRecords::where('pay_status', 1)
|
||
->where('merchant_id', $request->merchant_id)
|
||
->where('merchant_user_id', $request->merchant_user_id)
|
||
->count();
|
||
// $is_show_consult = TouristOrder::whereIn('pay_status',[1,4])->where('type','consult')->where('account_id',$request->merchant_user_id)->count();
|
||
$is_show_shop = TouristOrder::whereIn('pay_status', [1, 4])
|
||
->where('type', 'shop')
|
||
->where('merchant_id', $request->merchant_id)
|
||
->where('account_id', $request->merchant_user_id)
|
||
->count();
|
||
$is_show_evaluate = TouristOrder::whereIn('pay_status', [1, 4])
|
||
->where('type', 'evaluate')
|
||
->where('merchant_id', $request->merchant_id)
|
||
->where('account_id', $request->merchant_user_id)
|
||
->count();
|
||
|
||
$show_order['is_show_test'] = $is_show_test > 0 ? 1 : 0;
|
||
$show_order['is_show_service'] = $is_show_service > 0 ? 1 : 0;
|
||
$show_order['is_show_activity'] = $is_show_activity > 0 ? 1 : 0;
|
||
$show_order['is_show_course'] = $is_show_course > 0 ? 1 : 0;
|
||
$show_order['is_show_consult'] = $is_show_consult > 0 ? 1 : 0;
|
||
$show_order['is_show_shop'] = $is_show_shop > 0 ? 1 : 0;
|
||
$show_order['is_show_evaluate'] = $is_show_evaluate > 0 ? 1 : 0;
|
||
|
||
$statuses = $account->servicesStatus();
|
||
$show_status = [];
|
||
foreach ($statuses as $key => $value) {
|
||
if ($value != 1) continue;
|
||
if ($key == 'is_show_test') {
|
||
$show_status[] = "测试";
|
||
}elseif ($key == 'is_show_service') {
|
||
$show_status[] = "服务";
|
||
}elseif ($key == 'is_show_activity') {
|
||
$show_status[] = "活动";
|
||
}elseif ($key == 'is_show_course') {
|
||
$show_status[] = "课程";
|
||
}elseif ($key == 'is_show_consult') {
|
||
$show_status[] = "咨询";
|
||
}elseif ($key == 'is_show_shop') {
|
||
$show_status[] = "商城";
|
||
}elseif ($key == 'is_show_evaluate') {
|
||
$show_status[] = "测评";
|
||
}
|
||
}
|
||
|
||
// if ($anchor) {
|
||
// $is_show_activity = CommunityActivityResource::where('anchor_id', $anchor->id)
|
||
// ->where('class', 'one')
|
||
// ->where('type', 'business')
|
||
// ->where('status', 1)
|
||
// ->count();
|
||
// $is_show_service = CommunityActivityResource::where('anchor_id', $anchor->id)
|
||
// ->where('class', 'many')
|
||
// ->where('type', 'business')
|
||
// ->where('status', 1)
|
||
// ->count();
|
||
// } else {
|
||
// $is_show_activity = CommunityActivityResource::where('merchant_id', $request->merchant_id)
|
||
// ->where('class', 'one')
|
||
// ->where('status', 1)
|
||
// ->count();
|
||
// $is_show_service = CommunityActivityResource::where('merchant_id', $request->merchant_id)
|
||
// ->where('class', 'many')
|
||
// ->where('status', 1)
|
||
// ->count();
|
||
// }
|
||
// $is_show_test = QATest::where('merchant_id', $request->merchant_id)
|
||
// ->where('status', 1)
|
||
// ->count();
|
||
// $is_show_shop = MerchantShop::where('merchant_id', $request->merchant_id)
|
||
// ->where('is_show', 1)
|
||
// ->count();
|
||
// $consult_ids = ConsultAccount::where('merchant_id', $request->merchant_id)
|
||
// ->pluck('id')
|
||
// ->toArray();
|
||
// $is_show_consult = Consultation::whereIn('consult_account_id', $consult_ids)
|
||
// ->where('status', 1)
|
||
// ->count();
|
||
// $is_show_course = Course::where('merchant_id', $request->merchant_id)/*->where('type','business')*/
|
||
// ->where('is_show', 1);
|
||
// $is_show_evaluate = MerchantEvaluate::where('merchant_id', $request->merchant_id)
|
||
// ->count();
|
||
// if ($request->merchant_id != 88) {
|
||
// $is_show_course = $is_show_course
|
||
// ->where('type', 'business');
|
||
// }
|
||
// $is_show_course = $is_show_course->count();
|
||
// $show_service['is_show_activity'] = $is_show_activity > 0 ? 1 : 0;
|
||
// $show_service['is_show_service'] = $is_show_service > 0 ? 1 : 0;
|
||
// $show_service['is_show_test'] = $is_show_test > 0 ? 1 : 0;
|
||
// $show_service['is_show_shop'] = $is_show_shop > 0 ? 1 : 0;
|
||
// $show_service['is_show_consult'] = $is_show_consult > 0 ? 1 : 0;
|
||
// $show_service['is_show_course'] = $is_show_course > 0 ? 1 : 0;
|
||
// $show_service['is_show_evaluate'] = $is_show_evaluate > 0 ? 1 : 0;
|
||
$account = MerchantAccount::find($request->merchant_id);
|
||
$show_service = $account->servicesStatus();
|
||
return $this->success('ok', compact('show_order', 'show_service', 'show_status'));
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 商户个人信息
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function BusinessUser(Request $request)
|
||
{
|
||
try {
|
||
$merchant_id = $request->merchant_id;
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$merchant_user = MerchantUser::where('id', $merchant_user_id)->first();
|
||
$user['auth'] = 0;
|
||
$user_id = 0;
|
||
$user['authorize_at'] = null;
|
||
$user['is_merchant'] = 0;
|
||
if ($merchant_user) {
|
||
$user['auth'] = 1;
|
||
$user_id = $merchant_user->user_id;
|
||
$user['mobile'] = $merchant_user->mobile;
|
||
$user['authorize_at'] = $merchant_user->authorize_at;
|
||
$is_merchant = MerchantAccount::where('openid', $merchant_user->openid)->exists();
|
||
$user['is_merchant'] = empty($is_merchant) ? 0 : 1;
|
||
}
|
||
$user['nickname'] = $merchant_user->nickname ?? '匿名用户';
|
||
$user['avatar'] = $merchant_user->pic ?? User::DefaultAvatar;
|
||
$user['id'] = $merchant_user_id ?? 0;
|
||
// 是否福恋用户
|
||
// $user['love_user'] = false;
|
||
// $user['isCompletedProfile'] = false;
|
||
$love_user = User::where('id', $user_id)->first();
|
||
if ($merchant_id == 491) {//福恋平台
|
||
$user['love_user'] = true;
|
||
if ($love_user){
|
||
$user['hidden_profile'] = $love_user['hidden_profile'];
|
||
// 是否完善个人资料
|
||
$user['isCompletedProfile'] = $love_user->isCompletedProfile('mp_other_info') ? true : false;
|
||
}else{
|
||
$user['hidden_profile'] = 'single';
|
||
$user['isCompletedProfile'] = false;
|
||
}
|
||
}else {//其他平台
|
||
$user['love_user'] = false;
|
||
$user['isCompletedProfile'] = $merchant_user->isCompletedProfile();
|
||
}
|
||
// 是否授权商家同步个人信息
|
||
$user['authorization_status'] = IdentityAuthorization::where('m_user_id', $merchant_user_id)->where('m_id', $request->merchant_id)->exists();
|
||
$url = env('APP_URL') . '/pu/#/editorUserData';
|
||
$url = urlencode($url);
|
||
$m_id = $request->merchant_id;
|
||
$MerchantAccount = MerchantAccount::where('id', $m_id)->first();
|
||
if ($MerchantAccount) {
|
||
$url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?from_openid=' . $MerchantAccount->openid . '&merchant_id=' . $m_id . '&url=' . $url;
|
||
$user['share_qrcode'] = $MerchantAccount->qr_code;
|
||
} else {
|
||
$url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?from_openid=&merchant_id=' . $m_id . '&url=' . $url;
|
||
$user['share_qrcode'] = null;
|
||
}
|
||
$qr_code = Redis::get('friend-inviteUrl' . $m_id);
|
||
if (!$qr_code) {
|
||
$qr_code = $this->getPreviewQrcode($url);
|
||
Redis::setex('friend-inviteUrl' . $m_id, 60 * 60 * 24 * 30, $qr_code);
|
||
$qr_code = Redis::get('friend-inviteUrl' . $m_id);
|
||
}
|
||
$user['url'] = $url;
|
||
$user['qr_code'] = $qr_code;
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if ($wechatUser) {
|
||
$openid = $wechatUser->getId();
|
||
} else {
|
||
$openid = MerchantUser::where('id', $request->merchant_user_id)->value('openid');
|
||
}
|
||
$user['openid'] = $openid;
|
||
$vip = SaasMemberBuyInfo::where('saas_member_buy_infos.merchant_user_id',$merchant_user_id)
|
||
->where('saas_member_buy_infos.merchant_id',$m_id)
|
||
->join('tourist_orders',function ($join) use($request){
|
||
$join->on('saas_member_buy_infos.order_id','=','tourist_orders.id')
|
||
->whereIn('tourist_orders.pay_status',[1,4]);
|
||
},null,null,'left')
|
||
->orderBy('saas_member_buy_infos.id','desc')
|
||
->select('saas_member_buy_infos.*')
|
||
->first();
|
||
|
||
if(!$vip){
|
||
$user['member_level'] = null;
|
||
$user['member_expire_time'] = null;
|
||
}else{
|
||
$level = SaasMemberLevel::where('merchant_id',$m_id)->where('id',$vip->level_id)
|
||
->withTrashed()
|
||
->first();
|
||
if(!$level){
|
||
$user['member_level'] = null;
|
||
$user['member_expire_time'] = null;
|
||
}else{
|
||
$user['member_level'] = $level->level_title;
|
||
$user['member_expire_time'] = Carbon::instance($vip->created_at)->addYear($level->level_years)
|
||
->addMonths($level->level_month)->toDateString();
|
||
}
|
||
}
|
||
$member_level = SaasMemberLevel::where('merchant_id',$m_id)->first();
|
||
if($member_level){
|
||
$user['member'] = 1;
|
||
}else{
|
||
$user['member'] = 0;
|
||
}
|
||
//商家预约状态 0 未开启,1:可预约商家,2:可预约成员
|
||
$status = $this->appointmentStatus($m_id);
|
||
$user['merchant_appointment'] = $status;
|
||
return $this->success('ok', $user);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息,请稍后再试');
|
||
}
|
||
|
||
}
|
||
|
||
public function appointmentStatus($m_id)
|
||
{
|
||
$status = 0;
|
||
$appointments = SaasAppointment::where('merchant_id', $m_id)->where('appointment_type', 'App\Models\MerchantAccount')
|
||
->where('appointment_target_id', $m_id)
|
||
->where('status',1)
|
||
->whereNotNull('start_time')->whereNotNull('end_time')
|
||
->get();
|
||
$m_ids = SaasAppointmentMember::where('owner_m_id', $m_id)->where('status', 1)->pluck('m_id');
|
||
$other_appointments = SaasAppointment::whereHas('merchant', function ($sql) use($m_ids){
|
||
$sql->whereIn('merchant_id', $m_ids);
|
||
})->where('appointment_type', 'App\Models\MerchantAccount')
|
||
->where('status',1)
|
||
->whereNotNull('start_time')->whereNotNull('end_time')
|
||
->get();
|
||
if ($appointments->count()) {
|
||
$status = 1;
|
||
}
|
||
if ($other_appointments->count()) {
|
||
$status = 2;
|
||
}
|
||
return $status;
|
||
}
|
||
|
||
//当前登录用户是否授权 是否关注公众号 是否是会员
|
||
public function userAuthInfo(Request $request){
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
$merchant_user = MerchantUser::where('id',$request->merchant_user_id)->select('id','user_id','openid','unionid','authorize_at')->first();
|
||
if ($wechatUser) {
|
||
$openid = $wechatUser->getId();
|
||
} else {
|
||
$openid = $merchant_user->openid;
|
||
}
|
||
$course_id = $request->course_id;
|
||
$key = 'subcribe_course_id_'.$course_id;
|
||
if(Redis::get($key)){
|
||
$qrcode = Redis::get($key);
|
||
}else{
|
||
$sceneKey = env('APP_URL').'/h5/#/courseDetail/'.$course_id.'?c_id='.$course_id;
|
||
$result = $this->app->qrcode->forever($sceneKey);
|
||
$qrcode = $this->app->qrcode->url($result['ticket']);
|
||
Redis::set($key,$qrcode);
|
||
}
|
||
$is_auth = $merchant_user->unionid ? 1 : 0;
|
||
$is_subscribe = \WechatService::officialIsSubscribed($openid);
|
||
//当前用户是否是会员vip
|
||
$is_vip = $merchant_user->isVip();
|
||
$user_id = $this->matchFulinkUser($request->merchant_user_id);
|
||
if($is_vip > 0 && $user_id){
|
||
$user = User::find($user_id);
|
||
$rank_deadline = $user->cacheUserProperty('rank_deadline');
|
||
}else{
|
||
$rank_deadline = date('Y-m-d H:i:s');
|
||
}
|
||
$logo = 'https://image.fulllinkai.com/202207/04/0a34b743e18c31423c1d7ae98069be5c.png';
|
||
return $this->success('ok',compact('is_auth','is_subscribe','is_vip','qrcode','logo','rank_deadline'));
|
||
}
|
||
|
||
/**
|
||
* 已选择模板
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function templateChoose(Request $request)
|
||
{
|
||
$merchant_id = $request->merchant_id;
|
||
$anchor_openid = $request->anchor_openid;
|
||
// if(!$merchant_id) return $this->failure('未获取到商户信息');
|
||
// $merchant = MerchantAccount::where('id',$merchant_id)->first();
|
||
if ($merchant_id && $merchant_id != 'null') {
|
||
$merchant = MerchantAccount::getRedisMerchant($merchant_id);
|
||
// $merchant = MerchantAccount::where('id', $merchant_id)->first();
|
||
}
|
||
if (empty($merchant) && $anchor_openid) {
|
||
$merchant = MerchantAccount::getRedisMerchant(null, $anchor_openid);
|
||
// $merchant = MerchantAccount::where('openid', $anchor_openid)->first();
|
||
}
|
||
if (empty($merchant)) return $this->failure('未获取到商户信息');
|
||
$data = [];
|
||
$data['tabBarList'] = json_decode($merchant->choose_tarbar, true) ?? [];
|
||
$data['templateType'] = json_decode($merchant->template_position, true) ?? [];
|
||
return $this->success('ok', $data);
|
||
|
||
}
|
||
|
||
/**
|
||
* 老师入驻
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function RecruitingTeachers(Request $request)
|
||
{
|
||
try {
|
||
$mobile = $request->mobile;
|
||
$code = $request->code;
|
||
//检查验证码
|
||
$sms = new Sms(new App);
|
||
$result = $sms->check($mobile, $code);
|
||
if ($result)
|
||
return $this->failure($result, ['statu' => 1]);
|
||
$anchor = Anchor::where('mobile', $mobile)->first();
|
||
$viewer = Viewer::where('mobile', $mobile)->first();
|
||
$Teacher = false;
|
||
if ($viewer)
|
||
$Teacher = Anchor::where('viewer_id', $viewer->id)->first();
|
||
if (($anchor) || ($Teacher && $Teacher->cooperation_type)) return $this->success('fail', ['status' => 1]);
|
||
if ($Teacher) {
|
||
$anchor = $Teacher;
|
||
} else {
|
||
$anchor = new anchor;
|
||
$anchor->viewer_id = $viewer->id ?? 0;
|
||
$anchor->pic = $viewer->avatar ?? '';
|
||
$anchor->name = $request->name;
|
||
$anchor->status = 0;
|
||
$anchor->channel = 0;
|
||
}
|
||
$anchor->branch = $request->branch;
|
||
$anchor->service_nature = $request->service_nature ?? 'person';
|
||
$anchor->wechat = $request->wechat;
|
||
$anchor->from_openid = $request->from_openid;
|
||
$anchor->withdrawal_radio = 100;
|
||
$anchor->mobile = $request->mobile;
|
||
$anchor->openid = $request->openid;
|
||
$anchor->teaching_user = json_encode($request->teaching_user);
|
||
$anchor->cooperation_type = json_encode($request->cooperation_type);
|
||
|
||
$anchor->save();
|
||
\CommonUtilsService::addNewAnchorToUser($anchor);
|
||
$url = \CommonUtilsService::shortUrl(env('APP_URL') . '/pu_m/#/login');
|
||
$str = $this->getTradeNO();
|
||
$password = substr($str, 4, 8);
|
||
$message = '你的账号已注册成功,请访问' . $url['url'] . ' 完善信息 用户名 :' . $mobile . ' 密码 :' . $password . '【福恋】';
|
||
Message::create([
|
||
'phone' => $mobile,
|
||
'message' => $message,
|
||
'confirmed' => 1,
|
||
'ip' => request() ? request()->ip() : '127.0.0.1',
|
||
]);
|
||
$bool = MerchantAccount::where('openid', $anchor->openid)->first();
|
||
if ($bool) {
|
||
$arr = ['password' => encrypt($password)];
|
||
} else {
|
||
$arr = ['password' => encrypt($password), 'openid' => $anchor->openid];
|
||
}
|
||
MerchantAccount::updateOrCreate(['mobile' => $mobile], $arr);
|
||
Messengers::sendSMS($mobile, $message);
|
||
$type = ['service', 'activity', 'consult', 'course', 'shop'];
|
||
$MerchantAccount = MerchantAccount::where('mobile', $mobile)->first();
|
||
$anchor->m_id = $MerchantAccount->id;
|
||
$anchor->save();
|
||
foreach ($type as $key => $value) {
|
||
$rules = new MEarningRules();
|
||
$rules->m_id = $MerchantAccount->id;
|
||
$rules->name = $value;
|
||
$rules->ratio = 0;
|
||
$rules->first_sharer = 0;
|
||
$rules->last_sharer = 0;
|
||
$rules->other_sharer = 0;
|
||
$rules->forzen_time = 1;
|
||
$rules->save();
|
||
}
|
||
$app = \WechatService::officialApp();
|
||
$wechat_user = $app->user->get($request->openid);
|
||
$subscribe = 0;
|
||
if ($wechat_user && $wechat_user['subscribe'] == 1) {
|
||
$subscribe = 1;
|
||
}
|
||
// 推荐商家入驻奖励
|
||
$merchant_user = MerchantUser::where('openid', $request->from_openid)->first();
|
||
if ($merchant_user) {
|
||
$erning = new MEarning();
|
||
$erning->m_id = $request->merchant_id ?? 0;
|
||
$erning->m_user_id = $merchant_user->id;
|
||
$erning->m_order_id = $MerchantAccount->id;
|
||
$erning->type = 'enter';
|
||
$erning->sharer = 'first_sharer';
|
||
$erning->ratio = 1;
|
||
$erning->sub_ratio = 1;
|
||
$erning->value = 1;
|
||
$erning->status = 'finished';
|
||
$erning->save();
|
||
$Account = MEarningAccount::where('m_id', $request->merchant_id)->where('m_user_id', $merchant_user->id)->first();
|
||
if ($Account) {
|
||
$Account->increment('total_value', 1);
|
||
$Account->increment('balance', 1);
|
||
} else {
|
||
$Account = new MEarningAccount();
|
||
$Account->m_id = $request->merchant_id;
|
||
$Account->m_user_id = $merchant_user;
|
||
$Account->total_value = 1;
|
||
$Account->balance = 1;
|
||
$Account->save();
|
||
}
|
||
}
|
||
$data = ['merchant_id' => $MerchantAccount->id, 'anchor_id' => $anchor->id];
|
||
NewMerchantDefaultService::dispatch($data)->onQueue('love');
|
||
return $this->success('ok', ['subscribe' => $subscribe]);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('入驻失败,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取手机国家区号
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function getNationMobileCode(Request $request)
|
||
{
|
||
try {
|
||
$area_code_string = file_get_contents(public_path() . '/nation_mobile_area_code.json');
|
||
$area_code = json_decode($area_code_string, true);
|
||
return $this->success('ok', $area_code);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取地址信息
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function userInfoOptions()
|
||
{
|
||
try {
|
||
$address_arr = Address::where('name', '<>', '不限')->orderBy('codeId', 'asc')->select('codeId', 'name', 'parentId')->get()->toArray();
|
||
$address_arr = $this->addressSort($address_arr);
|
||
//行业
|
||
list($__sort, $__detail) = $this->industryJsonData();
|
||
$industry_arr = [];
|
||
foreach ($__sort as $key => $item) {
|
||
$industry_arr[] = [
|
||
'title' => $item,
|
||
'items' => $__detail[$key]
|
||
];
|
||
}
|
||
//协助H5更换地区地段
|
||
foreach ($address_arr as $key => &$value) {
|
||
$value['text'] = $value['name'];
|
||
$value['children'] = $value['son'];
|
||
unset($value['son']);
|
||
unset($value['name']);
|
||
foreach ($value['children'] as $k => &$v) {
|
||
$v['text'] = $v['name'];
|
||
$v['children'] = $v['son'];
|
||
unset($v['name']);
|
||
unset($v['son']);
|
||
foreach ($v['children'] as $k1 => &$v1) {
|
||
$v1['text'] = $v1['name'];
|
||
unset($v1['name']);
|
||
}
|
||
}
|
||
}
|
||
$address_arr = $address_arr[0]['children'];
|
||
return $this->success('ok', compact('address_arr', 'industry_arr'));
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 通用上架功能
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function putOnService(Request $request)
|
||
{
|
||
try {
|
||
$type = $request->type;
|
||
$type_id = $request->type_id;
|
||
// $type_arr = ['infor','video','community','shop','consult','course','test'];
|
||
if ($type == 'infor') {
|
||
MerchantInformation::where('id', $type_id)->update(['status' => 1]);
|
||
} elseif ($type == 'video') {
|
||
AnchorVideo::where('id', $type_id)->update(['status' => 1]);
|
||
} elseif ($type == 'community') {
|
||
CommunityActivity::where('id', $type_id)->update(['status' => 1]);
|
||
} elseif ($type == 'shop') {
|
||
MerchantShop::where('id', $type_id)->update(['is_show' => 1]);
|
||
} elseif ($type == 'consult') {
|
||
Consultation::where('id', $type_id)->update(['status' => 1]);
|
||
} elseif ($type == 'course') {
|
||
Course::where('id', $type_id)->update(['is_show' => 1]);
|
||
} elseif ($type == 'test') {
|
||
QATest::where('id', $type_id)->update(['status' => 1]);
|
||
} else {
|
||
throw new \Exception("类型有误", 1);
|
||
}
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息,请稍后再试');
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 商家用户绑定手机号
|
||
* @param Request $request
|
||
*/
|
||
public function merchantUserBindMobile(Request $request)
|
||
{
|
||
try {
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$mobile = $request->mobile;
|
||
$code = $request->code;
|
||
if (!$mobile || !$code) {
|
||
return $this->failure('手机号和验证码为必传参数');
|
||
}
|
||
$merchant_user = MerchantUser::where('id', $merchant_user_id)
|
||
->first();
|
||
if (!$merchant_user) {
|
||
return $this->failure('帐户不存在');
|
||
}
|
||
$sms = new Sms(new App);
|
||
$result = $sms->check($mobile, $code);
|
||
if ($result) {
|
||
switch ($result) {
|
||
case '请填写验证码':
|
||
return $this->respv2($result, ['status' => 7, 'message' => '请填写验证码']);
|
||
break;
|
||
case '验证码有误':
|
||
return $this->respv2($result, ['status' => 8, 'message' => '验证码有误']);
|
||
break;
|
||
case '验证码过期':
|
||
return $this->respv2($result, ['status' => 9, 'message' => '验证码过期']);
|
||
break;
|
||
case '验证码已使用':
|
||
return $this->respv2($result, ['status' => 10, 'message' => '验证码已使用']);
|
||
break;
|
||
default:
|
||
# code...
|
||
break;
|
||
}
|
||
}
|
||
DB::beginTransaction();
|
||
$old_mobile_user = MerchantUser::where('mobile', $mobile)
|
||
->first();
|
||
if($old_mobile_user){
|
||
return $this->failure('手机号已被另一帐号绑定,请联系客服');
|
||
}
|
||
$merchant_user->mobile = $mobile;
|
||
$merchant_user->save();
|
||
$user = User::where('mobile', $mobile)->first();
|
||
if ($user) {
|
||
$merchant_user->user_id = $user->id;
|
||
$merchant_user->save();
|
||
}
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
//云盾活体检测+实名认证
|
||
public function livePersonAuditV2(Request $request)
|
||
{
|
||
try {
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$merchant_user = MerchantUser::find($merchant_user_id);
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if ($wechatUser) {
|
||
$openid = $wechatUser->getId();
|
||
} else {
|
||
$openid = $merchant_user->openid;
|
||
}
|
||
DB::beginTransaction();
|
||
$user_id = $this->matchFulinkUser($merchant_user_id);
|
||
$user = User::find($user_id);
|
||
if(!$user){
|
||
$user_id = $this->getUseridByOpenid($openid,0);
|
||
$user = User::find($user_id);
|
||
}
|
||
if(!$user){
|
||
$user = new User();
|
||
$user->nickname = $merchant_user->nickname;
|
||
$user->sex = $merchant_user->sex;
|
||
$user->regist_channel = 'sass';
|
||
$user->photo = $merchant_user->pic;
|
||
$user->save();
|
||
if(!$merchant_user->user_id){
|
||
$merchant_user->user_id = $user->id;
|
||
$merchant_user->save();
|
||
}
|
||
}
|
||
if(empty($request->name)) return $this->failure('请输入真实姓名');
|
||
if(empty($request->card_num)) return $this->failure('请输入身份证号');
|
||
//添加身份证号
|
||
if ($user->is_real_approved == 1) {
|
||
$data = [
|
||
'type' => 1,
|
||
'message' => "您已认证"
|
||
];
|
||
return $this->success('认证失败', $data);
|
||
}
|
||
//是否身份已经验证过
|
||
$card_user = User::where('id', '<>', $user->id)->where('card_num', $request->card_num)->where(function ($sql) {
|
||
$sql->where('is_approved', 1)->orWhere('is_real_approved', 1);
|
||
})->first();
|
||
if ($card_user) {
|
||
$mobile = substr_replace($card_user->mobile, '****', 3, 4);
|
||
$message = "认证失败,身份信息已在其他账号" . PHP_EOL . $mobile . "认证";
|
||
$data = [
|
||
'type' => 1,
|
||
'message' => $message
|
||
];
|
||
return $this->success('认证失败', $data);
|
||
}
|
||
$yd_service = new YDService();
|
||
$result = $yd_service->livePersonAudit($request);
|
||
|
||
if (empty($result)) {
|
||
$data = [
|
||
'type' => 1,
|
||
'message' => '认证失败,系统繁忙,稍后重试'
|
||
];
|
||
return $this->success('认证失败', $data);
|
||
}
|
||
|
||
if ($result['code'] != 200) {
|
||
$data = [
|
||
'type' => 1,
|
||
'message' => $result['msg']
|
||
];
|
||
return $this->success('认证失败', $data);
|
||
}
|
||
if (!array_key_exists('status', $result['result'])) {
|
||
$data = [
|
||
'type' => 1,
|
||
'message' => '认证失败,系统繁忙,稍后重试'
|
||
];
|
||
return $this->success('认证失败', $data);
|
||
}
|
||
if ($result['result']['status'] != 1 && !empty($result['result']['reasonType'])) {
|
||
switch ($result['result']['reasonType']) {
|
||
case 2:
|
||
$type = 1;
|
||
$message = '认证失败,姓名身份证号一致,人脸比对非同一人';
|
||
break;
|
||
case 3:
|
||
$type = 1;
|
||
$message = '认证失败,姓名身份证号不一致';
|
||
break;
|
||
case 4:
|
||
$type = 3;
|
||
$message = "认证失败,活体检测不通过";
|
||
$extra = ["1、录制时,没有眨眼睛;", "2、录制时间过短,请超过3秒时长;", "3、在灯光较暗或曝光下,无法识别人脸;", "4、人脸拍摄不全,无法检测到人脸;", "5、保持正对手机,不要斜视屏幕;", "6、手机网络不顺畅,请检查网络状况"];
|
||
break;
|
||
case 5:
|
||
$type = 1;
|
||
$message = '认证失败,活体检测超时';
|
||
break;
|
||
case 6:
|
||
$type = 2;
|
||
$message = '认证失败,库中无此身份证照片';
|
||
break;
|
||
case 7:
|
||
$type = 2;
|
||
$message = '认证失败,库中无此身份证照片';
|
||
break;
|
||
case 8:
|
||
$type = 1;
|
||
$message = '认证失败,请勿过于靠近手机屏幕拍摄';
|
||
break;
|
||
case 9:
|
||
$type = 1;
|
||
$message = '认证失败,系统繁忙,请稍后重试';
|
||
break;
|
||
default:
|
||
$type = 1;
|
||
$message = '认证失败';
|
||
break;
|
||
}
|
||
$data = [
|
||
'type' => $type,
|
||
'message' => $message
|
||
];
|
||
if (!empty($extra)) {
|
||
$data['extra'] = $extra;
|
||
}
|
||
return $this->success('认证失败', $data);
|
||
}
|
||
$result['user_id'] = $user->id;
|
||
$result['avatar'] = $user->avatar;
|
||
if ($user->name != $request->name) {
|
||
$user->name = $request->name;
|
||
}
|
||
if ($user->card_num != $request->card_num) {
|
||
$user->card_num = $request->card_num;
|
||
}
|
||
|
||
//认证状态
|
||
$user->is_approved = 1;
|
||
$user->is_real_approved = 1;
|
||
//认证时间
|
||
$user->approve_date = date('Y-m-d H:i:s');
|
||
$user->save();
|
||
//增加认证记录
|
||
$history = ApproveHistory::where('user_id', $user->id)->where('type', 'name')->first();
|
||
if (empty($history)) {
|
||
ApproveHistory::create([
|
||
'user_id' => $user->id,
|
||
'type' => 'name',
|
||
'status' => 1,
|
||
'from_platform' => $request->from_platform,
|
||
'from_user_id' => $request->from_user_id,
|
||
'from_m_id'=>$request->merchant_id,
|
||
]);
|
||
} else {
|
||
$history->status = 1;
|
||
$history->save();
|
||
}
|
||
$body_history = ApproveHistory::where('user_id', $user->id)->where('type', 'body')->first();
|
||
if (empty($body_history)) {
|
||
ApproveHistory::create([
|
||
'user_id' => $user->id,
|
||
'type' => 'body',
|
||
'status' => 1,
|
||
'from_platform' => $request->from_platform,
|
||
'from_user_id' => $request->from_user_id,
|
||
'from_m_id'=>$request->merchant_id,
|
||
]);
|
||
} else {
|
||
$body_history->status = 1;
|
||
$body_history->save();
|
||
}
|
||
//更新出生年月日
|
||
$user->cardBirthdayToProfile();
|
||
//缓存用户认证
|
||
$user->updateCacheUser('is_approved');
|
||
$user->updateCacheUser('is_real_approved');
|
||
if ($request->has('from_user_id')) {
|
||
$from_user = User::find($request->from_user_id);
|
||
if ($from_user)
|
||
$from_user->addCoinLog('RECSYSTEM', $user->id, 50, '邀请好友认证');
|
||
}
|
||
StoreApproveWorthShare::dispatch($user->id, $request->from_user_id,$request->chat_user_id)->onQueue('love');
|
||
$data = [
|
||
'type' => 0,
|
||
'message' => '认证成功'
|
||
];
|
||
DB::commit();
|
||
//同步订单编号
|
||
$activity_id = 1937; //1937;
|
||
SyncOrderRemark::dispatch($activity_id, $user)->onQueue('love');
|
||
return $this->success('认证成功', $data);
|
||
} catch (\Exception $e) {
|
||
DB::rollback();
|
||
$this->getError($e);
|
||
$data = [
|
||
'type' => 1,
|
||
'message' => '认证失败,进行重新认证或人工认证'
|
||
];
|
||
return $this->success('认证失败', $data);
|
||
}
|
||
}
|
||
|
||
public function tencentRealApprove(Request $request)
|
||
{
|
||
try {
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if (empty($wechatUser)) {
|
||
$url = urlencode("https://love.ufutx.com/pu/#/realNameV2?merchant_id=491");
|
||
$url = 'https://love.ufutx.com/api/official/live/wechat/FamilyAuth?merchant_id=491&url='.$url;
|
||
return redirect($url);
|
||
}
|
||
$openid = $wechatUser->getId();
|
||
// $openid = '';
|
||
$name = $request->input('name');
|
||
$card_num = $request->input('card_num');
|
||
if(empty($name)) return $this->failure('请输入真实姓名');
|
||
if(empty($card_num)) return $this->failure('请输入身份证号');
|
||
// $merchant_user = MerchantUser::where('openid', $openid)->first();
|
||
// $user_id = $this->matchFulinkUser($merchant_user->id);
|
||
// $user = User::find($user_id);
|
||
// if(!$user){
|
||
// $user_id = $this->getUseridByOpenid($openid,0);
|
||
// $user = User::find($user_id);
|
||
// }
|
||
// if(!$user){
|
||
// $user = new User();
|
||
// $user->nickname = $merchant_user->nickname;
|
||
// $user->sex = $merchant_user->sex;
|
||
// $user->regist_channel = 'sass';
|
||
// $user->photo = $merchant_user->pic;
|
||
// $user->save();
|
||
// if(!$merchant_user->user_id){
|
||
// $merchant_user->user_id = $user->id;
|
||
// $merchant_user->save();
|
||
// }
|
||
// }
|
||
$extra = "openid=".$openid;
|
||
$merchant_id = '0NSJ2212081323290138';
|
||
$result = CommonUtilsService::tencentFaceid($merchant_id, $name, $card_num, $extra);
|
||
// dd($result);
|
||
if (empty($result)) return $this->failure();
|
||
//记录信息
|
||
$log = TencentFaceidLog::updateOrCreate(['openid'=>$openid], [
|
||
'url'=>$result->Url,
|
||
'eid_token'=>$result->EidToken,
|
||
'name'=>$name,
|
||
'card_num'=>$card_num,
|
||
]);
|
||
return $this->success('ok', $log);
|
||
}catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure();
|
||
}
|
||
}
|
||
|
||
public function tencentRealApproveRes(Request $request)
|
||
{
|
||
try {
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if (empty($wechatUser)) {
|
||
$url = urlencode("https://love.ufutx.com/pu/#/realNameV2?merchant_id=491");
|
||
$url = 'https://love.ufutx.com/api/official/live/wechat/FamilyAuth?merchant_id=491&url='.$url;
|
||
return redirect($url);
|
||
}
|
||
$openid = $wechatUser->getId();
|
||
$log = TencentFaceidLog::where("openid", $openid)->orderBy('id', 'desc')->first();
|
||
$data = [
|
||
'name' => null,
|
||
'card_num' => null,
|
||
'is_real_approved' => 0,
|
||
];
|
||
if (empty($log)) return $this->success('ok', $data);
|
||
$res = CommonUtilsService::tencentFaceidRes($log->eid_token);
|
||
$data['name'] = $log->name;
|
||
$data['card_num'] = $log->card_num;
|
||
if (isset($res->Text) && isset($res->Text->ErrCode) && $res->Text->ErrCode == 0) $data['is_real_approved'] = 1;
|
||
// $data['res'] = $res;
|
||
return $this->success('ok', $data);
|
||
}catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure();
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 人工认证
|
||
*/
|
||
public function manualApprove(Request $request)
|
||
{
|
||
try {
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$merchant_user = MerchantUser::find($merchant_user_id);
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if ($wechatUser) {
|
||
$openid = $wechatUser->getId();
|
||
} else {
|
||
$openid = $merchant_user->openid;
|
||
}
|
||
DB::beginTransaction();
|
||
$user_id = $this->matchFulinkUser($merchant_user_id);
|
||
$user = User::find($user_id);
|
||
if(!$user){
|
||
$user_id = $this->getUseridByOpenid($openid,0);
|
||
$user = User::find($user_id);
|
||
}
|
||
if(!$user){
|
||
$user = new User();
|
||
$user->nickname = $merchant_user->nickname;
|
||
$user->sex = $merchant_user->sex;
|
||
$user->regist_channel = 'sass';
|
||
$user->photo = $merchant_user->pic;
|
||
$user->save();
|
||
if(!$merchant_user->user_id){
|
||
$merchant_user->user_id = $user->id;
|
||
$merchant_user->save();
|
||
}
|
||
}
|
||
if ($user->is_real_approved == 1) return $this->failure("已通过真人认证");
|
||
$photos = $request->input('photos', []);
|
||
if (empty(count($photos)) && is_array($photos)) {
|
||
return $this->failure('请上传手持身份证照!');
|
||
}
|
||
$user->identification_photos = json_encode($photos);
|
||
$user->save();
|
||
//创建审核记录
|
||
ApproveHistory::updateOrCreate(['user_id' => $user->id,'type'=>'body'],['status' => 0,'ways' => 1,'from_user_id'=>$request->from_user_id,'from_m_id'=>$request->merchant_id]);
|
||
ApproveHistory::updateOrCreate(['user_id' => $user->id,'type'=>'name'],['status' => 0,'ways' => 1,'from_user_id'=>$request->from_user_id,'from_m_id'=>$request->merchant_id]);
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('人工认证申请失败,请稍后再试');
|
||
}
|
||
}
|
||
|
||
//学历认证
|
||
public function educateApprove(Request $request){
|
||
try {
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$merchant_user = MerchantUser::find($merchant_user_id);
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if ($wechatUser) {
|
||
$openid = $wechatUser->getId();
|
||
} else {
|
||
$openid = $merchant_user->openid;
|
||
}
|
||
$user_id = $this->matchFulinkUser($merchant_user_id);
|
||
$user = User::find($user_id);
|
||
DB::beginTransaction();
|
||
if(!$user){
|
||
$user_id = $this->getUseridByOpenid($openid,0);
|
||
$user = User::find($user_id);
|
||
}
|
||
if(!$user){
|
||
$user = new User();
|
||
$user->nickname = $merchant_user->nickname;
|
||
$user->sex = $merchant_user->sex;
|
||
$user->regist_channel = 'sass';
|
||
$user->photo = $merchant_user->pic;
|
||
$user->save();
|
||
if(!$merchant_user->user_id){
|
||
$merchant_user->user_id = $user->id;
|
||
$merchant_user->save();
|
||
}
|
||
}
|
||
$profile = ProfileCourtship::firstOrCreate(['user_id'=>$user->id]);
|
||
if ($request->input('degree') && $request->degree != $profile->degree) {
|
||
$profile->degree = $request->degree;
|
||
}
|
||
if ($request->input('graduate_school') && $request->graduate_school != $profile->graduate_school) {
|
||
$profile->graduate_school = $request->graduate_school;
|
||
}
|
||
$is_educate_approved = DB::table('users')->where('id', $user->id)->value('is_educate_approved');
|
||
if ($request->input('educate_photo') && ($is_educate_approved == 0 || $is_educate_approved == 3)) {
|
||
//毕业证书
|
||
$profile->educate_photo = $request->educate_photo;
|
||
$profile->edc_type = 0;
|
||
//创建认证记录
|
||
$user->updateApproveInfo('educate', 0,$request->merchant_id);
|
||
} else if ($request->input('chsi_code') && ($is_educate_approved == 0 || $is_educate_approved ==3)) {
|
||
//添加学信网CODE
|
||
$profile->chsi_code = $request->chsi_code;
|
||
$profile->edc_type = 1;
|
||
//创建认证记录
|
||
$user->updateApproveInfo('educate', 0,$request->merchant_id);
|
||
}
|
||
$profile->save();
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
\DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('学历认证失败,请重试');
|
||
}
|
||
|
||
}
|
||
|
||
//当前认证情况
|
||
public function approveInfo(Request $request){
|
||
try {
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$merchant_user = MerchantUser::find($merchant_user_id);
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if ($wechatUser) {
|
||
$openid = $wechatUser->getId();
|
||
} else {
|
||
$openid = $merchant_user->openid;
|
||
}
|
||
$user_id = $this->matchFulinkUser($merchant_user_id);
|
||
$user = User::find($user_id);
|
||
if(!$user){
|
||
$user_id = $this->getUseridByOpenid($openid,0);
|
||
$user = User::find($user_id);
|
||
}
|
||
if(!$user){
|
||
$user = new User();
|
||
$user->nickname = $merchant_user->nickname;
|
||
$user->sex = $merchant_user->sex;
|
||
$user->regist_channel = 'sass';
|
||
$user->photo = $merchant_user->pic;
|
||
$user->save();
|
||
if(!$merchant_user->user_id){
|
||
$merchant_user->user_id = $user->id;
|
||
$merchant_user->save();
|
||
}
|
||
}
|
||
$is_educate_approved = $user->is_educate_approved??0;
|
||
$is_real_approved = !empty($user) ? $user->is_real_approved : 0;
|
||
return $this->success('ok',compact('is_educate_approved','is_real_approved'));
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 获取学院,模糊查询学院
|
||
*/
|
||
public function collegeList(Request $request)
|
||
{
|
||
$name = $request->input('name');
|
||
$list = [];
|
||
try {
|
||
$list = College::where('name', 'like', '%' . $name . '%')->get();
|
||
return $this->success('ok', ['list' => $list]);
|
||
} catch (\Exception $e) {
|
||
return $this->success('ok', ['list' => $list]);
|
||
}
|
||
}
|
||
|
||
//获取学历信息
|
||
public function obtainDegree(Request $request){
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$merchant_user = MerchantUser::find($merchant_user_id);
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if ($wechatUser) {
|
||
$openid = $wechatUser->getId();
|
||
} else {
|
||
$openid = $merchant_user->openid;
|
||
}
|
||
$user_id = $this->matchFulinkUser($merchant_user_id);
|
||
$user = User::find($user_id);
|
||
if(!$user){
|
||
$user_id = $this->getUseridByOpenid($openid,0);
|
||
$user = User::find($user_id);
|
||
}
|
||
if(!$user){
|
||
$user = new User();
|
||
$user->nickname = $merchant_user->nickname;
|
||
$user->sex = $merchant_user->sex;
|
||
$user->regist_channel = 'sass';
|
||
$user->photo = $merchant_user->pic;
|
||
$user->save();
|
||
if(!$merchant_user->user_id){
|
||
$merchant_user->user_id = $user->id;
|
||
$merchant_user->save();
|
||
}
|
||
}
|
||
$profile = ProfileCourtship::firstOrCreate(['user_id'=>$user->id]);
|
||
$educate_photo = $profile->educate_photo;
|
||
$graduate_school = $profile->graduate_school;
|
||
$degree = $profile->degree;
|
||
$edc_type = $profile->edc_type;;
|
||
$is_educate_approved = $user->is_educate_approved;
|
||
return $this->success('ok',compact('educate_photo','graduate_school','degree','is_educate_approved','edc_type'));
|
||
}
|
||
|
||
//获取身份信息
|
||
public function obtainApproveInfo(Request $request){
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$merchant_user = MerchantUser::find($merchant_user_id);
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if ($wechatUser) {
|
||
$openid = $wechatUser->getId();
|
||
} else {
|
||
$openid = $merchant_user->openid;
|
||
}
|
||
$user_id = $this->matchFulinkUser($merchant_user_id);
|
||
$user = User::find($user_id);
|
||
if(!$user){
|
||
$user_id = $this->getUseridByOpenid($openid,0);
|
||
$user = User::find($user_id);
|
||
}
|
||
$card_num = $user ? $user->card_num : null;
|
||
$name = $user ? $user->name : null;
|
||
$is_real_approved = $user ? $user->is_real_approved : 0;
|
||
return $this->success('ok',compact('card_num','name','is_real_approved'));
|
||
}
|
||
|
||
/**
|
||
* 获取用户图片库列表
|
||
*/
|
||
public function getUserImageList(Request $request){
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$list = MerchantUserImage::where('type',MerchantUser::class)->where('type_id',$merchant_user_id)
|
||
->select('id','image_url')->get();
|
||
return $this->success('ok',$list);
|
||
}
|
||
|
||
/**
|
||
* 添加图片进入图片库
|
||
*/
|
||
public function addImageToStore(Request $request){
|
||
$image_url = $request->url;
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$image = MerchantUserImage::where('image_url',$image_url)->where('type_id',$merchant_user_id)
|
||
->where('type',MerchantUser::class)->first();
|
||
if($image){
|
||
return $this->success('ok');
|
||
}else{
|
||
$image = new MerchantUserImage();
|
||
$image ->type_id = $merchant_user_id;
|
||
$image ->type = MerchantUser::class;
|
||
$image->image_url = $image_url;
|
||
$image->save();
|
||
return $this->success('ok');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 删除图片库里的图片
|
||
*/
|
||
public function deleteImageFromStore(Request $request){
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$image_id = $request->id;
|
||
MerchantUserImage::where('type_id',$merchant_user_id)
|
||
->where('type',MerchantUser::class)
|
||
->where('id',$image_id)
|
||
->delete();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
/**
|
||
* 邀请的用户列表
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function invitationUsers(Request $request)
|
||
{
|
||
try {
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$merchant_id = $request->merchant_id;
|
||
$openid = MerchantUser::where('id',$merchant_user_id)->value('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
|
||
* @param $user_id
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function otherUser(Request $request,$user_id,SaasVipService $s)
|
||
{
|
||
try {
|
||
|
||
$merchant_id = $request->merchant_id;
|
||
$merchant_user_id = $request->merchant_user_id;
|
||
$spread_merchant_id = $request->input('spread_merchant_id');
|
||
$level_id = $request->input('vip_level_id');
|
||
$where = [
|
||
['merchant_id', '=', $merchant_id],
|
||
// ['merchant_user_id', '=', $merchant_user_id],
|
||
['spread_merchant_id', '=', $spread_merchant_id],
|
||
['level_id', '=', $level_id],
|
||
['fulink_user_id', '=', $user_id],
|
||
];
|
||
$spread_carrier = SaasMemberVipSpreadCarrier::select('id','level_id','link','merchant_user_id')->where($where)->first();
|
||
if (!$spread_carrier) {
|
||
return $this->failure('推广数据未找到');
|
||
}
|
||
$merchant_user = MerchantUser::select('id','nickname','pic','openid')->where('id',$merchant_user_id)->first();
|
||
$q = substr($spread_carrier->link, strripos($spread_carrier->link, "?") + 1);//url参数
|
||
$q = "from_openid={$merchant_user->openid}&{$q}";
|
||
$spread_carrier->new_link = env('APP_URL') . "/api/official/live/wechat/FamilyAuth?{$q}";
|
||
|
||
// $cache_key = "saas:vip_user_spread_carrier_qrcode:{$spread_carrier->id}";
|
||
// $spread_carrier->qrcode = Cache::get($cache_key);
|
||
// if (empty($spread_carrier->qrcode)) {
|
||
$spread_carrier->qrcode = $this->getPreviewQrcode($spread_carrier->new_link);
|
||
// Cache::put($cache_key, $spread_carrier->qrcode, 60 * 24); //有效期一天
|
||
// }
|
||
|
||
//vip数据
|
||
$vip = SaasMemberLevel::find($spread_carrier->level_id);
|
||
//是否购买状态
|
||
$is_buy = $s->checkBuyVip($merchant_id,$merchant_user_id,$level_id) ? 1 : 0;//是否购买状态
|
||
//推广商家数据
|
||
$spread_anchor = Anchor::select('id','m_id','name')->where('m_id',$spread_merchant_id)->first();
|
||
//本商家数据
|
||
$anchor = Anchor::select('id','m_id','name')->where('m_id',$merchant_id)->first();
|
||
//第几次购买
|
||
$vip_rank = 0;
|
||
$order = $s->getBuyVipOrder($merchant_id, $spread_carrier->merchant_user_id, $level_id);
|
||
$where = [
|
||
['type', '=', 'member'],
|
||
['type_id', '=', $level_id],
|
||
['merchant_id', '=', $merchant_id],
|
||
// ['id', '<=', $order->id],
|
||
['created_at', '<=', $order->created_at],
|
||
];
|
||
$vip_rank = TouristOrder::where($where)->whereIn('pay_status', [1, 4])->count();
|
||
|
||
|
||
$user_err_msg = '';
|
||
|
||
|
||
//是否在黑名单
|
||
// $is_black = LinkingBlacklist::where('user_id', $user_id)->where('other_user_id', auth()->id())->count();
|
||
// if ($is_black) return $this->failure('您已被对方拉入黑名单');
|
||
|
||
$frozen_state = $this->userCon->getUserBannedState($user_id);
|
||
if($frozen_state){
|
||
// return $this->failure('该用户资料异常,暂时无法查看');
|
||
$user_err_msg = '该用户资料异常,暂时无法查看';
|
||
}
|
||
|
||
$rd_user_key = User::cacheUserKey($user_id);
|
||
if (Cache::has($rd_user_key)) {
|
||
$user = $rd_user = Cache::get($rd_user_key);
|
||
} else {
|
||
$user = User::withCount('moments')->find($user_id);
|
||
// if (empty($user)) return $this->failure('真不巧,用户最近关闭了资料~');
|
||
if (empty($user)){
|
||
$user_err_msg = '真不巧,用户最近关闭了资料~';
|
||
}else{
|
||
$user->cacheUser();
|
||
$rd_user = Cache::get($rd_user_key);
|
||
}
|
||
}
|
||
// if (empty($user)) return $this->failure('真不巧,用户最近关闭了资料~');
|
||
if (empty($user)){
|
||
$user_err_msg = '真不巧,用户最近关闭了资料~';
|
||
}
|
||
|
||
if($user){
|
||
// $arr = $this->getSelfInfo($user);
|
||
$arr = [];
|
||
$arr['is_followed'] = 0;
|
||
$arr['is_friend'] = 0;
|
||
$arr['self'] = 0;
|
||
$arr['is_messenger'] = 0;
|
||
$arr['is_hidden'] = 0;
|
||
$arr['self_is_approved'] = 0;
|
||
$arr['self_base_info'] = 0;
|
||
$arr['self_other_info'] = 0;
|
||
$arr['self_is_real_approved'] = 0;
|
||
$arr['self_hidden_profile'] = 0;
|
||
foreach ($arr as $key => $value) {
|
||
$user->$key = $value;
|
||
}
|
||
|
||
$user->isSuperRank = $rd_user->is_super_rank;
|
||
$profile = $user->type == 'single' ? $rd_user->profileCourtship : $rd_user->profileMarriage;
|
||
if(!$profile){
|
||
// return $this->failure('用户信息已关闭');
|
||
$user_err_msg = '用户信息已关闭';
|
||
}
|
||
|
||
$user->profile_courtship = $profile;
|
||
|
||
//Ta是否完成资料
|
||
$isCompleteProfile = $this->userCon->isCompleteProfileV2($profile, $user->type);
|
||
if (!empty($user)) {
|
||
$isCompleteProfile = $user->id != $user_id ? $isCompleteProfile : true;
|
||
}
|
||
$user->isCompleteProfile = $isCompleteProfile;
|
||
//获取头像
|
||
$user->avatar = $user->userAvatar();
|
||
//没有购买会员且有临时会员
|
||
// $rank = $user->rank;
|
||
//年龄
|
||
$user->age = $rd_user->age ? ($rd_user->age) . '岁' : "未知";
|
||
//生活照
|
||
$profile_photos = $user->profilePhoto()->get()->toArray();
|
||
if (count($profile_photos) == 0 ) {
|
||
$photo = [];
|
||
if ($user->photo && $user->is_photo_audited == 1) {
|
||
$photo['photo'] = $user->photo;
|
||
}else {
|
||
// $photo['photo'] = User::DefaultAvatar;
|
||
}
|
||
if($photo){
|
||
$profile_photos[] = $photo;
|
||
}
|
||
}
|
||
$user->profile_photos = $profile_photos;
|
||
|
||
$user->year = null;
|
||
if($user->profile_courtship->birthday){
|
||
$user->year = substr($user->profile_courtship->birthday,2,2);
|
||
}
|
||
//粉丝数
|
||
$user->fans_count = $rd_user->fans_count;
|
||
if(isset($user->profileCourtship->mate_conditon))
|
||
$user->profileCourtship->mate_conditon = json_decode($user->profileCourtship->mate_conditon,true);
|
||
//点击数
|
||
$user->preview_count = (int)$user->previewCacheCount();
|
||
$user = $user->toArray();
|
||
$info = UserInfo::where('user_id',$user_id)->first();
|
||
$user['label_notice'] = $info ? $info->label_notice : 1;
|
||
if (isset($user['profile_courtship'])) {
|
||
if (!$user['profile_courtship']) {
|
||
$user['profile_courtship'] = $user['profile_marriage'];
|
||
}
|
||
} else {
|
||
$user['profile_courtship'] = $user['profile_marriage'];
|
||
}
|
||
//是否禁止登录
|
||
$now = date('Y-m-d H:i:s');
|
||
$sbl = SystemBlacklist::where('user_id', $user_id)->where('start_time', "<", $now)->where('end_time', '>', $now)->first();
|
||
$user['is_banned'] = $sbl?1:0;
|
||
$user['service_id'] = 1353;
|
||
//推荐服务id
|
||
unset($user['mobile'], $user['email']);
|
||
//过滤location
|
||
unset($user['profile_courtship']['mate_conditon']['location']);
|
||
}
|
||
|
||
if($user_err_msg){
|
||
$user = [];
|
||
}
|
||
|
||
return $this->success('ok', compact(
|
||
'user',
|
||
'spread_carrier',
|
||
'spread_anchor',
|
||
'anchor',
|
||
'vip',
|
||
'is_buy',
|
||
'merchant_user',
|
||
'user_err_msg',
|
||
'vip_rank'
|
||
));
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure($e->getMessage());
|
||
}
|
||
}
|
||
}
|