169 lines
7.0 KiB
PHP
169 lines
7.0 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
namespace App\Http\Controllers\Server\H5;
|
|||
|
|
|
|||
|
|
use App\Http\Controllers\Controller;
|
|||
|
|
use App\Models\SaasMemberVipSpreadCarrier;
|
|||
|
|
use App\Models\SaasVipContactSms;
|
|||
|
|
use App\Models\Server\TouristOrder;
|
|||
|
|
use App\Services\SaasVipService;
|
|||
|
|
use App\Utils\Http;
|
|||
|
|
use Illuminate\Http\Request;
|
|||
|
|
use Illuminate\Support\Facades\Cache;
|
|||
|
|
|
|||
|
|
class VipController extends Controller
|
|||
|
|
{
|
|||
|
|
/**
|
|||
|
|
* 我的vip订单
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return \Illuminate\Http\JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function orderList(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_id = $request->merchant_id;
|
|||
|
|
$merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$where = [
|
|||
|
|
['type','=','member'],
|
|||
|
|
['merchant_id','=',$merchant_id],
|
|||
|
|
['account_id','=',$merchant_user_id],
|
|||
|
|
];
|
|||
|
|
$order = TouristOrder::with('levelDetail')
|
|||
|
|
->where($where)
|
|||
|
|
->whereIn('pay_status',[1,4])
|
|||
|
|
->select('id','price','type','type_id','pay_status','trade_no','goods','desc','merchant_id','account_id')
|
|||
|
|
->orderBy('id','desc')
|
|||
|
|
->paginate();
|
|||
|
|
return $this->success('ok',$order);
|
|||
|
|
}catch (\Exception $e){
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure($e->getMessage());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 联系vip会员短信
|
|||
|
|
* @param Request $request
|
|||
|
|
* @param SaasVipService $s
|
|||
|
|
* @return \Illuminate\Http\JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function contactFulinkUserSms(Request $request,SaasVipService $s)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_id = $request->merchant_id;
|
|||
|
|
$merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$level_id = $request->level_id;
|
|||
|
|
$vip_user_spread_carrier_id = $request->vip_user_spread_carrier_id;
|
|||
|
|
//检查是否购买VIP
|
|||
|
|
if (!$s->checkBuyVip($merchant_id, $merchant_user_id, $level_id)) {
|
|||
|
|
return $this->failure('您未购买该VIP,无法发送联系短信');
|
|||
|
|
}
|
|||
|
|
$where = [
|
|||
|
|
['merchant_id','=',$merchant_id],
|
|||
|
|
['merchant_user_id','=',$merchant_user_id],
|
|||
|
|
['level_id','=',$level_id],
|
|||
|
|
['vip_user_spread_carrier_id','=',$vip_user_spread_carrier_id],
|
|||
|
|
];
|
|||
|
|
$check = SaasVipContactSms::where($where)->first();
|
|||
|
|
if($check){
|
|||
|
|
return $this->failure('短信已发送');
|
|||
|
|
}
|
|||
|
|
$order = $s->getBuyVipOrder($merchant_id, $merchant_user_id, $level_id);
|
|||
|
|
$send = $s->contactSms($vip_user_spread_carrier_id,$order->mobile);
|
|||
|
|
if ($send){
|
|||
|
|
$model = new SaasVipContactSms;
|
|||
|
|
$model->merchant_id = $merchant_id;
|
|||
|
|
$model->merchant_user_id = $merchant_user_id;
|
|||
|
|
$model->level_id = $level_id;
|
|||
|
|
$model->vip_user_spread_carrier_id = $vip_user_spread_carrier_id;
|
|||
|
|
if(!$model->save()) return $this->failure('写入数据失败');
|
|||
|
|
}
|
|||
|
|
return $this->success('ok');
|
|||
|
|
}catch (\Exception $e){
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure($e->getMessage());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 联系vip会员
|
|||
|
|
* @param Request $request
|
|||
|
|
* @param SaasVipService $s
|
|||
|
|
* @return \Illuminate\Http\JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function contactFulinkUser(Request $request,SaasVipService $s)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_id = $request->merchant_id;
|
|||
|
|
$merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$level_id = $request->level_id;
|
|||
|
|
$vip_user_spread_carrier_id = $request->vip_user_spread_carrier_id;
|
|||
|
|
//检查是否购买VIP
|
|||
|
|
if (!$s->checkBuyVip($merchant_id, $merchant_user_id, $level_id)) {
|
|||
|
|
return $this->failure('您未购买该VIP,无法发送联系短信');
|
|||
|
|
}
|
|||
|
|
//订单
|
|||
|
|
$order = $s->getBuyVipOrder($merchant_id, $merchant_user_id, $level_id);
|
|||
|
|
|
|||
|
|
//二维码
|
|||
|
|
$spread_carrier = SaasMemberVipSpreadCarrier::find($vip_user_spread_carrier_id);
|
|||
|
|
if(!$spread_carrier){
|
|||
|
|
return $this->failure('推广数据未找到');
|
|||
|
|
}
|
|||
|
|
$cache_key = "saas:vip_contact_ta_short_link:m_user_id{$merchant_user_id}__spread_carrier_id{$vip_user_spread_carrier_id}";
|
|||
|
|
$short_link = Cache::get($cache_key);
|
|||
|
|
if(empty($short_link)){
|
|||
|
|
// $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/generate_urllink?access_token=" . $access_token;
|
|||
|
|
$query = "id={$spread_carrier->fulink_user_id}&from_merchant_id={$spread_carrier->spread_merchant_id}";
|
|||
|
|
$data = [
|
|||
|
|
'path' => '/pages/home/information',
|
|||
|
|
'query' => $query,
|
|||
|
|
'expire_time' => time() + (60 * 60 * 24) //有效期一天
|
|||
|
|
];
|
|||
|
|
$result = Http::post($url, json_encode($data, JSON_UNESCAPED_UNICODE));
|
|||
|
|
$result = json_decode($result, true);
|
|||
|
|
$code = $result['errCode'] ?? '';
|
|||
|
|
$short_link = $result['url_link'] ?? '';
|
|||
|
|
if($code != 0 && empty($short_link)) return $this->failure('获取跳转小程序短链失败');
|
|||
|
|
Cache::put($cache_key, $short_link, 60 * 24); //有效期一天
|
|||
|
|
}
|
|||
|
|
//只发送一次短信
|
|||
|
|
$where = [
|
|||
|
|
['merchant_id','=',$merchant_id],
|
|||
|
|
['merchant_user_id','=',$merchant_user_id],
|
|||
|
|
['level_id','=',$level_id],
|
|||
|
|
['vip_user_spread_carrier_id','=',$vip_user_spread_carrier_id],
|
|||
|
|
];
|
|||
|
|
$check = SaasVipContactSms::where($where)->first();
|
|||
|
|
if(!$check){
|
|||
|
|
$send = $s->contactSms($vip_user_spread_carrier_id,$order->mobile);
|
|||
|
|
if ($send){
|
|||
|
|
$model = new SaasVipContactSms;
|
|||
|
|
$model->merchant_id = $merchant_id;
|
|||
|
|
$model->merchant_user_id = $merchant_user_id;
|
|||
|
|
$model->level_id = $level_id;
|
|||
|
|
$model->vip_user_spread_carrier_id = $vip_user_spread_carrier_id;
|
|||
|
|
if(!$model->save()) return $this->failure('写入数据失败');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return $this->success('ok',compact('short_link'));
|
|||
|
|
}catch (\Exception $e){
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure($e->getMessage());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|