192 lines
7.6 KiB
PHP
192 lines
7.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Server\Admin;
|
|
|
|
use App\Contracts\UserContract;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\MerchantAccount;
|
|
use App\Models\SaasMemberVipSpreadCarrier;
|
|
use App\Models\Server\SaasVipSpreadMerchant;
|
|
use App\Models\TouristOrder;
|
|
use App\Models\User;
|
|
use App\Services\SaasVipUserService;
|
|
use App\Utils\Http;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class VipUserController extends Controller
|
|
{
|
|
protected $userCon;
|
|
public function __construct(UserContract $userCon)
|
|
{
|
|
$this->userCon = $userCon;
|
|
}
|
|
|
|
/**
|
|
* vip用户列表 获取未注册福恋小程序 展示的跳转码
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\JsonResponse|string
|
|
*/
|
|
public function qrcodeByNoRegFulink(Request $request)
|
|
{
|
|
try {
|
|
$merchant_id = $request->account_id;
|
|
$merchant_user_id = $request->input('merchant_user_id');
|
|
if(!$merchant_user_id) return $this->failure('merchant_user_id不能为空');
|
|
|
|
$cache_key = "saas:vip_user_no_reg_fulink_qrcode:{$merchant_user_id}";
|
|
$qrcode = Cache::get($cache_key);
|
|
if(empty($qrcode)){
|
|
// $app = \EasyWeChat::miniProgram();
|
|
// $token = $app->access_token->getToken();
|
|
// $access_token = $token['access_token'];
|
|
$access_token = "";
|
|
$resp = Http::get("https://love.ufutx.com/go/api/mp/access_token?token=go_love");
|
|
if ($resp) {
|
|
if ($resp) {
|
|
$res = json_decode($resp, true);
|
|
$access_token = $res["data"]['access_token'];
|
|
}
|
|
}
|
|
if (empty($access_token)) {
|
|
return $this->failure("缺少access_token");
|
|
}
|
|
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token;
|
|
$data = [
|
|
'page' => 'pages/users/unmarriV2',
|
|
'scene' => "merchant_user_id={$merchant_user_id}"
|
|
];
|
|
$result = Http::post($url, json_encode($data, JSON_UNESCAPED_UNICODE));
|
|
$path = storage_path('qrcode/'.time()."_saas_vip_user_no_reg_fulink_qrcode_{$merchant_user_id}.png");
|
|
file_put_contents($path, $result);
|
|
$qrcode = $this->uploadFile($path);
|
|
unlink($path);
|
|
Cache::put($cache_key, $qrcode, 60 * 24); //有效期一天
|
|
}
|
|
return $this->success('ok',compact('qrcode'));
|
|
}catch (\Exception $e){
|
|
$this->getError($e);
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* vip用户生成推广数据
|
|
* @param Request $request
|
|
* @param SaasVipUserService $s
|
|
* @return \Illuminate\Http\JsonResponse|string
|
|
*/
|
|
public function createSpreadCarrier(Request $request,SaasVipUserService $s)
|
|
{
|
|
try {
|
|
$merchant_id = $request->account_id;
|
|
$spread_merchant_id = $request->input('spread_merchant_id');
|
|
if(!$spread_merchant_id) return $this->failure('spread_merchant_id不能为空');
|
|
|
|
$merchant_user_id = $request->input('merchant_user_id');
|
|
if(!$merchant_user_id) return $this->failure('merchant_user_id不能为空');
|
|
|
|
$level_id = $request->input('level_id');
|
|
if(!$level_id) return $this->failure('level_id不能为空');
|
|
|
|
$where = [
|
|
['merchant_id','=',$merchant_id],
|
|
['merchant_user_id','=',$merchant_user_id],
|
|
['level_id','=',$level_id],
|
|
['spread_merchant_id','=',$spread_merchant_id],
|
|
];
|
|
$check = SaasMemberVipSpreadCarrier::where($where)->first();
|
|
if($check) return $this->failure('该推广商家已选择过了');
|
|
|
|
$order_id = $request->order_id;
|
|
$order = TouristOrder::find($order_id);
|
|
if(!$order_id) return $this->failure('order_id不能为空');
|
|
|
|
$where = [
|
|
['merchant_id','=',$merchant_id],
|
|
['merchant_user_id','=',$merchant_user_id],
|
|
['level_id','=',$level_id],
|
|
];
|
|
$carrier = SaasMemberVipSpreadCarrier::where($where)->orderBy('id','asc')->first();
|
|
$fulink_user_id = $carrier->fulink_user_id ?? 0;
|
|
if(!$fulink_user_id){
|
|
$fulink_user_id = $s->matchFulinkUser($merchant_user_id,$order->mobile);
|
|
if(!$fulink_user_id) return $this->failure('该用户未注册福恋小程序');
|
|
}
|
|
|
|
//判断用户数据是否可以正常展示
|
|
$frozen_state = $this->userCon->getUserBannedState($fulink_user_id);
|
|
if($frozen_state){
|
|
return $this->failure('该小程序用户已被封禁');
|
|
}
|
|
$fulink_user = User::find($fulink_user_id);
|
|
if($fulink_user->hidden_profile == 'ALLSEX'){
|
|
return $this->failure('该小程序用户已关闭资料');
|
|
}
|
|
|
|
$jump_url = urlencode(env('APP_URL') . "/pu/#/VIPUserDetail/{$fulink_user_id}");
|
|
$query = "merchant_id={$merchant_id}&spread_merchant_id={$spread_merchant_id}&vip_level_id={$level_id}&url={$jump_url}";
|
|
$link = env('APP_URL') . "/api/official/live/wechat/FamilyAuth?{$query}";
|
|
$qrcode = $this->getPreviewQrcode($link);
|
|
|
|
$model = new SaasMemberVipSpreadCarrier;
|
|
$model->merchant_id = $merchant_id;
|
|
$model->spread_merchant_id = $spread_merchant_id;
|
|
$model->merchant_user_id = $merchant_user_id;
|
|
$model->fulink_user_id = $fulink_user_id;
|
|
$model->level_id = $level_id;
|
|
$model->link = $link;
|
|
$model->qrcode = $qrcode;
|
|
|
|
if(!$model->save()){
|
|
return $this->failure('写入数据失败');
|
|
}
|
|
return $this->success('ok',compact('link','qrcode'));
|
|
}catch (\Exception $e){
|
|
$this->getError($e);
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* vip用户 推广载体列表
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\JsonResponse|string
|
|
*/
|
|
public function spreadCarrierList(Request $request)
|
|
{
|
|
try {
|
|
$merchant_id = $request->account_id;
|
|
// $spread_merchant_id = $request->input('spread_merchant_id');
|
|
// if(!$spread_merchant_id) return $this->failure('spread_merchant_id不能为空');
|
|
|
|
$merchant_user_id = $request->input('merchant_user_id');
|
|
if(!$merchant_user_id) return $this->failure('merchant_user_id不能为空');
|
|
|
|
$level_id = $request->input('level_id');
|
|
if(!$level_id) return $this->failure('level_id不能为空');
|
|
|
|
$keyword = $request->input('keyword');
|
|
|
|
$where = [
|
|
['merchant_id','=',$merchant_id],
|
|
['merchant_user_id','=',$merchant_user_id],
|
|
['level_id','=',$level_id],
|
|
];
|
|
|
|
$list = SaasMemberVipSpreadCarrier::with('spreadAnchor')
|
|
->whereHas('spreadAnchor', function ($query) use ($keyword) {
|
|
if ($keyword) {
|
|
$query->where('name', 'like', "%{$keyword}%");
|
|
}
|
|
})
|
|
->where($where)
|
|
->orderBy('id', 'desc')
|
|
->paginate();
|
|
return $this->success('ok', $list);
|
|
}catch (\Exception $e){
|
|
$this->getError($e);
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
} |