551 lines
25 KiB
PHP
551 lines
25 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
namespace App\Http\Controllers\Server\H5;
|
|||
|
|
|
|||
|
|
use App\Models\CommunityActivity;
|
|||
|
|
use App\Models\Consultation;
|
|||
|
|
use App\Models\ConsultationRecords;
|
|||
|
|
use App\Models\Course\UserCourses;
|
|||
|
|
use App\Models\Server\CollageGroup;
|
|||
|
|
use App\Models\Server\CollageGroupBatch;
|
|||
|
|
use App\Models\Server\CollageGroupHistories;
|
|||
|
|
use App\Models\Server\MerchantUser;
|
|||
|
|
use App\Models\Server\TouristOrder;
|
|||
|
|
use App\Models\ShopRecive;
|
|||
|
|
use App\Models\User;
|
|||
|
|
use App\Models\Wechat;
|
|||
|
|
use Illuminate\Http\Request;
|
|||
|
|
use App\Http\Controllers\Controller;
|
|||
|
|
use Illuminate\Support\Facades\DB;
|
|||
|
|
use Illuminate\Support\Facades\Log;
|
|||
|
|
use Illuminate\Support\Facades\Redis;
|
|||
|
|
|
|||
|
|
class CollageGroupController extends Controller
|
|||
|
|
{
|
|||
|
|
/**
|
|||
|
|
* 未完成拼团列表
|
|||
|
|
* **/
|
|||
|
|
public function unfinishedGroups(Request $request)
|
|||
|
|
{
|
|||
|
|
$merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$merchant_user = MerchantUser::find($merchant_user_id);
|
|||
|
|
$type = $request->type;
|
|||
|
|
if ($type == 'activity' || $type == 'service') {
|
|||
|
|
$public_type = 'community';
|
|||
|
|
}else{
|
|||
|
|
$public_type = $type;
|
|||
|
|
}
|
|||
|
|
$type_id = $request->type_id;
|
|||
|
|
if (config('app.debug')) {
|
|||
|
|
if (!$type || !$type_id) {
|
|||
|
|
return $this->failure('参数不全');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$group = CollageGroup::where('type', $public_type)->where('type_id', $type_id)->first();
|
|||
|
|
if (!$group) {
|
|||
|
|
return $this->success('ok', []);
|
|||
|
|
}
|
|||
|
|
if ($merchant_user) {
|
|||
|
|
//已参与
|
|||
|
|
if($type == 'service' || $type == 'course'){
|
|||
|
|
$exists = TouristOrder::where('type', $public_type)->where('type_id', $type_id)->where('group_id',$group->id)
|
|||
|
|
->whereIn('pay_status', [1, 4])->where('account_id', $merchant_user_id)
|
|||
|
|
->first();
|
|||
|
|
if ($exists) return $this->success('ok', []);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$time = date('Y-m-d H:i:s');
|
|||
|
|
$histories = CollageGroupHistories::with('tOrder')->whereHas('tOrder', function ($sql) use($group){
|
|||
|
|
$sql->whereIn('pay_status', [1, 4])->where('group_id',$group->id);
|
|||
|
|
})
|
|||
|
|
->where('group_id', $group->id)->where('is_initiator', 1)
|
|||
|
|
->where('status', 0)->where('deadline', '>', $time)
|
|||
|
|
->where('m_user_id','!=',$merchant_user_id)
|
|||
|
|
->get();
|
|||
|
|
foreach ($histories as $key => $history) {
|
|||
|
|
$require_num = $history->group->require_num;
|
|||
|
|
//已经参与人数
|
|||
|
|
$history_ids = CollageGroupBatch::where('batch',$history->group_master_id)->pluck('history_id')->toArray();
|
|||
|
|
$num = count($history_ids);
|
|||
|
|
$need = ($require_num - $num) > 0 ? $require_num - $num : 0;
|
|||
|
|
$history->need_count = $need;
|
|||
|
|
$history->avatar = $history->mUser ? $history->mUser->pic : User::DefaultAvatar;
|
|||
|
|
if (empty($history->avatar)) $history->avatar = User::DefaultAvatar;
|
|||
|
|
$history->nickname = $history->mUser->nickname ? mb_substr(trim($history->mUser->nickname), 0, 1) . '**' : '***';
|
|||
|
|
unset($history->mUser);
|
|||
|
|
unset($history->tOrder);
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $histories);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 热门拼团
|
|||
|
|
* **/
|
|||
|
|
public function hotGroups(Request $request)
|
|||
|
|
{
|
|||
|
|
$time = date('Y-m-d H:i:s');
|
|||
|
|
$m_user_id = $request->merchant_user_id;
|
|||
|
|
$merchant_user = MerchantUser::find($m_user_id);
|
|||
|
|
$type = $request->type;
|
|||
|
|
$current_type_id = $request->current_type_id;
|
|||
|
|
$merchant_id = $request->merchant_id;
|
|||
|
|
if (config('app.debug')) {
|
|||
|
|
if (!$merchant_id || !$type) {
|
|||
|
|
return $this->failure('参数不全');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$join_ids = [];
|
|||
|
|
if ($merchant_user) {
|
|||
|
|
//我是否参与
|
|||
|
|
$join_ids = TouristOrder::where('type', $type)->where('account_id', $m_user_id)
|
|||
|
|
->where('type_id','!=',$current_type_id)
|
|||
|
|
->whereIn('pay_status', [1, 4])->pluck('type_id')
|
|||
|
|
->toArray();
|
|||
|
|
}
|
|||
|
|
$groups = CollageGroup::where('m_id', $merchant_id)->where('type', $type)->where('start_time', '<', $time)
|
|||
|
|
->with($type)->whereHas($type,function ($query){
|
|||
|
|
$query->whereNull('deleted_at');
|
|||
|
|
})
|
|||
|
|
->where('end_time', '>', $time)
|
|||
|
|
->where('type_id','!=',$current_type_id)
|
|||
|
|
->when(sizeof($join_ids) > 0,function ($query) use($join_ids){
|
|||
|
|
$query->whereNotIn('type_id', $join_ids);
|
|||
|
|
})
|
|||
|
|
->limit(5)
|
|||
|
|
->get();
|
|||
|
|
foreach ($groups as $key => $group) {
|
|||
|
|
$type = $group->type;
|
|||
|
|
switch ($type){
|
|||
|
|
case 'course':
|
|||
|
|
$group->title = $group->$type ? $group->$type->title : '未获取';
|
|||
|
|
$group->pic = $group->$type ? $group->$type->thumb : '未获取';
|
|||
|
|
break;
|
|||
|
|
case 'activity':
|
|||
|
|
case 'service':
|
|||
|
|
case 'community':
|
|||
|
|
case 'consult':
|
|||
|
|
$group->title = $group->$type ? $group->$type->title : '未获取';
|
|||
|
|
$group->pic = $group->$type ? $group->$type->pic : '未获取';
|
|||
|
|
break;
|
|||
|
|
case 'shop':
|
|||
|
|
$group->title = $group->$type ? $group->$type->title : '未获取';
|
|||
|
|
$group->pic = $group->$type ? $group->$type->icon : '未获取';
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
$group->title = null;
|
|||
|
|
$group->pic = null;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
$group->sku = json_decode($group->sku, true) ?? null;
|
|||
|
|
$min_price = [];
|
|||
|
|
$single_buy = $group->price;
|
|||
|
|
foreach ($group->sku as $skus) {
|
|||
|
|
$min_price[] = $skus['discount_price'];
|
|||
|
|
}
|
|||
|
|
if(!empty($min_price)){
|
|||
|
|
$group->discount_price = min($min_price);
|
|||
|
|
}else{
|
|||
|
|
$group->discount_price = $group->price;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
foreach ($group->sku as $skus) {
|
|||
|
|
if ($group->discount_price == $skus['discount_price']) {
|
|||
|
|
$single_buy = $skus['price'];
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$group->single_buy = $single_buy;
|
|||
|
|
// $group->single_buy = $group->sku[0]['price'];
|
|||
|
|
// $group->discount_price = $group->sku[0]['discount_price'];
|
|||
|
|
$group->save_money = ($group->single_buy - $group->discount_price) > 0 ?
|
|||
|
|
number_format($group->single_buy - $group->discount_price, 2) : 0;
|
|||
|
|
unset($group->$type);
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $groups);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 拼团订单详情
|
|||
|
|
* **/
|
|||
|
|
public function groupOrderDetail(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$merchant_user = MerchantUser::find($merchant_user_id);
|
|||
|
|
$order_id = $request->order_id;
|
|||
|
|
$history_id = $request->history_id;
|
|||
|
|
if ($history_id) {
|
|||
|
|
$history = CollageGroupHistories::where('id',$history_id)->where('m_order_id',$order_id)->first();
|
|||
|
|
if(!$history){
|
|||
|
|
if(config('app.debug')){
|
|||
|
|
return $this->failure('拼团ID不正确');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}else{
|
|||
|
|
$history = CollageGroupHistories::where('m_order_id',$order_id)->first();
|
|||
|
|
}
|
|||
|
|
$linkmen['name'] = $merchant_user ? $merchant_user->name : '';
|
|||
|
|
$linkmen['mobile'] = $merchant_user ? $merchant_user->mobile : '';
|
|||
|
|
if ($history && !empty($history->group_id)) {
|
|||
|
|
$group = CollageGroup::where('id', $history->group_id)
|
|||
|
|
->select('id', 'type', 'type_id', 'describe', 'require_num', 'sku', 'price')
|
|||
|
|
->first();
|
|||
|
|
} else {
|
|||
|
|
$group = null;
|
|||
|
|
}
|
|||
|
|
if (!$group) return $this->failure('拼团信息已完成或不存在');
|
|||
|
|
//订单
|
|||
|
|
$order = TouristOrder::where('id', $order_id)->select('id', 'price', 'desc', 'goods', 'group_id', 'account_id',
|
|||
|
|
'pay_status', 'pay_type', 'created_at', 'trade_no','type','type_id','num','merchant_id')
|
|||
|
|
->first();
|
|||
|
|
if(!$order){
|
|||
|
|
return $this->failure('订单不存在');
|
|||
|
|
}
|
|||
|
|
$group->sku = json_decode($group->sku);
|
|||
|
|
$group->linkmen = $linkmen;
|
|||
|
|
$type = $group->type;
|
|||
|
|
switch ($type){
|
|||
|
|
case 'course':
|
|||
|
|
$order->title = $group->$type ? $group->$type->title : '未获取';
|
|||
|
|
$order->pic = $group->$type ? $group->$type->thumb : '未获取';
|
|||
|
|
break;
|
|||
|
|
case 'activity':
|
|||
|
|
case 'service':
|
|||
|
|
case 'community':
|
|||
|
|
case 'consult':
|
|||
|
|
$order->title = $group->$type ? $group->$type->title : '未获取';
|
|||
|
|
$order->pic = $group->$type ? $group->$type->pic : '未获取';
|
|||
|
|
break;
|
|||
|
|
case 'shop':
|
|||
|
|
$order->title = $group->$type ? $group->$type->title : '未获取';
|
|||
|
|
$order->pic = $group->$type ? $group->$type->icon : '未获取';
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
$order->title = null;
|
|||
|
|
$order->pic = null;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
$result = $group->$type;
|
|||
|
|
$result->sku = json_decode($result->sku, true);
|
|||
|
|
$group->insurance = $result->insurance;
|
|||
|
|
$group->anchor_id = $result->anchor_id;
|
|||
|
|
unset($group->$type);
|
|||
|
|
$history_ids = CollageGroupBatch::where('batch',$history->group_master_id)->pluck('history_id')->toArray();
|
|||
|
|
if (count($history_ids) == 0) return $this->failure('该团已解散');
|
|||
|
|
$user_ids = CollageGroupHistories::with('tOrder')->whereHas('tOrder', function ($sql) {
|
|||
|
|
$sql->whereIn('pay_status', [1, 4]);
|
|||
|
|
})
|
|||
|
|
->whereIn('id',$history_ids)
|
|||
|
|
->where('group_id', $history->group_id)
|
|||
|
|
->orderBy('id', 'desc')->pluck('m_user_id')
|
|||
|
|
->toArray();
|
|||
|
|
$str = implode(',', $user_ids);
|
|||
|
|
//团长id
|
|||
|
|
$initiator_id = $history->m_user_id;
|
|||
|
|
$is_head = $initiator_id == $merchant_user_id ? 1 : 0;
|
|||
|
|
$original_price = $result->price;
|
|||
|
|
if ($group && $group->sku) {
|
|||
|
|
foreach ($group->sku as $skus) {
|
|||
|
|
if ($order->goods == $skus->name) {
|
|||
|
|
$original_price = $skus->price;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$result->single_buy = $original_price;
|
|||
|
|
$save_money = $original_price - $order->price;
|
|||
|
|
$result->save_money = number_format($save_money, 2);
|
|||
|
|
$count = sizeof($history_ids);
|
|||
|
|
$need = $history->status == 1 ? 0 : ($group->require_num - $count);//还差几人拼团成功
|
|||
|
|
$history->need_count = $need <= 0 ? 0 : $need;
|
|||
|
|
|
|||
|
|
$virtual_num = CollageGroupBatch::where('history_id', 0)->where('batch', $history->group_master_id)
|
|||
|
|
->get()
|
|||
|
|
->count();//本团虚拟用户数量
|
|||
|
|
$group_users = [];
|
|||
|
|
$users = MerchantUser::whereIn('id', $user_ids)->select('id', 'user_id', 'pic')
|
|||
|
|
->orderByRaw(DB::raw('FIELD(id,' . $str . ') desc'))->get();
|
|||
|
|
foreach ($users as $key => $value) {
|
|||
|
|
if ($value->user_id) {
|
|||
|
|
$group_users[$key]['avatar'] = $value->pic ?: User::DefaultAvatar;
|
|||
|
|
} else {
|
|||
|
|
$group_users[$key]['avatar'] = User::DefaultAvatar;
|
|||
|
|
}
|
|||
|
|
$group_users[$key]['is_initiator'] = $value->id == $initiator_id ? 1 : 0;
|
|||
|
|
}
|
|||
|
|
if ($virtual_num > 0) {
|
|||
|
|
for ($i = 1; $i <= $virtual_num; $i++) {
|
|||
|
|
$group_users[$key + $i]['avatar'] = User::DefaultAvatar;
|
|||
|
|
$group_users[$key + $i]['is_initiator'] = 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//$qrcode = $this->shareGroupMp($history->id);
|
|||
|
|
//当前用户是否参与此团
|
|||
|
|
$is_member = in_array($merchant_user_id, $user_ids) ? 1 : 0;
|
|||
|
|
$wechatUser = session('wechat.oauth_user.new');
|
|||
|
|
if ($wechatUser) {
|
|||
|
|
$openid = $wechatUser->getId();
|
|||
|
|
} else {
|
|||
|
|
$merchant_user = MerchantUser::where('id', $request->merchant_user_id)->first();
|
|||
|
|
$openid = $merchant_user->openid;
|
|||
|
|
}
|
|||
|
|
$jump_url = urlencode(env('APP_URL') . '/pu/#/groupData?id=' . $order->type_id.'&order_id='.
|
|||
|
|
$order->id.'&history_id='.$history->id.'&type='.$order->type);
|
|||
|
|
$url = env('APP_URL') . '/api/official/live/wechat/groupOrderAuth?merchant_id=' . $order->merchant_id .
|
|||
|
|
'&id=' . $order->type_id.'&order_id='. $order->id.'&history_id='.$history->id.'&type='.$order->type.
|
|||
|
|
'&url=' . $jump_url.'&from_openid=' . $openid;;
|
|||
|
|
$qr_code = Redis::get('group_order_details' . $order->id);
|
|||
|
|
if (!$qr_code) {
|
|||
|
|
$qr_code = $this->getPreviewQrcode($url);
|
|||
|
|
Redis::setex('group_order_details' . $order->id, 60 * 60 * 24 * 30, $qr_code);
|
|||
|
|
$qr_code = Redis::get('group_order_details' . $order->id);
|
|||
|
|
}
|
|||
|
|
if($order->num > 0){
|
|||
|
|
$order->single_price = $order->price / $order->num;
|
|||
|
|
}else{
|
|||
|
|
$order->single_price = 0;
|
|||
|
|
}
|
|||
|
|
$order->group_price = round($order->price / $order->num,2);
|
|||
|
|
return $this->success('ok', compact('group', 'order', 'group_users', 'history', 'result',
|
|||
|
|
'is_head','is_member','qr_code'));
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息,请稍后再试');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 个人中心 我发起的拼团(未过有效期)
|
|||
|
|
* */
|
|||
|
|
public function myGroups(Request $request)
|
|||
|
|
{
|
|||
|
|
$now = date('Y-m-d H:i:s');
|
|||
|
|
$merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$merchant_id = $request->merchant_id;
|
|||
|
|
$merchant_user = MerchantUser::find($merchant_user_id);
|
|||
|
|
if ($merchant_user) {
|
|||
|
|
// $histories = CollageGroupHistories::where('m_user_id',$m_user_id)->where('deadline','>',$now)
|
|||
|
|
//->where('status',0)->where('is_initiator',1)
|
|||
|
|
//->get();
|
|||
|
|
$m_order_ids = CollageGroupHistories::where('m_user_id', $merchant_user_id)->where('deadline', '>', $now)
|
|||
|
|
->where('status', 0)->pluck('m_order_id')
|
|||
|
|
->toArray();
|
|||
|
|
$pay_ids = TouristOrder::whereIn('id', $m_order_ids)->whereIn('pay_status', [1, 4])
|
|||
|
|
->where('merchant_id',$merchant_id)
|
|||
|
|
->whereNotNull('group_id')->pluck('id')->toArray();
|
|||
|
|
$histories = CollageGroupHistories::whereIn('m_order_id', $pay_ids)->get();
|
|||
|
|
foreach ($histories as $key => $value) {
|
|||
|
|
$type = $value->group->type;
|
|||
|
|
switch ($type){
|
|||
|
|
case 'course':
|
|||
|
|
$value->title = $value->group->$type ? $value->group->$type->title : '未获取';
|
|||
|
|
$value->pic = $value->group->$type ? $value->group->$type->thumb : '未获取';
|
|||
|
|
break;
|
|||
|
|
case 'activity':
|
|||
|
|
case 'service':
|
|||
|
|
case 'community':
|
|||
|
|
case 'consult':
|
|||
|
|
$value->title = $value->group->$type ? $value->group->$type->title : '未获取';
|
|||
|
|
$value->pic = $value->group->$type ? $value->group->$type->pic : '未获取';
|
|||
|
|
break;
|
|||
|
|
case 'shop':
|
|||
|
|
$value->title = $value->group->$type ? $value->group->$type->title : '未获取';
|
|||
|
|
$value->pic = $value->group->$type ? $value->group->$type->icon : '未获取';
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
$value->title = null;
|
|||
|
|
$value->pic = null;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
//目前参与人员
|
|||
|
|
$user_ids = CollageGroupBatch::where('batch',$value->group_master_id)
|
|||
|
|
->pluck('history_id')->toArray();
|
|||
|
|
$count = count($user_ids);
|
|||
|
|
$value->type = $type;
|
|||
|
|
$value->type_id = $value->group->type_id;
|
|||
|
|
$need_count = $value->group->require_num - $count;
|
|||
|
|
if($need_count ==0){
|
|||
|
|
unset($histories[$key]);
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
$value->need_count = $need_count;
|
|||
|
|
unset($value->group);
|
|||
|
|
}
|
|||
|
|
$histories = array_values($histories->toArray());
|
|||
|
|
return $this->success('ok', $histories);
|
|||
|
|
} else {
|
|||
|
|
return $this->success('ok', []);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 参与别人拼单
|
|||
|
|
* **/
|
|||
|
|
public function joinGroup(Request $request)
|
|||
|
|
{
|
|||
|
|
$id = $request->id;
|
|||
|
|
$merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$sku_id = $request->sku_id;
|
|||
|
|
$openid = null;
|
|||
|
|
$num = $request->num ?? 1;
|
|||
|
|
$from_open_id = $request->from_open_id;
|
|||
|
|
$history = CollageGroupHistories::where('id',$id)->where('is_initiator',1)->where('status',0)->first();
|
|||
|
|
if (!$history) {
|
|||
|
|
return $this->failure('你来晚了一步~本次拼团已被他人抢先一步完成');
|
|||
|
|
}
|
|||
|
|
$group = CollageGroup::where('id', $history->group_id)->select('id', 'type', 'type_id', 'describe', 'require_num','sku','price')
|
|||
|
|
->first();
|
|||
|
|
$team_order = TouristOrder::where('id', $history->m_order_id)->whereIn('pay_status', [1, 4])->first();
|
|||
|
|
if (!$team_order) {
|
|||
|
|
return $this->failure('拼团订单不存在');
|
|||
|
|
}
|
|||
|
|
$history_ids = CollageGroupBatch::where('batch',$id)->pluck('history_id')->toArray();
|
|||
|
|
if(sizeof($history_ids) >= $group->require_num){
|
|||
|
|
return $this->failure('你来晚了一步~本次拼团已被他人抢先一步完成');
|
|||
|
|
}
|
|||
|
|
$now = date('Y-m-d H:i:s');
|
|||
|
|
if ($history->deadline < $now) return $this->failure('你来晚了一步~本次拼团有效期已过');
|
|||
|
|
$skus = json_decode($group->sku, true) ?? null;
|
|||
|
|
if($skus && sizeof($skus)>0 &&$sku_id){
|
|||
|
|
$skus = array_column($skus, null, 'sku_id');
|
|||
|
|
$sku = $skus[$sku_id];
|
|||
|
|
$price = $sku['discount_price'];
|
|||
|
|
}else{
|
|||
|
|
$price = $group->price;
|
|||
|
|
}
|
|||
|
|
$pay_price = number_format($num * $price,2);
|
|||
|
|
$user_group = CollageGroupHistories::where('group_id', $history->group_id)
|
|||
|
|
->where('m_user_id', $merchant_user_id)
|
|||
|
|
->first();
|
|||
|
|
$order = TouristOrder::where('type',$group->type)->where('type_id',$group->type_id)
|
|||
|
|
->where('account_id',$merchant_user_id)
|
|||
|
|
->where('group_id',$group->id)
|
|||
|
|
->whereIn('pay_status',[1,4])
|
|||
|
|
->first();
|
|||
|
|
if($user_group && $order){
|
|||
|
|
if($group->type == 'community'){
|
|||
|
|
$class = CommunityActivity::where('id',$group->type_id)->value('class');
|
|||
|
|
if($class == 'one' || $group->type == 'course'){
|
|||
|
|
return $this->failure('不能重复参加');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$merchant_id = $request->merchant_id;
|
|||
|
|
$wechatUser = session('wechat.oauth_user.new');
|
|||
|
|
if ($wechatUser) {
|
|||
|
|
$openid = $wechatUser->getId();
|
|||
|
|
} else {
|
|||
|
|
$merchant_user = MerchantUser::where('id', $request->merchant_user_id)->first();
|
|||
|
|
$openid = $merchant_user->openid;
|
|||
|
|
}
|
|||
|
|
$trade_no = $this->getTradeNo();
|
|||
|
|
$order = array(
|
|||
|
|
'open_id' => $openid,
|
|||
|
|
'price' => $pay_price,
|
|||
|
|
'num' => $num,
|
|||
|
|
'pay_type' => 'wechat',
|
|||
|
|
'type' => $team_order->type,
|
|||
|
|
'type_id' => $team_order->type_id,
|
|||
|
|
'pay_status' => 0,
|
|||
|
|
'trade_no' => $trade_no,
|
|||
|
|
'withdrawal_radio' => 100,
|
|||
|
|
'from_openid' => $request->from_openid,
|
|||
|
|
'merchant_id' => $merchant_id,
|
|||
|
|
'share_channel_id' => $request->share_channel_id,
|
|||
|
|
'alliance_id' => $request->alliance_id,
|
|||
|
|
'group_id' => $team_order->group_id,
|
|||
|
|
'name' => $request->name ?? ($request->linkmen[0]['name'] ?? '未获取'),
|
|||
|
|
'mobile' => $request->mobile ?? ($request->linkmen[0]['mobile'] ?? '未获取'),
|
|||
|
|
'area_code' => $request->area_code ??($request->linkmen[0]['area_code'] ?? '未获取'),
|
|||
|
|
'channel' => 0,
|
|||
|
|
'account_id' => $merchant_user_id,
|
|||
|
|
'goods' => $team_order->goods,
|
|||
|
|
'desc' => $team_order->desc,
|
|||
|
|
'linkmen' => isset($request->linkmen) ? json_encode($request->linkmen) : '',
|
|||
|
|
'insurance' => isset($request->insurance) ? $request->insurance : 0,
|
|||
|
|
'insurance_info' => (isset($request->insurance) && $request->insurance == 1) ? json_encode($request->insurance_info) : null,
|
|||
|
|
);
|
|||
|
|
$order = TouristOrder::create($order);
|
|||
|
|
$type = $group->type;
|
|||
|
|
if($group->type == 'consult'){
|
|||
|
|
$config = Consultation::where('id', $group->type_id)->first();
|
|||
|
|
$Consultation = new ConsultationRecords();
|
|||
|
|
$Consultation->anchor_id = 0;
|
|||
|
|
$Consultation->merchant_id = $merchant_id;
|
|||
|
|
$Consultation->merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$Consultation->consulation_id = $order->type_id;
|
|||
|
|
$Consultation->name = $request->name;
|
|||
|
|
$Consultation->phone = $request->phone;
|
|||
|
|
$Consultation->price = $pay_price;
|
|||
|
|
$Consultation->num = $num;
|
|||
|
|
$Consultation->type = $request->type ?? 'voice';
|
|||
|
|
$Consultation->class = $request->class;
|
|||
|
|
$Consultation->expect = $request->expect;
|
|||
|
|
$Consultation->desc = $request->desc;
|
|||
|
|
$Consultation->pay_status = 0;
|
|||
|
|
$Consultation->duration = $config->duration;
|
|||
|
|
$Consultation->Remaining_duration = $config->duration * 60;
|
|||
|
|
$Consultation->viewer_id = 0;
|
|||
|
|
$Consultation->trade_no = $trade_no;
|
|||
|
|
$Consultation->from_open_id = $from_open_id;
|
|||
|
|
$Consultation->save();
|
|||
|
|
}
|
|||
|
|
$CollageGroupHistories = new CollageGroupHistories();
|
|||
|
|
$CollageGroupHistories->m_user_id = $merchant_user_id;
|
|||
|
|
$CollageGroupHistories->group_id = $order->group_id;
|
|||
|
|
$CollageGroupHistories->m_order_id = $order->id;
|
|||
|
|
$CollageGroupHistories->group_master_id = $id;
|
|||
|
|
$CollageGroupHistories->is_initiator = 0;
|
|||
|
|
$CollageGroupHistories->status = 0;
|
|||
|
|
$CollageGroupHistories->deadline =$history->deadline;
|
|||
|
|
$CollageGroupHistories->save();
|
|||
|
|
$callback = config('app.url') . '/api/app/callback/Community/' . $trade_no;
|
|||
|
|
$attributes = array(
|
|||
|
|
'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP...
|
|||
|
|
'body' => $group->$type->title,
|
|||
|
|
'detail' => $group->$type->title,
|
|||
|
|
'out_trade_no' => $trade_no,
|
|||
|
|
'total_fee' => $pay_price * 100,
|
|||
|
|
'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
|
|||
|
|
'openid' => $openid,
|
|||
|
|
'order_id' => $order->id,
|
|||
|
|
);
|
|||
|
|
switch ($type){
|
|||
|
|
case 'course':
|
|||
|
|
$user_course = new UserCourses();
|
|||
|
|
$user_course->user_id = 0;
|
|||
|
|
$user_course->course_id = $team_order->type_id;
|
|||
|
|
$user_course->type = 'business';
|
|||
|
|
$user_course->trade_no = $trade_no;
|
|||
|
|
$user_course->status = 0;
|
|||
|
|
$user_course->open_id = $openid;
|
|||
|
|
$user_course->merchant_user_id = $merchant_user_id;
|
|||
|
|
$user_course->save();
|
|||
|
|
break;
|
|||
|
|
case 'shop':
|
|||
|
|
$ShopRecive = new ShopRecive();
|
|||
|
|
if(!$request->name || !$request->mobile || !$request->address){
|
|||
|
|
return $this->failure('姓名 手机号 收货地址都不能为空');
|
|||
|
|
}
|
|||
|
|
$ShopRecive->name = $request->name;
|
|||
|
|
$ShopRecive->mobile = $request->mobile;
|
|||
|
|
$ShopRecive->address = $request->address;
|
|||
|
|
$ShopRecive->order_id = $order->id;
|
|||
|
|
$ShopRecive->order_status = 0;
|
|||
|
|
$ShopRecive->account_id = $merchant_user_id;
|
|||
|
|
$ShopRecive->merchant_id = $merchant_id;
|
|||
|
|
$ShopRecive->save();
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
$wx_pay = \WechatService::officialPay($attributes);
|
|||
|
|
$order->save();
|
|||
|
|
//同步订单相关的用户
|
|||
|
|
\App\Jobs\SyncSaasUserByOrder::dispatch($order)->onQueue('love');
|
|||
|
|
return $this->success('ok', $wx_pay);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|