2856 lines
132 KiB
PHP
2856 lines
132 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Server\Admin;
|
||
|
||
use App\Events\OutUserMatch;
|
||
use App\Exports\ActivityApplyUserExport;
|
||
use App\Exports\ActivityMemberExportV2;
|
||
use App\Facades\CommonUtilsService;
|
||
use App\Jobs\InsideUserMatch;
|
||
use App\Jobs\OutUserMatchListener;
|
||
use App\Models\Activity;
|
||
use App\Models\ClientComment;
|
||
use App\Models\Live\Viewer;
|
||
use App\Models\Match\Profile;
|
||
use App\Models\PortraitRecord;
|
||
use App\Models\Server\ActivityMeeting;
|
||
use App\Models\Server\ActivityMeetingApply;
|
||
use App\Models\Server\ActivityPhoto;
|
||
use App\Models\Server\CommunityActivityMember;
|
||
use App\Models\Server\MarketService;
|
||
use App\Models\Server\MatchLog;
|
||
use App\Models\Server\MEarningRule;
|
||
use App\Models\Server\MerchantEvaluate;
|
||
use App\Models\Server\MerchantMembers;
|
||
use App\Models\Server\MerchantService;
|
||
use App\Models\Server\MRefundOrder;
|
||
use App\Models\Server\QrCode;
|
||
use App\Models\Server\SignIn;
|
||
use App\Models\Server\TouristOrder as Order;
|
||
use App\Services\CommunityActivityService;
|
||
use App\Services\UserMatchService;
|
||
use Illuminate\Database\Eloquent\Builder;
|
||
use Illuminate\Http\JsonResponse;
|
||
use Illuminate\Http\Request;
|
||
use App\Http\Controllers\Controller;
|
||
use App\Models\CommunityActivity;
|
||
use App\Models\Consultation;
|
||
use App\Models\Course\Course;
|
||
use App\Models\Live\Anchor;
|
||
use App\Models\Live\LiveBanner;
|
||
use App\Models\MerchantShop;
|
||
use App\Models\Server\CollageGroup;
|
||
use App\Models\Server\MEarning;
|
||
use App\Models\Server\MerchantAccount;
|
||
use App\Models\Server\MerchantUser;
|
||
use App\Models\Server\MOrderFollow;
|
||
use App\Models\Server\TouristOrder;
|
||
use App\Models\User;
|
||
use App\Models\WangYiYunUser;
|
||
use App\Models\Wechat;
|
||
use App\Services\IMService;
|
||
use Illuminate\Pagination\LengthAwarePaginator;
|
||
use Illuminate\Pagination\Paginator;
|
||
use Illuminate\Support\Facades\Cache;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Illuminate\Support\Facades\Hash;
|
||
use Illuminate\Support\Facades\Log;
|
||
use Illuminate\Support\Facades\Redis;
|
||
use Illuminate\Support\Facades\Validator;
|
||
use function Clue\StreamFilter\fun;
|
||
|
||
class ActivityController extends Controller
|
||
{
|
||
//社群活动 /或服务控制器 class:one 活动 class:many 服务
|
||
//测试方法
|
||
public function testAdmin()
|
||
{
|
||
return $this->success("这是一个Admin测试接口");
|
||
}
|
||
|
||
/**
|
||
* 列表
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function platCommunityActivities(Request $request)
|
||
{
|
||
try {
|
||
$keyword = $request->keyword;
|
||
$status = $request->status ?? 2;
|
||
$class = $request->class;
|
||
$mobile = MerchantAccount::where('id', $request->account_id)->value('mobile');
|
||
$anchor = Anchor::where('m_id', $request->account_id)->first();
|
||
$id = 0;
|
||
if ($anchor) {
|
||
$id = $anchor->id;
|
||
}
|
||
$my_market_services_ids = MarketService::where('merchant_id', $request->account_id)
|
||
->where('type', 'community')
|
||
->pluck('type_id')
|
||
->toArray();
|
||
$merchant_service_ids = MerchantService::where('merchant_id', $request->account_id)
|
||
->where('type', 'community')
|
||
->pluck('type_id')
|
||
->toArray();
|
||
|
||
$activities = CommunityActivity::whereIn('community_activities.id', $merchant_service_ids)
|
||
->join('merchant_services', function ($join) use ($request) {
|
||
$join->on('community_activities.id', '=', 'merchant_services.type_id')
|
||
->where('merchant_services.merchant_id', $request->account_id)
|
||
->where('merchant_services.type', 'community')
|
||
->whereNull('merchant_services.deleted_at');
|
||
}, null, null, 'left')
|
||
->select('community_activities.pic', 'community_activities.title', 'community_activities.price',
|
||
'community_activities.pv', 'merchant_services.status', 'community_activities.pay_type',
|
||
'community_activities.reward_status', 'community_activities.created_at', 'merchant_services.is_top',
|
||
'merchant_services.service_type', 'community_activities.id', 'community_activities.sku', 'community_activities.Subtitle','community_activities.start_time',
|
||
'community_activities.end_time', 'community_activities.top_time')
|
||
->with('banners:class_id,icon');
|
||
if ($status != 2) {
|
||
$activities = $activities->where('merchant_services.status', $status);
|
||
}
|
||
if ($class != 'all') {
|
||
$activities = $activities->where('community_activities.class', $class);
|
||
}
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$activities = $activities->where(function ($sql) use ($keyword) {
|
||
$sql->where('title', 'like', '%' . $keyword . '%')
|
||
->orWhere('community_activities.id', $keyword);
|
||
});
|
||
}
|
||
$time = date('Y-m-d H:i:s');
|
||
|
||
$activities = $activities
|
||
->orderBy('merchant_services.status', 'desc')
|
||
->orderBy('merchant_services.is_top', 'desc');
|
||
// ->orderBy('merchant_services.top_time', 'desc');
|
||
$order_by_time = $request->input("order_by_time");
|
||
if ($order_by_time) {
|
||
$activities = $activities->orderBy('community_activities.start_time', $order_by_time);
|
||
}else {
|
||
$activities = $activities->orderBy('community_activities.id', 'desc');
|
||
}
|
||
$activities = $activities->paginate();
|
||
foreach ($activities as $activity) {
|
||
if ($my_market_services_ids) {
|
||
if (in_array($activity->id, $my_market_services_ids)) {
|
||
$activity->is_my_market_service = 1;
|
||
} else {
|
||
$activity->is_my_market_service = 0;
|
||
}
|
||
} else {
|
||
$activity->is_my_market_service = 0;
|
||
}
|
||
|
||
if (!empty($activity) && !empty($activity->banners) && !empty($activity->banners->icon)) {
|
||
if (!is_array($activity->banners->icon)) {
|
||
$activity->banners->icon = json_decode($activity->banners->icon, true);
|
||
}
|
||
}
|
||
if ($activity->sku && $activity->sku != 'null') $activity->sku = json_decode($activity->sku, true);
|
||
$is_deadline = 0;
|
||
if ($activity->class == 'one' && $activity->apply_deadline) {
|
||
if ($activity->apply_deadline <= $time) {
|
||
$is_deadline = 1;
|
||
}
|
||
}
|
||
$activity->is_deadline = $is_deadline;
|
||
if ($activity->reward_status == 1) {
|
||
$reward_money = TouristOrder::where('type', 'reward_activity')->where('type_id', $activity->id)
|
||
->whereIn('pay_status', [1, 4])
|
||
->sum('price');
|
||
$activity->reward_money = $reward_money;
|
||
} else {
|
||
$activity->reward_money = 0;
|
||
}
|
||
$member_count = TouristOrder::where('type', 'community')->where('type_id', $activity->id)
|
||
->where('pay_status', '<>', 0)
|
||
->where('merchant_id', $request->account_id)
|
||
->count();
|
||
$activity->member_count = $member_count;
|
||
}
|
||
return $this->success('ok', $activities);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
}
|
||
|
||
public function platServicePreviewers(Request $request, $id)
|
||
{
|
||
$type = $request->input('type');
|
||
switch ($type) {
|
||
case "activity":
|
||
case "service":
|
||
$service = CommunityActivity::find($id);
|
||
break;
|
||
case "course":
|
||
$service = Course::find($id);
|
||
break;
|
||
case "consult":
|
||
$service = Consultation::find($id);
|
||
break;
|
||
case 'evaluate':
|
||
$service = MerchantEvaluate::find($id);
|
||
break;
|
||
case "shop":
|
||
$service = MerchantShop::find($id);
|
||
break;
|
||
}
|
||
|
||
if (empty($service)) return $this->success('ok', []);
|
||
$previews = $service->previews()->where(function ($sql) {
|
||
$sql->whereHas('merchantUser')->orWhereHas('mpUser');
|
||
})
|
||
->with('merchantUser:id,nickname,mobile,pic as photo', 'mpUser:id,nickname,mobile,photo')
|
||
->orderBy('id', 'desc')
|
||
->paginate();
|
||
foreach ($previews as $preview) {
|
||
$preview->user = $preview->merchantUser?:$preview->mpUser;;
|
||
$preview->type = ($preview->previewed_type == 'App\\Models\\User') ? 1 : 2;
|
||
unset($preview->merchantUser, $preview->mpUser);
|
||
}
|
||
return $this->success('ok', $previews);
|
||
}
|
||
|
||
/**
|
||
* 列表-后台选择
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function platCommunityList(Request $request)
|
||
{
|
||
try {
|
||
$anchor_id = $request->anchor_id;
|
||
$activities = CommunityActivity::where('anchor_id', $anchor_id)->where('status', 1)->where('type', 'fulllink')->orderBy('sort', 'desc')->get();
|
||
return $this->success('ok', $activities);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 创建网易云信帐号
|
||
* @param $data
|
||
*/
|
||
public function createWyyUser($data)
|
||
{
|
||
try {
|
||
$im_service = new IMService(env('IM_APP_KEY'), env('IM_APP_SECRET'));
|
||
$result = $im_service->createUserId($data['accid'], $data['nickname'], $props = '{}', null);
|
||
//Log::info('创建网易云账号');
|
||
//\Log::info($result);
|
||
if ($result['code'] == 200) {
|
||
$wyyUser = new WangYiYunUser;
|
||
$wyyUser->anchor_id = $data['anchor_id'];
|
||
$wyyUser->accid = $data['accid'];
|
||
$wyyUser->name = $data['nickname'];
|
||
$wyyUser->gender = $data['sex'];
|
||
$wyyUser->token = $result['info']['token'];
|
||
$wyyUser->save();
|
||
} elseif ($result['code'] == 414 && $result['desc'] == 'already register') {
|
||
$result = $im_service->getUinfos([$data['accid']]);
|
||
if ($result['code'] == 200) {
|
||
$info = $result['uinfos'][0];
|
||
$accid = '';
|
||
$name = '';
|
||
$gender = '';
|
||
$icon = '';
|
||
if (array_key_exists("accid", $info)) {
|
||
$accid = $info['accid'];
|
||
}
|
||
if (array_key_exists("name", $info)) {
|
||
$name = $info['name'];
|
||
}
|
||
if (array_key_exists("gender", $info)) {
|
||
$gender = $info['gender'];
|
||
}
|
||
if (array_key_exists("icon", $info)) {
|
||
$icon = $info['icon'];
|
||
}
|
||
$wyyUser = new WangYiYunUser;
|
||
$wyyUser->accid = $accid;
|
||
$wyyUser->name = $name;
|
||
$wyyUser->gender = $gender;
|
||
$wyyUser->icon = $icon;
|
||
$wyyUser->save();
|
||
|
||
//更新网易云token
|
||
$result = $im_service->updateUserToken($accid);
|
||
if ($result['code'] == 200) {
|
||
$wyyUser->token = $result['info']['token'];
|
||
}
|
||
$wyyUser->save();
|
||
}
|
||
}
|
||
return $wyyUser;
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 保存至草稿箱
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function saveToDrafts(Request $request)
|
||
{
|
||
try {
|
||
//商城 服务 活动 咨询 课程
|
||
// $value = ['shop','service','activity','consult','course','consult_account'];
|
||
$merchant_id = $request->account_id;
|
||
$type = $request->type;
|
||
if ($type == 'video' || $type == 'audio' || empty($type)) {
|
||
$type = 'information';
|
||
}
|
||
$key = 'drafts_' . $type . '_merchant_id_' . $merchant_id;
|
||
$all = $request->all();
|
||
Cache::forever($key, $all);
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 读取草稿箱
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function readDrafts(Request $request)
|
||
{
|
||
try {
|
||
$merchant_id = $request->account_id;
|
||
$type = $request->type;
|
||
$key = 'drafts_' . $type . '_merchant_id_' . $merchant_id;
|
||
$result = [];
|
||
if (Cache::has($key)) {
|
||
$result = Cache::get($key);
|
||
return $this->success('ok', $result);
|
||
}
|
||
return $this->success('ok', $result);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 创建服务或 活动
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function createPlatConsulator(Request $request)
|
||
{
|
||
try {
|
||
$await_checkoutTextArray = [];
|
||
$class = $request->class ?? 'one';
|
||
$anchor = Anchor::where('m_id', $request->account_id)->first();
|
||
if (!$anchor) return $this->fail('创建失败,请重新登录', 2);
|
||
$forzen_time = $request->forzen_time;
|
||
$banners = $request->banners;
|
||
$price = $request->price ? $request->price : 0;
|
||
if (!is_numeric($price) || $price < 0) return $this->failure('请输入正确的价格');
|
||
$await_checkoutTextArray[] = $price;
|
||
$title = $request->title;
|
||
$await_checkoutTextArray[] = $title;
|
||
$pic = $request->pic;
|
||
$Subtitle = $request->Subtitle;
|
||
$await_checkoutTextArray[] = $Subtitle;
|
||
$pay_type = $request->pay_type ? $request->pay_type : 'wechat';
|
||
$describe = $request->describe;
|
||
$agree_title = $request->agree_title;
|
||
$agree_content = $request->agree_content;
|
||
$share_thumb = $request->share_thumb;
|
||
if ($class == 'one') {
|
||
$start_time = $request->start_time;
|
||
if (empty($start_time)) return $this->failure('请填写活动开始时间');
|
||
$end_time = $request->end_time;
|
||
if (empty($end_time)) return $this->failure('请填写活动结束时间');
|
||
$apply_deadline = $request->apply_deadline;
|
||
if (empty($apply_deadline)) return $this->failure('请填写活动截止报名时间');
|
||
}
|
||
// $sku = null;
|
||
// if ($request->has('sku') && $request->sku)
|
||
// $sku = json_encode($request->sku);
|
||
// $await_checkoutTextArray[] = $describe;
|
||
$sort = $request->input('sort', 0);
|
||
$await_checkoutTextArray[] = $title;
|
||
$status = $request->input('status', 0);
|
||
$hidden_avatar = $request->input('hidden_avatar',0);
|
||
$hidden_order_total = $request->input('hidden_order_total',0);
|
||
$join_type = $request->input('join_type','single');
|
||
//敏感词汇过滤
|
||
$result = \CommonUtilsService::checkoutTextArrayV3($await_checkoutTextArray);
|
||
if ($result['code'] == 1) {
|
||
return $this->failure($result['cause']);
|
||
}
|
||
|
||
// $result = \CommonUtilsService::imageContentCecurity([$pic]);
|
||
// if ($result && isset($result['result']) && $result['result']) {
|
||
// return $this->failure('图片' . $result['result'] . ',请换一张照片');
|
||
// }
|
||
//
|
||
// $result = \CommonUtilsService::imageContentCecurity($banners);
|
||
// if ($result && isset($result['result']) && $result['result']) {
|
||
// return $this->failure('图片' . $result['result'] . ',请换一张照片');
|
||
// }
|
||
|
||
$consulator = new CommunityActivity();
|
||
$consulator->anchor_id = $anchor->id;
|
||
$consulator->merchant_id = $request->account_id;
|
||
$consulator->price = $price;
|
||
$consulator->title = $title;
|
||
$consulator->share_thumb = $share_thumb;
|
||
if ($request->location == 1) {
|
||
//线上或线下
|
||
$consulator->location = $request->location;
|
||
$consulator->location_longitude = $request->location_longitude;
|
||
$consulator->location_latitude = $request->location_latitude;
|
||
$consulator->address = $request->address;
|
||
}
|
||
// 是否参保
|
||
$consulator->insurance = $request->insurance ?: 0;
|
||
$consulator->Subtitle = $Subtitle;
|
||
$consulator->pay_type = $pay_type;
|
||
$consulator->describe = $describe;
|
||
$consulator->sort = $sort;
|
||
// $consulator->sku = $sku;
|
||
$consulator->status = $status;
|
||
$consulator->pic = $pic;
|
||
$consulator->class = $class;
|
||
$consulator->agree_title = $agree_title;
|
||
$consulator->agree_content = $agree_content;
|
||
if ($class == 'one') {
|
||
$consulator->start_time = $start_time;
|
||
$consulator->end_time = $end_time;
|
||
$consulator->apply_deadline = $apply_deadline;
|
||
}
|
||
$consulator->type = 'business';
|
||
$consulator->hidden_avatar = $hidden_avatar;
|
||
$consulator->hidden_order_total = $hidden_order_total;
|
||
$consulator->join_type = $join_type;
|
||
DB::beginTransaction();
|
||
// if($consulator->class=='one'){
|
||
// // 创建聊天室
|
||
// $accid = 1000000+$request->account_id;
|
||
// $wyyuser = WangYiYunUser::where('accid',$accid)->first();
|
||
// if(!$wyyuser){
|
||
// $data['anchor_id'] = $anchor->id;
|
||
// $data['accid'] = $accid;
|
||
// $data['nickname'] = $anchor->name;
|
||
// $data['sex'] = 0;
|
||
// $this->createWyyUser($data);
|
||
// }
|
||
// $chat_room = \CommonUtilsService::createChatRoom($accid,$title);
|
||
// if (empty($chat_room)) throw new \Exception("创建IM聊天室失败", 1);
|
||
// $consulator->chat_room_id = $chat_room['roomid'];
|
||
// }
|
||
$consulator->save();
|
||
//同步sku
|
||
$s = new CommunityActivityService();
|
||
$s->syncSku('add',$consulator->id,$request->sku);
|
||
|
||
if (isset($request->banners)) {
|
||
if($request->banners == null || $request->banners == 'null' || $request->banners == ''){
|
||
LiveBanner::create([
|
||
'icon' => json_encode([]),
|
||
'class' => 'community',
|
||
'status' => 1,
|
||
'sort' => 0,
|
||
'class_id' => $consulator->id,
|
||
]);
|
||
}else{
|
||
LiveBanner::create([
|
||
'icon' => json_encode($banners),
|
||
'class' => 'community',
|
||
'status' => 1,
|
||
'sort' => 0,
|
||
'class_id' => $consulator->id,
|
||
]);
|
||
}
|
||
}
|
||
|
||
|
||
if ($request->ratio > 1.0) {
|
||
return $this->failure('利润分成比例不能大于100%');
|
||
}
|
||
$MEarningRule = new MEarningRule();
|
||
$MEarningRule->m_id = $request->account_id;
|
||
if ($consulator->class == 'one') {
|
||
$MEarningRule->name = 'activity';
|
||
} else {
|
||
$MEarningRule->name = 'service';
|
||
}
|
||
$rule = MEarningRule::where('m_id', $request->account_id)
|
||
->where('name', $MEarningRule->name)
|
||
->where('type_id', 0)
|
||
->first();
|
||
$MEarningRule->forzen_time = $forzen_time ?? 1;
|
||
$MEarningRule->ratio = number_format($request->ratio, 2);
|
||
$MEarningRule->type_id = $consulator->id;
|
||
$MEarningRule->first_sharer = $rule?$rule->first_sharer:0.3;
|
||
$MEarningRule->last_sharer = $rule?$rule->last_sharer:0.5;
|
||
$MEarningRule->other_sharer = $rule?$rule->other_sharer:0.2;
|
||
$MEarningRule->save();
|
||
$merchant_market_service = new MerchantService();
|
||
$merchant_market_service->merchant_id = $request->account_id;
|
||
$merchant_market_service->type = 'community';
|
||
$merchant_market_service->service_type = 0;
|
||
$merchant_market_service->status = $status;
|
||
$merchant_market_service->type_id = $consulator->id;
|
||
$merchant_market_service->save();
|
||
//生成签到二维码
|
||
$qr_code = QrCode::where('type', 'community')
|
||
->where('type_id', $consulator->id)
|
||
->where('merchant_id', $request->account_id)
|
||
->first();
|
||
if (!$qr_code) {
|
||
$qr_code = new QrCode();
|
||
$qr_code->type = 'community';
|
||
$qr_code->merchant_id = $request->account_id;
|
||
$qr_code->type_id = $consulator->id;
|
||
$qr_code->save();
|
||
$temp_url = urlencode(env('APP_URL') . '/pu/#/activitySignIn/' . $consulator->id);
|
||
$jump_url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $request->account_id .
|
||
'&qr_code_id=' . $qr_code->id . '&url=' . $temp_url;;
|
||
$image_url = $this->getPreviewQrcode($jump_url);
|
||
$qr_code->jump_url = $jump_url;
|
||
$qr_code->url = $image_url;
|
||
$qr_code->save();
|
||
}
|
||
DB::commit();
|
||
//保存后删除缓存草稿箱内容
|
||
if (Cache::has('drafts_activity_merchant_id_' . $request->account_id) && $request->class == 'one') Cache::forget('drafts_activity_merchant_id_' . $request->account_id);
|
||
if (Cache::has('drafts_service_merchant_id_' . $request->account_id) && $request->class == 'many') Cache::forget('drafts_service_merchant_id_' . $request->account_id);
|
||
return $this->success('ok', ['id' => $consulator->id]);
|
||
} catch (\Exception $e) {
|
||
DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 编辑服务或活动
|
||
* @param Request $request
|
||
* @param $id
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function updatePlatConsulator(Request $request, $id)
|
||
{
|
||
try {
|
||
$forzen_time = $request->forzen_time;
|
||
$status = $request->input('status');
|
||
$consulator = CommunityActivity::where('id', $id)->where('merchant_id', $request->account_id)
|
||
->first();
|
||
$my_merchant_service = MerchantService::where('type_id', $id)->where('type', 'community')
|
||
->where('merchant_id', $request->account_id)
|
||
->first();
|
||
$activity = CommunityActivity::where('id', $id)
|
||
->first();
|
||
$type = ($activity->class == "one")?'activity':"service";
|
||
if (!$consulator) {
|
||
$consulator = CommunityActivity::where('id', $id)
|
||
->first();
|
||
if ($my_merchant_service) {
|
||
if (isset($status)) {
|
||
if ($activity->status != 1 && $status == 1) {
|
||
return $this->failure('该服务已被提供商下架');
|
||
}
|
||
$my_merchant_service->status = $status;
|
||
$my_merchant_service->save();
|
||
}
|
||
if (isset($request->is_top)) {
|
||
$my_merchant_service->is_top = $request->is_top;
|
||
$my_merchant_service->top_time = date('Y-m-d H:i:s');
|
||
$my_merchant_service->save();
|
||
}
|
||
if ($request->has('ratio') && $request->ratio >= 0) {
|
||
if ($request->ratio > 1.0) {
|
||
return $this->failure('利润分成不可以大于100%');
|
||
}
|
||
$rule = MEarningRule::where('m_id', $request->account_id)->where('type_id', 0)->where('name', $type)->first();
|
||
$MEarningRule = MEarningRule::where('m_id', $request->account_id)->where('type_id', $id)
|
||
->when($consulator->class, function ($query) use ($consulator) {
|
||
switch ($consulator->class) {
|
||
case 'one':
|
||
$query->where('name', 'activity');
|
||
break;
|
||
case 'many':
|
||
$query->where('name', 'service');
|
||
break;
|
||
}
|
||
})
|
||
->first();
|
||
|
||
if ($MEarningRule === null) {
|
||
$MEarningRule = new MEarningRule();
|
||
$MEarningRule->m_id = $request->account_id;
|
||
if ($consulator->class == 'one') {
|
||
$MEarningRule->name = 'activity';
|
||
} else {
|
||
$MEarningRule->name = 'service';
|
||
}
|
||
$MEarningRule->forzen_time = $forzen_time ?? 1;
|
||
$MEarningRule->ratio = number_format($request->ratio, 2);
|
||
$MEarningRule->type_id = $id;
|
||
$MEarningRule->first_sharer = $rule?$rule->first_sharer:0.3;
|
||
$MEarningRule->last_sharer = $rule?$rule->last_sharer:0.5;
|
||
$MEarningRule->other_sharer = $rule?$rule->other_sharer:0.2;
|
||
$MEarningRule->save();
|
||
} else {
|
||
if ($consulator->class == 'one') {
|
||
$MEarningRule->name = 'activity';
|
||
} else {
|
||
$MEarningRule->name = 'service';
|
||
}
|
||
$MEarningRule->forzen_time = $forzen_time ?? 1;
|
||
$MEarningRule->ratio = number_format($request->ratio, 2);
|
||
$MEarningRule->first_sharer = $rule?$rule->first_sharer:0.3;
|
||
$MEarningRule->last_sharer = $rule?$rule->last_sharer:0.5;
|
||
$MEarningRule->other_sharer = $rule?$rule->other_sharer:0.2;
|
||
$MEarningRule->save();
|
||
}
|
||
}
|
||
return $this->success('ok');
|
||
} else {
|
||
return $this->failure('活动不存在');
|
||
}
|
||
}
|
||
$await_checkoutTextArray = [];
|
||
$price = $request->input('price', 0);
|
||
if (!is_numeric($price) || $price < 0) return $this->failure('请输入正确价格');
|
||
if (is_numeric($request->price) && $request->price != $consulator->price) {
|
||
$consulator->price = $request->price;
|
||
$await_checkoutTextArray[] = $request->price;
|
||
}
|
||
if ($request->title && $request->title != $consulator->title) {
|
||
$consulator->title = $request->title;
|
||
$await_checkoutTextArray[] = $request->title;
|
||
}
|
||
|
||
if ($request->pay_type && $request->pay_type != $consulator->pay_type) {
|
||
$consulator->pay_type = $request->pay_type;
|
||
}
|
||
if ($request->describe && $request->describe != $consulator->describe) {
|
||
$consulator->describe = $request->describe;
|
||
// $await_checkoutTextArray[] = $request->describe;
|
||
}
|
||
if ($consulator->class == 'one' && $request->start_time && $request->start_time != $consulator->start_time) {
|
||
$consulator->start_time = $request->start_time;
|
||
}
|
||
if ($consulator->class == 'one' && $request->end_time && $request->end_time != $consulator->end_time) {
|
||
$consulator->end_time = $request->end_time;
|
||
}
|
||
if ($consulator->class == 'one' && $request->apply_deadline && $request->apply_deadline != $consulator->apply_deadline) {
|
||
$consulator->apply_deadline = $request->apply_deadline;
|
||
}
|
||
if ($request->pic && $request->pic != $consulator->pic) {
|
||
$consulator->pic = $request->pic;
|
||
$result = \CommonUtilsService::imageContentCecurity([$request->pic]);
|
||
if ($result && isset($result['result']) && $result['result']) {
|
||
return $this->failure('图片' . $result['result'] . ',请换一张照片');
|
||
}
|
||
}
|
||
//订单购买完成后流程修改
|
||
if ($request->flow && json_encode($request->flow) != $consulator->flow) {
|
||
$consulator->flow = json_encode($request->flow);
|
||
}
|
||
if($request->has('report')){
|
||
$consulator->report = json_encode($request->report);
|
||
if(empty($request->report)) $consulator->report = null;
|
||
}
|
||
//是否展示报名人头像
|
||
if ($request->has('hidden_avatar')) {
|
||
$consulator->hidden_avatar = $request->hidden_avatar;
|
||
}
|
||
if ($request->has('share_thumb')) {
|
||
$consulator->share_thumb = $request->share_thumb;
|
||
}
|
||
if ($request->has('status')) {
|
||
$my_merchant_service->status = $status;
|
||
$consulator->status = $status;
|
||
$consulator->save();
|
||
$my_merchant_service->save();
|
||
if ($request->status == 0) {
|
||
$market_service = MarketService::where('type_id', $id)
|
||
->where('type', 'community')
|
||
->where('merchant_id', $request->account_id)
|
||
->first();
|
||
if ($market_service) {
|
||
MerchantService::where('type_id', $id)->where('type', 'community')
|
||
->update(['status' => 0, 'updated_at' => date('Y-m-d H:i:s')]);
|
||
}
|
||
}
|
||
}
|
||
if ($request->has('Subtitle')) {
|
||
$consulator->Subtitle = $request->Subtitle;
|
||
}
|
||
if ($request->has('agree_title')) {
|
||
$consulator->agree_title = $request->agree_title;
|
||
}
|
||
if ($request->has('agree_content')) {
|
||
$consulator->agree_content = $request->agree_content;
|
||
}
|
||
if ($request->has('reward_status')) {
|
||
$consulator->reward_status = $request->reward_status;
|
||
}
|
||
if ($request->has('ratio') && $request->ratio >= 0) {
|
||
if ($request->ratio > 1.0) {
|
||
return $this->failure('利润分成不可以大于100%');
|
||
}
|
||
$rule = MEarningRule::where('m_id', $request->account_id)->where('type_id', 0)->where('name', $type)->first();
|
||
$MEarningRule = MEarningRule::where('m_id', $request->account_id)->where('type_id', $id)
|
||
->when($consulator->class, function ($query) use ($consulator) {
|
||
switch ($consulator->class) {
|
||
case 'one':
|
||
$query->where('name', 'activity');
|
||
break;
|
||
case 'many':
|
||
$query->where('name', 'service');
|
||
break;
|
||
}
|
||
})
|
||
->first();
|
||
|
||
if ($MEarningRule === null) {
|
||
$MEarningRule = new MEarningRule();
|
||
$MEarningRule->m_id = $request->account_id;
|
||
if ($consulator->class == 'one') {
|
||
$MEarningRule->name = 'activity';
|
||
} else {
|
||
$MEarningRule->name = 'service';
|
||
}
|
||
$MEarningRule->forzen_time = $forzen_time ?? 1;
|
||
$MEarningRule->ratio = number_format($request->ratio, 2);
|
||
$MEarningRule->type_id = $id;
|
||
$MEarningRule->first_sharer = $rule?$rule->first_sharer:0.3;
|
||
$MEarningRule->last_sharer = $rule?$rule->last_sharer:0.5;
|
||
$MEarningRule->other_sharer = $rule?$rule->other_sharer:0.2;
|
||
$MEarningRule->save();
|
||
} else {
|
||
if ($consulator->class == 'one') {
|
||
$MEarningRule->name = 'activity';
|
||
} else {
|
||
$MEarningRule->name = 'service';
|
||
}
|
||
$MEarningRule->forzen_time = $forzen_time ?? 1;
|
||
$MEarningRule->ratio = number_format($request->ratio, 2);
|
||
$MEarningRule->first_sharer = $rule?$rule->first_sharer:0.3;
|
||
$MEarningRule->last_sharer = $rule?$rule->last_sharer:0.5;
|
||
$MEarningRule->other_sharer = $rule?$rule->other_sharer:0.2;
|
||
$MEarningRule->save();
|
||
}
|
||
}
|
||
// if ($request->has('sku')) {
|
||
//// $consulator->sku = json_encode($request->sku);
|
||
// //是否配置团购
|
||
// $group = CollageGroup::where('type', 'community')->where('type_id', $id)->first();
|
||
// if ($group) {
|
||
// $group_sku = json_decode($group->sku, true);
|
||
// $new_sku = [];
|
||
// foreach ($request->sku as $key => $s) {
|
||
// $new_sku[$key]['sku_id'] = $s['sku_id'];
|
||
// $new_sku[$key]['name'] = $s['name'];
|
||
// $new_sku[$key]['price'] = $s['price'];
|
||
// if ($consulator->class == 'one') $new_sku[$key]['num'] = $s['num'];
|
||
// $new_sku[$key]['discount_price'] = !empty($group_sku[$key]['discount_price']) ? $group_sku[$key]['discount_price'] : $s['price'];
|
||
// //if($new_sku[$key]['discount_price'] > $new_sku[$key]['price']) return $this->failure('拼团优惠价不能大于原始价格');
|
||
// }
|
||
// $group->update(['sku' => json_encode($new_sku)]);
|
||
// }
|
||
// }
|
||
if ($request->has('is_top')) {//置顶
|
||
$my_merchant_service->is_top = $request->is_top;
|
||
$my_merchant_service->top_time = date('Y-m-d H:i:s');
|
||
$consulator->is_top = $request->is_top;
|
||
$consulator->top_time = date('Y-m-d H:i:s');
|
||
$consulator->save();
|
||
$my_merchant_service->save();
|
||
}
|
||
//线上或线下
|
||
if ($request->has('location')) {
|
||
$consulator->location = $request->location;
|
||
if ($consulator->location == 1) {
|
||
$consulator->location_longitude = $request->location_longitude;
|
||
$consulator->location_latitude = $request->location_latitude;
|
||
$consulator->address = $request->address;
|
||
}
|
||
}
|
||
// 是否参保
|
||
if ($request->has('insurance')) {
|
||
$consulator->insurance = $request->insurance ?: 0;
|
||
}
|
||
if ($request->has('hidden_order_total')) {//隐藏报名人数
|
||
$consulator->hidden_order_total = $request->hidden_order_total;
|
||
}
|
||
// if($result['code'] == 1){
|
||
// return $this->failure($result['cause']);
|
||
// }
|
||
if ($request->has('join_type')) { //参加用户类型
|
||
$consulator->join_type = $request->join_type;
|
||
}
|
||
|
||
DB::beginTransaction();
|
||
if (isset($request->banners)) {
|
||
if($request->banners == null || $request->banners == 'null' || $request->banners == ''){
|
||
LiveBanner::updateOrCreate(['class' => 'community', 'class_id' => $consulator->id], ['icon' => json_encode([])]);
|
||
}else{
|
||
LiveBanner::updateOrCreate(['class' => 'community', 'class_id' => $consulator->id], ['icon' => json_encode($request->banners)]);
|
||
}
|
||
}
|
||
$consulator->save();
|
||
//同步sku
|
||
if($request->sku){
|
||
$s = new CommunityActivityService();
|
||
$after_sku = $s->syncSku('edit',$consulator->id,$request->sku);
|
||
//是否配置团购
|
||
$group = CollageGroup::where('type', 'community')->where('type_id', $id)->first();
|
||
if ($group) {
|
||
$group_sku = json_decode($group->sku, true);
|
||
$new_sku = [];
|
||
foreach ($after_sku as $key => $s) {
|
||
$new_sku[$key]['sku_id'] = $s['sku_id'];
|
||
$new_sku[$key]['name'] = $s['name'];
|
||
$new_sku[$key]['price'] = $s['price'];
|
||
if ($consulator->class == 'one') $new_sku[$key]['num'] = $s['num'];
|
||
$new_sku[$key]['discount_price'] = !empty($group_sku[$key]['discount_price']) ? $group_sku[$key]['discount_price'] : $s['price'];
|
||
//if($new_sku[$key]['discount_price'] > $new_sku[$key]['price']) return $this->failure('拼团优惠价不能大于原始价格');
|
||
}
|
||
$group->update(['sku' => json_encode($new_sku)]);
|
||
}
|
||
}
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure($e->getMessage());
|
||
}
|
||
|
||
}
|
||
|
||
//用户提交报告列表
|
||
public function userReports(Request $request){
|
||
try {
|
||
$id = $request->id;
|
||
$keyword = trim($request->keyword);
|
||
$result = TouristOrder::with('mUser')->where('type','community')->where('type_id',$id)->whereNotNull('report_answer')
|
||
->select('id','account_id','report_answer','created_at');
|
||
if($keyword){
|
||
$result = $result->whereHas('mUser',function($sql) use($keyword){
|
||
$sql->where('nickname','like',"%$keyword%")
|
||
->orWhere('mobile','like',"%$keyword%");
|
||
});
|
||
}
|
||
$result = $result->orderBy('id','desc')->paginate();
|
||
foreach ($result as $key => $value) {
|
||
$value->report_answer = json_decode($value->report_answer,true);
|
||
}
|
||
return $this->success('ok',$result);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure();
|
||
}
|
||
}
|
||
/**
|
||
* 活动或服务详情
|
||
* @param Request $request
|
||
* @param $id
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function communityActivityPlat(Request $request, $id)
|
||
{
|
||
try {
|
||
$account_id = $request->account_id;
|
||
$type = $request->type ?? 'business';
|
||
$serve_tab = $request->serve_tab;
|
||
$openid = MerchantAccount::where('id', $account_id)->value('openid');
|
||
$activity = CommunityActivity::with('banners:class_id,icon')
|
||
->where('id', $id)->where('type', $type)
|
||
->where('merchant_id', $account_id)
|
||
->first();
|
||
if (!$activity) {
|
||
$merchant_service = MerchantService::where('type_id', $id)->where('merchant_id', $request->account_id)
|
||
->where('type', 'community')
|
||
->first();
|
||
if ($merchant_service) {
|
||
$activity = CommunityActivity::where('id', $merchant_service->type_id)
|
||
->first();
|
||
if (!$activity) {
|
||
return $this->failure('活动不存在');
|
||
}
|
||
$activity->service_type = 1;
|
||
} else {
|
||
return $this->failure('活动不存在');
|
||
}
|
||
$activity->is_my_market_service = 0;
|
||
} else {
|
||
$activity->service_type = 0;
|
||
$market_service = MarketService::where('merchant_id', $request->account_id)
|
||
->where('type_id', $activity->id)
|
||
->where('type', 'community')
|
||
->first();
|
||
if ($market_service) {
|
||
$activity->is_my_market_service = 1;
|
||
} else {
|
||
$activity->is_my_market_service = 0;
|
||
}
|
||
}
|
||
|
||
if ($activity->class == 'one') {
|
||
$activity['rule'] = MEarningRule::where('m_id', $request->account_id)
|
||
->where('name', 'activity')->where('type_id', $id)
|
||
->select('ratio', 'forzen_time')
|
||
->first();
|
||
if (empty($activity['rule'])) {
|
||
$activity['rule'] = MEarningRule::where('m_id', $request->account_id)
|
||
->where('name', 'activity')->where('type_id', 0)
|
||
->select('ratio', 'forzen_time')
|
||
->first();
|
||
}
|
||
//$activity['ratio'] = number_format($activity['ratio'], 2);
|
||
$jump_url = urlencode(env('APP_URL') . '/pu/#/activityDetails/' . $activity->id);
|
||
$key = 'ActivityDetail_S';
|
||
} else {
|
||
$activity['rule'] = MEarningRule::where('m_id', $request->account_id)
|
||
->where('name', 'service')->where('type_id', $id)
|
||
->select('ratio', 'forzen_time')
|
||
->first();
|
||
if (empty($activity['rule'])) {
|
||
$activity['rule'] = MEarningRule::where('m_id', $request->account_id)
|
||
->where('name', 'service')->where('type_id', 0)
|
||
->select('ratio', 'forzen_time')
|
||
->first();
|
||
}
|
||
$jump_url = urlencode(env('APP_URL') . '/pu/#/serveDetails/' . $activity->id);
|
||
$key = 'ServeDetail_S';
|
||
}
|
||
$url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $account_id . '&from_openid=' . $openid . '&serve_tab=' . $serve_tab . '&url=' . $jump_url;
|
||
$qr_code = Redis::get($key . '_' . $id . '_' . $openid);
|
||
if (!$qr_code) {
|
||
$qr_code = $this->getPreviewQrcode($url);
|
||
Redis::setex($key . '_' . $id . '_' . $openid, 60 * 60 * 24 * 30, $qr_code);
|
||
$qr_code = Redis::get($key . '_' . $id . '_' . $openid);
|
||
}
|
||
if ($activity->banners) {
|
||
if ($activity->banners->icon != 'null') {
|
||
$activity->banners->icon = json_decode($activity->banners->icon, true);
|
||
}
|
||
} else {
|
||
$activity->banners = [];
|
||
}
|
||
$activity->qr_codes = $qr_code;
|
||
if ($activity->sku && $activity->sku != 'null') {
|
||
$activity->sku = json_decode($activity->sku, true);
|
||
} else {
|
||
$activity->sku = null;
|
||
}
|
||
$activity->share_url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $account_id . '&serve_tab=' . $serve_tab . '&from_openid=' . $openid . '&url=' . $jump_url;
|
||
$time = date('Y-m-d H:i:s');
|
||
$is_deadline = 0;
|
||
if ($activity->class == 'one' && $activity->apply_deadline) {
|
||
if ($activity->apply_deadline <= $time) $is_deadline = 1;
|
||
}
|
||
$activity->is_deadline = $is_deadline;
|
||
$sign_qr_codes = QrCode::where('merchant_id', $request->account_id)
|
||
->where('type','community')
|
||
->where('type_id',$activity->id)
|
||
->value('url');
|
||
$activity->sign_qr_codes = $sign_qr_codes;
|
||
return $this->success('ok', $activity);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 移除活动或服务
|
||
* @param Request $request
|
||
* @param $id
|
||
* @return JsonResponse
|
||
*/
|
||
public function remmoveCommunityActivityPlat(Request $request, $id)
|
||
{
|
||
try {
|
||
$account_id = $request->account_id;
|
||
DB::beginTransaction();
|
||
$activity = CommunityActivity::where('id', $id)->where('merchant_id', $account_id)
|
||
->first();
|
||
if (!$activity) {
|
||
MerchantService::where('type_id', $id)
|
||
->where('type', 'community')
|
||
->where('merchant_id', $account_id)
|
||
->delete();
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
}
|
||
MarketService::where('type_id', $id)
|
||
->where('type', 'community')
|
||
->where('merchant_id', $account_id)
|
||
->delete();
|
||
MerchantService::where('type_id', $id)
|
||
->where('type', 'community')
|
||
->delete();
|
||
$activity->delete();
|
||
DB::commit();
|
||
return $this->success('ok');
|
||
|
||
} catch (\Exception $e) {
|
||
DB::rollBack();
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 活动或服务 报名成员
|
||
* *
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function platJoinMembers(Request $request)
|
||
{
|
||
$consulator_id = $request->consulator_id;
|
||
$merchant_id = $request->account_id;
|
||
$activity = CommunityActivity::find($consulator_id);
|
||
$service_type = 0;
|
||
$source_merchant = MerchantAccount::where('id', $activity->merchant_id)
|
||
->select('id', 'share_icon', 'share_title')
|
||
->first();
|
||
$keyword = $request->keyword;
|
||
$pay_status = $request->pay_status ?? 2;
|
||
if ($activity->merchant_id != $merchant_id) {
|
||
$service_type = 1;
|
||
}
|
||
$members = TouristOrder::with('merUser', 'alliance', 'merchant:id,share_icon,share_title','orderStatusLink:id,order_id,status', 'mEarning:id,m_user_id,m_order_id,sharer,ratio,sub_ratio,value', 'mAdvanceEarning:id,m_user_id,m_order_id,sharer,ratio,sub_ratio,value', 'mEarning.user:id,pic,nickname,mobile', 'mAdvanceEarning.user:id,pic,nickname,mobile')->withCount(['blacklist'=>function($sql) {
|
||
$sql->where('type', 'activity');
|
||
}])
|
||
->where('type', 'community')
|
||
->where('type_id', $consulator_id)
|
||
->orderBy('id', 'desc');
|
||
// if($pay_status != 2){
|
||
// $members = $members->where('pay_status',$pay_status);
|
||
// }
|
||
if ($service_type) {
|
||
$members = $members->where('merchant_id', $merchant_id);
|
||
}
|
||
if ($pay_status != 2) {
|
||
if ($pay_status == 1) {//已支付
|
||
$members = $members->whereIn('pay_status', [1, 4]);
|
||
//是否使用优惠券或实际金额
|
||
if ($request->is_coupon) {
|
||
$members = $members->whereNotNull('user_coupon_id');
|
||
}
|
||
if ($request->is_cash) {
|
||
$members = $members->where('price', '<>', 0);
|
||
}
|
||
} else {
|
||
$members = $members->where('pay_status', $pay_status);
|
||
}
|
||
}
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$members = $members->where(function ($sql) use ($keyword) {
|
||
$sql->where('name', 'like', '%' . $keyword . '%')->orWhere('mobile', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$members = $members->paginate();
|
||
$qr_code = QrCode::where('type', 'community')->where('type_id', $consulator_id)
|
||
->first();
|
||
if($qr_code){
|
||
$have_qr_code = 1;
|
||
}else{
|
||
$have_qr_code = 0;
|
||
}
|
||
|
||
foreach ($members as $key => $value) {
|
||
$value->insurance_info = json_decode($value->insurance_info, true);
|
||
$value->linkmen = json_decode($value->linkmen,true);
|
||
$value->fromUsers;
|
||
$fol = MOrderFollow::where('order_id', $value->id)->where('result', '订单状态修改')->first();
|
||
$is_start = !empty($fol) ? $fol->is_start : 0;
|
||
$value->is_start = $is_start;
|
||
if ($value->created_at < '2022-3-21 18:00') {
|
||
$temp_sku = explode('-', $value->desc);
|
||
if (!empty($temp_sku[1])) {
|
||
$value->goods = $temp_sku[1];
|
||
}
|
||
}
|
||
if($have_qr_code){
|
||
$sign = SignIn::where('qr_code_id',$qr_code->id)->where('merchant_user_id',$value->account_id)
|
||
->first();
|
||
if($sign){
|
||
$value->qr_code_id = $qr_code->id;
|
||
$value->sign = 1;
|
||
}else{
|
||
$value->sign = 0;
|
||
$value->qr_code_id = $qr_code->id;
|
||
}
|
||
}else{
|
||
$value->sign = 2;
|
||
$value->sign_id = null;
|
||
}
|
||
|
||
$value->source_merchant = $source_merchant;
|
||
if ($value->channel == '福恋小程序') { //渠道:0商家H5,1福恋H5,2福恋app,3福恋小程序
|
||
$wechat = Wechat::where('openid', $value->open_id)->first();
|
||
if ($wechat) {
|
||
$user = User::where('id', $wechat->user_id)->first();
|
||
if ($user) {
|
||
$userinfo['nickname'] = $user->nickname;
|
||
$userinfo['mobile'] = $user->mobile;
|
||
$userinfo['pic'] = $user->photo ?: ($user->circle_avatar ?: User::DefaultAvatar);
|
||
$value->merchant_user = $userinfo;
|
||
}
|
||
}
|
||
|
||
} else { //渠道:0商家H5,1福恋H5,2福恋app,3福恋小程序
|
||
$value->merchant_user = $value->merUser;
|
||
unset($value->merUser);
|
||
}
|
||
}
|
||
if (count($members)) {
|
||
$code = CommonUtilsService::randString(16);
|
||
Redis::set('activity:'.$consulator_id.':members:export:code', $code);
|
||
$members[0]['code'] = $code;
|
||
}
|
||
$members = $members->toArray();
|
||
$members['enroll_num'] = TouristOrder::selectRaw("sum( if(left(linkmen,1)='[',JSON_LENGTH( linkmen ) ,1)) as count")
|
||
->whereIn('pay_status',[1,4])
|
||
->where('type','community')
|
||
->where('type_id',$consulator_id)
|
||
->value('count');
|
||
return $this->success('ok-test', $members);
|
||
}
|
||
public function memberExport(Request $request, $activity_id)
|
||
{
|
||
try {
|
||
$code = $request->input('code');
|
||
if (empty($code)) throw new \Exception('缺少参数code');
|
||
$value = Redis::get('activity:'.$activity_id.':members:export:code');
|
||
if ($code != $value) throw new \Exception('code失效');
|
||
$orders = TouristOrder::with('user:id,openid,user_id', 'user.user:id,name,sex,card_num,is_real_approved', 'tcfaceid:openid,name,card_num,is_real_approved')->where('type', 'community')->where('type_id',$activity_id)->where('pay_status', '!=', 0)->select('id', 'open_id', 'name', 'mobile', 'account_id', 'insurance_info','linkmen')->get();
|
||
$data = [];
|
||
foreach ($orders as $key => $order)
|
||
{
|
||
$real_name = '';
|
||
if ($order->user && $order->user->user) {
|
||
$mp_user = $order->user->user;
|
||
$sex = $mp_user->sex;
|
||
if (empty($mp_user->sex) && $mp_user->card_num && $mp_user->is_real_approved) {
|
||
$sex = \CommonUtilsService::getSexByCard($mp_user->card_num);
|
||
}
|
||
$real_name = $mp_user->name;
|
||
$is_real_approved = $mp_user->is_real_approved;
|
||
|
||
}else{
|
||
$sex = " ";
|
||
$is_real_approved = 0;
|
||
}
|
||
if(empty($is_real_approved) && $order->tcfaceid) {
|
||
$is_real_approved = $order->tcfaceid->is_real_approved;
|
||
$sex = \CommonUtilsService::getSexByCard($order->tcfaceid->card_num);
|
||
$real_name = $order->tcfaceid->name;
|
||
}
|
||
if ($sex == 1) {
|
||
$sex = "男";
|
||
}elseif ($sex == 2) {
|
||
$sex = '女';
|
||
}else{
|
||
$sex = ' ';
|
||
}
|
||
$order->remark = $sex.($key+1);
|
||
$order->sex = $sex;
|
||
$order->real_name = $real_name;
|
||
$order->is_real_approved = $is_real_approved?"是":"否";
|
||
$insurance_info = '';
|
||
if ($order->insurance_info) {
|
||
$order->insurance_info = json_decode($order->insurance_info, true);
|
||
foreach ($order->insurance_info as $info) {
|
||
$insurance_info .= $info['name'].': '.$info['idCard'].' ';
|
||
}
|
||
}
|
||
$linkmen = json_decode($order->linkmen, true);
|
||
$institution = ($linkmen && isset($linkmen[0]['institution']))?$linkmen[0]['institution']:"";
|
||
$data[] = ['name'=>$order->name, 'real_name'=>$order->real_name, 'mobile'=>$order->mobile, 'is_real_approved'=>$order->is_real_approved, 'sex'=>$order->sex, 'remark'=>$order->remark, 'insurance_info'=>$insurance_info, 'institution'=>$institution];
|
||
TouristOrder::where('id', $order->id)->update(['remark'=>$order->remark]);
|
||
}
|
||
$title = CommunityActivity::where('id', $activity_id)->value('title');
|
||
return \Excel::download(new ActivityMemberExportV2($data), $title.'.xlsx');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure();
|
||
}
|
||
|
||
}
|
||
|
||
public function matchMembers(Request $request)
|
||
{
|
||
$activity_id = $request->activity_id;
|
||
$m_id = $request->account_id;
|
||
$orders = TouristOrder::where('type', 'community')->where('type_id', $activity_id)->where('merchant_id', $m_id)->whereIn('pay_status', [1, 4])->select('id', 'name', 'linkmen', 'remark')->get();
|
||
foreach ($orders as $key => $value) {
|
||
$value->linkmen = json_decode($value->linkmen);
|
||
}
|
||
return $this->success('ok', $orders);
|
||
}
|
||
|
||
/**
|
||
* 删除报名成员
|
||
* @param Request $request
|
||
* @param $id
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function removeCommunityMemberPlat(Request $request, $id)
|
||
{
|
||
try {
|
||
$order = TouristOrder::find($id);
|
||
if (!$order) return $this->failure('要删除的id不存在');
|
||
$order->delete();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('操作失败');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 移动端活动 服务详情
|
||
* @param Request $request
|
||
* @param $id
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function phoneCommunityActivity(Request $request, $id)
|
||
{
|
||
try {
|
||
$serve_tab = $request->serve_tab;
|
||
$activity = CommunityActivity::withTrashed()->where('id', $id)->select('id', 'merchant_id', 'title', 'price'
|
||
, 'pv', 'pic', 'start_time', 'end_time', 'apply_deadline', 'describe', 'sku', 'Subtitle', 'status',
|
||
'class', 'deleted_at',"location_longitude","location_latitude","address","location")->first();
|
||
$openid = MerchantAccount::where('id', $activity->merchant_id)->value('openid');
|
||
if (!$openid) $openid = Anchor::where('m_id', $activity->merchant_id)->value('openid');
|
||
if (empty($activity)) return $this->failure('该服务不存在');
|
||
$banner = LiveBanner::where('class', 'community')->where('class_id', $id)->value('icon');
|
||
//消费人数
|
||
$consume_user_count = TouristOrder::where('type', 'community')->where('type_id', $id)->whereIn('pay_status', [1, 4])->groupBy('open_id')->get()->count();
|
||
//订单数
|
||
$consume_order_count = TouristOrder::where('type', 'community')->where('type_id', $id)->whereIn('pay_status', [1, 4])->count();
|
||
//收入(元)
|
||
$income_amount = TouristOrder::where('type', 'community')->where('type_id', $id)->whereIn('pay_status', [1, 4])->sum('price');
|
||
//商家分成金额
|
||
$order_ids = TouristOrder::where('type', 'community')->where('type_id', $id)->whereIn('pay_status', [1, 4])->pluck('id')->toArray();
|
||
$merchant_income_value = MEarning::whereIn('m_order_id', $order_ids)->where('m_user_id', 0)->sum('value');
|
||
if ($activity->class == 'one') {
|
||
$jump_url = urlencode(env('APP_URL') . '/pu/#/activityDetails/' . $activity->id);
|
||
$key = 'ActivityDetail_S';
|
||
} else {
|
||
$jump_url = urlencode(env('APP_URL') . '/pu/#/serveDetails/' . $activity->id);
|
||
$key = 'ServeDetail_S';
|
||
}
|
||
$url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $request->account_id . '&serve_tab=' . $serve_tab . '&url=' . $jump_url . '&from_openid=' . $openid;
|
||
// if($activity->qrcode){
|
||
// $activity->qrcode = $this->getPreviewQrcode($url);
|
||
$share_qr_code = $this->getPreviewQrcode($url);
|
||
// $activity->save();
|
||
$activity->share_qr_code = $share_qr_code;
|
||
// }
|
||
$activity->consume_user_count = $consume_user_count;
|
||
$activity->income_amount = $income_amount;
|
||
$activity->merchant_income_value = $merchant_income_value;
|
||
$activity->consume_order_count = $consume_order_count;
|
||
if ($banner && $banner != 'null') {
|
||
$activity->banner = json_decode($banner);
|
||
} else {
|
||
$activity->banner = [];
|
||
}
|
||
if ($activity->sku && $activity->sku != 'null') {
|
||
$activity->sku = json_decode($activity->sku);
|
||
} else {
|
||
$activity->sku = [];
|
||
}
|
||
if ($activity->start_time && $activity->end_time) {
|
||
$activity->start_time = date('Y-m-d H:i', strtotime($activity->start_time));
|
||
$activity->end_time = date('Y-m-d H:i', strtotime($activity->end_time));
|
||
}
|
||
$avatar = [];//购买人头像
|
||
$photo = [];//分成人头像
|
||
$orders = TouristOrder::where('type', 'community')->where('type_id', $id)->whereIn('pay_status', [1, 4])->orderBy('id', 'desc')->limit(3)->get();
|
||
$value = TouristOrder::where('type', 'community')->where('type_id', $id)->whereIn('pay_status', [1, 4])->orderBy('id', 'desc')->first();
|
||
// MEarning::where('m_order_id',$value->id)->pluck
|
||
foreach ($orders as $key => $order) {
|
||
$avatar[$key] = MerchantUser::where('id', $order->account_id)->value('pic') ?? User::DefaultAvatar;
|
||
if (empty($avatar[$key])) $avatar[$key] = User::DefaultAvatar;
|
||
}
|
||
$activity->avatar = $avatar;
|
||
//下架或删除状态 0下架 1正常上架 2已删除
|
||
$publish_state = 0;
|
||
if ($activity->deleted_at) {
|
||
$publish_state = 2;
|
||
} elseif ($activity->status == 1) {
|
||
$publish_state = 1;
|
||
} else {
|
||
$publish_state = 0;
|
||
}
|
||
$activity->publish_state = $publish_state;
|
||
if($activity->merchant_id != $request->account_id){
|
||
$activity->service_type = 1;
|
||
}else{
|
||
$activity->service_type = 0;
|
||
}
|
||
return $this->success('ok', $activity);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('获取详情失败,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 移动端订单数据
|
||
* *
|
||
* @param Request $request
|
||
* @param $id
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function phoneMerhcantOrder(Request $request, $id)
|
||
{
|
||
try {
|
||
$keyword = $request->keyword;
|
||
$type = $request->type ?? 'community';
|
||
$avatar = User::DefaultAvatar;
|
||
if ($type == 'community') {
|
||
$goods = CommunityActivity::where('id', $id)->value('title');
|
||
$orders = TouristOrder::with('merUser')->where('type', 'community')->where('type_id', $id)->whereIn('pay_status', [1, 4])
|
||
->select('open_id', 'type', 'type_id', 'price', 'created_at');
|
||
} elseif ($type == 'course') {
|
||
$goods = Course::where('id', $id)->value('title');
|
||
$orders = TouristOrder::with('merUser')->where('type', 'course')->where('type_id', $id)->whereIn('pay_status', [1, 4])
|
||
->select('open_id', 'type', 'type_id', 'price', 'created_at');
|
||
} elseif ($type == 'consult') {
|
||
$goods = Consultation::where('id', $id)->value('title');
|
||
$orders = TouristOrder::with('merUser')->where('type', 'consult')->where('type_id', $id)->whereIn('pay_status', [1, 4])
|
||
->select('open_id', 'type', 'type_id', 'price', 'created_at');
|
||
} elseif ($type == 'shop') {
|
||
$goods = MerchantShop::where('id', $id)->value('title');
|
||
$orders = TouristOrder::with('merUser')->where('type', 'shop')->where('type_id', $id)->whereIn('pay_status', [1, 4])
|
||
->select('open_id', 'type', 'type_id', 'price', 'created_at');
|
||
}
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$orders = $orders->where(function ($sql) use ($keyword) {
|
||
$sql->where('desc', 'like', '%' . $keyword . '%');
|
||
})->orWhereHas('merUser', function ($sql) use ($keyword) {
|
||
$sql->where('nickname', 'like', '%' . $keyword . '%')
|
||
->orWhere('mobile', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$orders = $orders->orderBy('id', 'desc')->paginate();
|
||
foreach ($orders as $order) {
|
||
$order['pic'] = $order->merUser ? $order->merUser['pic'] : User::DefaultAvatar;
|
||
$order->text = $order->created_at . '购买了《' . $goods . '》';
|
||
|
||
$order->name = $order->merUser ? $order->merUser->nickname : '匿名用户';
|
||
if (empty($order['pic'])) $order['pic'] = User::DefaultAvatar;
|
||
}
|
||
return $this->success('ok', $orders);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('获取订单数据失败,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 收益分成
|
||
* @param Request $request
|
||
* @param $id
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function phoneEarning(Request $request, $id)
|
||
{
|
||
$keyword = $request->keyword;
|
||
$merchant_id = $request->account_id;
|
||
$type = $request->type ?? 'community';
|
||
$orders = TouristOrder::with('mEarning', 'merUser:openid,nickname,mobile,pic')->whereIn('pay_status', [1, 4])
|
||
->select('id', 'account_id', 'created_at', 'price', 'open_id')->where('merchant_id', $merchant_id);
|
||
if ($type == 'community') {
|
||
$orders = $orders->where('type', 'community')->where('type_id', $id);
|
||
} elseif ($type == 'course') {
|
||
$orders = $orders->where('type', 'course')->where('type_id', $id);
|
||
} elseif ($type == 'consult') {
|
||
$orders = $orders->where('type', 'consult')->where('type_id', $id);
|
||
} elseif ($type == 'shop') {
|
||
$orders = $orders->where('type', 'shop')->where('type_id', $id);
|
||
}
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$orders = $orders->where(function ($sql) use ($keyword) {
|
||
$sql->where('mobile', 'like', '%' . $keyword . '%')
|
||
->orWhere('name', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
$orders = $orders->orderBy('id', 'desc')->paginate();
|
||
// return $this->success('ok',$orders);
|
||
foreach ($orders as $order) {
|
||
$list = [];
|
||
$payUser = MerchantUser::where('id', $order->account_id)->first();
|
||
$order->pay_user_name = $payUser->nickname ?? '匿名用户';
|
||
$order->pay_price = $order->price;
|
||
$order->pay_mobile = $order->mobile ?? '';
|
||
$order->pay_pic = $payUser['pic'] ?? User::DefaultAvatar;
|
||
if (empty($order->pay_pic)) $order->pay_pic = User::DefaultAvatar;
|
||
foreach ($order->mEarning as $k => $value) {
|
||
$list[$k]['type'] = $value->sharer;
|
||
$list[$k]['value'] = $value->value;
|
||
if ($value->user) {
|
||
$list[$k]['name'] = $value->user ? $value->user->nickname : '匿名用户';
|
||
$list[$k]['pic'] = $value->user ? $value->user['pic'] : User::DefaultAvatar;
|
||
if (empty($list[$k]['pic'])) $list[$k]['pic'] = User::DefaultAvatar;
|
||
} else {
|
||
$user = MerchantAccount::where('id', $merchant_id)->first();
|
||
$list[$k]['name'] = $user->anchor->name ?? '匿名用户';
|
||
$list[$k]['pic'] = $user->anchor['pic'] ?? User::DefaultAvatar;
|
||
if (empty($list[$k]['pic'])) $list[$k]['pic'] = User::DefaultAvatar;
|
||
}
|
||
|
||
unset($order->mEarning);
|
||
unset($order->viewer);
|
||
}
|
||
$order->list = $list;
|
||
}
|
||
return $this->success('ok', $orders);
|
||
}
|
||
|
||
/**
|
||
* 活动复制
|
||
* @param Request $request
|
||
*/
|
||
public function putActivityCopy(Request $request)
|
||
{
|
||
try {
|
||
$activity_id = $request->activity_id;
|
||
$merchant_id = $request->account_id;
|
||
$start_time = $request->start_time;
|
||
$title = $request->title;
|
||
$Subtitle = $request->Subtitle;
|
||
if (!$activity_id || !$start_time || !$title) {
|
||
return $this->failure('参数不全');
|
||
}
|
||
if (strtotime($start_time) < time()) {
|
||
//return $this->failure('开始时间不能小于当前时间');
|
||
}
|
||
$communityActivity = CommunityActivity::where('merchant_id', $merchant_id)
|
||
->where('id', $activity_id)
|
||
->first();
|
||
if (!$communityActivity) {
|
||
return $this->failure('活动不存在');
|
||
} else {
|
||
$communityActivity = $communityActivity->toArray();
|
||
}
|
||
$banner = LiveBanner::where('class_id', $communityActivity['id'])
|
||
->first();
|
||
if ($banner) {
|
||
$banner->toArray();
|
||
}
|
||
if (empty($communityActivity['start_time'])) {
|
||
return $this->failure('原始活动没有开始时间');
|
||
}
|
||
$communityActivity['end_time'] = date('Y-m-d H:i:s', strtotime($start_time) + (strtotime($communityActivity['end_time'])
|
||
- strtotime($communityActivity['start_time'])));
|
||
$communityActivity['apply_deadline'] = date('Y-m-d H:i:s', strtotime($start_time) + (strtotime($communityActivity['apply_deadline'])
|
||
- strtotime($communityActivity['start_time'])));
|
||
$communityActivity['title'] = $title;
|
||
$communityActivity['start_time'] = $start_time;
|
||
$communityActivity['Subtitle'] = $Subtitle;
|
||
$communityActivity['created_at'] = date('Y-m-d H:i:s', time());
|
||
$communityActivity['updated_at'] = date('Y-m-d H:i:s', time());
|
||
$communityActivity['chat_room_id'] = null;
|
||
$communityActivity['pv'] = 0;
|
||
$communityActivity['status'] = 0;
|
||
$old_id = $communityActivity['id'];
|
||
unset($communityActivity['id']);
|
||
if($communityActivity['flow']){
|
||
$communityActivity['flow'] = json_encode($communityActivity['flow']);
|
||
}
|
||
if($communityActivity['report']){
|
||
$communityActivity['report'] = json_encode($communityActivity['report']);
|
||
}
|
||
$id = DB::table('community_activities')->insertGetId($communityActivity);
|
||
if ($banner) {
|
||
$banner = $banner->toArray();
|
||
unset($banner['id']);
|
||
$banner['class_id'] = $id;
|
||
$banner['created_at'] = date('Y-m-d H:i:s', time());
|
||
$banner['updated_at'] = date('Y-m-d H:i:s', time());
|
||
DB::table('live_banners')->insert($banner);
|
||
}
|
||
$rule = MEarningRule::where('name', $communityActivity['class'])
|
||
->where('type_id', $old_id)
|
||
->where('m_id', $merchant_id)
|
||
->first();
|
||
if ($rule) {
|
||
unset($rule['id']);
|
||
$rule->toArray();
|
||
$rule['type_id'] = $id;
|
||
$rule['created_at'] = date('Y-m-d H:i:s', time());
|
||
$rule['updated_at'] = date('Y-m-d H:i:s', time());
|
||
DB::table('m_earning_rules')->insert($rule);
|
||
}
|
||
$merchant_market_service = new MerchantService();
|
||
$merchant_market_service->merchant_id = $merchant_id;
|
||
$merchant_market_service->type = 'community';
|
||
$merchant_market_service->service_type = 0;
|
||
$merchant_market_service->status = $communityActivity['status'];
|
||
$merchant_market_service->type_id = $id;
|
||
$merchant_market_service->save();
|
||
//生成签到二维码
|
||
$qr_code = QrCode::where('type', 'community')
|
||
->where('type_id', $id)
|
||
->where('merchant_id', $request->account_id)
|
||
->first();
|
||
if (!$qr_code) {
|
||
$qr_code = new QrCode();
|
||
$qr_code->type = 'community';
|
||
$qr_code->merchant_id = $request->account_id;
|
||
$qr_code->type_id = $id;
|
||
$qr_code->save();
|
||
$temp_url = urlencode(env('APP_URL') . '/pu/#/activitySignIn/' . $id);
|
||
$jump_url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' .
|
||
$merchant_id . '&qr_code_id=' . $qr_code->id . '&url=' . $temp_url;;
|
||
$image_url = $this->getPreviewQrcode($jump_url);
|
||
$qr_code->jump_url = $jump_url;
|
||
$qr_code->url = $image_url;
|
||
$qr_code->save();
|
||
}
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息了,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 活动导出
|
||
* @param Request $request
|
||
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function getActivityExport(Request $request)
|
||
{
|
||
try {
|
||
$pay_status = $request->pay_status;
|
||
$activity_id = $request->activity_id;
|
||
$activity_type = $request->type;
|
||
$merchant_id = $request->account_id;
|
||
$is_match = $request->is_match;
|
||
// if (!($merchant_id == 491 || $merchant_id == 974)) {
|
||
// return $this->failure('暂不提供此功能!');
|
||
// }
|
||
$orders = TouristOrder::where('type_id', $activity_id)
|
||
->where('merchant_id', $merchant_id);
|
||
if (isset($pay_status)) {
|
||
if ($pay_status == 1) {
|
||
$orders = $orders->whereIn('pay_status', [1, 4]);
|
||
}elseif($pay_status ==2) {
|
||
|
||
}else{
|
||
$orders = $orders->where('pay_status',$pay_status);
|
||
}
|
||
}
|
||
$orders = $orders->where('match_config',1)->orderBy('id', 'desc');
|
||
if($is_match == 1){
|
||
//内部匹配过滤同一个用户多笔订单
|
||
$orders = $orders->groupBy('account_id')->get();
|
||
}else{
|
||
$orders = $orders->get();
|
||
}
|
||
$t1 = microtime(true);
|
||
$user_info_list = $this->touristOrdersExport($orders);
|
||
$t2 = sprintf("耗时: %f秒", round(microtime(true)-$t1,3));
|
||
$type = [];
|
||
//$user_info_list = $this->arraySort($user_info_list, '年龄', SORT_DESC);
|
||
if ($merchant_id == 491 || $merchant_id == 974) {
|
||
foreach ($user_info_list as $key => $val) {
|
||
if (!empty($val['性别'])) {
|
||
if ($val['性别'] == '男') {
|
||
Log::info($val);
|
||
if ($val['常居地'] == '未设置' || $val['常居地'] == '未提供' || $val['婚姻状态'] == '未设置' ||
|
||
$val['婚姻状态'] == '未提供' || $val['年龄'] == '未提供' || $val['年龄'] == '未设置' ||
|
||
$val['常居地'] == '未设置-未设置' || $val['生日'] == '未设置' || $val['真实姓名'] == '未设置') {
|
||
$type['unknown'][] = $val;
|
||
} else {
|
||
$type['man'][] = $val;
|
||
}
|
||
} elseif ($val['性别'] == '女') {
|
||
if ($val['常居地'] == '未设置' || $val['常居地'] == '未提供' || $val['婚姻状态'] == '未设置' ||
|
||
$val['婚姻状态'] == '未提供' || $val['年龄'] == '未提供' || $val['年龄'] == '未设置' ||
|
||
$val['常居地'] == '未设置-未设置' || $val['生日'] == '未设置' || $val['真实姓名'] == '未设置') {
|
||
$type['unknown'][] = $val;
|
||
} else {
|
||
$type['women'][] = $val;
|
||
}
|
||
} else {
|
||
$type['unknown'][] = $val;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return $this->success('ok', compact('user_info_list', 'type','t2'));
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 添加活动成员
|
||
*/
|
||
public function addActivityMember(Request $request)
|
||
{
|
||
try {
|
||
$activity_id = $request->activity_id;
|
||
if(empty($activity_id)) return $this->failure('活动id不能为空');
|
||
$activity = CommunityActivity::find($activity_id);
|
||
$merchant_id = $request->merchant_id;
|
||
if(empty($merchant_id)) return $this->failure('商家id不能为空');
|
||
$user_id = $request->user_id;
|
||
if(empty($user_id)) return $this->failure('用户id不能为空');
|
||
$user = User::select('nickname','mobile','photo')->where('id',$user_id)->first();
|
||
$merchnat_user = MerchantUser::where('user_id', $user_id)->first();
|
||
$order = new TouristOrder();
|
||
$order->price = 0;
|
||
$order->pay_type = 'free';
|
||
$order->type = 'community';
|
||
$order->type_id = $activity_id;
|
||
$order->pay_status = 1;
|
||
$order->trade_no = \CommonUtilsService::getTradeNO();
|
||
$order->desc = '后台添加成员';
|
||
$order->name = $user->nickname??'匿名用户';
|
||
$order->mobile = $user->mobile??'匿名用户';
|
||
$order->goods = $activity->title;
|
||
$order->merchant_id = $merchant_id;
|
||
$order->account_id = $merchnat_user->id ?? null;
|
||
$order->open_id = $merchnat_user->openid ?? null;
|
||
$res = $order->save();
|
||
if(!$res){
|
||
return $this->failure('添加失败');
|
||
}
|
||
return $this->success('ok',compact('activity_id','merchant_id','user_id'));
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 修改嘉宾编号
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function updateGuestNumber(Request $request)
|
||
{
|
||
try {
|
||
$merchant_id = $request->account_id;
|
||
$order_id = $request->order_id;
|
||
$value = $request->value;
|
||
if (!$order_id) {
|
||
return $this->failure('参数错误');
|
||
}
|
||
if(empty($value)){
|
||
return $this->failure('修改的编号不能为空');
|
||
}
|
||
$where = [
|
||
'id' => $order_id,
|
||
'merchant_id' => $merchant_id
|
||
];
|
||
$order = TouristOrder::where($where)->first();
|
||
if (!$order) {
|
||
return $this->failure('订单未找到');
|
||
}
|
||
$order->remark = $value;
|
||
$extend = json_decode($order->extend,true);
|
||
$extend['is_update_remark'] = 1;
|
||
$order->extend = json_encode($extend);
|
||
$order->save();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure($e->getMessage());
|
||
}
|
||
}
|
||
|
||
|
||
function arraySort($multi_array, $sort_key, $sort = SORT_ASC)
|
||
{
|
||
if (is_array($multi_array)) {
|
||
foreach ($multi_array as $row_array) {
|
||
if (is_array($row_array)) {
|
||
$key_array[] = $row_array[$sort_key];
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
} else {
|
||
return false;
|
||
}
|
||
array_multisort($key_array, $sort, $multi_array);
|
||
return $multi_array;
|
||
}
|
||
|
||
/**
|
||
* 获取服务订单列表
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function getServicesOrders(Request $request)
|
||
{
|
||
try {
|
||
$keyword = $request->keyword;
|
||
$nopage = $request->input('nopage', 1);
|
||
$account_id = $request->account_id;
|
||
$market_service_ids = MerchantService::where('merchant_services.merchant_id', $account_id)
|
||
->join('community_activities', function ($join) use ($request) {
|
||
$join->on('community_activities.id', '=', 'merchant_services.type_id')
|
||
->where('community_activities.class', 'many')
|
||
->whereNull('merchant_services.deleted_at');
|
||
}, null, null, 'right')
|
||
->where('merchant_services.type', 'community')
|
||
->where('merchant_services.service_type', 1)
|
||
->pluck('merchant_services.type_id')
|
||
->toArray();
|
||
$account = MerchantAccount::where('id', $account_id)
|
||
->select('id', 'share_icon', 'share_title')
|
||
->first();
|
||
$community_ids = CommunityActivity::withTrashed()
|
||
->where('merchant_id', $account_id)
|
||
->where('type', 'business')->where('class', 'many')
|
||
->pluck('id')
|
||
->toArray();
|
||
|
||
$orders = $this->getOrder($community_ids, $keyword, $nopage, $account, $request, $market_service_ids);
|
||
foreach ($orders as $key => $val) {
|
||
if (in_array($val->type_id, $community_ids)) {
|
||
$val->source_merchant = $account;
|
||
} elseif (in_array($val->type_id, $market_service_ids)) {
|
||
$market_service_merchant_id = CommunityActivity::where('id', $val->type_id)
|
||
->value('merchant_id');
|
||
$val->source_merchant = MerchantAccount::where('id', $market_service_merchant_id)
|
||
->select('id', 'share_icon', 'share_title')
|
||
->first();
|
||
} else {
|
||
$val->source_merchant = $account;
|
||
}
|
||
}
|
||
return $this->success('ok', $orders);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取订单列表子程序
|
||
* @param $community_ids
|
||
* @param $keyword
|
||
* @param $nopage
|
||
* @param $account
|
||
* @param $request
|
||
* @param $my_market_services_ids
|
||
* @return TouristOrder|Builder|mixed
|
||
*/
|
||
private function getOrder($community_ids, $keyword, $nopage, $account, $request, $market_service_ids)
|
||
{
|
||
$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')->withCount('follow');
|
||
$orders = $orders->where('type', 'community')
|
||
->where(function ($query) use ($community_ids, $market_service_ids, $account) {
|
||
$query->whereIn('type_id', $community_ids);
|
||
if ($market_service_ids) {
|
||
$query->orwhere(function ($orWhereQuery) use ($market_service_ids, $account) {
|
||
$orWhereQuery->whereIn('type_id', $market_service_ids)->where('merchant_id', $account->id);
|
||
});
|
||
}
|
||
});
|
||
|
||
if (isset($request->pay_status)) {
|
||
if ($request->pay_status == 1) {
|
||
$orders = $orders->whereIn('pay_status', [1, 4]);
|
||
} else {
|
||
$orders = $orders->where('pay_status', $request->pay_status);
|
||
}
|
||
|
||
}
|
||
if ($keyword) {
|
||
$keyword = trim($keyword);
|
||
$orders = $orders->where(function ($sql) use ($keyword) {
|
||
$sql->where('name', 'like', '%' . $keyword . '%')
|
||
->orWhere('mobile', 'like', '%' . $keyword . '%')
|
||
->orWhere('desc', 'like', '%' . $keyword . '%');
|
||
});
|
||
}
|
||
if ($nopage) {
|
||
$orders = $orders->orderBy('created_at', 'desc')
|
||
->paginate();
|
||
} else {
|
||
$orders = $orders->orderBy('created_at', 'desc')
|
||
->get();
|
||
}
|
||
// $can_withdraw_total = 0; //总收益
|
||
foreach ($orders as $key => $order) {
|
||
if ($order->mobile == '未获取') {
|
||
if ($order->open_id) {
|
||
$mobile = MerchantUser::where('openid', $order->open_id)->value('mobile');
|
||
if ($mobile) {
|
||
$orders[$key]['mobile'] = $mobile;
|
||
}
|
||
}
|
||
}
|
||
if ($request->account_id == 491) {
|
||
if (strstr($order->desc, '牵线') !== false || strstr($order->desc, '盲盒') !== false &&
|
||
($order->pay_status == 1 || $order->pay_status == 4)) {
|
||
$order->show_match_user_button = 1;
|
||
} else {
|
||
$order->show_match_user_button = 0;
|
||
}
|
||
}
|
||
|
||
if ($order->created_at < '2022-3-21 18:00') {
|
||
$temp_sku = explode('-', $order->desc);
|
||
if (is_array($temp_sku) && count($temp_sku) >= 2) {
|
||
$order->goods = $temp_sku[1];
|
||
}
|
||
}
|
||
|
||
$max_refund = $this->getMaxRefund($order->trade_no);
|
||
$order->max_refund = $max_refund;
|
||
|
||
if ($order->channel == '福恋小程序') { //渠道:0商家H5,1福恋H5,2福恋app,3福恋小程序
|
||
$wechat = Wechat::where('openid', $order->open_id)->first();
|
||
if ($wechat) {
|
||
$user = User::where('id', $wechat->user_id)->first();
|
||
if ($user) {
|
||
$userinfo['nickname'] = $user->nickname;
|
||
$userinfo['pic'] = $user->photo ?: ($user->circle_avatar ?: User::DefaultAvatar);
|
||
$order->merchant_user = $userinfo;
|
||
}
|
||
}
|
||
|
||
$wechat = Wechat::where('openid', $order->from_openid)->first();
|
||
if ($wechat && $order->from_openid) {
|
||
$user = User::where('id', $wechat->user_id)->first();
|
||
if ($user) {
|
||
$userinfo['nickname'] = $user->nickname;
|
||
$userinfo['id'] = $user->id;
|
||
$userinfo['pic'] = $user->photo ?: ($user->circle_avatar ?: User::DefaultAvatar);
|
||
$order->fromUser = $userinfo;
|
||
}
|
||
}
|
||
|
||
} else { //渠道:0商家H5,1福恋H5,2福恋app,3福恋小程序
|
||
$rand_str = $this->randString(8);
|
||
$nickname = '用户' . $rand_str;
|
||
if ($order->mobile && !($order->mobile == '匿名用户' || $order->mobile == '未获取')) {
|
||
$user = User::where('mobile', $order->mobile)
|
||
->select('nickname', 'circle_avatar as pic')
|
||
->first();
|
||
if ($user && ($user['nickname'] || $user['pic'])) {
|
||
$order->merchant_user = $user;
|
||
} else {
|
||
if ($order->mer_user && $order->mer_user['pic']) {
|
||
$user_info['pic'] = $order->mer_user['pic'];
|
||
} elseif ($order->viewer && $order->viewer['pic']) {
|
||
$user_info['pic'] = $order->viewer['pic'];
|
||
} else {
|
||
$user_info['pic'] = User::DefaultAvatar;
|
||
}
|
||
if ($order->mer_user && $order->mer_user['nickname']) {
|
||
$user_info['nickname'] = $order->mer_user['nickname'];
|
||
} elseif ($order->viewer && $order->viewer['nickname']) {
|
||
$user_info['nickname'] = $order->viewer['nickname'];
|
||
} else {
|
||
$user_info['nickname'] = '未获取';
|
||
}
|
||
$order->merchant_user = $user_info;
|
||
}
|
||
} elseif ($order->open_id) {
|
||
$wechat = Wechat::where('official_openid', $order->open_id)
|
||
->select('user_id', 'nickname', 'avatar as pic')
|
||
->first();
|
||
if ($wechat && ($wechat['nickname'] || $wechat['pic'])) {
|
||
$order->merchant_user = $wechat;
|
||
} elseif ($wechat && $wechat->user_id) {
|
||
$user = User::where('id', $wechat->user_id)
|
||
->select('nickname', 'circle_avatar as pic')
|
||
->first();
|
||
if ($user && ($user['nickname'] || $user['pic'])) {
|
||
$order->merchant_user = $user;
|
||
} else {
|
||
if ($order->mer_user && $order->mer_user['pic']) {
|
||
$user_info['pic'] = $order->mer_user['pic'];
|
||
} elseif ($order->viewer && $order->viewer['pic']) {
|
||
$user_info['pic'] = $order->viewer['pic'];
|
||
} else {
|
||
$user_info['pic'] = User::DefaultAvatar;
|
||
}
|
||
if ($order->mer_user && $order->mer_user['nickname']) {
|
||
$user_info['nickname'] = $order->mer_user['nickname'];
|
||
} elseif ($order->viewer && $order->viewer['nickname']) {
|
||
$user_info['nickname'] = $order->viewer['nickname'];
|
||
} else {
|
||
$user_info['nickname'] = '未获取';;
|
||
}
|
||
$order->merchant_user = $user_info;
|
||
}
|
||
} else {
|
||
if ($order->mer_user && $order->mer_user['pic']) {
|
||
$user_info['pic'] = $order->mer_user['pic'];
|
||
} elseif ($order->viewer && $order->viewer['pic']) {
|
||
$user_info['pic'] = $order->viewer['pic'];
|
||
} else {
|
||
$user_info['pic'] = User::DefaultAvatar;
|
||
}
|
||
if ($order->mer_user && $order->mer_user['nickname']) {
|
||
$user_info['nickname'] = $order->mer_user['nickname'];
|
||
} elseif ($order->viewer && $order->viewer['nickname']) {
|
||
$user_info['nickname'] = $order->viewer['nickname'];
|
||
} else {
|
||
$user_info['nickname'] = '未获取';
|
||
}
|
||
$order->merchant_user = $user_info;
|
||
}
|
||
} else {
|
||
if ($order->mer_user && $order->mer_user['pic']) {
|
||
$user_info['pic'] = $order->mer_user['pic'];
|
||
} elseif ($order->viewer && $order->viewer['pic']) {
|
||
$user_info['pic'] = $order->viewer['pic'];
|
||
} else {
|
||
$user_info['pic'] = User::DefaultAvatar;
|
||
}
|
||
if ($order->mer_user && $order->mer_user['nickname']) {
|
||
$user_info['nickname'] = $order->mer_user['nickname'];
|
||
} elseif ($order->viewer && $order->viewer['nickname']) {
|
||
$user_info['nickname'] = $order->viewer['nickname'];
|
||
} else {
|
||
$user_info['nickname'] = '未获取';
|
||
}
|
||
$order->merchant_user = $user_info;
|
||
}
|
||
}
|
||
if ($order->mobile == '匿名用户' || $order->mobile == '未获取') {
|
||
$order->mobile = null;
|
||
}
|
||
if (isset($order['merUser']['pic']) && $order['merUser']['pic'] == null) {
|
||
$order['merUser']['pic'] = User::DefaultAvatar;
|
||
}
|
||
if (isset($order['merUser']['nickname']) && $order['merUser']['nickname'] == null) {
|
||
$order['merUser']['nickname'] = '未获取';
|
||
}
|
||
$order->can_withdraw_count = ($order->price) * ($order->withdrawal_radio / 100);
|
||
$order->can_withdraw_count = number_format($order->can_withdraw_count, 2);
|
||
$order->registered_income = 0;
|
||
if ($account->registered_income >= 1)
|
||
$order->registered_income = ($order->price * $account->registered_income) / 100;
|
||
$order->pay_income = 0;
|
||
$order->linkmen = json_decode($order->linkmen, true);
|
||
if ($account->pay_income >= 1)
|
||
$order->pay_income = ($order->price * $account->pay_income) / 100;
|
||
// $can_withdraw_total = $can_withdraw_total+$order->can_withdraw_count;
|
||
if (!empty($order->remark) && $order->remark != 'null') $order->remark = json_decode($order->remark, true);
|
||
$fol = MOrderFollow::where('order_id', $order->id)->where('result', '订单状态修改')->first();
|
||
if ($fol) {
|
||
$is_start = $fol->is_start;
|
||
} else {
|
||
$is_start = 0;
|
||
}
|
||
$order->is_start = $is_start;
|
||
}
|
||
return $orders;
|
||
}
|
||
|
||
/**
|
||
* 获取该笔订单最大退款金额
|
||
* *
|
||
* @param $trade_no
|
||
*/
|
||
public function getMaxRefund($trade_no)
|
||
{
|
||
try {
|
||
$max_price = 0;
|
||
$has_refund = 0;
|
||
$order = Order::where('trade_no', $trade_no)->first();
|
||
if (!$order || $order->pay_status == 0 || $order->pay_status == 3) return 0;
|
||
if ($order->pay_status == 4) { //收益已到账 退商家收益
|
||
//生成收益时间
|
||
$created_at = MEarning::where('m_order_id', $order->id)->value('created_at');
|
||
if ($created_at) {
|
||
$has_refund = MRefundOrder::where('trade_no', $trade_no)->where('is_hook', 1)->where('created_at', '>', $created_at)->sum('refund_fee');
|
||
}
|
||
$value = MEarning::where('m_order_id', $order->id)->where('m_user_id', 0)->sum('value');
|
||
$max_price = $value - $has_refund;
|
||
} else {
|
||
//已经退款金额 收益冻结(钱没分出去) 可退全款
|
||
$has_refund = MRefundOrder::where('trade_no', $trade_no)->where('is_hook', 1)->sum('refund_fee');
|
||
$max_price = $order->price - $has_refund;
|
||
}
|
||
if ($max_price < 0) return 0;
|
||
return $max_price;
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取活动订单列表
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function getActivityOrders(Request $request)
|
||
{
|
||
try {
|
||
$keyword = $request->keyword;
|
||
$nopage = $request->input('nopage', 1);
|
||
$account_id = $request->account_id;
|
||
$account = MerchantAccount::where('id', $account_id)
|
||
->select('id', 'share_icon', 'share_title')
|
||
->first();
|
||
$market_service_ids = MerchantService::where('merchant_services.merchant_id', $account_id)
|
||
->join('community_activities', function ($join) use ($request) {
|
||
$join->on('community_activities.id', '=', 'merchant_services.type_id')
|
||
->where('community_activities.class', 'one');
|
||
}, null, null, 'right')
|
||
->where('merchant_services.type', 'community')
|
||
->where('merchant_services.service_type', 1)
|
||
->pluck('merchant_services.type_id')
|
||
->toArray();
|
||
|
||
$community_ids = CommunityActivity::withTrashed()
|
||
->where('merchant_id', $account_id)
|
||
->where('type', 'business')
|
||
->where('class', 'one')
|
||
->pluck('id')
|
||
->toArray();
|
||
|
||
$orders = $this->getOrder($community_ids, $keyword, $nopage, $account, $request, $market_service_ids);
|
||
foreach ($orders as $key => $val) {
|
||
if (in_array($val->type_id, $community_ids)) {
|
||
$val->source_merchant = $account;
|
||
} elseif (in_array($val->type_id, $market_service_ids)) {
|
||
$market_service_merchant_id = CommunityActivity::where('id', $val->type_id)
|
||
->value('merchant_id');
|
||
$val->source_merchant = MerchantAccount::where('id', $market_service_merchant_id)
|
||
->select('id', 'share_icon', 'share_title')
|
||
->first();
|
||
} else {
|
||
$val->source_merchant = $account;
|
||
}
|
||
}
|
||
return $this->success('ok', $orders);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @param Request $request
|
||
*/
|
||
public function getInitUser(Request $request)
|
||
{
|
||
try {
|
||
$matchService = new UserMatchService();
|
||
$matchService->initUser();
|
||
return $this->success('ok');
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 根据订单号获取用户信息
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function getOrderUser(Request $request)
|
||
{
|
||
try {
|
||
$order_id = $request->order_id;
|
||
$account_id = $request->account_id;
|
||
$order = TouristOrder::where('merchant_id', $account_id)
|
||
->where('id', $order_id)
|
||
->first();
|
||
if ($order) {
|
||
$user_info = $this->getOrderUserInfo($order);
|
||
if ($user_info) {
|
||
if ($user_info->profileCourtship) {
|
||
$user_info->profile = $user_info->profileCourtship;
|
||
$user_info->merchant_user_id = $order->account_id;
|
||
} else {
|
||
$user_info->profile = null;
|
||
$user_info->merchant_user_id = null;
|
||
}
|
||
}
|
||
return $this->success('ok', $user_info);
|
||
} else {
|
||
return $this->failure('无订单信息');
|
||
}
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 盲盒用户内部匹配
|
||
* @param Request $request
|
||
*/
|
||
public function getInsideUserMatch(Request $request)
|
||
{
|
||
try {
|
||
$activity_id = $request->activity_id;
|
||
$merchant_id = $request->account_id;
|
||
$man = $request->man;
|
||
$women = $request->women;
|
||
$women_number = $request->women_number;
|
||
$man_number = $request->man_number;
|
||
if (!$man || !$women || !$women_number || !$man_number) {
|
||
return $this->failure('参数不全');
|
||
}
|
||
if (sizeof($man) != sizeof($women)) {
|
||
return $this->failure('男女数量不相等');
|
||
}
|
||
if (sizeof($man) < 3 || sizeof($women) < 3) {
|
||
return $this->failure('男女生数量小于3个,不能匹配');
|
||
}
|
||
$man_list = Profile::with('member:id,name,hidden_profile')
|
||
->whereIn('user_id', $man)
|
||
->orderByRaw(DB::raw('FIND_IN_SET(user_id, "' . implode(",", $man) . '"' . ")"))
|
||
->get()
|
||
->toArray();
|
||
if (sizeof($man_list) != sizeof($man)) {
|
||
return $this->failure('男生有用户资料缺失');
|
||
}
|
||
foreach ($man_list as $key => $val) {
|
||
if (!$val['sex'] || !$val['birthday'] || !$val['province']) {
|
||
return $this->failure('用户ID: ' . $val['user_id'] . ' 资料不全');
|
||
}
|
||
if ($val['member']['hidden_profile'] != 'NONE') {
|
||
//return $this->failure('用户ID: ' . $val['user_id'] . ' 资料设置为隐藏');
|
||
}
|
||
if (!$val['state']) {
|
||
return $this->failure('用户ID: ' . $val['user_id'] . ' 未设置婚姻状态');
|
||
}
|
||
$man_list[$key]['number'] = $man_number[$key];
|
||
}
|
||
$women_list = Profile::with('member:id,name,hidden_profile')
|
||
->whereIn('user_id', $women)
|
||
->orderByRaw(DB::raw('FIND_IN_SET(user_id, "' . implode(",", $women) . '"' . ")"))
|
||
->get()
|
||
->toArray();
|
||
if (sizeof($women_list) != sizeof($women)) {
|
||
return $this->failure('女生有用户资料缺失');
|
||
}
|
||
foreach ($women_list as $key => $val) {
|
||
if (!$val['sex'] || !$val['birthday'] || !$val['province']) {
|
||
return $this->failure('用户ID: ' . $val['user_id'] . ' 资料不全');
|
||
}
|
||
if ($val['member']['hidden_profile'] != 'NONE') {
|
||
//return $this->failure('用户ID: ' . $val['user_id'] . ' 资料设置为隐藏');
|
||
}
|
||
if (!$val['state']) {
|
||
return $this->failure('用户ID: ' . $val['user_id'] . ' 未设置婚姻状态');
|
||
}
|
||
$women_list[$key]['number'] = $women_number[$key];
|
||
}
|
||
$community = CommunityActivity::where('merchant_id', $merchant_id)
|
||
->where('type', 'business')->where('id', $activity_id)
|
||
->pluck('id');
|
||
if (!$community) {
|
||
$this->failure('活动不存在');
|
||
}
|
||
if (!($merchant_id == 491 || $merchant_id == 974)) {
|
||
return $this->failure('暂不提供此功能!');
|
||
}
|
||
$sum = 0;
|
||
foreach ($man as $key => $val) {
|
||
$sum += $val;
|
||
}
|
||
foreach ($women as $key => $val) {
|
||
$sum += $val;
|
||
}
|
||
$redis = Redis::connection('big_data');
|
||
$result = json_decode(Redis::get('ai:recmd:score:inside:' . $activity_id . '_' . $sum), true);
|
||
// $result = json_decode($redis->get('activity:'.$activity_id.':match'), true);
|
||
if (!$result) {
|
||
$proc_status = Redis::get('InsideUserMatch:' . $activity_id);
|
||
if ($proc_status) {
|
||
$data['status'] = 1;
|
||
return $this->success('正在匹配中,请稍后再试', $data);
|
||
} else {
|
||
$orders = TouristOrder::where('type', 'community')
|
||
->where('type_id', $activity_id)
|
||
->whereIn('pay_status', [1, 4])
|
||
->get();
|
||
if (!$orders) {
|
||
return $this->failure('暂无此活动的订单');
|
||
}
|
||
InsideUserMatch::dispatch($man_list, $women_list, $activity_id)->onQueue('match_user');
|
||
Redis::setex('InsideUserMatch:' . $activity_id, 60, 1);
|
||
$data['status'] = 1;
|
||
$redis->set('activity:'.$activity_id.':'.'female', json_encode($women));
|
||
$redis->set('activity:'.$activity_id.':'.'male', json_encode($man));
|
||
return $this->success('已开始执行匹配任务,请1分钟后重试', $data);
|
||
}
|
||
}
|
||
|
||
return $this->success('ok', $result);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 盲盒活动外部匹配
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function getOutUserMatch(Request $request)
|
||
{
|
||
try {
|
||
$perPage = 10;
|
||
$trade_no = $request->trade_no;
|
||
$merchant_id = $request->account_id;
|
||
if (!($merchant_id == 491 || $merchant_id == 974)) {
|
||
//return $this->failure('无权限执行操作');
|
||
}
|
||
$order = TouristOrder::where('merchant_id', $merchant_id)
|
||
->where('trade_no', $trade_no)
|
||
->whereIn('pay_status', [0, 1, 4])
|
||
->select('id', 'open_id', 'mobile', 'channel', 'trade_no', 'account_id', 'linkmen')
|
||
->first();
|
||
if (!$order) {
|
||
return $this->failure('订单不存在');
|
||
}
|
||
$user = $this->getOrderUserInfo($order);
|
||
if (!$user) {
|
||
return $this->failure('获取用户资料失败');
|
||
} else {
|
||
if (!$user->type) {
|
||
return $this->failure('用户未设置是单身还是介绍人状态');
|
||
}
|
||
if ($user->type == 'marriage') {
|
||
return $this->failure('用户设置为已结婚状态');
|
||
}
|
||
if ($user->profileCourtship) {
|
||
if (!$user->profileCourtship['sex'] || !$user->profileCourtship['province'] || !$user->profileCourtship->city) {
|
||
return $this->failure('用户详细资料不全,没有居住省和城市或性别');
|
||
}
|
||
} else {
|
||
return $this->failure('用户没有详细资料');
|
||
}
|
||
}
|
||
if ($request->has('page')) {
|
||
$current_page = $request->input('page');
|
||
$current_page = $current_page <= 0 ? 1 : $current_page;
|
||
} else {
|
||
$current_page = 1;
|
||
}
|
||
$result = json_decode(Redis::get('ai:recmd:score:all:' . $user->id), true);
|
||
if (!$result) {
|
||
$proc_status = Redis::get('OutUserMatch:' . $order->id);
|
||
if ($proc_status) {
|
||
return $this->failure('正在匹配中,请稍后再试');
|
||
} else {
|
||
// event(new OutUserMatch($order));
|
||
OutUserMatchListener::dispatch($order)->onQueue('match_user');
|
||
Redis::setex('OutUserMatch:' . $order->id, 60 * 5, 1);
|
||
return $this->failure('已开始执行匹配任务,请1分钟后重试');
|
||
}
|
||
}
|
||
/**
|
||
* if(!empty($result[0])){
|
||
* if(empty($result[0]['match_time']) || time() - strtotime($result[0]['match_time']) > 86400){
|
||
* event(new OutUserMatch($order));
|
||
* return $this->failure('已开始执行匹配任务,请1分钟后重试');
|
||
* }
|
||
* }
|
||
* **/
|
||
$item = array_slice($result, ($current_page - 1) * $perPage, $perPage);//$Array为要分页的数组
|
||
$totals = count($item);
|
||
foreach ($item as $key => $val) {
|
||
if ($val['send_user']) {
|
||
unset($item[$key]['send_user']['mobile']);
|
||
}
|
||
}
|
||
$paginator = new LengthAwarePaginator($item, $totals, $perPage, $current_page, [
|
||
'path' => Paginator::resolveCurrentPath(),
|
||
'pageName' => 'page',
|
||
]);
|
||
return $this->success('ok', $paginator);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 牵线匹配
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function getMatchmakersMatch(Request $request)
|
||
{
|
||
try {
|
||
$degree = [
|
||
'其他' => 0, '小学' => 1, '初中' => 2, '初中及初中以下' => 2, '中专' => 4, '高中' => 4,
|
||
'高中/中专' => 4, '大专' => 5, '专科' => 5, '本科' => 6, '硕士' => 7,'硕士以上' => 7, '博士' => 8,
|
||
];
|
||
$trade_no = $request->trade_no;
|
||
$merchant_id = $request->account_id;
|
||
$mate_condition = json_decode($request->getContent(), true);
|
||
if (!$mate_condition) {
|
||
return $this->failure('匹配参数不存在');
|
||
}
|
||
if ($mate_condition && !empty($mate_condition['location_province'])) {
|
||
$mate_condition['location'] = $mate_condition['location_province'];
|
||
}
|
||
if (!($merchant_id == 491 || $merchant_id == 974)) {
|
||
//return $this->failure('无权限执行操作');
|
||
}
|
||
$order = TouristOrder::where('merchant_id', $merchant_id)
|
||
->where('trade_no', $trade_no)
|
||
->whereIn('pay_status', [0, 1, 4])
|
||
->select('id', 'open_id', 'mobile', 'channel', 'trade_no', 'account_id', 'linkmen')
|
||
->first();
|
||
if (!$order) {
|
||
return $this->failure('订单不存在或未支付');
|
||
}
|
||
$send_user = $this->getOrderUserInfo($order);
|
||
if (!$send_user) {
|
||
return $this->failure('获取用户资料失败');
|
||
} else {
|
||
if ($send_user->profileCourtship) {
|
||
if (!$send_user->profileCourtship->matchmaker_condition || $send_user->profileCourtship->matchmaker_condition != $mate_condition) {
|
||
$data_object = $send_user->profileCourtship;
|
||
if (!$data_object->matchmaker_condition) {
|
||
$data_object->matchmaker_condition = json_encode([]);
|
||
}
|
||
if(!$data_object->mate_conditon){
|
||
$data_object->mate_conditon = json_encode([]);
|
||
}
|
||
$data_object->matchmaker_condition = json_encode(array_merge(json_decode($data_object->mate_conditon, true), $mate_condition));
|
||
$data_object->save();
|
||
}
|
||
} else {
|
||
return $this->failure('获取用户详细资料缺失');
|
||
}
|
||
if (!$send_user['sex']) {
|
||
return $this->failure('用户性别未设置,不能进行匹配');
|
||
} else {
|
||
if ($send_user['sex'] == 1) {
|
||
$sex = 2;
|
||
} elseif ($send_user['sex'] == 2) {
|
||
$sex = 1;
|
||
} else {
|
||
return $this->failure('用户性别异常,不能进行匹配');
|
||
}
|
||
}
|
||
$no_match_user = json_decode(Redis::get('no_match_user_' . $send_user->id),true);
|
||
$users = Profile::with('member:photo,name,is_real_approved,id')->where('sex', $sex)
|
||
->when(!empty($mate_condition['age']), function ($query) use ($mate_condition) {
|
||
if (!($mate_condition['age'] == '年龄不限' || $mate_condition['age'] == '不限')) {
|
||
list($min_age, $max_age) = explode('-', $mate_condition['age']);
|
||
$min_age = str_replace('岁', '', $min_age);
|
||
$max_age = str_replace('岁', '', $max_age);
|
||
$min_age = (date('Y') - $min_age) . '-12-31';
|
||
$max_age = (date('Y') - $max_age) . '-01-01';
|
||
if ($min_age != '不限') {
|
||
$query->when($min_age, function ($sub_query) use ($min_age) {
|
||
$sub_query->where('birthday', '<=', $min_age);
|
||
});
|
||
}
|
||
if ($max_age != '不限') {
|
||
$query->when($max_age, function ($sub_query) use ($max_age) {
|
||
$sub_query->where('birthday', '>=', $max_age);
|
||
});
|
||
}
|
||
}
|
||
})
|
||
->when(!empty($mate_condition['belief']), function ($query) use ($mate_condition) {
|
||
if (!($mate_condition['belief'] == '信仰不限' || $mate_condition['belief'] == '不限')) {
|
||
$query->where('belief', $mate_condition['belief']);
|
||
}
|
||
})
|
||
->when(!empty($mate_condition['degree']), function ($query) use ($mate_condition, $degree) {
|
||
if (!($mate_condition['degree'] == '学历不限' || $mate_condition['degree'] == '不限')) {
|
||
list($min_degree, $max_degree) = explode('-', $mate_condition['degree']);
|
||
if ($max_degree) {
|
||
if ($max_degree != '不限') {
|
||
$min_degree_temp = $degree[$min_degree];
|
||
$max_degree_temp = $degree[$max_degree];
|
||
$degree_array = [];
|
||
foreach ($degree as $key => $val) {
|
||
if ($val >= $min_degree_temp && $val <= $max_degree_temp) {
|
||
$degree_array[] = $key;
|
||
}
|
||
}
|
||
if($degree_array){
|
||
$query->whereIn('degree', $degree_array);
|
||
}
|
||
}else{
|
||
$min_degree_temp = $degree[$min_degree];
|
||
foreach ($degree as $key => $val) {
|
||
if ($val >= $min_degree_temp) {
|
||
$degree_array[] = $key;
|
||
}
|
||
}
|
||
|
||
if($degree_array){
|
||
$query->whereIn('degree', $degree_array);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
})
|
||
->when(!empty($mate_condition['location_province']), function ($query) use ($mate_condition) {
|
||
if (!($mate_condition['location_province'] == '所在地不限' || $mate_condition['location_province'] == '不限')) {
|
||
$query->where('province', $mate_condition['location_province']);
|
||
}
|
||
})
|
||
->when(!empty($mate_condition['location_city']), function ($query) use ($mate_condition) {
|
||
if (!($mate_condition['location_city'] == '不限' || $mate_condition['location_city'] == '所在地不限')) {
|
||
$query->where('city', $mate_condition['location_city']);
|
||
}
|
||
})
|
||
->when(!empty($mate_condition['resident_province']), function ($query) use ($mate_condition) {
|
||
if (!($mate_condition['resident_province'] == '不限' || $mate_condition['resident_province'] == '所在地不限')) {
|
||
$query->where('resident_province', $mate_condition['resident_province']);
|
||
}
|
||
})
|
||
->when(!empty($mate_condition['resident_city']), function ($query) use ($mate_condition) {
|
||
if (!($mate_condition['resident_city'] == '不限' || $mate_condition['resident_city'] == '所在地不限')) {
|
||
$query->where('resident_city', $mate_condition['resident_city']);
|
||
}
|
||
})
|
||
->when(!empty($mate_condition['stature']), function ($query) use ($mate_condition) {
|
||
if ($mate_condition['stature'] != '不限') {
|
||
list($min_stature, $max_stature) = explode('-', $mate_condition['stature']);
|
||
if ($max_stature) {
|
||
$max_stature = str_replace('cm', '', $max_stature);
|
||
if ($max_stature != '不限') {
|
||
$query->when($max_stature, function ($sub_query) use ($max_stature) {
|
||
$sub_query->where('stature', '<=', $max_stature);
|
||
});
|
||
}
|
||
}
|
||
if ($min_stature) {
|
||
$min_stature = str_replace('cm', '', $min_stature);
|
||
$query->where('stature', '>=', $min_stature);
|
||
}
|
||
}
|
||
})
|
||
->when(!empty($mate_condition['weight']), function ($query) use ($mate_condition) {
|
||
if (!($mate_condition['weight'] == '不限' || $mate_condition['weight'] == '身高不限')) {
|
||
list($min_weight, $max_weight) = explode('-', $mate_condition['weight']);
|
||
if ($max_weight) {
|
||
if ($max_weight != '不限') {
|
||
$query->where('weight', '<=', $max_weight);
|
||
}
|
||
}
|
||
if ($min_weight) {
|
||
if ($min_weight != '不限') {
|
||
$query->where('weight', '>=', $min_weight);
|
||
}
|
||
}
|
||
}
|
||
})
|
||
->when(!empty($mate_condition['state']), function ($query) use ($mate_condition) {
|
||
if ($mate_condition['state'] != '不限') {
|
||
if (is_array($mate_condition['state'])) {
|
||
if(in_array('未婚',$mate_condition['state']) || in_array('从未结婚',$mate_condition['state']) ){
|
||
$query->whereIn('state', array_merge(['未婚', '从未结婚'],$mate_condition['state']));
|
||
}else{
|
||
$query->whereIn('state',$mate_condition['state']);
|
||
}
|
||
}
|
||
}
|
||
})
|
||
->when(!empty($mate_condition['year_income']), function ($query) use ($mate_condition) {
|
||
if ($mate_condition['year_income'] != '不限') {
|
||
if (strpos('~', $mate_condition['year_income']) !== false) {
|
||
list($min_income, $max_income) = explode('~', $mate_condition['year_income']);
|
||
$min_income = str_replace('万', '', $min_income);
|
||
$max_income = str_replace('万', '', $max_income);
|
||
$min_income = str_replace('w', '', $min_income);
|
||
$max_income = str_replace('w', '', $max_income);
|
||
if ($min_income != '不限') {
|
||
$query->where('income', '>=', $min_income);
|
||
}
|
||
|
||
if ($max_income != '不限') {
|
||
$max_income = str_replace('w', '', $max_income);
|
||
$query->where('income', '<=', $max_income);
|
||
}
|
||
} else { //处理5W以下
|
||
$min_income = str_replace('万', '', $mate_condition['year_income']);
|
||
$query->where('income', '<=', $min_income);
|
||
}
|
||
}
|
||
})
|
||
->when($no_match_user,function ($query) use($no_match_user){
|
||
$query->whereNotIn('user_id',$no_match_user);
|
||
})
|
||
->whereHas('member', function ($query) {
|
||
$query->where('type', 'single')->whereNotNull('photo')
|
||
->where('hidden_profile', 'NONE')
|
||
->select();
|
||
})
|
||
->select('birthday', 'sex', 'resident_province', 'resident_city', 'province', 'city', 'user_id','belief')
|
||
->paginate();
|
||
foreach ($users as $key => $val){
|
||
$match = MatchLog::where('send_user_id',$send_user->id)
|
||
->where('receive_user_id',$val->user_id)
|
||
->first();
|
||
if($match){
|
||
$val->is_matched = 1;
|
||
}else{
|
||
$val->is_matched = 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
return $this->success('ok', $users);
|
||
} catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 匹配后给被匹配用户发通知
|
||
* @param Request $request
|
||
*/
|
||
public function sendTemplateMessageToMatchUser(Request $request){
|
||
try {
|
||
$merchant_id = $request->account_id;
|
||
$receive_user_id = $request->receive_user_id;
|
||
$send_user_id = $request->send_user_id;
|
||
$order_id = $request->order_id;
|
||
if (!$receive_user_id || !$send_user_id || !$order_id) {
|
||
return $this->failure('参数不全');
|
||
}
|
||
$order = Order::where('id',$order_id)->where('merchant_id',$merchant_id)
|
||
->first();
|
||
if(!$order){
|
||
return $this->failure('订单不存在');
|
||
}
|
||
$user = $this->getOrderUserInfo($order);
|
||
if(!$user || $user->id != $send_user_id){
|
||
return $this->failure('订单用户不匹配');
|
||
}
|
||
$mobile = User::where('id', $receive_user_id)->value('mobile');
|
||
$send_user = User::where('id', $send_user_id)->value('mobile');
|
||
if(!$send_user){
|
||
return $this->failure('用户信息不存在');
|
||
}
|
||
if ($mobile) {
|
||
$url = 'https://love.ufutx.com/h5/#/userDetail/'.$send_user_id.'?receive_user_id='.$receive_user_id;
|
||
$url = \CommonUtilsService::shortUrlv3($url);
|
||
$message = '【福恋】你的过去我来不及参与,你的未来我奉陪到底。已为您匹配出一名异性,请点击(' . $url['url'] . ') 查看Ta的信息';
|
||
MatchLog::create([
|
||
'm_order_id' => $order_id,
|
||
'send_user_id' => $send_user_id, //订单用户ID
|
||
'receive_user_id' => $receive_user_id,
|
||
'pattern' => 2, //匹配推荐
|
||
'is_positive' => 1, //主动匹配
|
||
'status' => 3 , //发送沟通请求
|
||
'admin_id' => $request->merchant_admin_id ?? 0,
|
||
'created_at' => date('Y-m-d H:i:s'),
|
||
'updated_at' => date('Y-m-d H:i:s'),
|
||
]);
|
||
MatchLog::create([
|
||
'm_order_id' => $order_id,
|
||
'send_user_id' => $receive_user_id,
|
||
'receive_user_id' => $send_user_id, //订单用户ID
|
||
'pattern' => 2, //匹配推荐
|
||
'is_positive' => 0, //被动匹配
|
||
'status' => 3 , //发送沟通请求
|
||
'admin_id' => $request->merchant_admin_id ?? 0,
|
||
'created_at' => date('Y-m-d H:i:s'),
|
||
'updated_at' => date('Y-m-d H:i:s'),
|
||
]);
|
||
if($request->merchant_admin_id){
|
||
$name = MerchantMembers::where('mch_id',$merchant_id)->where('admin_id',$request->merchant_admin_id)
|
||
->value('name');
|
||
$maker_user_id = $this->getMakerUserId($request->merchant_admin_id,$merchant_id);
|
||
}else{
|
||
$name = Anchor::where('m_id',$merchant_id)->value('name');
|
||
$maker_user_id = $this->getMakerUserId(0,$merchant_id);
|
||
}
|
||
ClientComment::create([
|
||
'user_id'=>$receive_user_id,
|
||
'maker_user_id'=>$maker_user_id,
|
||
'type'=>'mobile',
|
||
'pics'=>null,
|
||
'comment'=>'管理员:'.$name.'通过匹配推荐了用户ID:'.$send_user_id,
|
||
]);
|
||
ClientComment::create([
|
||
'user_id'=>$send_user_id,
|
||
'maker_user_id'=>$maker_user_id,
|
||
'type'=>'mobile',
|
||
'pics'=>null,
|
||
'comment'=>'管理员id:'.$name.'通过匹配推荐了用户ID:'.$receive_user_id,
|
||
]);
|
||
$this->sentMessage($mobile,$message);
|
||
}else{
|
||
return $this->failure('用户信息不存在');
|
||
}
|
||
return $this->success('ok');
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取匹配时不匹配的用户
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function getNoMatchUser(Request $request){
|
||
try {
|
||
$user_id = $request->user_id;
|
||
$no_match_user = json_decode(Redis::get('no_match_user_' . $user_id),true);
|
||
if(!empty($no_match_user)){
|
||
$users = Profile::with('member:photo,name,is_real_approved,id')->whereIn('user_id', $no_match_user)
|
||
->select('birthday', 'sex', 'resident_province', 'resident_city', 'province', 'city', 'user_id', 'belief')
|
||
->paginate();
|
||
}else{
|
||
$users = Profile::whereNull('id')->paginate();
|
||
}
|
||
|
||
return $this->success('ok', $users);
|
||
}catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 更新匹配时不匹配的用户
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function updateNoMatchUser(Request $request){
|
||
try {
|
||
$user_id = $request->user_id;
|
||
$no_match_user_list = $request->no_match_user_list;
|
||
if(!$no_match_user_list || !is_array($no_match_user_list)){
|
||
return $this->fail('no_match_user_list不能为空');
|
||
}
|
||
$no_match_user = json_decode(Redis::get('no_match_user_' . $user_id),true);
|
||
if(!$no_match_user){
|
||
$no_match_user = [];
|
||
}
|
||
$no_match_user_list = array_merge($no_match_user_list, $no_match_user);
|
||
Redis::set('no_match_user_' . $user_id,json_encode($no_match_user_list));
|
||
return $this->success('ok');
|
||
}catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 生成签到码
|
||
*/
|
||
public function makeSignQrcode(Request $request){
|
||
|
||
$lists = CommunityActivity::where('status',1)->where('class','one')->get();
|
||
foreach ($lists as $key => $val) {
|
||
//生成签到二维码
|
||
$qr_code = QrCode::where('type', 'community')
|
||
->where('type_id', $val->id)
|
||
->where('merchant_id', $val->account_id)
|
||
->first();
|
||
if (!$qr_code) {
|
||
$qr_code = new QrCode();
|
||
$qr_code->type = 'community';
|
||
$qr_code->merchant_id = $val->merchant_id;
|
||
$qr_code->type_id = $val->id;
|
||
$qr_code->save();
|
||
$temp_url = urlencode(env('APP_URL') . '/pu/#/activitySignIn/' . $val->id);
|
||
$jump_url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' .
|
||
$val->merchant_id . '&qr_code_id=' . $qr_code->id . '&url=' . $temp_url;;
|
||
$image_url = $this->getPreviewQrcode($jump_url);
|
||
$qr_code->jump_url = $jump_url;
|
||
$qr_code->url = $image_url;
|
||
$qr_code->save();
|
||
}
|
||
}
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function activityPhotos(Request $request, $id) {
|
||
$type = 'activity';
|
||
$photos = ActivityPhoto::where('type', $type)->where('type_id', $id)->orderByDesc('id')->paginate();
|
||
return $this->success('ok', $photos);
|
||
}
|
||
|
||
public function storeActvityPhotos(Request $request, $id) {
|
||
$pics = $request->input('pics');
|
||
$data = [];
|
||
foreach ($pics as $pic) {
|
||
$param = [
|
||
'type'=>'activity',
|
||
'type_id'=>$id,
|
||
'pic'=>$pic,
|
||
'thumb_pic'=>$pic.'?x-oss-process=image/auto-orient,1/resize,p_20/quality,q_80',
|
||
'created_at'=> date('Y-m-d H:i:s'),
|
||
'updated_at'=> date('Y-m-d H:i:s'),
|
||
];
|
||
$data[] = $param;
|
||
}
|
||
ActivityPhoto::insert($data);
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function deleteActvityPhotos(Request $request, $id)
|
||
{
|
||
ActivityPhoto::where('id',$id)->delete();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
public function addActivityMenu(Request $request){
|
||
try {
|
||
$activity_id = $request->id;
|
||
$activity = CommunityActivity::where('id',$activity_id)->first();
|
||
if(empty($activity)){
|
||
return $this->failure('活动不存在');
|
||
}
|
||
$data = $request->only(['total_desk','menu','back_images','desk_images','start_desk','user_number','sign_images','desk_back_images']);
|
||
$validator = Validator::make($request->all(), [
|
||
'total_desk' => 'required',
|
||
'back_images' => 'required',
|
||
'desk_images' => 'required',
|
||
'start_desk' => 'required',
|
||
'user_number' => 'required',
|
||
'sign_images' => 'required',
|
||
], [
|
||
'total_desk.required' => '请填写总桌数',
|
||
'back_images.required' => '请上传背景图',
|
||
'desk_images.required' => '请上传座位图',
|
||
'start_desk.required' => '请填写开始桌号',
|
||
'user_number.required' => '请填写每桌人数',
|
||
'sign_images.required' => '请上传签到背景图'
|
||
]);
|
||
|
||
$error = $validator->errors()->first();
|
||
if ($error) {
|
||
return $this->failure($error);
|
||
}
|
||
$menus = $data['menu'];
|
||
|
||
$meeting = ActivityMeeting::where('activity_id',$activity_id)->first();
|
||
|
||
if(!empty($menus)){
|
||
array_push($menus,['name'=>"座位查询",'images'=>$data['desk_back_images']]);
|
||
}
|
||
unset($data['desk_back_images']);
|
||
|
||
if(empty($meeting)){
|
||
$data['activity_id'] = $activity_id;
|
||
}
|
||
$data['menu'] = json_encode($menus);
|
||
|
||
if($meeting){
|
||
ActivityMeeting::where('activity_id',$activity_id)->update($data);
|
||
}else{
|
||
$merchant_id = $request->account_id;
|
||
$temp_url = urlencode(env('APP_URL') . '/pu/#/activitySignIn/' . $activity_id);
|
||
$jump_url = env('APP_URL') . '/api/official/live/wechat/activityMeetingAuth?merchant_id=' . $merchant_id . '&url=' . $temp_url;
|
||
$qrcode = $this->getPreviewQrcode($jump_url);
|
||
$data['qr_code'] = $qrcode;
|
||
$data['qr_code_url'] = $jump_url;
|
||
ActivityMeeting::create($data);
|
||
}
|
||
return $this->success('ok');
|
||
}catch (\Exception $e){
|
||
return $this->failure($e->getMessage());
|
||
}
|
||
}
|
||
|
||
public function getActivityMenu(Request $request){
|
||
try {
|
||
$activity_id = $request->id;
|
||
$meeting = ActivityMeeting::where('activity_id',$activity_id)->first();
|
||
if($meeting){
|
||
$temp_menu = json_decode($meeting->menu,true);
|
||
foreach ($temp_menu as $index => $menu){
|
||
if($menu['name'] == "座位查询"){
|
||
$meeting->desk_back_images = $menu['images'];
|
||
unset($temp_menu[$index]);
|
||
}
|
||
}
|
||
sort($temp_menu);
|
||
$meeting->menu = $temp_menu;
|
||
}
|
||
return $this->success('ok',$meeting);
|
||
}catch (\Exception $e){
|
||
return $this->failure($e->getMessage());
|
||
}
|
||
}
|
||
|
||
public function getMeetingApplyUser(Request $request){
|
||
try {
|
||
$activity_id = $request->id;
|
||
$keyword = $request->keyword;
|
||
$is_export = $request->is_export;
|
||
$no_page = $request->no_page;
|
||
if($is_export){
|
||
$no_page = true;
|
||
}
|
||
$query = CommunityActivityMember::query();
|
||
$query->when($keyword,function ($query) use ($keyword){
|
||
$query->where('name','%'.$keyword.'%');
|
||
});
|
||
$query->where('activity_id',$activity_id);
|
||
|
||
if($no_page){
|
||
$apply_user = $query->get();
|
||
}else{
|
||
$apply_user = $query->paginate();
|
||
}
|
||
foreach ($apply_user as $item){
|
||
$sign = ActivityMeetingApply::where('activity_id',$activity_id)->where('mobile',$item->mobile)->first();
|
||
$item->is_sign = false;
|
||
$item->sign_time = '';
|
||
if(!empty($sign)){
|
||
$item->is_sign = true;
|
||
$item->sign_time = $sign->created_at->toDateTimeString();
|
||
}
|
||
}
|
||
if($is_export){
|
||
return \Excel::download(new ActivityApplyUserExport($apply_user), 'activity_member.xlsx');
|
||
}
|
||
return $this->success('ok',$apply_user);
|
||
}catch (\Exception $e){
|
||
return $this->failure($e->getMessage());
|
||
}
|
||
}
|
||
|
||
}
|