2815 lines
114 KiB
PHP
2815 lines
114 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Mobile;
|
||
|
||
use App\Jobs\SendEarningMessage;
|
||
use App\Models\AppointmentHistory;
|
||
use App\Models\Appointment;
|
||
use App\Models\Live\Viewer;
|
||
use App\Services\LiveAlipayService;
|
||
use App\Jobs\SendRankNotice;
|
||
use App\Models\Live\SingleActivity;
|
||
use App\Models\Live\Anchor;
|
||
use App\Models\Live\Live;
|
||
use App\Utils\Messenger;
|
||
use App\Jobs\SendTemplateMsg;
|
||
use App\Utils\Messenger as Messengers;
|
||
use Illuminate\Container\Container as App;
|
||
use App\Models\Address;
|
||
use App\Models\MEarningRules;
|
||
use App\Models\Coupon;
|
||
use App\Models\UserCoupon;
|
||
use App\Models\Order;
|
||
use App\Models\Message;
|
||
use App\Models\Course\Course;
|
||
use App\Models\Course\UserCourses;
|
||
use App\Models\PayOrder;
|
||
use App\Models\UserReservation;
|
||
use App\Models\Coin;
|
||
use App\Models\Server\SaasNotice;
|
||
use App\Models\SubRank;
|
||
use App\Models\CoinLog;
|
||
use App\Models\Rank;
|
||
use App\Models\SingleService;
|
||
use App\Http\Controllers\Controller;
|
||
use App\Models\BlackIp;
|
||
use App\Models\Wechat;
|
||
use App\Repositories\Eloquent\SmsRepository as Sms;
|
||
use App\Repositories\Eloquent\DynamicRepository as DynamicR;
|
||
use App\Contracts\UserContract;
|
||
use App\Contracts\OrderContract;
|
||
use App\Jobs\NewMerchantDefaultService;
|
||
use App\Services\UserService;
|
||
use Illuminate\Http\Request;
|
||
use App\Models\User;
|
||
use App\Models\MyQuestion;
|
||
use App\Models\ProfileCourtship;
|
||
use App\Models\Blacklist;
|
||
use App\Models\Live\AnchorViewer;
|
||
use App\Models\RedPacketOrder;
|
||
use App\Models\App\Team;
|
||
use App\Jobs\SendMpRed;
|
||
use App\Models\ChatMessage;
|
||
use App\Models\ClientComment;
|
||
use App\Models\Earning;
|
||
use App\Models\EarningAccount;
|
||
use App\Models\EarningTransfer;
|
||
use App\Models\EarningWithdraw;
|
||
use App\Models\Live\Video;
|
||
use Illuminate\Support\Facades\Redis;
|
||
use App\Utils\Str;
|
||
use App\Utils\IP;
|
||
use App\Models\Red\RedAnswer;
|
||
use App\Models\Red\RedQuestion;
|
||
use EasyWeChat\Kernel\Messages\Text;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\ServiceValueResolver;
|
||
use App\Services\YDService;
|
||
use Illuminate\Pagination\LengthAwarePaginator;
|
||
use Illuminate\Support\Facades\Cache;
|
||
use App\Models\LoveStory;
|
||
use App\Models\MarriageMessenger;
|
||
use App\Models\MerchantInfo;
|
||
use App\Models\ProfilePhoto;
|
||
use App\Models\Server\EnterpriseSettlement;
|
||
use App\Models\Server\MerchantAccount;
|
||
use App\Models\Server\MerchantUser;
|
||
use App\Models\UpperWallHistory;
|
||
use App\Models\UserInfo;
|
||
use EasyWeChat\Factory;
|
||
|
||
class UserController extends Controller
|
||
{
|
||
|
||
protected $sms;
|
||
protected $dynamic;
|
||
protected $userCon;
|
||
protected $mobile;
|
||
protected $orderCon;
|
||
protected $app;
|
||
protected $config;
|
||
public function __construct(Sms $sms, DynamicR $dynamic, UserContract $userCon, OrderContract $orderCon){
|
||
$this->sms = $sms;
|
||
$this->dynamic = $dynamic;
|
||
$this->userCon = $userCon;
|
||
$this->orderCon = $orderCon;
|
||
$this->mobile = '15872844805';
|
||
$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);
|
||
}
|
||
|
||
public function storeProfile(Request $request)
|
||
{
|
||
//接收数据
|
||
$photo = $request->input('photo');
|
||
if (empty($photo)) {
|
||
return $this->failure('请上传头像');
|
||
}
|
||
$name = $request->input('name');
|
||
if (empty($name)) {
|
||
return $this->failure('请输入姓名');
|
||
}
|
||
$sex = $request->input('sex');
|
||
if (empty($sex)) {
|
||
return $this->failure('请选择性别');
|
||
}
|
||
$belief = $request->input('belief');
|
||
if (empty($belief)) {
|
||
return $this->failure('请选择信仰');
|
||
}
|
||
$birthday = $request->input('birthday');
|
||
if (empty($birthday)) {
|
||
return $this->failure('请选择出生日期');
|
||
}
|
||
$arr = [$name];
|
||
$result = \CommonUtilsService::textContentCecurity($arr);
|
||
if ($result && $result['result']) {
|
||
return $this->failure('您填写的内容【'.$result['context']."】:".$result['result'].",请重新输入");
|
||
}
|
||
|
||
$user = auth()->user();
|
||
//更新user
|
||
$user->photo = $photo;
|
||
$user->name = $name;
|
||
$user->sex = $sex;
|
||
$user->belief = $belief;
|
||
$user->save();
|
||
//创建信息
|
||
$profile = $user->profileCourtship;
|
||
if (empty($profile)) {
|
||
$profile = new ProfileCourtship();
|
||
}
|
||
$profile->user_id = $user->id;
|
||
$profile->belief = $belief;
|
||
$profile->sex = $sex;
|
||
$profile->birthday = $birthday;
|
||
$profile->save();
|
||
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function profile(Request $request)
|
||
{
|
||
$user = auth()->user();
|
||
$user->profileCourtship;
|
||
return $this->success('ok', $user);
|
||
}
|
||
//我要上墙
|
||
public function postwall(Request $request)
|
||
{
|
||
$name = $request->name;
|
||
$sex = $request->sex;
|
||
$city=$request->city;
|
||
$birthday=$request->birthday;
|
||
//学历
|
||
$degree = $request->degree;
|
||
//职业
|
||
$post = $request->post;
|
||
//婚姻状态
|
||
$state = $request->state;
|
||
$result = $this->sms->check($request->mobile, $request->code);
|
||
if ($result)
|
||
return $this->failure($result);
|
||
//我的视频
|
||
$videos = json_encode($request->videos);
|
||
$photos = json_encode($request->photos);
|
||
$questions['hobby'] = $request->hobby;
|
||
$questions['last_book'] = $request->last_book;
|
||
$questions['travel'] = $request->travel;
|
||
$questions['friends_Comments'] = $request->friends_Comments;
|
||
$questions['godfather'] = $request->godfather;
|
||
$questions['expectation_of_marriage'] = $request->expectation_of_marriage;
|
||
$questions['dislike'] = $request->dislike;
|
||
$questions['belief'] = $request->belief;
|
||
$questions['last_hours'] = $request->last_hours;
|
||
$questions['self_evaluation'] = $request->self_evaluation;
|
||
$questions['videos'] = $videos;
|
||
$questions['photos'] = $photos;
|
||
$questions['relatives_evaluate'] = $request->relatives_evaluate;
|
||
$questions['expect'] = $request->expect;
|
||
$questions['my_story'] = $request->my_story;
|
||
$questions['status'] = 0;
|
||
|
||
$user = User::where('mobile',$request->mobile)->first();
|
||
|
||
try {
|
||
if($user){
|
||
$user->name = $name;
|
||
$user->save();
|
||
$profile = ProfileCourtship::where('user_id',$user->id)->first();
|
||
}else{
|
||
$user = $this->userCon->addUser($request);
|
||
//注册渠道
|
||
DB::table('user_register_channels')->insert(
|
||
['user_id' => $user->id,
|
||
'channel' => 'official',
|
||
'created_at' => date('Y-m-d H:i:s'),
|
||
'updated_at' => date('Y-m-d H:i:s')]
|
||
);
|
||
$profile = new ProfileCourtship;
|
||
$profile->belief = '其他';
|
||
}
|
||
$profile->user_id = $user->id;
|
||
$profile->city = $city;
|
||
$profile->birthday = $birthday;
|
||
$profile->sex = $sex;
|
||
$profile->degree = $degree;
|
||
$profile->post = $post;
|
||
$profile->state = $state;
|
||
$profile->save();
|
||
MyQuestion::updateOrCreate(['user_id'=>$user->id],$questions);
|
||
return $this->success('提交成功');
|
||
} catch (\Exception $e) {
|
||
\Log::info('wall'.$e->getMessage());
|
||
return $this->failure('提交失败,请稍后再试');
|
||
}
|
||
|
||
|
||
|
||
}
|
||
//我的上墙信息
|
||
public function getwall(Request $request)
|
||
{
|
||
$user = auth()->user();
|
||
$data['my_questions'] = MyQuestion::where('user_id',$user->id)->first();
|
||
$data['my_questions']['videos'] = json_decode( $data['my_questions']['videos'],true);
|
||
$data['my_questions']['photos'] = json_decode( $data['my_questions']['photos'],true);
|
||
$userinfo['name']= $user->name;
|
||
$userinfo['sex']= $user->sex;
|
||
$userinfo['mobile']= $user->mobile;
|
||
$userinfo['birthday']= $user->profileCourtship->birthday;
|
||
$userinfo['age'] = $this->getAge($user->profileCourtship->birthday);
|
||
$userinfo['post']= $user->profileCourtship->post;
|
||
$userinfo['state']= $user->profileCourtship->state;
|
||
$userinfo['city']= $user->profileCourtship->city;
|
||
$userinfo['degree']= $user->profileCourtship->degree;
|
||
$data['user'] = $userinfo;
|
||
return $this->success('ok',$data);
|
||
}
|
||
|
||
// 婚姻使者
|
||
public function MarriageMessenger(Request $request)
|
||
{
|
||
$exists = MerchantAccount::where('mobile',$request->mobile)->exists();
|
||
if($exists) return $this->success('您的手机号已经使用,无法再次申请',['status'=>1]);
|
||
$code = $request->code;
|
||
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if(empty( $wechatUser)){
|
||
$openId = $request->openid;
|
||
}else{
|
||
$openId = $wechatUser->getId();
|
||
}
|
||
//检查验证码
|
||
$sms = new Sms(new App);
|
||
$result = $sms->check($request->mobile, $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;
|
||
}
|
||
}
|
||
try {
|
||
\DB::beginTransaction();
|
||
$str = $this->getTradeNO();
|
||
$password = substr($str,4,8);
|
||
$exists = MerchantAccount::where('openId',$openId)->exists();
|
||
if($exists){
|
||
\Log::info('婚姻使者:openid重复:'.$openId.'手机号'.$request->mobile);
|
||
$openId = null;
|
||
}
|
||
$MerchantAccount = new MerchantAccount();
|
||
$MerchantAccount->mobile = $request->mobile;
|
||
$MerchantAccount->openid = $openId;
|
||
$MerchantAccount->password = encrypt($password);
|
||
$MerchantAccount->save();
|
||
$MerchantAccount->token = $this->api_token($MerchantAccount);
|
||
$anchor = new Anchor();
|
||
$anchor->name = $request->nickname;
|
||
$anchor->pic = User::DefaultAvatar;
|
||
$anchor->mobile = $request->mobile;
|
||
$anchor->from_openid = $request->from_openid;
|
||
$anchor->openid = $openId;
|
||
$anchor->channel = 1;
|
||
$anchor->m_id = $MerchantAccount->id;
|
||
$anchor->save();
|
||
// 商家配置信息
|
||
$type = ['service','activity','consult','course','shop'];
|
||
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 = 0;
|
||
$rules->save();
|
||
}
|
||
$marriage_messengers = new MarriageMessenger();
|
||
$marriage_messengers->m_id = $MerchantAccount->id;
|
||
$marriage_messengers->name = $request->name;
|
||
$marriage_messengers->nickname = $request->nickname;
|
||
$marriage_messengers->birthday = $request->birthday;
|
||
$marriage_messengers->sex = $request->sex;
|
||
$marriage_messengers->marriage_time = $request->marriage_time;
|
||
$marriage_messengers->marriage_age = $request->marriage_age;
|
||
$marriage_messengers->province = $request->province;
|
||
$marriage_messengers->city = $request->city;
|
||
$marriage_messengers->marriage_status = $request->marriage_status;
|
||
$marriage_messengers->reason = json_encode($request->reason);
|
||
$marriage_messengers->advantage = $request->advantage;
|
||
$marriage_messengers->certificate = $request->certificate;
|
||
$marriage_messengers->save();
|
||
|
||
\DB::commit();
|
||
} catch (\Exception $e) {
|
||
//回滚事务
|
||
\DB::rollback();
|
||
\Log::error($e->getMessage().';line-'.$e->getLine());
|
||
return $this->failure('提交失败,请稍后再试~');
|
||
|
||
}
|
||
$url = \CommonUtilsService::shortUrl(env('APP_URL').'/pu_m/#/');
|
||
$str = $this->getTradeNO();
|
||
$password = substr($str,4,8);
|
||
$message = '你的账号已注册成功,请访问'.$url['url'].' 完善信息 用户名 :'.$request->mobile.' 密码 :'.$password.'【福恋】';
|
||
Message::create([
|
||
'phone' => $request->mobile,
|
||
'message' => $message,
|
||
'confirmed' => 1,
|
||
'ip' => request() ? request()->ip() : '127.0.0.1',
|
||
]);
|
||
Messengers::sendSMS($request->mobile, $message);
|
||
$data = ['merchant_id'=>$MerchantAccount->id,'anchor_id'=>$anchor->id];
|
||
NewMerchantDefaultService::dispatch($data)->onQueue('love');
|
||
$MerchantUser = MerchantUser::where('openid',$request->from_openid)->first();
|
||
// 是否关注公众号
|
||
$app = \WechatService::officialApp();
|
||
$content = '服务商'.$request->name.'已通过您的邀请入驻成功';
|
||
$wechat_user = $app->user->get($request->from_openid);
|
||
if($wechat_user&&$wechat_user['subscribe']==1){
|
||
$data['touser'] = $request->from_openid;
|
||
$data['template_id'] = 'KCSYnW4IKslhTOmKQ8cFzWcvRVvrDSV-I_wfEm_ZW-U';
|
||
$data['url'] = env('APP_URL').'/h5/#/my';
|
||
$data['data'] = [
|
||
'first' => $content,
|
||
'keyword1' =>$request->name,
|
||
'keyword2' => now(),
|
||
'reamrk' => '',
|
||
];
|
||
SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
||
//增加邀请入驻记录
|
||
$s_merchant = 0;
|
||
$s_anchor = Viewer::where('openid',$request->from_openid)->first();
|
||
if($s_anchor) $s_merchant = MerchantAccount::where('mobile',$s_anchor->mobile)->first();
|
||
if($s_merchant){
|
||
SaasNotice::addRecord($s_merchant->id,0,'m_invite',$MerchantAccount->id,$content,1);
|
||
}
|
||
}else{
|
||
// 短信推送
|
||
if($MerchantUser&&$MerchantUser->mobile){
|
||
Message::create([
|
||
'phone' => $MerchantUser->mobile,
|
||
'message' => $content,
|
||
'confirmed' => 1,
|
||
'ip' => request() ? request()->ip() : '127.0.0.1',
|
||
]);
|
||
Messengers::sendSMS($MerchantUser->mobile, $content);
|
||
}
|
||
//增加邀请入驻记录
|
||
$s_merchant = 0;
|
||
$s_anchor = Anchor::where('openid',$request->from_openid)->first();
|
||
if($s_anchor) $s_merchant = MerchantAccount::where('mobile',$s_anchor->mobile)->first();
|
||
if($s_merchant){
|
||
SaasNotice::addRecord($s_merchant->id,0,'m_invite',$MerchantAccount->id,$content,1);
|
||
}
|
||
}
|
||
//增加入驻记录通知
|
||
$content = '恭喜您,成功入驻福恋智能商家版,欢迎使用!';
|
||
SaasNotice::addRecord($MerchantAccount->id,0,'recruiting',$MerchantAccount->id,$content,1);
|
||
return $this->success('ok',['status'=>0]);
|
||
}
|
||
|
||
//企业入驻
|
||
public function enterpriseSettlement(Request $request){
|
||
$exists = MerchantAccount::where('mobile',$request->mobile)->first();
|
||
if($exists) {
|
||
$password = decrypt($exists->password);
|
||
return $this->success('该号码已经使用,无法再次申请',['status'=>1,'mobile'=>$request->mobile,'password'=>$password]);
|
||
}
|
||
$code = $request->code;
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if(empty( $wechatUser)){
|
||
$openId = $request->openid;
|
||
}else{
|
||
$openId = $wechatUser->getId();
|
||
}
|
||
$is_subscribe = $this->getSubscribeStatus($openId);
|
||
//检查验证码
|
||
$sms = new Sms(new App);
|
||
$result = $sms->check($request->mobile, $code);
|
||
if ($result){
|
||
switch ($result) {
|
||
case '请填写验证码':
|
||
return $this->resp($result,['status'=>7,'message'=>'请填写验证码','is_subscribe'=>$is_subscribe]);
|
||
break;
|
||
case '验证码有误':
|
||
return $this->resp($result,['status'=>8,'message'=>'验证码有误','is_subscribe'=>$is_subscribe]);
|
||
break;
|
||
case '验证码过期':
|
||
return $this->resp($result,['status'=>9,'message'=>'验证码过期','is_subscribe'=>$is_subscribe]);
|
||
break;
|
||
case '验证码已使用':
|
||
return $this->resp($result,['status'=>10,'message'=>'验证码已使用','is_subscribe'=>$is_subscribe]);
|
||
break;
|
||
default:
|
||
# code...
|
||
break;
|
||
}
|
||
}
|
||
try {
|
||
\DB::beginTransaction();
|
||
$str = $this->getTradeNO();
|
||
$password = substr($str,4,8);
|
||
$exists = MerchantAccount::where('openId',$openId)->exists();
|
||
if($exists){
|
||
\Log::info('企业入驻:openid重复:'.$openId.'手机号'.$request->mobile);
|
||
$openId = null;
|
||
}
|
||
$account = new MerchantAccount();
|
||
$account->mobile = $request->mobile;
|
||
$account->openid = $openId;
|
||
$account->password = encrypt($password);
|
||
$account->save();
|
||
$account->token = $this->api_token($account);
|
||
$anchor = new Anchor();
|
||
$anchor->name = $request->name;
|
||
$anchor->pic = User::DefaultAvatar;
|
||
$anchor->mobile = $request->mobile;
|
||
$anchor->from_openid = $request->from_openid;
|
||
$anchor->openid = $openId;
|
||
$anchor->channel = 5;
|
||
$anchor->m_id = $account->id;
|
||
$anchor->save();
|
||
// 商家配置信息
|
||
$type = ['service','activity','consult','course','shop'];
|
||
foreach ($type as $key => $value) {
|
||
$rules = new MEarningRules();
|
||
$rules->m_id = $account->id;
|
||
$rules->name = $value;
|
||
$rules->ratio = 0;
|
||
$rules->first_sharer = 0;
|
||
$rules->last_sharer = 0;
|
||
$rules->other_sharer = 0;
|
||
$rules->forzen_time = 0;
|
||
$rules->save();
|
||
}
|
||
$settle = new EnterpriseSettlement();
|
||
$settle->m_id = $account->id;
|
||
$settle->mobile = $request->mobile;
|
||
$settle->name = $request->name;
|
||
$settle->scale = $request->scale;
|
||
$settle->pic = User::DefaultAvatar;
|
||
$settle->industry = $request->industry;
|
||
$settle->industry_sub = $request->industry_sub;
|
||
$settle->address = $request->address;
|
||
$settle->save();
|
||
$info = new MerchantInfo();
|
||
$info->m_id = $account->id;
|
||
$info->address = $request->address;
|
||
$info->province = $request->province;
|
||
$info->city = $request->city;
|
||
$info->district = $request->district;
|
||
$info->location_longitude = $request->location_longitude;
|
||
$info->location_latitude = $request->location_latitude;
|
||
$info->save();
|
||
DB::commit();
|
||
} catch (\Exception $e) {
|
||
//回滚事务
|
||
DB::rollback();
|
||
\Log::error($e->getMessage().';line-'.$e->getLine());
|
||
return $this->failure('提交失败,请稍后再试~');
|
||
}
|
||
$url = \CommonUtilsService::shortUrl(env('APP_URL').'/pu_m/#/');
|
||
$message = '你的账号已注册成功,请访问'.$url['url'].' 完善信息 用户名 :'.$request->mobile.' 密码 :'.$password.'【福恋】';
|
||
Message::create([
|
||
'phone' => $request->mobile,
|
||
'message' => $message,
|
||
'confirmed' => 1,
|
||
'ip' => request() ? request()->ip() : '127.0.0.1',
|
||
]);
|
||
Messengers::sendSMS($request->mobile, $message);
|
||
$data = ['merchant_id'=>$account->id,'anchor_id'=>$anchor->id];
|
||
NewMerchantDefaultService::dispatch($data)->onQueue('love');
|
||
$MerchantUser = MerchantUser::where('openid',$request->from_openid)->first();
|
||
// 是否关注公众号
|
||
$app = \WechatService::officialApp();
|
||
$content = '企业'.$request->name.'已通过您的邀请入驻成功';
|
||
$wechat_user = $app->user->get($request->from_openid);
|
||
if($wechat_user&&$wechat_user['subscribe']==1){
|
||
$data['touser'] = $request->from_openid;
|
||
$data['template_id'] = 'KCSYnW4IKslhTOmKQ8cFzWcvRVvrDSV-I_wfEm_ZW-U';
|
||
$data['url'] = env('APP_URL').'/h5/#/my';
|
||
$data['data'] = [
|
||
'first' => $content,
|
||
'keyword1' =>$request->name,
|
||
'keyword2' => now(),
|
||
'reamrk' => '',
|
||
];
|
||
SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
||
//增加邀请入驻记录
|
||
$s_merchant = 0;
|
||
$s_anchor = Anchor::where('openid',$request->from_openid)->first();
|
||
if($s_anchor) $s_merchant = MerchantAccount::where('mobile',$s_anchor->mobile)->first();
|
||
if($s_merchant){
|
||
SaasNotice::addRecord($s_merchant->id,0,'m_invite',$account->id,$content,1);
|
||
}
|
||
}else{
|
||
// 短信推送
|
||
if($MerchantUser&&$MerchantUser->mobile){
|
||
Message::create([
|
||
'phone' => $MerchantUser->mobile,
|
||
'message' => $content,
|
||
'confirmed' => 1,
|
||
'ip' => request() ? request()->ip() : '127.0.0.1',
|
||
]);
|
||
Messengers::sendSMS($MerchantUser->mobile, $content);
|
||
}
|
||
//增加邀请入驻记录
|
||
$s_merchant = 0;
|
||
$s_anchor = Anchor::where('openid',$request->from_openid)->first();
|
||
if($s_anchor) $s_merchant = MerchantAccount::where('mobile',$s_anchor->mobile)->first();
|
||
if($s_merchant){
|
||
SaasNotice::addRecord($s_merchant->id,0,'m_invite',$account->id,$content,1);
|
||
}
|
||
}
|
||
//增加入驻记录通知
|
||
$content = '恭喜您,成功入驻福恋智能商家版,欢迎使用!';
|
||
SaasNotice::addRecord($account->id,0,'recruiting',$account->id,$content,1);
|
||
// if($is_subscribe){
|
||
// $app = $this->app;
|
||
// $app->server->push(function ($message) use ($app) {
|
||
// //处理事件类型
|
||
// //已入驻商户发送消息
|
||
// $result = $this->subOperatV2($app,$message['FromUserName']);
|
||
// if (empty($result)) throw new \Exception("发送小程序信息失败", 1);
|
||
// $text = new Text($result);
|
||
// $result = $app->customer_service->message($text)->to($message['FromUserName'])->send();
|
||
// $news = $this->scanQrcode($message);
|
||
// return $news;
|
||
// return isset($news)?$news:null;
|
||
// });
|
||
// $response = $app->server->serve();
|
||
// return $response;
|
||
// }
|
||
return $this->success('ok',['status'=>0,'is_subscribe'=>$is_subscribe,'mobile'=>$request->mobile,'password'=>$password]);
|
||
}
|
||
|
||
// 地区信息和问题信息
|
||
public function MarriageOptions(Request $request)
|
||
{
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if(empty($wechatUser)){
|
||
$openid = $request->openid;
|
||
}else{
|
||
$openid = $wechatUser->getId();
|
||
}
|
||
$address_arr = Address::where('name', '<>', '不限')->orderBy('codeId', 'asc')->select('codeId', 'name', 'parentId')->get()->toArray();
|
||
$address_arr = $this->addressSort($address_arr);
|
||
//协助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']);
|
||
}
|
||
}
|
||
}
|
||
$questions = [
|
||
[
|
||
'id'=>1,
|
||
'value'=>'我认为只有一男一女,一夫一妻,一心一意,一生一世的婚姻关系,才是真正成功,并承载、延续祝福的婚姻',
|
||
'state'=>false,
|
||
],
|
||
[
|
||
'id'=>2,
|
||
'value'=>'我对凑合婚姻,出轨,离婚,同性恋及大龄不婚等乱象感到忧心,希望能尽一份心力,帮助做出一点点改变',
|
||
'state'=>false,
|
||
],
|
||
[
|
||
'id'=>3,
|
||
'value'=>'我喜欢和志同道合的人一起,为同一个使命而努力。',
|
||
'state'=>false,
|
||
],
|
||
[
|
||
'id'=>4,
|
||
'value'=>'在同伴需要帮助扶持的时候我能给予鼓励,同时在我软弱的时候也需要有人陪伴和扶持',
|
||
'state'=>false,
|
||
],
|
||
[
|
||
'id'=>5,
|
||
'value'=>'我想陪伴单身成长,帮助他们正确对待婚姻',
|
||
'state'=>false,
|
||
],
|
||
[
|
||
'id'=>6,
|
||
'value'=>'其他,请描述',
|
||
'state'=>false,
|
||
],
|
||
];
|
||
$app = \WechatService::officialApp();
|
||
$wechat_user = $app->user->get($openid);
|
||
$wechat_user = $wechat_user['subscribe']??0;
|
||
return $this->success('ok',compact('address_arr','questions','wechat_user'));
|
||
}
|
||
|
||
//获取验证码
|
||
|
||
public function sendOfficialRegisterCode(Request $request){
|
||
$mobile = $request->input('mobile');
|
||
//限制请求次数
|
||
$key = $mobile.'sendOfficialRegisterCode';
|
||
$is_request = Redis::get($key);
|
||
if($is_request){
|
||
return $this->resp('请求频率过快',['status'=>6]);
|
||
}
|
||
Redis::setex($key, 60, 1);
|
||
$result = $this->sendCode($mobile, 'register', ['paas'=>$request->input('paas')]);
|
||
return $result;
|
||
}
|
||
|
||
//爱情故事
|
||
|
||
public function loveStory(Request $request)
|
||
{
|
||
$mobile = $request->mobile;
|
||
$city = $request->city;
|
||
$province = $request->province;
|
||
$mobile = $request->mobile;
|
||
$result = LoveStory::where('mobile',$mobile)->where('status','<>',2)->count();
|
||
if($result) return $this->failure('您已经提交过资料啦~');
|
||
$user = User::where('mobile',$request->mobile)->first();
|
||
if($user){
|
||
$profile = ProfileCourtship::where('user_id',$user->id)->first();
|
||
}else{
|
||
$user = $this->userCon->addUser($request);
|
||
//注册渠道
|
||
DB::table('user_register_channels')->insert(
|
||
['user_id' => $user->id,
|
||
'channel' => 'official',
|
||
'created_at' => date('Y-m-d H:i:s'),
|
||
'updated_at' => date('Y-m-d H:i:s')]
|
||
);
|
||
$profile = new ProfileCourtship;
|
||
$profile->belief = '其他';
|
||
}
|
||
$profile->user_id = $user->id;
|
||
$profile->city = $profile->city??$city;
|
||
$profile->province = $profile->province??$province;
|
||
$profile->save();
|
||
|
||
$lovestory = new loveStory;
|
||
$lovestory->name = $request->name;
|
||
$lovestory->mobile = $request->mobile;
|
||
$lovestory->city = $request->city;
|
||
$lovestory->acquaintance = $request->acquaintance;
|
||
$lovestory->acquaintance_photos = json_encode($request->acquaintance_photos);
|
||
$lovestory->know_each_other = $request->know_each_other;
|
||
$lovestory->know_each_other_photos = json_encode($request->know_each_other_photos);
|
||
$lovestory->loveing = $request->loveing;
|
||
$lovestory->loveing_photos = json_encode($request->loveing_photos);
|
||
$lovestory->open_communication = $request->open_communication;
|
||
$lovestory->open_communication_photos = json_encode($request->open_communication_photos);
|
||
$lovestory->marry = $request->marry;
|
||
$lovestory->marry_photos = json_encode($request->marry_photos);
|
||
$lovestory->proposal = $request->proposal;
|
||
$lovestory->proposal_photos = json_encode($request->proposal_photos);
|
||
$lovestory->save();
|
||
return $this->success('提交成功!');
|
||
|
||
}
|
||
|
||
|
||
//预约.收藏直播
|
||
|
||
public function reservations(Request $request)
|
||
{
|
||
$user = auth()->user();
|
||
//reservations:预约直播,favorite 收藏直播
|
||
$type = $request->type??'reservations';
|
||
//被预约的用户id
|
||
$text = '收藏';
|
||
if($type=='reservations')
|
||
$text = '预约';
|
||
$live_id = $request->live_id;
|
||
$result = Live::where('id',$live_id)->first();
|
||
if(!$result)return $this->failure('操作失败~请稍后再试');
|
||
if($type=='reservations'){
|
||
if($result->end_time<now())
|
||
return $this->failure('操作失败~直播已结束!');
|
||
}
|
||
|
||
$exists = UserReservation::where('user_id',$user->id)->where('type',$type)->where('type_id',$live_id)->first();
|
||
if(!$exists){
|
||
$UserReservation = new UserReservation;
|
||
$UserReservation->user_id = $user->id;
|
||
$UserReservation->type_id = $live_id;
|
||
$UserReservation->type = $type;
|
||
$UserReservation->save();
|
||
$remind = 1;
|
||
}elseif($exists->status==2){
|
||
$exists->status=0;
|
||
$exists->save();
|
||
$remind = 1;
|
||
}else{
|
||
$exists->status=2;
|
||
$exists->save();
|
||
$remind = 0;
|
||
}
|
||
$data['type'] = $type;
|
||
$data['remind'] = $remind;
|
||
$key = 'h5live'.$live_id.'user'.$user->id;
|
||
cache::forget($key);
|
||
return $this->success('操作成功~', $data);
|
||
}
|
||
|
||
//取消预约.收藏直播
|
||
|
||
public function user(Request $request, User $user)
|
||
{
|
||
#生活照
|
||
$profile_photos = $user->profilePhoto()->get()->toArray();
|
||
if (count($profile_photos) == 0) {
|
||
if ($user->wechat) {
|
||
$photo['photo'] = $user->wechat->avatar2;
|
||
$profile_photos[] = $photo;
|
||
}
|
||
}
|
||
$user->profile_photos = $profile_photos;
|
||
//上次登录时间
|
||
// $login_time = Dynamic::where('user_id', $user->id)->orderBy('id', 'desc')->value('created_at');
|
||
// $login_time_str = '';
|
||
// if ($login_time) {
|
||
// $login_time = $login_time->toDateTimeString();
|
||
// $time = date('Y-m-d H:i:s', time());
|
||
// $login_time = $this->getTime($time, $login_time);
|
||
// $login_time_str = $this->timeAgo($login_time);
|
||
// }
|
||
// $user->login_time_str = $login_time_str;
|
||
//隐藏身份证
|
||
if ($user->card_num && mb_strlen($user->card_num)) {
|
||
$user->card_num = substr_replace($user->card_num, '********',-8,8);
|
||
}else{
|
||
$user->card_num = '********';
|
||
}
|
||
$user->profileCourtship;
|
||
$age = '未知';
|
||
#年龄
|
||
if (!empty($user->profileCourtship) && !empty($user->profileCourtship->birthday)) {
|
||
$age = $this->getAge($user->profileCourtship->birthday);
|
||
$age = $age.'岁';
|
||
}
|
||
$user->age = $age;
|
||
return $this->success('ok', $user);
|
||
}
|
||
|
||
/**
|
||
* 上次使用时间
|
||
*/
|
||
public function timeAgo($login_time)
|
||
{
|
||
$login_time_str = '';
|
||
if ($login_time['day']) {
|
||
$login_time_str = $login_time['day'].'天前';
|
||
}elseif ($login_time['hour']) {
|
||
$login_time_str = $login_time['hour'].'小时前';
|
||
}elseif ($login_time['min']) {
|
||
$login_time_str = $login_time['min'].'分钟前';
|
||
}elseif ($login_time['sec']) {
|
||
$login_time_str = $login_time['sec'].'秒钟前';
|
||
}
|
||
return $login_time_str;
|
||
}
|
||
|
||
/**
|
||
* 拉黑用户,隐藏用户
|
||
*/
|
||
public function blackUser(Request $request, User $user)
|
||
{
|
||
$mine = auth()->user();
|
||
$blacklist = Blacklist::firstOrCreate([
|
||
'user_id'=>$mine->id,
|
||
'other_user_id'=>$user->id,
|
||
]);
|
||
return $this->success('ok', $blacklist);
|
||
}
|
||
|
||
public function updateProfile(Request $request)
|
||
{
|
||
$arr = [$request->input('name'), $request->input('introduction'), $request->input('ideal_mate')];
|
||
$result = \CommonUtilsService::textContentCecurity($arr);
|
||
if ($result && $result['result']) {
|
||
return $this->failure('您填写的内容【'.$result['context']."】:".$result['result'].",请重新输入");
|
||
}
|
||
if ($request->input('photo')) {
|
||
$arr = [$request->photo];
|
||
$result = \CommonUtilsService::imageContentCecurity($arr);
|
||
if ($result && isset($result['result']) && $result['result']) {
|
||
return $this->failure('图片'.$result['result'].',请换一张照片');
|
||
}
|
||
}
|
||
$this->userCon->updateUser($request);
|
||
$this->userCon->updateProfile($request);
|
||
return $this->success('ok');
|
||
}
|
||
|
||
|
||
/**
|
||
* 微信授权登录
|
||
* @param Request $request
|
||
* @return \Illuminate\Http\RedirectResponse
|
||
*/
|
||
public function socialStore(Request $request){
|
||
$wechatUser = session('wechat.oauth_user.default');
|
||
$openId = $wechatUser->getId();
|
||
if($request->fromopenid){
|
||
// 绑定分享人跟领取红包人openid
|
||
Redis::setex($openId, 600, $request->fromopenid);
|
||
}
|
||
// 绑定来源
|
||
if($request->has('source') && $request->source){
|
||
Redis::set($openId.'source', $request->source);
|
||
}
|
||
|
||
$moreInfo = $wechatUser->getOriginal();
|
||
|
||
|
||
if (config('app.env') == 'local') {
|
||
// dd($request->input('type'));
|
||
$redirect_url = 'http://localhost:8081/#/ploveHelpMarriage?openid='.$openId;
|
||
return redirect($redirect_url);
|
||
}else {
|
||
$redirect_url = env('APP_URL').'/mobile/#/ploveHelpMarriage?openid='.$openId;
|
||
return redirect($redirect_url);
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 关注公众号奖励
|
||
* @param Request $request
|
||
*/
|
||
public function getMpReward(Request $request){
|
||
//$ip = $request->getClientIp();
|
||
$openId = $request->openid;
|
||
Redis::exists($openId.'_request_num') ? Redis::incr($openId.'_request_num') : Redis::set($openId.'_request_num', 1);
|
||
|
||
$source = Redis::get($openId.'source');
|
||
|
||
$ip = IP::getip();
|
||
$blackIpArr = BlackIp::where('type', 1)->pluck('ip')->toArray();
|
||
if(in_array($ip, $blackIpArr)){
|
||
return $this->failure('网络段繁忙,请换个时间来领取红包!');
|
||
}
|
||
|
||
|
||
// 教会来源的用户直接通过
|
||
if(isset($source) && $source){
|
||
|
||
}else {
|
||
// 查看链接是否正确
|
||
if (config('red.is_validate')) {
|
||
// Redis::del($openId . 'validate');
|
||
$rightAnswer = Redis::get($openId . 'validate');
|
||
// print_r($rightAnswer);die;
|
||
// 没有发送过问题,先发送问题
|
||
if(!$rightAnswer){
|
||
$this->sendQuestion($openId);
|
||
return $this->failure('完成公众号发送的问题后可领取红包');
|
||
}
|
||
|
||
// 是否超过试错上限
|
||
$errorNum = Redis::get($openId.'error_num');
|
||
$errorMax = config('red.error_max');
|
||
|
||
if ($errorNum >= $errorMax) {
|
||
return $this->failure('点击错误次数超过上限');
|
||
}
|
||
|
||
if (!$request->has('answer') || $request->answer != $rightAnswer) {
|
||
Redis::exists($openId.'error_num') ? Redis::incr($openId.'error_num') : Redis::set($openId.'error_num', 1);
|
||
// 再次发送答题验证
|
||
$this->sendQuestion($openId);
|
||
return $this->failure('点击了错误的答案,点错三次将无法领取红包');
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
$fromOpenid = Redis::get($openId);
|
||
if(!$this->hasSubscribeOfficial($openId)){
|
||
$data = [
|
||
'status' => 1,
|
||
'msg' => "您还未关注公众号",
|
||
];
|
||
return $this->success('ok', compact('data'));
|
||
}
|
||
|
||
$haveReceive = RedPacketOrder::where('official_openid', $openId)->where('type', 'MP')->count();
|
||
$haveReceiveRedis = Redis::get($openId.'red');
|
||
if ($haveReceive || $haveReceiveRedis) {
|
||
// if($haveReceiveRedis){
|
||
$data = [
|
||
'status' => 2,
|
||
'msg' => "您已领取过红包"
|
||
];
|
||
if($openId != 'okaDW01puu_wkkFJloO0hEeMQIzs'){
|
||
return $this->success('ok', $data);
|
||
}
|
||
}
|
||
if((date('G')>=23 || date('G')<=8) && !in_array($source, ['glore','kingneo153','huangshi','YANBIN','AXY01','Wangxuejun'])){
|
||
return $this->failure('弟兄姊妹您好,夜深了请注意休息,每天早上九点开始领红包!');
|
||
}
|
||
/*if(!isset($source) || in_array($source, ['auto','ploves_menu'])) {
|
||
return $this->failure('只有福恋会员才能参与领取红包,敬请期待集九果活动');
|
||
}*/
|
||
//无渠道红包受到限制日限额。
|
||
if(Redis::get('NotenoughAlarm') && (!isset($source) || in_array($source, ['auto','ploves_menu']))){
|
||
$red_wave = Redis::get('NotenoughAlarm');
|
||
return $this->failure('第'.$red_wave.'波红包已经领完,明天早上九点继续来领红包!');
|
||
}
|
||
/**
|
||
* TODO:各渠道配额限制及提示
|
||
* 1、从red_pack_activity中查寻
|
||
* 2、任务中计算当前各渠道红包配额及状态
|
||
*/
|
||
|
||
|
||
// 未领取红包
|
||
// 发红包给当前用户
|
||
$userId = Wechat::where('official_openid', $openId)->value('user_id') ?: 0;
|
||
$amount = $this->receiveRed($openId, $userId, 'MP', $fromOpenid, $ip, $source);
|
||
// 标记为已领取
|
||
Redis::setnx($openId.'red', 1);
|
||
|
||
$data = [
|
||
'status' => 0,
|
||
'msg' => $amount
|
||
];
|
||
return $this->success('ok', $data);
|
||
|
||
}
|
||
|
||
/**
|
||
* @param Request $request
|
||
* 领取红包前判断
|
||
*/
|
||
public function inspect(Request $request){
|
||
$distance = $this->getDistance(113.93041, 22.53332, 113.05198187, 23.02751736);
|
||
$openId = $request->openid;
|
||
if(!$this->hasSubscribeOfficial($openId)){
|
||
$data = [
|
||
'status' => 1,
|
||
];
|
||
return $this->success('', $data);
|
||
}
|
||
$haveReceive = RedPacketOrder::where('official_openid', $openId)->where('type', 'MP')->count();
|
||
if($haveReceive){
|
||
$data = [
|
||
'status' => 2,
|
||
];
|
||
if($openId != 'okaDW01puu_wkkFJloO0hEeMQIzs') {
|
||
return $this->success('', $data);
|
||
}
|
||
}
|
||
$data = [
|
||
'status' => 0,
|
||
];
|
||
|
||
return $this->success('', $data);
|
||
}
|
||
|
||
|
||
/**
|
||
* @param Request $request
|
||
* @return \Illuminate\Http\JsonResponse|string
|
||
* 被分享贡献红包列表
|
||
*/
|
||
public function redDetailed(Request $request){
|
||
$openId = $request->openid;
|
||
$list = RedPacketOrder::with('fromWechat')->where('official_openid', $openId)
|
||
->where('type', 'SHAREMP')->where('from_official_openid', '!=', '')->where('err_code', 'SUCCESS')
|
||
->select('amount', 'from_official_openid')->orderBy('id', 'desc')->get()->toArray();
|
||
|
||
$myArr['from_wechat'] = Wechat::where('official_openid', $openId)->first();
|
||
$myArr['from_official_openid'] = $openId;
|
||
$myArr['amount'] = RedPacketOrder::where('official_openid', $openId)->where('type', 'SHAREMP')->sum('amount') ?: 0.00;
|
||
array_unshift($list, $myArr);
|
||
|
||
$app = \WechatService::officialApp();
|
||
foreach ($list as &$item) {
|
||
if(!$item['from_wechat']){
|
||
$wechatUser = $app->user->get($item['from_official_openid']);
|
||
$item['from_wechat']['avatar'] = isset($wechatUser['headimgurl'])?$wechatUser['headimgurl']:'http://images.ufutx.com/201811/12/0e8b72aae6fa640d9e73ed312edeebf3.png';
|
||
$item['from_wechat']['nickname'] = isset($wechatUser['nickname'])?$wechatUser['nickname']:"已取消关注";
|
||
}
|
||
}
|
||
|
||
//dd($list);
|
||
return $this->success('ok', compact('list'));
|
||
}
|
||
|
||
public function receiveRed($openId, $userId = 0, $type = 'MP', $fromOpenid='', $ip, $source){
|
||
return false;
|
||
$trade_no = \CommonUtilsService::getTradeNO();
|
||
//生成红包
|
||
$array = [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4];
|
||
$key = array_rand($array);
|
||
$amount = $array[$key] / 10 + mt_rand(0, 9)/100;
|
||
// $amount = $array[$key] / 100;
|
||
|
||
$sendName = "福恋小助手脱单红包(请保持关注)";
|
||
// $haveReceive = RedPacketOrder::where('official_openid', $openId)->where('type', 'MP')->count();
|
||
|
||
// if($haveReceive > 0){
|
||
// return $amount;
|
||
// }
|
||
|
||
$order = new RedPacketOrder();
|
||
$order->user_id = $userId;
|
||
$order->type = $type;
|
||
$order->trade_no = $trade_no;
|
||
$order->amount = $amount;
|
||
$order->official_openid = $openId;
|
||
$order->from_official_openid = $fromOpenid;
|
||
$order->trigged='0';
|
||
$order->send_name = $sendName;
|
||
$order->ip = $ip;
|
||
$order->source = $source;
|
||
$order->save();
|
||
|
||
$packet_data = [
|
||
'openid'=>$openId,
|
||
'amount'=>$amount,
|
||
'send_name'=> $sendName,
|
||
'packet_type'=>'normal',
|
||
'trade_no'=>$trade_no,
|
||
'type'=>$type,
|
||
'id'=>$order->id,
|
||
'from_openid'=>$fromOpenid,
|
||
'ip'=>$ip,
|
||
'source' => $source,
|
||
];
|
||
|
||
SendMpRed::dispatch($packet_data)->onQueue('love');
|
||
return $amount;
|
||
}
|
||
|
||
/**
|
||
* 是否关注
|
||
* @param $openId
|
||
* @return int|mixed
|
||
*/
|
||
public function hasSubscribeOfficial($openId){
|
||
// 判断数据是否存在
|
||
$app = \WechatService::officialApp();
|
||
// $wechatCount = Wechat::where('official_openid', $openId)->count();
|
||
// if (!$wechatCount) {
|
||
// return 0;
|
||
// }
|
||
$wechatUser = $app->user->get($openId);
|
||
|
||
$result = !empty($wechatUser)&&isset($wechatUser['subscribe']);
|
||
$is_subscribe = $result?$wechatUser['subscribe']:0;
|
||
|
||
// 已关注的话判断是否存入到WeChat过,没有就新增一条记录
|
||
if($is_subscribe){
|
||
if(isset($wechatUser['unionid'])){
|
||
$wechat = Wechat::where('unionid',$wechatUser['unionid'])->first();
|
||
if (!$wechat) {
|
||
$wechat = Wechat::create([
|
||
'official_openid' => $openId,
|
||
'nickname' => $wechatUser['nickname'],
|
||
'avatar' => $wechatUser['headimgurl'],
|
||
'unionid' => $wechatUser['unionid'],
|
||
]);
|
||
}else{
|
||
if(!$wechat->official_openid){
|
||
$wechat->official_openid = $openId;
|
||
$wechat->save();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return $is_subscribe;
|
||
}
|
||
|
||
/**
|
||
* @param Request $request
|
||
* 发送问题验证
|
||
*/
|
||
public function sendQuestion($openId){
|
||
|
||
$randArr = [];
|
||
for ($i=0; $i<4; $i++){
|
||
$randArr[] = rand(100000,999999);
|
||
}
|
||
|
||
$questionList = RedQuestion::select('id','title')->with('answer:id,content,question_id,is_right')->get()->toArray();
|
||
$key = array_rand($questionList);
|
||
$question = $questionList[$key];
|
||
|
||
// 拼接微信公众号通知
|
||
if (config('app.env') == 'local') {
|
||
$redirect_url = "http://wlj.test/api/receivered?openid=".$openId;
|
||
}else {
|
||
$redirect_url = env('APP_URL').'/api/receivered?openid={$openId}';
|
||
}
|
||
|
||
|
||
$content = $question['title']."\n";
|
||
foreach ($question['answer'] as $k => $item) {
|
||
$redirect_url .= "&answer=".$randArr[$k];
|
||
$content .= "<a href='{$redirect_url}'>".$item['content']."</a>\n";
|
||
if($item['is_right']){
|
||
Redis::setex($openId.'validate', 600, $randArr[$k]);
|
||
}
|
||
}
|
||
|
||
$text = new Text($content);
|
||
$app = \WechatService::officialApp();
|
||
$result = $app->customer_service->message($text)->to($openId)->send();
|
||
|
||
if($result['errcode'] != 0){
|
||
\Log::info([$openId=>$result]);
|
||
}
|
||
}
|
||
|
||
//超级会员
|
||
public function superRank(Request $request){
|
||
{
|
||
$rank = Rank::with(['subRanks' => function ($query) {
|
||
$query->where('is_show_web', 1);
|
||
}])->where('name', '超级会员')->first()->toArray();
|
||
if (!empty($rank)) {
|
||
$rank['explain'] = json_decode($rank['explain']);
|
||
$rank['feature'] = json_decode($rank['feature']);
|
||
}
|
||
return $this->success('ok', $rank);
|
||
}
|
||
}
|
||
|
||
//我的预约.收藏
|
||
public function MyAppointment(Request $request)
|
||
{
|
||
$user = auth()->user();
|
||
$type = $request->type??'favorite';
|
||
$result = UserReservation::select('id','user_id','status','type_id')
|
||
->where('type',$type)
|
||
->where('user_id',$user->id)
|
||
->where('status','!=',2)
|
||
->paginate();
|
||
foreach ($result as $key => $value) {
|
||
$value->title = $value->live->title;
|
||
$value->poster = $value->live->poster;
|
||
$value->status = $value->live->status;
|
||
$value->start_time = $value->live->start_time;
|
||
$value->pv = Redis::zscore('page_pv', $value->live->id);
|
||
unset($value->live);
|
||
}
|
||
return $result ;
|
||
|
||
}
|
||
//标记用户未读信息
|
||
public function remakeMessage(Request $request){
|
||
$request = ChatMessage::where('other_user_id',$request->user_id)->where('status',0)->update(['status'=>1]);
|
||
return $this->success('ok', $request);
|
||
}
|
||
//直播课程推荐
|
||
|
||
public function liveCourseRecommend(Request $request)
|
||
{
|
||
$userId = 0;
|
||
if (\Auth::guard('api')->check()) {
|
||
$userId = \Auth::guard('api')->user()->id;
|
||
}
|
||
$teacher_id = $request->user_id;
|
||
$live_id = $request->live_id;
|
||
$Course_ids = Live::where('id',$live_id)->value('recommend_course_id');
|
||
if($Course_ids){
|
||
$Course_ids = json_decode($Course_ids,true);
|
||
$courses = Course::select('id','title','charge','thumb')->where('is_show',1)->wherein('id',$Course_ids)->withCount('videos')->inRandomOrder()->first();
|
||
if($courses)
|
||
$courses['videos_count'] = $courses->videos_count??0;
|
||
|
||
}else{
|
||
// $ids= UserCourses::where('user_id',$userId)->where('status',1)->pluck('course_id');
|
||
// $courses = Course::select('id','title','charge','thumb')->where('type','fullink')->where('is_show',1)->where('user_id',$teacher_id)->wherenotin('id',$ids)->withCount('videos')->inRandomOrder()->first();
|
||
// if($courses)
|
||
// $courses['videos_count'] = $courses->videos_count??0;
|
||
$courses = [];
|
||
}
|
||
return $this->success('ok',$courses);
|
||
}
|
||
|
||
//老师课程
|
||
|
||
public function teacherCourses(Request $request)
|
||
{
|
||
|
||
$user = auth()->user();
|
||
$user_id = 0;
|
||
if(isset($user))
|
||
$user_id = $user->id;
|
||
$teacher_id = $request->user_id;
|
||
$key = 'teacher-course'.$teacher_id.'user'.$user_id;
|
||
$result = cache::remember($key,5,function()use($user,$teacher_id){
|
||
if($teacher_id==0)
|
||
$teacher_id = -1;
|
||
$courses = Course::where('is_show',1)->where('user_id',$teacher_id)->withCount('videos')->orderBy('sort','desc')->orderBy('user_count','desc')->paginate();
|
||
foreach ($courses as $key => $value) {
|
||
//原价
|
||
$value->original_price = $value->charge;
|
||
$value->discount_status = 0;
|
||
if($value->end_time_discount>now()&&$value->start_time_discount<now()&&$value->discount_price){
|
||
$value->charge = $value->discount_price;
|
||
$value->discount_status = 1;
|
||
}
|
||
$value['videos_count'] = $value->videos_count;
|
||
$value['paymentStatus'] = false;
|
||
if(isset($user->id))
|
||
$value['paymentStatus'] = UserCourses::where('course_id',$value->id)->where('user_id',$user->id)->where('status',1)->count()?true:false;
|
||
}
|
||
return $courses;
|
||
});
|
||
return $this->success('ok', $result);
|
||
|
||
}
|
||
|
||
|
||
//首页推荐
|
||
public function livelist(Request $request){
|
||
|
||
$lives = Live::select('id','title','url','status','anchor_id')->where('recommend', 1)->orderBy('sort','desc')->get();
|
||
foreach ($lives as $live){
|
||
// $live->pv = Redis::zscore('page_pv', $live->id);
|
||
$live->name = '未知';
|
||
$live->avatar = null;
|
||
$live->user_id = 0;
|
||
$live->designation = null;
|
||
if($live->teacher){
|
||
$Viewer = Viewer::where('id',$live->teacher->viewer_id)->first();
|
||
if(!$Viewer){
|
||
continue;
|
||
}
|
||
$user = User::select('id','name')->where('mobile',$Viewer->mobile)->first();
|
||
$Anchor = Anchor::where('viewer_id',$Viewer->id)->first();
|
||
$live->name = $user->name??$Anchor->name;
|
||
$live->avatar = $Anchor->pic??'';
|
||
$live->user_id = $user->id??0;
|
||
$live->designation = $live->teacher['designation'];
|
||
}
|
||
|
||
unset($live->teacher);
|
||
}
|
||
|
||
$result = Team::select('id','icon','logo','tname','owner')->where('type','h5')->limit(5)->get();
|
||
$teams = [];
|
||
foreach ($result as $key => $value) {
|
||
$value->name = User::where('id', $value->owner)->value('name');
|
||
$count = Course::where('team_id',$value->id)->where('is_show',1)->count();
|
||
if($count){
|
||
if($value->owner==58020)
|
||
$value->name = '何张沛然';
|
||
if($value->owner==61261)
|
||
$value->name = '马丁';
|
||
array_push($teams,$value);
|
||
}
|
||
}
|
||
$banner = Redis::get('home_banner');
|
||
$banner = json_decode($banner);
|
||
return $this->success('ok', compact('lives','banner','teams'));
|
||
}
|
||
|
||
//关注专区
|
||
|
||
public function FocusArea(Request $request)
|
||
{
|
||
$openid = $request->openid;
|
||
// 用户的观看id
|
||
$viewer_id = Viewer::where('openid', $openid)->value('id');
|
||
if($viewer_id){
|
||
//获取用户的关注主播
|
||
if(!$request->anchor_id){
|
||
$anchors = AnchorViewer::where('viewer_id', $viewer_id)->where('focusing',1)->pluck('anchor_id');
|
||
//获取主播的观看id
|
||
}else{
|
||
$anchors[] = $request->anchor_id;
|
||
}
|
||
$lives = live::select('id','title','poster','start_time','anchor_id','status')
|
||
->wherein('anchor_id', $anchors)
|
||
->where('is_show',1)
|
||
->wherenotin('status',[3,4])
|
||
->orderBy('sort','desc')
|
||
->paginate();
|
||
foreach ($lives as $key => $value) {
|
||
$value->pv = Redis::zscore('page_pv', $value->id);
|
||
}
|
||
return $this->success('ok', $lives);
|
||
}else{
|
||
$page = $request->page??1;
|
||
$perPage = 10;
|
||
$offset = 0;
|
||
$result = new LengthAwarePaginator(array_slice([], $offset, $perPage, true), 0, $perPage, $page, ['path' => $request->url(), 'query' => $request->query()]);
|
||
return $this->success('ok', $result);
|
||
}
|
||
}
|
||
|
||
//关注标签
|
||
public function FocusLabel(Request $request)
|
||
{
|
||
|
||
if(\Auth::guard('api')->check()){
|
||
$user = \Auth::guard('api')->user();
|
||
// 用户的观看id
|
||
$viewer_id = Viewer::where('user_id', $user->id)->value('id');
|
||
$anchors = AnchorViewer::where('viewer_id', $viewer_id)->where('focusing',1)->pluck('anchor_id');
|
||
//获取主播的观看id
|
||
$anchor_ids= Anchor::wherein('id',$anchors)->pluck('viewer_id');
|
||
//获取主播的信息
|
||
$users = Viewer::select('id','user_id')->wherein('id',$anchor_ids)->get();
|
||
$data = [];
|
||
foreach ($users as $key => $value) {
|
||
$value->anchor_id = $value->anchor->id;
|
||
$value->name = $value->anchor->name;
|
||
unset($value->anchor);
|
||
array_push($data,$value);
|
||
}
|
||
return $this->success('ok', $data);
|
||
}else{
|
||
return $this->success('ok', []);
|
||
}
|
||
}
|
||
|
||
//名师推荐
|
||
public function recommend(Request $request)
|
||
{
|
||
$anchors = Anchor::select('id','viewer_id','pic','introduction','name','pic')->with('viewer')->where('is_rec','1')->orderby('sort','desc')->paginate();
|
||
foreach ($anchors as $key => $value) {
|
||
$value->is_followed = false;
|
||
$openId = $request->openid;
|
||
$viewer = Viewer::where('openid', $openId)->first();
|
||
if($viewer)
|
||
$is_focu = AnchorViewer::where('viewer_id',$viewer->id)->where('anchor_id', $value->id)->where('focusing', 1)->count();
|
||
$value->is_followed = !empty($is_focu) ? 1 : 0;
|
||
}
|
||
return $this->success('ok',$anchors);
|
||
}
|
||
|
||
//领取优惠券
|
||
|
||
public function getcoupon(Request $request)
|
||
{
|
||
$user_id = 0;
|
||
if(\Auth::guard('api')->check()){
|
||
$user_id = \Auth::guard('api')->user()->id;
|
||
}
|
||
$openId = $request->openid;
|
||
$coupons_id = $request->coupons_id;
|
||
$Coupon = Coupon::where('id',$coupons_id)->where('status',1)->first();
|
||
if(!$Coupon)
|
||
return $this->failure('该优惠券不存在或已下架');
|
||
if($Coupon->remain_num<=0)
|
||
return $this->failure('该优惠券已经领取完啦~');
|
||
$user_coupon = UserCoupon::where('coupons_id',$coupons_id)->where(function ($query) use($openId,$user_id) {
|
||
$query->where('openid', $openId)
|
||
->orWhere('user_id', $user_id);
|
||
})->exists();
|
||
if($user_coupon)
|
||
return $this->failure('您已经领取过该优惠券~');
|
||
$UserCoupon = new UserCoupon;
|
||
if($user_id){
|
||
$UserCoupon->user_id = $user_id;
|
||
}else{
|
||
$UserCoupon->openid = $openId;
|
||
}
|
||
$UserCoupon->coupons_id = $coupons_id;
|
||
$UserCoupon->save();
|
||
Coupon::where('id',$coupons_id)->decrement('remain_num',1);
|
||
$key = 'couponInfo'.$coupons_id.'user'.$user_id.'openId'.$openId;
|
||
cache::forget($key );
|
||
$key = 'mycoupon'.$user_id.'openId'.$openId.'course';
|
||
cache::forget($key );
|
||
return $this->success('领取成功', $UserCoupon);
|
||
}
|
||
|
||
//优惠券信息
|
||
public function couponInfo(Request $request)
|
||
{
|
||
$openId = $request->openid;
|
||
$user_id = 0;
|
||
$coupons_id = $request->coupons_id;
|
||
if(\Auth::guard('api')->check()){
|
||
$user_id = \Auth::guard('api')->user()->id;
|
||
}
|
||
$key = 'couponInfo'.$coupons_id.'user'.$user_id.'openId'.$openId;
|
||
$result = cache::remember($key,1440,function() use($openId,$user_id,$coupons_id){
|
||
$coupon = Coupon::select('id','name','qrcode','desc','type_id','type','payment_method','preferential_amount','expiration_time','share_user_id','remain_num')->where('id',$coupons_id)->where('status',1)->first();
|
||
if(!$coupon)return ;
|
||
$exists = UserCoupon::where('coupons_id',$coupons_id)->where(function ($query) use($openId,$user_id) {
|
||
$query->where('openid', $openId)
|
||
->orWhere('user_id', $user_id);
|
||
})->exists();
|
||
$coupon->receive_status = 0;//未领取
|
||
if($coupon->expiration_time &&$coupon->expiration_time<now())
|
||
$coupon->receive_status = 2;//已过期
|
||
if($coupon->remain_num<=0)
|
||
$coupon->receive_status = 3;//已失效
|
||
if($exists)
|
||
$coupon->receive_status = 1;//已领取
|
||
if($coupon->payment_method=='free'&&$coupon->type=='course'){
|
||
$coupon->preferential_amount = $coupon->course->charge;
|
||
unset($coupon->course);
|
||
}
|
||
$user = User::select('nickname','photo','app_avatar','circle_avatar')->where('id',$coupon->share_user_id)->first();
|
||
$coupon->nickname = $user->nickname;
|
||
$coupon->avatar = $user->avatar;
|
||
return $coupon;
|
||
});
|
||
if(!$result)
|
||
return $this->failure('未查询到该优惠券信息');
|
||
return $this->success('ok',$result);
|
||
|
||
|
||
}
|
||
//我的优惠券
|
||
|
||
public function myCoupon(Request $request)
|
||
{
|
||
$user_id = 0;
|
||
if(\Auth::guard('api')->check()){
|
||
$user_id = \Auth::guard('api')->user()->id;
|
||
}
|
||
$course_id = $request->course_id;
|
||
$openId = $request->openid;
|
||
|
||
$key = 'mycoupon'.$user_id.'openId'.$openId.'course'.$course_id;
|
||
$result = cache::remember($key,3,function() use($user_id,$openId){
|
||
$result = UserCoupon::where(function ($query) use($openId,$user_id) {
|
||
if($openId){
|
||
$query->where('openid', $openId);
|
||
$query->orWhere('user_id', $user_id);
|
||
}else{
|
||
$query->where('user_id', $user_id);
|
||
}
|
||
})->paginate();
|
||
foreach ($result as $key => $value) {
|
||
if(isset($value->coupon) && $value->coupon) {
|
||
$value->name = $value->coupon->name;
|
||
$value->payment_method = $value->coupon->payment_method;
|
||
if($value->status==0&&$value->coupon->expiration_time&&$value->coupon->expiration_time<now())
|
||
$value->status = 2;
|
||
$value->type = $value->coupon->type;
|
||
$value->type_id = $value->coupon->type_id;
|
||
$value->expiration_time = $value->coupon->expiration_time;
|
||
if($value->coupon->payment_method=='free'&&$value->coupon->type=='course'){
|
||
$value->preferential_amount = Course::where('id',$value->coupon->type_id)->value('charge')??0;
|
||
}else{
|
||
$value->preferential_amount = $value->coupon->preferential_amount;
|
||
}
|
||
|
||
$value->preferential_amount = floatval($value->preferential_amount);
|
||
$value->desc = $value->coupon->desc;
|
||
unset($value->coupon);
|
||
}
|
||
}
|
||
return $result;
|
||
});
|
||
|
||
return $this->success('ok',$result);
|
||
}
|
||
|
||
//编辑资料选项
|
||
|
||
public function userInfoOptions(Request $request)
|
||
{
|
||
//年龄
|
||
$sex_arr = [
|
||
['key'=>'男','value'=>1],
|
||
['key'=>'女','value'=>2]
|
||
];
|
||
//身高
|
||
$stature_arr = [];
|
||
for ($i=139; $i < 202; $i++) {
|
||
if ($i === 139) {
|
||
$key = $i.'cm以下';
|
||
$arr = ['key'=> $key, 'value'=>$i];
|
||
$stature_arr[] = $arr;
|
||
continue;
|
||
}elseif ($i === 201) {
|
||
$key = $i.'cm以上';
|
||
$arr = ['key'=> $key, 'value'=>$i];
|
||
$stature_arr[] = $arr;
|
||
continue;
|
||
}
|
||
$arr =['key'=> $i.'cm', 'value'=>$i];
|
||
$stature_arr[] = $arr;
|
||
}
|
||
$weight_arr = [];
|
||
for ($i=39; $i < 132; $i++) {
|
||
if ($i === 39) {
|
||
$key = $i.'kg以下';
|
||
$arr = ['key'=> $key, 'value'=>$i];
|
||
$weight_arr[] = $arr;
|
||
continue;
|
||
}elseif ($i === 131) {
|
||
$key = $i.'kg以上';
|
||
$arr = ['key'=> $key, 'value'=>$i];
|
||
$weight_arr[] = $arr;
|
||
continue;
|
||
}
|
||
$arr =['key'=> $i.'kg', 'value'=>$i];
|
||
$weight_arr[] = $arr;
|
||
}
|
||
$address_arr = Address::where('name', '<>', '不限')->orderBy('codeId', 'asc')->select('codeId', 'name', 'parentId')->get()->toArray();
|
||
$address_arr = $this->addressSort($address_arr);
|
||
|
||
//协助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']);
|
||
}
|
||
}
|
||
}
|
||
$state_arr = ['从未结婚','离异','丧偶'];
|
||
$degree_arr = ['小学','初中', '高中','中专','大专','本科','硕士','博士','其他'];
|
||
$income_arr = ['5~10w', '10~15w', '15~20w', '15~30w', '30~50w', '50~100w', '100~500w', '500w以上'];
|
||
$belief_arr = ['基督教','佛教', '伊斯兰教','其他'];
|
||
//行业
|
||
list($__sort, $__detail) = $this->industryJsonData();
|
||
$industry_arr =[];
|
||
foreach($__sort as $key => $item){
|
||
$industry_arr[] =[
|
||
'title' => $item,
|
||
'items' => $__detail[$key]
|
||
];
|
||
}
|
||
//单身状态
|
||
$type_arr = [
|
||
['key'=>'single', 'value'=>'目前单身'],
|
||
['key'=>'marriage', 'value'=>'已有对象']
|
||
];
|
||
//身高
|
||
$stature = [];
|
||
$init = 130;
|
||
for($i = 1;$i<=80;$i++){
|
||
$stature[] = $init+$i;
|
||
}
|
||
//体重
|
||
$weight = [];
|
||
$init = 40;
|
||
for($i = 1;$i<=60;$i++){
|
||
$weight[] = $init+$i;
|
||
}
|
||
return $this->success('ok', compact('address_arr', 'state_arr', 'degree_arr', 'income_arr', 'belief_arr', 'industry_arr', 'type_arr','stature','weight'));
|
||
}
|
||
/**
|
||
* 会员套餐
|
||
* @param Request $request [description]
|
||
* @return [type] [description]
|
||
*/
|
||
public function singleServices(Request $request)
|
||
{
|
||
try {
|
||
$services = SingleService::with('rank')->where('id','<>',5)->where('is_show',0)->where('is_show_web',1)->orderBy('id', 'asc')->get();
|
||
foreach ($services as $service) {
|
||
$service->desc = json_decode($service->desc);
|
||
if(empty($service->feature)){
|
||
$feature = [];
|
||
if ($service->discount_price == 100) {
|
||
$feature = [
|
||
['icon'=>'http://images.ufutx.com/201901/08/8c8f8c785daf0a3680895f507c59b58b.png', 'text'=>'强更灵活', 'sub_text'=>'搜索功能'],
|
||
['icon'=>'http://images.ufutx.com/201901/08/8c8f8c785daf0a3680895f507c59b58b.png', 'text'=>'每天无限', 'sub_text'=>'查看全球资料'],
|
||
['icon'=>'http://images.ufutx.com/201901/08/8c8f8c785daf0a3680895f507c59b58b.png', 'text'=>'每天可加', 'sub_text'=>'7个好友'],
|
||
['icon'=>'http://images.ufutx.com/201901/08/8c8f8c785daf0a3680895f507c59b58b.png', 'text'=>'所有好友', 'sub_text'=>'交流互动'],
|
||
];
|
||
}elseif ($service->discount_price == 599) {
|
||
$feature = [
|
||
['icon'=>'http://images.ufutx.com/201901/08/8c8f8c785daf0a3680895f507c59b58b.png', 'text'=>'专业老师', 'sub_text'=>'为你联络对方'],
|
||
['icon'=>'http://images.ufutx.com/201901/08/8c8f8c785daf0a3680895f507c59b58b.png', 'text'=>'建立3人', 'sub_text'=>'微信小群'],
|
||
['icon'=>'http://images.ufutx.com/201901/08/8c8f8c785daf0a3680895f507c59b58b.png', 'text'=>'辅导2人', 'sub_text'=>'交往'],
|
||
['icon'=>'http://images.ufutx.com/201901/08/8c8f8c785daf0a3680895f507c59b58b.png', 'text'=>'赠送', 'sub_text'=>'超级会员'],
|
||
];
|
||
}elseif ($service->discount_price == 3900) {
|
||
$feature = [
|
||
['icon'=>'http://images.ufutx.com/201901/08/8c8f8c785daf0a3680895f507c59b58b.png', 'text'=>'专业老师', 'sub_text'=>'一对一辅导'],
|
||
['icon'=>'http://images.ufutx.com/201901/08/8c8f8c785daf0a3680895f507c59b58b.png', 'text'=>'辅导设定', 'sub_text'=>'择偶条件'],
|
||
['icon'=>'http://images.ufutx.com/201901/08/8c8f8c785daf0a3680895f507c59b58b.png', 'text'=>'老师筛选', 'sub_text'=>'匹配对象'],
|
||
['icon'=>'http://images.ufutx.com/201901/08/8c8f8c785daf0a3680895f507c59b58b.png', 'text'=>'引荐认识', 'sub_text'=>'辅导交往'],
|
||
];
|
||
}
|
||
$service->feature = $feature;
|
||
}else{
|
||
$service->feature = json_decode($service->feature);
|
||
}
|
||
if ($service->discount_desc_type == 'json') {
|
||
$service->discount_desc = json_decode($service->discount_desc);
|
||
}else{
|
||
$service->discount_desc = explode('****',$service->discount_desc);
|
||
}
|
||
|
||
}
|
||
return $this->success('ok', $services);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('获取会员套餐信息失败,请稍后再试');
|
||
}
|
||
}
|
||
|
||
//购买会员
|
||
public function memberChargeV2(Request $request)
|
||
{
|
||
\DB::beginTransaction();
|
||
try {
|
||
$user = auth()->user();
|
||
//购买的会员等级
|
||
$sub_rank_id = $request->input('sub_rank_id');
|
||
$from_user_id = $request->from_user_id??0;
|
||
|
||
$is_set = Viewer::where('user_id', $user->id)->count();
|
||
if(!$is_set){
|
||
return $this->failure('请重新授权并绑定手机号');
|
||
}
|
||
$sub_rank = SubRank::find($sub_rank_id);
|
||
if (empty($sub_rank)) {
|
||
return $this->failure('没有该会员');
|
||
}
|
||
$rank = Rank::find($sub_rank->rank_id);
|
||
$goods = '购买'.$sub_rank->month.'个月'.$rank->name.'VIP';
|
||
//订单号
|
||
$trade_no = $this->getTradeNO();
|
||
|
||
$price = $sub_rank->discount_price;
|
||
$score = 0;
|
||
$cash = $price;
|
||
$pay_type = $request->pay_type;
|
||
$remark = '';
|
||
if($pay_type=='coin'&&$rank->pay_type=='coin'&&$rank->can_cash_amount>0&&$rank->can_coin_amount){
|
||
//当前福币
|
||
$total_coin = $user->totalCoin();
|
||
if($total_coin){//如果福币充足
|
||
if($total_coin>=$rank->can_coin_amount){
|
||
$cash = $cash-$rank->can_cash_amount;
|
||
$remark = '花费福币'.$rank->can_coin_amount.'个,抵扣金额'.$rank->can_cash_amount.'元';
|
||
$score = $rank->can_coin_amount;
|
||
}else{//
|
||
$cash = $cash- ($total_coin/10);
|
||
$remark = '花费福币'.($total_coin).'个,抵扣金额'.($total_coin/10).'元';
|
||
$score = $total_coin;
|
||
}
|
||
|
||
}
|
||
}
|
||
//订单
|
||
$pay_order = array(
|
||
'user_id' => $user->id,
|
||
'trade_no' => $trade_no,
|
||
'pay_status' => 'UNPAID',
|
||
'cash' => $cash,
|
||
'from_user_id' => $from_user_id,
|
||
'score' => $score,
|
||
);
|
||
$order = array(
|
||
'user_id'=>$user->id,
|
||
'type_id'=>$sub_rank_id,
|
||
'goods'=>$goods,
|
||
'price'=>$price,
|
||
'num'=>1,
|
||
'type'=>'rank',
|
||
'from_user_id' => $from_user_id,
|
||
'pay_type'=>'h5',
|
||
'remark'=>$remark,
|
||
'trade_no'=>$trade_no,
|
||
'from_openid'=>$request->input('from_openid'),
|
||
'share_type'=>$request->input('share_type', 'normal'),
|
||
);
|
||
|
||
//支付订单
|
||
$order_pay = PayOrder::create($pay_order);
|
||
$order = Order::create($order);
|
||
$wx_pay = [];
|
||
if ($cash>0) {
|
||
$wx_pay = $this->constructWXPay($pay_order, $user->id, '购买会员');
|
||
}else{
|
||
$order_pay->pay_status = 'PAID';
|
||
$order_pay->is_hooked = 1;
|
||
$order->pay_status = 'PAID';
|
||
$order_pay->save();
|
||
$order->save();
|
||
$this->markRankOrder($order->id);
|
||
}
|
||
$order_pay->wx_pay = $wx_pay;
|
||
\DB::commit();
|
||
return $this->success('ok', $order_pay);
|
||
} catch (\Exception $e) {
|
||
\DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('支付失败,请稍后再试');
|
||
}
|
||
}
|
||
|
||
public function constructWXPay($pay_order, $user_id, $detail='福恋')
|
||
{
|
||
$openid = Viewer::where('user_id', $user_id)->value('openid');
|
||
$attributes = array(
|
||
'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP...
|
||
'body' => $detail,
|
||
'detail' => $detail,
|
||
'out_trade_no' => $pay_order['trade_no'],
|
||
'total_fee' => round($pay_order['cash']*100),
|
||
'notify_url' => config('app.url').'/api/official/callback/orders/'.$pay_order['trade_no'], // 支付结果通知网址,如果不设置则会使用配置里的默认地址
|
||
'openid' => $openid,
|
||
);
|
||
$result = \WechatService::officialPay($attributes);
|
||
return $result;
|
||
}
|
||
|
||
public function markRankOrder($order_id)
|
||
{
|
||
$order = Order::find($order_id);
|
||
$user = User::find($order->user_id);
|
||
$pay_order = PayOrder::where('trade_no', $order->trade_no)->first();
|
||
switch ($order->type){
|
||
case 'rank':
|
||
$sub_rank_id = $order->type_id;
|
||
//购买成功 发送短信通知
|
||
$m = Message::create([
|
||
'phone' => $user->mobile,
|
||
'message' => '',
|
||
'confirmed' => 1,
|
||
'code' => '购买会员',
|
||
'ip' => request() ? request()->ip() : '127.0.0.1',
|
||
]);
|
||
$url = \CommonUtilsService::createShortUrl(env('APP_URL').'/h5/#/buyVipPackage',$m->id);
|
||
$message = '恭喜您成为福恋的超级会员,尊享VIP专属特权,点击 '.$url.' 查看您的会员权益';
|
||
$m->message = $message;
|
||
$m->save();
|
||
$this->sms->sentMessage($user->mobile, $message);
|
||
break;
|
||
case 'single_service':
|
||
$single_service = SingleService::find($order->type_id);
|
||
$sub_rank_id = SubRank::where('rank_id', $single_service->rank_id)->where('month', $single_service->rank_month)->value('id');
|
||
if (config('app.env') == 'production') {
|
||
if ($single_service->type == 'active' || $single_service->type == 'passive') {
|
||
$user_name = $user->nickname;
|
||
$message = '用户'.$user_name.'购买了'.$single_service->title.'服务';
|
||
$this->sms->sentMessage('13377553550', $message);
|
||
//短信通知购买用户
|
||
$notice = '您已成功购买【'.$single_service->title.'】服务套餐,福恋工作人员将尽快联系您为您服务,请耐心等待。如有问题,请联系:18922809346';
|
||
$this->sms->sentMessage($user->mobile, $message);
|
||
}
|
||
}
|
||
break;
|
||
default :
|
||
$sub_rank_id = 0;
|
||
break;
|
||
}
|
||
if ($pay_order->score > 0) {
|
||
//扣除对应福币
|
||
$result = $this->changeScore($order->user_id, $pay_order->score, 'used', $message='升级VIP',$order);
|
||
if (!$result) {
|
||
$this->sms->sentMessage('15872844805', '订单号:'.$order->trade_no.' 福分溢出');
|
||
return false;
|
||
}
|
||
}
|
||
$this->changeRank($order->user_id, $sub_rank_id);
|
||
|
||
//微信通知
|
||
$user = User::with('wechat')->find($order->user_id);
|
||
$sub_rank = SubRank::find($sub_rank_id);
|
||
$array['openid'] = $user->wechat->openid;
|
||
$array['rank_id'] = $sub_rank->rank_id;
|
||
SendRankNotice::dispatch($array)->onQueue('love');
|
||
return true;
|
||
}
|
||
|
||
public function changeRank($user_id, $sub_rank_id)
|
||
{
|
||
$sub_rank = SubRank::find($sub_rank_id);
|
||
$rank_id = $sub_rank->rank_id;
|
||
$month = $sub_rank->month;
|
||
$user = User::find($user_id);
|
||
$result = $user->addSuperRank($day=0, $month);
|
||
return ;
|
||
}
|
||
|
||
public function changescore($user_id, $score, $type, $message='',$order , $other_user_id=null)
|
||
{
|
||
//本地福币
|
||
// $score = $score*10;
|
||
$score_obj = Coin::where('user_id', $user_id)->first();
|
||
if (empty($score_obj)) {
|
||
$score_obj = Coin::create([
|
||
'user_id'=>$user_id,
|
||
]);
|
||
}
|
||
if ($type == 'gained') {
|
||
//更新积分
|
||
if($score_obj->amount_from_other >= $score){
|
||
$score_obj->increment('amount_from_other', $score);
|
||
}else{
|
||
Coin::where('id', $score_obj->id)->update(['amount_from_other'=>0,'remain_amount'=>$score->amount_from_other]);
|
||
}
|
||
}else{
|
||
if (($score_obj->remain_amount+$score_obj->amount_from_other) >= $score) {
|
||
if($score_obj->amount_from_other >= $score){
|
||
$score_obj->decrement('amount_from_other', $score);
|
||
}else{
|
||
$score_obj->amount_from_other= 0;
|
||
$score_obj->remain_amount = $score_obj->remain_amount - ($score - $score_obj->amount_from_other);
|
||
$score_obj->save();
|
||
}
|
||
}else{
|
||
$this->sms->sentMessage('15872844805', '用户id:'.$user_id.', 福币不足.'.$message);
|
||
throw new \Exception('用户id:'.$user_id.', 福币不足.'.$message, 1);
|
||
|
||
}
|
||
$score_obj->increment('used_amount', $score);
|
||
}
|
||
switch ($order->type){
|
||
case 'rank':
|
||
$type = 'RANK';
|
||
break;
|
||
case 'single_service':
|
||
$type = 'SERVICE';
|
||
break;
|
||
default:
|
||
$type = 'RANK';
|
||
break;
|
||
}
|
||
//生成积分记录
|
||
CoinLog::create([
|
||
'user_id'=>$user_id,
|
||
'type'=>$type,
|
||
'type_id'=>$order->type_id,
|
||
'coin'=>$score,
|
||
'remark'=>'使用福币支付',
|
||
'is_hooked'=>1,
|
||
]);
|
||
return true;
|
||
}
|
||
|
||
public function buySingleServices(Request $request)
|
||
{
|
||
\DB::beginTransaction();
|
||
try {
|
||
$user = auth()->user();
|
||
$from_user_id = $request->from_user_id??0;
|
||
$is_set = Viewer::where('user_id', $user->id)->count();
|
||
if(!$is_set){
|
||
return $this->failure('请重新授权并绑定手机号');
|
||
}
|
||
|
||
$single_service = SingleService::find($request->service_id);
|
||
if(empty($single_service)){
|
||
return $this->failure('服务套餐不存在');
|
||
}
|
||
|
||
$cash = $single_service->discount_price;
|
||
//购买的会员等级
|
||
$goods = $single_service->title;
|
||
$score = 0;
|
||
//订单号
|
||
$trade_no = $this->getTradeNO();
|
||
$pay_type = $request->pay_type;
|
||
$remark = '';
|
||
if($pay_type=='coin'&&$single_service->pay_type=='coin'&&$single_service->can_cash_amount>0&&$single_service->can_coin_amount){
|
||
//当前福币
|
||
$total_coin = $user->totalCoin();
|
||
if($total_coin){//如果福币充足
|
||
if($total_coin>=$single_service->can_coin_amount){
|
||
$cash = $cash-$single_service->can_cash_amount;
|
||
$remark = '花费福币'.$single_service->can_coin_amount.'个,抵扣金额'.$single_service->can_cash_amount.'元';
|
||
$score = $single_service->can_coin_amount;
|
||
}else{//
|
||
$cash = $cash- ($total_coin/10);
|
||
$remark = '花费福币'.($total_coin).'个,抵扣金额'.($total_coin/10).'元';
|
||
$score = $total_coin;
|
||
}
|
||
|
||
}
|
||
}
|
||
//订单
|
||
$pay_order = array(
|
||
'user_id' => $user->id,
|
||
'trade_no' => $trade_no,
|
||
'pay_status' => 'UNPAID',
|
||
'cash' => $cash,
|
||
'from_user_id' => $from_user_id,
|
||
'score' => $score,
|
||
);
|
||
$order = array(
|
||
'user_id'=>$user->id,
|
||
'type_id'=>$single_service->id,
|
||
'goods'=>$goods,
|
||
'price'=>$cash,
|
||
'pay_status'=>'UNPAID',
|
||
'num'=>1,
|
||
'type'=>'single_service',
|
||
'from_user_id' => $from_user_id,
|
||
'pay_type'=>'h5',
|
||
'trade_no'=>$trade_no,
|
||
'from_openid'=>$request->input('from_openid'),
|
||
'from_user_id'=>$request->input('from_user_id'),
|
||
'remark'=>$remark,
|
||
'share_type'=>$request->input('share_type', 'normal'),
|
||
);
|
||
|
||
//支付订单
|
||
$order_pay = PayOrder::create($pay_order);
|
||
$order = Order::create($order);
|
||
$wx_pay = [];
|
||
if ($cash>0) {
|
||
$wx_pay = $this->constructWXPay($pay_order, $user->id,$single_service->title);
|
||
}else{
|
||
$order_pay->pay_status = 'PAID';
|
||
$order_pay->is_hooked = 1;
|
||
$order->pay_status = 'PAID';
|
||
$order_pay->save();
|
||
$order->save();
|
||
$this->markrankOrder($order->id);
|
||
}
|
||
$order_pay->wx_pay = $wx_pay;
|
||
\DB::commit();
|
||
//购买成功 发送短信通知
|
||
// $m = Message::create([
|
||
// 'phone' => $user->mobile,
|
||
// 'message' => '',
|
||
// 'confirmed' => 1,
|
||
// 'code' => '购买服务套餐',
|
||
// 'ip' => request() ? request()->ip() : '127.0.0.1',
|
||
// ]);
|
||
// $message = '您已成功购买【'.$single_service->title.'】服务套餐,福恋工作人员将尽快联系您为您服务,请耐心等待。如有问题,请联系4000401707';
|
||
// $m->message = $message;
|
||
// $m->save();
|
||
// Messenger::sendSMS($user->mobile, $message);
|
||
return $this->success('ok', $order_pay);
|
||
} catch (\Exception $e) {
|
||
\DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('支付失败,请稍后再试');
|
||
}
|
||
}
|
||
|
||
//订单回调
|
||
public function callbackOrder(Request $request, $trade_no)
|
||
{
|
||
try {
|
||
if (empty($trade_no)) {
|
||
throw new \Exception("回调接口没有订单号", 1);
|
||
}
|
||
$order = Order::where('trade_no', $trade_no)->first();
|
||
$pay_order = PayOrder::where('trade_no', $trade_no)->first();
|
||
if (empty($pay_order)) {
|
||
$message = '订单不存在,订单号:'.$trade_no;
|
||
throw new \Exception($message, 1);
|
||
}
|
||
if ($pay_order->is_hooked) {
|
||
return $this->success('订单已经回调');
|
||
}
|
||
if ($pay_order->cash > 0) {//现金支付
|
||
//当前时间大于订单时间30天不能查询
|
||
$now_time = date('Y-m-d H:i:s');
|
||
$order_time = $pay_order->created_at->toDateTimeString();
|
||
$compare_result = $this->compareTime($now_time, $order_time);
|
||
if ($compare_result) {
|
||
if ($order->pay_type === 'h5') {
|
||
$result = \WechatService::officialOrderPaid($trade_no);
|
||
// $result = true;
|
||
}elseif ($order->pay_type === 'alipay') {
|
||
//todo 支付宝查询订单
|
||
$result = true;
|
||
}else{
|
||
throw new \Exception("订单检查失败", 1);
|
||
}
|
||
if (empty($result)) throw new \Exception("微信端没有订单 订单未支付成功", 1);
|
||
$result = $this->markOrder($order, $pay_order);
|
||
if (empty($result)) throw new \Exception("订单回调失败 订单未支付成功", 1);
|
||
}else{
|
||
throw new \Exception("订单时间超过30天", 1);
|
||
}
|
||
}
|
||
return $this->success('订单回调成功');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('订单回调失败');
|
||
}
|
||
}
|
||
|
||
public function compareTime($time1, $time2)
|
||
{
|
||
$str_time1 = strtotime($time1);
|
||
$str_time2 = strtotime($time2) + 30 * 24 * 3600;
|
||
if ($str_time1 >= $str_time2) {//已過期
|
||
return false;
|
||
}else{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 分类回调订单
|
||
* @param [type] $order [description]
|
||
* @param [type] $pay_order [description]
|
||
* @return [type] [description]
|
||
*/
|
||
public function markOrder($order, $pay_order)
|
||
{
|
||
try {
|
||
//会员订单
|
||
if ($order->type === 'rank') {
|
||
$result = $this->markRankOrderCallback($order, $pay_order);
|
||
if (empty($result)) throw new \Exception("回调会员订单失败", 1);
|
||
}elseif ($order->type === 'activity') {
|
||
$result = $this->markActivityOrder($order, $pay_order);
|
||
if (empty($result)) throw new \Exception("回调活动订单失败", 1);
|
||
}elseif ($order->type === 'community') {
|
||
$result = $this->markCommunityOrder($order,$pay_order);
|
||
if (empty($result)) throw new \Exception("回调社群订单失败", 1);
|
||
}elseif ($order->type === 'single_service') {
|
||
$result = $this->markSingleServiceOrder($order,$pay_order);
|
||
if (empty($result)) throw new \Exception("回调单身服务订单失败", 1);
|
||
}elseif ($order->type === 'coin') {//福币充值订单
|
||
$result = $this->markCoinOrder($order, $pay_order);
|
||
if (empty($result)) throw new \Exception("回调福币充值订单失败,订单号:".$order->trade_no, 1);
|
||
}
|
||
\DB::beginTransaction();
|
||
PayOrder::where('trade_no', $order->trade_no)->update(['is_hooked'=>1,'pay_status'=>'PAID']);
|
||
Order::where('trade_no', $order->trade_no)->update(['pay_status'=>'PAID']);
|
||
\DB::commit();
|
||
$redis = Redis::connection('big_data');
|
||
$redis->lpush('love:earning:order:ids', $order->id);
|
||
SendEarningMessage::dispatch($order->id)->onQueue('love')->delay(now()->addMinutes(1));
|
||
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
\DB::rollback();
|
||
$this->getError($e);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
//购买会员回调
|
||
public function markRankOrderCallback($order, $pay_order)
|
||
{
|
||
try {
|
||
\DB::beginTransaction();
|
||
$user = User::find($order->user_id);
|
||
if ($pay_order->score > 0) {
|
||
//扣除对应积分
|
||
$score = $pay_order->score;
|
||
$result = $this->changescore($user->id, $score, 'used', $messenger='购买会员', $order);
|
||
if (empty($result)) {
|
||
\DB::rollback();
|
||
throw new \Exception("订单回调失败,福气溢出,订单号:".$order->trade_no, 1);
|
||
}
|
||
}
|
||
//更改会员
|
||
$month = SubRank::where('id', $order->type_id)->value('month');
|
||
$result = $user->addSuperRank($day=0, $month);
|
||
if (empty($result)) {
|
||
\DB::rollback();
|
||
throw new \Exception("订单回调失败,更改会员等级失败,订单号:".$order->trade_no, 1);
|
||
}
|
||
\DB::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
\DB::rollback();
|
||
$this->getError($e);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
//购买套餐回调
|
||
public function markSingleServiceOrder($order, $pay_order)
|
||
{
|
||
try {
|
||
\DB::beginTransaction();
|
||
$user = User::where('id', $order->user_id)->first();
|
||
//扣除福气
|
||
if ($pay_order->score > 0) {
|
||
//扣除对应积分
|
||
$score = $pay_order->score;
|
||
$result = $this->changescore($user->id, $score, 'used', $messenger='购买会员', $order);;
|
||
if (empty($result)) {
|
||
\DB::rollback();
|
||
throw new \Exception("订单回调失败,福气溢出,订单号:".$order->trade_no, 1);
|
||
}
|
||
}
|
||
//查询服务
|
||
$service = SingleService::where('id', $order->type_id)->first();
|
||
if (empty($service)) {
|
||
throw new \Exception("单身服务不存在,订单号:".$order->trade_no, 1);
|
||
}
|
||
// //生成服务记录
|
||
// $this->addServiceHistory($user->id, $service->type, $service->type_id);
|
||
//添加会员期限
|
||
$month = $service->rank_month;
|
||
$result = $user->addSuperRank($day=0, $month);
|
||
if (empty($result)) {
|
||
throw new \Exception("修改用户会员失败,订单号:".$order->trade_no, 1);
|
||
}
|
||
//短信通知艳斌
|
||
if (config('app.env') == 'production') {
|
||
if ($service->type == 'active' || $service->type == 'passive') {
|
||
$user_name = $user->nickname;
|
||
$message = '用户'.$user_name.'购买了'.$service->title.'服务';
|
||
$this->sms->sentMessage('13377553550', $message);
|
||
}
|
||
}
|
||
\DB::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
\DB::rollback();
|
||
\Log::info($e->getMessage());
|
||
$this->getError($e);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
//2020冬季主内单身联谊活动
|
||
public function joinSingleActivity(Request $request){
|
||
\DB::beginTransaction();
|
||
try {
|
||
$user = auth()->user();
|
||
if (empty($user)) {
|
||
$user = $this->authCheck();
|
||
}
|
||
|
||
//检查验证码
|
||
if($request->code){
|
||
$result = $this->sms->check($request->mobile, $request->code);
|
||
if ($result) {
|
||
return $this->failure($result);
|
||
}
|
||
}
|
||
|
||
//未登录
|
||
if(empty($user)){
|
||
$user = User::with('profileCourtship')->where('mobile', $request->mobile)->first();
|
||
}
|
||
|
||
//没有用户就创建一个
|
||
if(empty($user)){
|
||
$userCon = New UserService();
|
||
$request->merge([
|
||
'from_platform'=>'single_activity',
|
||
]);
|
||
$user = $userCon->loginByMobile($request);
|
||
}
|
||
$is_set = SingleActivity::where('user_id', $user->id)->count();
|
||
if($is_set){
|
||
return $this->failure('您已报名');
|
||
}
|
||
|
||
if($user->type != 'single'){
|
||
return $this->failure('您不是单身');
|
||
}
|
||
$resident_place = $request->resident_place;
|
||
$place = $request->place;
|
||
if(empty($request->name)){
|
||
return $this->failure('名字不能为空');
|
||
}
|
||
if(empty($request->birthday)){
|
||
return $this->failure('生日不能为空');
|
||
}
|
||
if(empty($request->resident_place) && !is_array($request->place)){
|
||
return $this->failure('出生地不能为空');
|
||
}
|
||
if(empty($request->place) && !is_array($request->place)){
|
||
return $this->failure('所在地不能为空');
|
||
}
|
||
if(empty($request->status)){
|
||
return $this->failure('单身情况不能为空');
|
||
}
|
||
if(empty($request->degree)){
|
||
return $this->failure('学历不能为空');
|
||
}
|
||
if(empty($request->work)){
|
||
return $this->failure('工作不能为空');
|
||
}
|
||
$single_activity = New SingleActivity();
|
||
$single_activity->user_id = $user->id;
|
||
$single_activity->viewer_id = 0;
|
||
$single_activity->from_id = $request->from_id?:0;
|
||
$single_activity->name = $request->name;
|
||
$single_activity->sex = $request->sex;
|
||
$single_activity->birthday = $request->birthday;
|
||
$single_activity->mobile = $request->mobile;
|
||
$single_activity->resident_province = $resident_place[1];
|
||
$single_activity->resident_city = $resident_place[2];
|
||
$single_activity->resident_dist = $request->resident_dist ?: '未知';
|
||
$single_activity->province = $place[1];
|
||
$single_activity->city = $place[2];
|
||
$single_activity->dist = $request->dist ?: '未知';
|
||
$single_activity->status = $request->status;
|
||
$single_activity->degree = $request->degree;
|
||
$single_activity->work = $request->work;
|
||
$single_activity->salary = $request->salary;
|
||
$single_activity->belief = $request->belief;
|
||
$single_activity->experience = $request->experience;
|
||
$single_activity->belief_status = $request->belief_status;
|
||
$single_activity->join_place = $request->join_place?: '无';
|
||
$single_activity->belief_place = $request->belief_place?: '无';
|
||
$single_activity->ideal_mate = $request->ideal_mate?: '无';
|
||
$single_activity->introduction = $request->introduction?: '无';
|
||
$single_activity->photo = json_encode($request->photo);
|
||
$single_activity->forte = $request->forte?: '无';
|
||
$single_activity->cert = $request->cert?: '无';
|
||
$single_activity->si = $request->si?: '无';
|
||
$single_activity->save();
|
||
|
||
$is_set = ProfileCourtship::where('user_id', $user->id)->count();
|
||
if(empty($is_set)){
|
||
$soft_delete = ProfileCourtship::where('user_id', $user->id)->first();
|
||
if (empty($soft_delete)) {
|
||
$profile = new ProfileCourtship();
|
||
$profile->user_id = $user->id;
|
||
$profile->birthday = $request->birthday;
|
||
$profile->resident_province = $resident_place[1];
|
||
$profile->resident_city = $resident_place[2];
|
||
$profile->province = $place[1];
|
||
$profile->city = $place[2];
|
||
$profile->degree = $request->degree;
|
||
$profile->belief = $request->belief;
|
||
$profile->ideal_mate = $request->ideal_mate;
|
||
$profile->introduction = $request->introduction;
|
||
$profile->save();
|
||
}
|
||
}else{
|
||
$profile = ProfileCourtship::where('user_id', $user->id)->first();
|
||
if($profile->birthday != $request->birthday){
|
||
$profile->birthday = $request->birthday;
|
||
}
|
||
if($profile->resident_province != $resident_place[1]){
|
||
$profile->resident_province = $resident_place[1];
|
||
}
|
||
if($profile->resident_city != $resident_place[2]){
|
||
$profile->resident_city = $resident_place[2];
|
||
}
|
||
if($profile->province != $place[1]){
|
||
$profile->province = $place[1];
|
||
}
|
||
if($profile->city != $place[2]){
|
||
$profile->city = $place[2];
|
||
}
|
||
if($profile->degree != $request->degree){
|
||
$profile->degree = $request->degree;
|
||
}
|
||
if($profile->belief != $request->belief){
|
||
$profile->belief = $request->belief;
|
||
}
|
||
if($profile->introduction != $request->introduction){
|
||
$profile->introduction = $request->introduction;
|
||
}
|
||
$profile->save();
|
||
}
|
||
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if(empty($wechatUser)){
|
||
$openid = $request->openid;
|
||
}else{
|
||
$openid = $wechatUser->getId();
|
||
}
|
||
$viewer = Viewer::where('openid', $openid)->first();
|
||
if(!empty($viewer)){
|
||
if(empty($viewer->mobile)){
|
||
$viewer->mobile = $request->mobile;
|
||
}
|
||
if(empty($viewer->user_id)){
|
||
$viewer->user_id= $user->id;
|
||
}
|
||
$viewer->save();
|
||
}
|
||
\DB::commit();
|
||
return $this->success('ok');
|
||
|
||
} catch (\Exception $e) {
|
||
\DB::rollBack();
|
||
\Log::info($e->getMessage());
|
||
// $this->getError($e);
|
||
return $this->failure('报名失败,请稍后再试');
|
||
}
|
||
}
|
||
|
||
public function singleActivity(Request $request)
|
||
{
|
||
$user = auth()->user();
|
||
if (empty($user)) {
|
||
$user = $this->authCheck();
|
||
}
|
||
$single_activity = SingleActivity::where('user_id', $user->id)->first();
|
||
$single_activity->photo = json_decode($single_activity->photo);
|
||
return $this->success('ok', $single_activity);
|
||
}
|
||
|
||
public function addServiceHistory($user_id, $type, $type_id)
|
||
{
|
||
$appointment = Appointment::where('type', $type)->where('id', $type_id)->first();
|
||
if (empty($appointment)) {
|
||
return;
|
||
}
|
||
AppointmentHistory::create([
|
||
'user_id'=>$user_id,
|
||
'point_id'=>$appointment->id,
|
||
'price'=>$appointment->price,
|
||
'type'=>$type,
|
||
'num'=>$appointment->num,
|
||
]);
|
||
return;
|
||
}
|
||
//删除回放记录
|
||
public function delVideo(Request $request)
|
||
{
|
||
$video_id = $request->video_id;
|
||
$result = Video::where('id',$video_id)->delete();
|
||
return '删除记录:'.$result.'行';
|
||
}
|
||
//创建token
|
||
public function api_token($account){
|
||
$token = MerchantAccount::where('id',$account->id)->value('api_token');
|
||
if($token){
|
||
$result = decrypt($token);
|
||
$time = explode('-', $result)[2];
|
||
if(time()-$time>604800){
|
||
$token = encrypt($account->id.'-'.$account->mobile.'-'.time().'-'.$account->email);
|
||
MerchantAccount::where('id',$account->id)->update(['api_token'=>$token]);
|
||
}
|
||
}else{
|
||
$token = encrypt($account->id.'-'.$account->mobile.'-'.time().'-'.$account->email);
|
||
MerchantAccount::where('id',$account->id)->update(['api_token'=>$token]);
|
||
}
|
||
return $token;
|
||
}
|
||
|
||
private function sendCode($mobile, $key, $params=[]){
|
||
if(!Str::isMobile($mobile)){
|
||
return $this->resp('手机号无效',['status'=>11]);
|
||
}
|
||
$start_time = date('Y-m-d 00:00:00');
|
||
$end_time = date('Y-m-d 23:59:59');
|
||
//该手机号是否到达限制
|
||
$count = Message::where('phone', $mobile)->whereBetween('created_at', [$start_time, $end_time])->count();
|
||
if ($count > 50) {
|
||
return $this->resp('短信发送失败, 短信服务次数限制',['status'=>12]);
|
||
}
|
||
$this->sms->create([
|
||
'phone' => $mobile,
|
||
'message' => [$key, $params],
|
||
'ip' => request()->ip(),
|
||
'confirmed' => 0
|
||
]);
|
||
|
||
|
||
return $this->success('短信已发送',['status'=>0]);
|
||
}
|
||
|
||
|
||
|
||
// 我的钱包
|
||
public function myAccount(Request $request)
|
||
{
|
||
$user = auth()->user();
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if(empty( $wechatUser)){
|
||
$openId = $request->openid;
|
||
}else{
|
||
$openId = $wechatUser->getId();
|
||
}
|
||
$account = EarningAccount::where('user_id',$user->id)->first();
|
||
$transfer = EarningTransfer::select('id','user_id','account','name')->where('user_id',$user->id)->where('way','alipay')->first();
|
||
if(!$account){
|
||
$account = new EarningAccount();
|
||
$account->user_id = $user->id;
|
||
$account->total_value = 0;
|
||
$account->balance = 0;
|
||
$account->withdrawl = 0;
|
||
$account->frozen_withdraw = 0;
|
||
$account->frozen_earning = 0;
|
||
$account->save();
|
||
}
|
||
$account->transfer = $transfer;
|
||
$order = EarningWithdraw::where('status', 'finished')->orderBy('id','desc')->limit(6)->get();
|
||
foreach ($order as $key => $value) {
|
||
$value->pic = $user->userAvatar($value->user_id)??User::DefaultAvatar;
|
||
}
|
||
$account->order = $order ;
|
||
// 是否关注公众号
|
||
// $app = \WechatService::officialApp();
|
||
$account->is_subscribe = 1;
|
||
$account->poundage = Redis::get('withdrawal_poundage') ?? 2; //提现手续费百分比
|
||
// $wechat_user = $app->user->get($openId);
|
||
// if($wechat_user) $account->is_subscribe = $wechat_user['subscribe'];
|
||
return $this->success('ok',$account);
|
||
}
|
||
|
||
// 绑定支付宝账号
|
||
public function bindAlipay(Request $request)
|
||
{
|
||
$user = auth()->user();
|
||
$account = $request->account;
|
||
$name = $request->name;
|
||
EarningTransfer::updateOrCreate(['user_id'=> $user->id],['way'=>'alipay','account'=> $account,'name'=> $name,'is_user'=>1]);
|
||
$result = EarningTransfer::select('user_id','account','name','way')->where('user_id',$user->id)->where('way','alipay')->first();
|
||
|
||
return $this->success('ok',$result);
|
||
}
|
||
|
||
// 收益来源
|
||
public function myIncome(Request $request)
|
||
{
|
||
$user = auth()->user();
|
||
$result = Earning::where('user_id', $user->id)->where('type','rank')->orderBy('id','desc')->paginate();
|
||
foreach ($result as $key => $value) {
|
||
$value->title = $value->order->goods??'';
|
||
unset($value->order);
|
||
}
|
||
return $this->success('ok',$result);
|
||
|
||
}
|
||
|
||
// 提现记录
|
||
public function withdrawalRecord(Request $request)
|
||
{
|
||
$user = auth()->user();
|
||
$result = EarningWithdraw::where('user_id', $user->id)->where('status','<>','canceled')->orderBy('id','desc')->paginate();
|
||
return $this->success('ok',$result);
|
||
}
|
||
|
||
// 提现
|
||
public function UserWithdrawal(Request $request)
|
||
{
|
||
$user = auth()->user();
|
||
$account = $request->account;
|
||
$alipay_real_name = $request->name;
|
||
$amount = $request->amount;
|
||
$data = [];
|
||
// 查询用户的提现余额是否充足
|
||
$earning_accounts = EarningAccount::where('user_id',$user->id)->first();
|
||
if(!$earning_accounts) return $this->failure('您暂无提现额度');
|
||
if($amount<0.1) return $this->failure('提现额度有误,请重新输入');
|
||
if($earning_accounts->balance<$amount) return $this->failure('提现额度不足,请重新输入');
|
||
$poundage = Redis::get('withdrawal_poundage') ?? 2; //提现手续费百分比
|
||
$poundage = $amount * ($poundage /100) >= 0.01 ? $amount * ($poundage /100): 0.01;//收取手续费费用 不足1分 按一分处理
|
||
$poundage = ceil($poundage*100)/100;
|
||
$actual_received = $amount - $poundage;//实际到账金额
|
||
$trade_no =\CommonUtilsService::getTradeNO();
|
||
$data['payee_account'] = $account;//支付宝账号
|
||
$data['payee_real_name'] = $alipay_real_name;//支付宝绑定姓名
|
||
$data['remark'] = '提现已到账'; //提现备注
|
||
$data['out_biz_no'] = $trade_no;
|
||
$data['amount'] = $actual_received;
|
||
|
||
$ali = new LiveAlipayService();
|
||
$result = $ali->platTransferAccount($data);
|
||
if(is_array($result)){
|
||
// 短信通知
|
||
$mobile = '15707534403';
|
||
$message = '福恋H5用户'.$alipay_real_name.' 提现'.$amount.'元失败,原因:'.$result['msg'];
|
||
Message::create([
|
||
'phone' => $mobile,
|
||
'message' => $message,
|
||
'confirmed' => 1,
|
||
'ip' => request() ? request()->ip() : '127.0.0.1',
|
||
]);
|
||
Messenger::sendSMS($mobile, $message);
|
||
//模板通知 邓智锋
|
||
$data['touser'] = ['oPC_2vnSECnYp5p--uaq3rca3Ry0','oPC_2vpJd34uN2E1tTsFbf8Lhlcs'];
|
||
$data['template_id'] = 'AqwVt0liVmQfzfnX3ZGvmVOdOh62nkCbhlOUI0NVQGs';
|
||
$data['url'] = '';
|
||
$data['data'] = [
|
||
'first' => '福恋H5用户'.$alipay_real_name,
|
||
'keyword1' => $amount.'元',
|
||
'keyword2' => '支付宝',
|
||
'keyword3' => $result['msg'],
|
||
'remark' => '点击查看提现记录',
|
||
];
|
||
$withdraw = EarningWithdraw::create([
|
||
'user_id' => $user->id,
|
||
'way' => $way??'alipay',
|
||
'value' => $amount,
|
||
'real_value' => $actual_received,
|
||
'account' => $account,
|
||
'name' => $alipay_real_name,
|
||
'trade_no' => $trade_no,
|
||
'status' => 'canceled',
|
||
'err_msg'=>$result['msg']
|
||
]);//收款账号不存在或户名有误,建议核实账号和户名是否准确
|
||
SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
||
if($result['msg'] == '余额不足,建议尽快充值。后续可登录电脑端支付宝,自主设置余额预警提醒功能。') {
|
||
$withdraw->status = 'freezing';
|
||
$withdraw->save();
|
||
return $this->success('ok',['status' => 0,'msg'=>'您的提现将会在24小时内处理']);
|
||
} else {
|
||
$withdraw->status = 'canceled';
|
||
$withdraw->save();
|
||
return $this->success('fail',['status' => 2,'msg'=>$result['msg']]);
|
||
}
|
||
|
||
}else{//提现成功
|
||
EarningWithdraw::create([
|
||
'user_id' => $user->id,
|
||
'way' => 'alipay',
|
||
'value' => $amount,
|
||
'real_value' => $actual_received,
|
||
'account' => $account,
|
||
'name' => $alipay_real_name,
|
||
'trade_no' => $trade_no,
|
||
'status' => 'finished',
|
||
]);
|
||
$earning_accounts->balance = $earning_accounts->balance-$amount;
|
||
$earning_accounts->withdrawl = $earning_accounts->withdrawl+$amount;
|
||
$earning_accounts->save();
|
||
}
|
||
return $this->success('ok',['status' => 1]);
|
||
}
|
||
|
||
//提交提现申请
|
||
public function withdrawApply(Request $request){
|
||
try {
|
||
$user = auth()->user();
|
||
if(empty($user)) return $this->failure('当前处于未登录状态,请先登录');
|
||
$account = $request->account;
|
||
$alipay_real_name = $request->name;
|
||
$amount = $request->amount;
|
||
$data = [];
|
||
// 查询用户的提现余额是否充足
|
||
$earning_accounts = EarningAccount::where('user_id',$user->id)->first();
|
||
if(!$earning_accounts) return $this->failure('您暂无提现额度');
|
||
if($amount<0.1) return $this->failure('提现额度有误,请重新输入');
|
||
if($earning_accounts->balance<$amount) return $this->failure('提现额度不足,请重新输入');
|
||
$poundage = Redis::get('withdrawal_poundage') ?? 2; //提现手续费百分比
|
||
$poundage = $amount * ($poundage /100) >= 0.01 ? $amount * ($poundage /100): 0.01;//收取手续费费用 不足1分 按一分处理
|
||
$poundage = ceil($poundage*100)/100;
|
||
$actual_received = $amount - $poundage;//实际到账金额
|
||
$trade_no = \CommonUtilsService::getTradeNO();
|
||
DB::beginTransaction();
|
||
//用户账户余额处理
|
||
$earning_accounts->balance = $earning_accounts->balance - $amount;
|
||
$earning_accounts->frozen_withdraw = $earning_accounts->frozen_withdraw + $amount;
|
||
$earning_accounts->save();
|
||
//增加提现记录
|
||
$insert = ['user_id'=>$user->id,'way'=>'alipay','value'=>$amount,'real_value'=>$actual_received,'account'=>$account,'name'=>$alipay_real_name,'trade_no' => $trade_no,'status' => 'freezing','created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')];
|
||
EarningWithdraw::insert($insert);
|
||
//todo短信通知
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if(empty( $wechatUser)){
|
||
$openId = $request->openid;
|
||
}else{
|
||
$openId = $wechatUser->getId();
|
||
}
|
||
$data['touser'] = $openId;
|
||
$data['template_id'] = 'OwXPF2dKEjPQUoGyzH944ATsJ6SgxpZ8kzB-KVVxanY';
|
||
$data['url'] = '';
|
||
$data['data'] = [
|
||
'first' => '你已申请提现,正在审核中',
|
||
'keyword1' => $user->name,
|
||
'keyword2' => date('Y-m-d H:i:s'),
|
||
'keyword3' => $actual_received.'元',
|
||
'keyword4' => '支付宝',
|
||
'remark' => '审核结果请留意服务通知',
|
||
];
|
||
SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
||
$message = $user->name.',你已申请提现,正在审核中,审核结果请留意手机短信,请耐心等待。';
|
||
$this->sentMessage($user->mobile,$message);
|
||
DB::commit();
|
||
return $this->success('ok',['status' => 1]);
|
||
} catch (\Exception $e) {
|
||
DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息,请稍后再试');
|
||
}
|
||
|
||
}
|
||
|
||
//校验是否符合上墙信息
|
||
public function checkUserInfo(Request $request){
|
||
$user = auth()->user();
|
||
//80 后才能申请
|
||
$deadline = strtotime('1980-01-01 00:00:00');
|
||
if(!$user) return $this->failure('请先登录');
|
||
$profile = $user->profileCourtship;
|
||
if(!$profile) return $this->failure('暂不符合上墙资格');
|
||
$is_single = $user->type == 'single' ? 1 : 0;
|
||
$is_real_approved = $user->is_real_approved == 1 ? 1 : 0;
|
||
$introduction = $profile->introduction ? 1 : 0;
|
||
$ideal_mate = $profile->ideal_mate ? 1 : 0;
|
||
$profile_photo_count = ProfilePhoto::where('user_id',$user->id)->count();
|
||
$profile_photo = $profile_photo_count >= 3 ? 1 : 0;
|
||
if(empty($profile->birthday)){
|
||
$bitrh_adaptation = 0;
|
||
}else{
|
||
$user_age = strtotime($profile->birthday);
|
||
$bitrh_adaptation = $user_age >= $deadline ? 1 : 0;
|
||
}
|
||
// dd($deadline,$user_age);
|
||
return $this->success('ok',compact('is_single','is_real_approved','introduction','ideal_mate','profile_photo','bitrh_adaptation'));
|
||
}
|
||
|
||
// 我要上墙v2
|
||
public function postwallV2(Request $request){
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if(empty( $wechatUser)){
|
||
$openId = $request->openid;
|
||
}else{
|
||
$openId = $wechatUser->getId();
|
||
}
|
||
\Log::info('upperwall_openid='.$openId);
|
||
$result = $this->sms->check($request->mobile, $request->code);
|
||
if ($result) return $this->failure($result);
|
||
$user_id = $this->getUseridByOpenid($openId,1) ? : User::where('mobile',$request->mobile)->value('id');
|
||
if($user_id){
|
||
$user = User::find($user_id);
|
||
if ($user->type != 'single') return $this->failure("您的帐号为已婚状态,如设置有误,请联系客服小天使");
|
||
$info = UpperWallHistory::where('user_id',$user_id)->whereIn('status',[0,1])->first();
|
||
if($info) return $this->failure('资料正在审核或已通过 请勿重复提交');
|
||
}
|
||
$nickname = $request->nickname;
|
||
$sex = $request->sex ?? 1;
|
||
$birthday = $request->birthday;
|
||
$state = $request->state;
|
||
$stature = $request->stature;
|
||
$weight = $request->weight;
|
||
$degree = $request->degree;
|
||
$industry = $request->industry;
|
||
$industry_sub = $request->industry_sub;
|
||
$province = $request->province;
|
||
$city = $request->city;
|
||
$resident_province = $request->resident_province;
|
||
$resident_city = $request->resident_city;
|
||
$introduction = $request->introduction;
|
||
$ideal_mate = $request->ideal_mate;
|
||
$await_checkoutTextArray[] = $introduction;
|
||
$await_checkoutTextArray[] = $ideal_mate;
|
||
//敏感词汇过滤
|
||
if ($await_checkoutTextArray) {
|
||
$result = \CommonUtilsService::checkoutTextArrayV3($await_checkoutTextArray);
|
||
if ($result['code'] == 1) {
|
||
return $this->failure($result['cause']);
|
||
}
|
||
}
|
||
$photos = $request->photos;
|
||
try {
|
||
DB::beginTransaction();
|
||
if($user_id && isset($user)){
|
||
$user->nickname = $nickname;
|
||
$user->industry = $industry;
|
||
$user->industry_sub = $industry_sub;
|
||
if(!$user->mobile) $user->mobile = $request->mobile;
|
||
// $user->sex = $sex;
|
||
$user->save();
|
||
}else{
|
||
$user = new User();
|
||
$user->nickname = $nickname;
|
||
$user->industry = $industry;
|
||
$user->industry_sub = $industry_sub;
|
||
$user->mobile = User::where('mobile',$request->mobile)->first() ? null : $request->mobile;
|
||
$user->sex = $sex;
|
||
$user->regist_channel = 'official';
|
||
$user->save();
|
||
DB::table('user_register_channels')->insert(
|
||
['user_id' => $user->id,
|
||
'channel' => 'official',
|
||
'created_at' => date('Y-m-d H:i:s'),
|
||
'updated_at' => date('Y-m-d H:i:s')]
|
||
);
|
||
}
|
||
Viewer::updateOrCreate(['user_id'=>$user->id],[
|
||
'viewer_id'=>0,
|
||
'mobile'=>$request->mobile,
|
||
'sex'=>$sex,
|
||
'nickname'=>$nickname,
|
||
]);
|
||
ProfileCourtship::updateOrCreate(['user_id'=>$user->id],[
|
||
'birthday'=>$birthday,
|
||
'sex'=>$sex,
|
||
'state'=>$state,
|
||
'stature'=>$stature,
|
||
'weight'=>$weight,
|
||
'degree'=>$degree,
|
||
'province'=>$province,
|
||
'resident_province'=>$resident_province,
|
||
'resident_city'=>$resident_city,
|
||
'introduction'=>$introduction,
|
||
'ideal_mate'=>$ideal_mate,
|
||
'city'=>$city,
|
||
]);
|
||
ProfilePhoto::where('user_id',$user->id)->delete();
|
||
$insert_arr = [];
|
||
foreach ($photos as $key => $item) {
|
||
$snap_arr['user_id'] = $user->id;
|
||
$snap_arr['photo'] = $item;
|
||
$snap_arr['dateline'] = date('Y-m-d');
|
||
$snap_arr['created_at'] = date('Y-m-d H:i:s');
|
||
$snap_arr['updated_at'] = date('Y-m-d H:i:s');
|
||
$insert_arr[] = $snap_arr;
|
||
}
|
||
ProfilePhoto::insert($insert_arr);
|
||
UpperWallHistory::create([
|
||
'user_id'=>$user->id,
|
||
'status'=>0,
|
||
'reason'=>'',
|
||
'admin_id'=>0,
|
||
]);
|
||
//生成备注
|
||
ClientComment::create([
|
||
'user_id'=>$user->id,
|
||
'maker_user_id'=>0,
|
||
'type'=>'active',
|
||
'pics'=>null,
|
||
'comment'=>'通过h5申请上墙'
|
||
]);
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息,请稍后再试');
|
||
}
|
||
}
|
||
|
||
//获取上墙信息
|
||
public function getWallInfo(Request $request){
|
||
$wechatUser = session('wechat.oauth_user.new');
|
||
if(empty( $wechatUser)){
|
||
$openId = $request->openid;
|
||
}else{
|
||
$openId = $wechatUser->getId();
|
||
}
|
||
$user_id = $this->getUseridByOpenid($openId,1);
|
||
$user = User::find($user_id);
|
||
if(!$user) return $this->success('ok',[]);
|
||
$user = User::find($user_id);
|
||
$user->profilePhoto;
|
||
$profile_photo = [];
|
||
if($user->profilePhoto){
|
||
foreach ($user->profilePhoto as $key => $value) {
|
||
$profile_photo[] = $value->photo;
|
||
}
|
||
}
|
||
$user->profileCourtship;
|
||
$user->profile_photo = $profile_photo;
|
||
unset($user->profilePhoto);
|
||
return $this->success('ok',$user);
|
||
}
|
||
|
||
//短链接
|
||
public function mpJumpUrl(Request $request){
|
||
$url = $request->url;
|
||
$path_arr = parse_url($url);
|
||
$path = $path_arr['path'];
|
||
$query = !empty($path_arr['query']) ? $path_arr['query'] : null;
|
||
$result = \CommonUtilsService::getWecharLink($path,$query);
|
||
return $this->success('ok',$result);
|
||
}
|
||
}
|