391 lines
14 KiB
PHP
391 lines
14 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Server\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\CommunityActivity;
|
|
use App\Models\Consultation;
|
|
use App\Models\Course\Course;
|
|
use App\Models\MerchantAccount;
|
|
use App\Models\MerchantShop;
|
|
use App\Models\Server\EvaluateList;
|
|
use App\Models\Server\MerchantEvaluate;
|
|
use App\Models\Server\MerchantService;
|
|
use App\Models\Server\SaasMemberVipGain;
|
|
use App\Models\Server\SaasVipSpreadMerchant;
|
|
use App\Models\Server\TouristOrder;
|
|
use App\Services\SaasVipSpreadService;
|
|
use App\Utils\Http;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class VipSpreadController extends Controller
|
|
{
|
|
/**
|
|
* 选择saas的商家
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\JsonResponse|string|void
|
|
*/
|
|
public function selectSaasMerchantList(Request $request)
|
|
{
|
|
try {
|
|
$keyword = $request->input('keyword');
|
|
$where = [
|
|
['id', '!=', $request->account_id]
|
|
];
|
|
$list = MerchantAccount::with('anchorV2')
|
|
->whereHas('anchorV2', function ($query) use ($keyword) {
|
|
if ($keyword) {
|
|
$query->where('name', 'like', "%{$keyword}%");
|
|
}
|
|
})
|
|
->where($where)
|
|
->get();
|
|
return $this->success('ok', $list);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 推广商家
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\JsonResponse|void
|
|
*/
|
|
public function spreadMerchantList(Request $request)
|
|
{
|
|
try {
|
|
$keyword = $request->input('keyword');
|
|
$level_id = $request->input('level_id');
|
|
$where = [];
|
|
if ($level_id) {
|
|
$where[] = ['level_id', '=', $level_id];
|
|
}
|
|
$list = SaasVipSpreadMerchant::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());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 添加推广商家
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\JsonResponse|void
|
|
*/
|
|
public function addSpreadMerchant(Request $request)
|
|
{
|
|
try {
|
|
$merchant_id = $request->account_id;
|
|
// $spread_merchant_id = $request->input('spread_merchant_id');
|
|
$spread_merchant_ids = $request->input('spread_merchant_ids');
|
|
$spread_merchant_ids = explode(',', $spread_merchant_ids);
|
|
$level_id = $request->input('level_id');
|
|
if (!$spread_merchant_ids) {
|
|
return $this->failure('spread_merchant_ids null');
|
|
}
|
|
if (!$level_id) {
|
|
return $this->failure('level_id null');
|
|
}
|
|
$model = new SaasVipSpreadMerchant();
|
|
$data = [];
|
|
$time = time();
|
|
foreach ($spread_merchant_ids as $spread_merchant_id) {
|
|
$item = [];
|
|
$item['level_id'] = $level_id;
|
|
$item['merchant_id'] = $merchant_id;
|
|
$item['spread_merchant_id'] = $spread_merchant_id;
|
|
// $jump_url = urlencode(env('APP_URL') . "/pu/#/VIPDetail/{$level_id}?spread_merchant_id={$spread_merchant_id}");
|
|
$jump_url = urlencode(env('APP_URL') . "/pu/#/VIPDetail/{$level_id}");
|
|
$query = "merchant_id={$merchant_id}&spread_merchant_id={$spread_merchant_id}&url={$jump_url}";
|
|
$url = env('APP_URL') . "/api/official/live/wechat/FamilyAuth?{$query}";
|
|
$qrcode = $this->getPreviewQrcode($url);
|
|
$item['qrcode'] = $qrcode;
|
|
$item['link'] = $url;
|
|
$item['created_at'] = date('Y-m-d H:i:s', $time);
|
|
//过滤已存在的推广商家
|
|
$where = [
|
|
['level_id','=',$level_id],
|
|
['merchant_id','=',$merchant_id],
|
|
['spread_merchant_id','=',$spread_merchant_id],
|
|
];
|
|
$check = $model->where($where)->first();
|
|
if($check){
|
|
return $this->failure('推广商家已存在-'.$spread_merchant_id);
|
|
}
|
|
$data[] = $item;
|
|
}
|
|
|
|
if (!$model->insert($data)) {
|
|
return $this->failure('添加失败');
|
|
}
|
|
return $this->success('ok');
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除推广商家
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\JsonResponse|string
|
|
*/
|
|
public function delSpreadMerchant(Request $request)
|
|
{
|
|
try {
|
|
$id = $request->input('id');
|
|
$spread_merchant_id = $request->input('spread_merchant_id');
|
|
if (!$id) {
|
|
return $this->failure('id null');
|
|
}
|
|
if (!$spread_merchant_id) {
|
|
return $this->failure('spread_merchant_id null');
|
|
}
|
|
$where = [
|
|
['id', '=', $id],
|
|
['spread_merchant_id', '=', $spread_merchant_id]
|
|
];
|
|
$res = SaasVipSpreadMerchant::where($where)->delete();
|
|
if (!$res) {
|
|
return $this->failure('删除失败');
|
|
}
|
|
return $this->success('ok');
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 商家推广码
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\JsonResponse|void
|
|
*/
|
|
public function spreadMerchantQrcode(Request $request)
|
|
{
|
|
try {
|
|
|
|
return $this->success('ok');
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* vip权益
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\JsonResponse|string
|
|
*/
|
|
public function vipGainList(Request $request)
|
|
{
|
|
try {
|
|
$type = $request->input('type');
|
|
if (empty($type)) {
|
|
return $this->failure('type null');
|
|
}
|
|
$spread_merchant_id = $request->input('spread_merchant_id');
|
|
$keyword = $request->input('keyword');
|
|
$data = null;
|
|
switch ($type) {
|
|
case 'activity'://活动
|
|
$where = [
|
|
['class', '=', 'one']
|
|
];
|
|
if ($spread_merchant_id) {
|
|
$where[] = ['merchant_id', '=', $spread_merchant_id];
|
|
}
|
|
if ($keyword) {
|
|
$where[] = ['title', 'like', "%{$keyword}%"];
|
|
}
|
|
$data = CommunityActivity::where($where)->orderBy('id', 'desc')->get();
|
|
foreach ($data as $item){
|
|
if($item->sku){
|
|
$item->sku = json_decode($item->sku);
|
|
}
|
|
}
|
|
break;
|
|
case 'consultation'://咨询
|
|
$where = [];
|
|
if ($keyword) {
|
|
$where[] = ['title', 'like', "%{$keyword}%"];
|
|
}
|
|
$data = Consultation::with('teacher')
|
|
->whereHas('teacher', function ($query) use ($spread_merchant_id) {
|
|
if ($spread_merchant_id) {
|
|
$query->where('merchant_id', $spread_merchant_id);
|
|
}
|
|
})
|
|
->where($where)
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
break;
|
|
case 'course'://课程
|
|
$where = [];
|
|
if ($spread_merchant_id) {
|
|
$where[] = ['merchant_id', '=', $spread_merchant_id];
|
|
}
|
|
if ($keyword) {
|
|
$where[] = ['title', 'like', "%{$keyword}%"];
|
|
}
|
|
$data = Course::where($where)->orderBy('id', 'desc')->get();
|
|
break;
|
|
case 'evaluation'://测评
|
|
$where = [];
|
|
if ($spread_merchant_id) {
|
|
$where[] = ['merchant_id', '=', $spread_merchant_id];
|
|
}
|
|
if ($keyword) {
|
|
$where[] = ['title', 'like', "%{$keyword}%"];
|
|
}
|
|
$data = MerchantEvaluate::where($where)->orderBy('id', 'desc')->get();
|
|
break;
|
|
case 'service'://服务
|
|
$where = [
|
|
['class', '=', 'many']
|
|
];
|
|
if ($spread_merchant_id) {
|
|
$where[] = ['merchant_id', '=', $spread_merchant_id];
|
|
}
|
|
if ($keyword) {
|
|
$where[] = ['title', 'like', "%{$keyword}%"];
|
|
}
|
|
$data = CommunityActivity::where($where)
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
foreach ($data as $item){
|
|
if($item->sku){
|
|
$item->sku = json_decode($item->sku);
|
|
}
|
|
}
|
|
break;
|
|
case 'shop'://商城商品
|
|
$where = [];
|
|
if($spread_merchant_id){
|
|
$where[] = ['merchant_id','=',$spread_merchant_id];
|
|
}
|
|
if ($keyword) {
|
|
$where[] = ['title', 'like', "%{$keyword}%"];
|
|
}
|
|
$data = MerchantShop::where($where)
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
foreach ($data as $item){
|
|
if($item->sku){
|
|
$item->sku = json_decode($item->sku);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
return $this->success('ok', $data);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure($e->getMessage() . $e->getLine());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 推广记录
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\JsonResponse|string
|
|
*/
|
|
public function orderList(Request $request)
|
|
{
|
|
try {
|
|
$spread_merchant_id = $request->spread_merchant_id;
|
|
$level_id = $request->level_id;
|
|
$where = [];
|
|
if ($spread_merchant_id) {
|
|
$where[] = ['spread_merchant_id', '=', $spread_merchant_id];
|
|
}
|
|
if ($level_id) {
|
|
$where[] = ['type_id', '=', $level_id];
|
|
}
|
|
$orders = TouristOrder::with('viewer:avatar,mobile,openid,sex,nickname', 'merchant:id,share_icon,share_title',
|
|
'fromUser:user_id as id,avatar,mobile,openid,sex,nickname', 'merUser', 'alliance')
|
|
->where('type', 'member')
|
|
->where($where)
|
|
->whereIn('pay_status',[1,4])
|
|
->orderBy('id', 'desc')
|
|
->paginate();
|
|
$orders->transform(function ($value) {
|
|
$value->linkmen = json_decode($value->linkmen,true);
|
|
return $value;
|
|
});
|
|
return $this->success('ok', $orders);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure($e->getMessage() . $e->getLine());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 用户购买vip的权益列表数据展示
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\JsonResponse|string
|
|
*/
|
|
public function userBuyVipGainList(Request $request)
|
|
{
|
|
try {
|
|
$merchant_user_id = $request->merchant_user_id;
|
|
$level_id = $request->level_id;
|
|
// $saas_member_vip_gain = new SaasMemberVipGain();
|
|
$where = [
|
|
['merchant_user_id', '=', $merchant_user_id],
|
|
['level_id', '=', $level_id],
|
|
];
|
|
$list = SaasMemberVipGain::where($where)->orderBy('id', 'desc')->get();
|
|
$s = new SaasVipSpreadService();
|
|
foreach ($list as $item){
|
|
// $item->gain_info = $s->getGain($item->type,$item->spread_merchant_id,$item->type_id);
|
|
$item->gain_info = $s->getGain($item->type,0,$item->type_id);
|
|
}
|
|
return $this->success('ok', $list);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索已添加的推广商家
|
|
* @return \Illuminate\Http\JsonResponse|string
|
|
*/
|
|
public function selectExistSpreadMerchant(Request $request)
|
|
{
|
|
try {
|
|
$merchant_id = $request->account_id;
|
|
$level_id = $request->input('level_id');
|
|
$keyword = $request->input('keyword');
|
|
|
|
$where = [
|
|
['level_id','=',$level_id],
|
|
['merchant_id','=',$merchant_id],
|
|
];
|
|
$ids = SaasVipSpreadMerchant::where($where)->pluck('spread_merchant_id');
|
|
$list = MerchantAccount::with('anchorV2')
|
|
->whereHas('anchorV2', function ($query) use ($keyword) {
|
|
if ($keyword) {
|
|
$query->where('name', 'like', "%{$keyword}%");
|
|
}
|
|
})
|
|
->whereIn('id',$ids)
|
|
->get();
|
|
return $this->success('ok',$list);
|
|
}catch (\Exception $e){
|
|
$this->getError($e);
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
} |