merchant_id) ->where('id',$order->type_id) ->first(); $gain = json_decode($level->gain); $extend = json_decode($order->extend); if (!$gain){ return; } $time = time(); //默认数据 赠送福恋小程序一个月vip 团契卡 待领取的 $card = new FellowingCard(); $card->share_user_id = 0; $card->user_id = 69938; $card->name = '【天路合一】购买会员权益系统自动赠送:'.$order->account_id; $card->num = 1; $card->remain_num = 1; $card->rank_id = 9; $card->month = 1; $card->day = 0; $card->save(); $data = [ [ 'merchant_user_id' => $order->account_id, 'merchant_id' => $order->merchant_id, 'spread_merchant_id' => 0, 'level_id' => $level->id, 'type' => 'vip', 'type_id' => $card->id, 'order_id' => $order->id, 'created_at' => date('Y-m-d H:i:s',$time) ] ]; $model = new SaasMemberVipGain(); foreach ($gain as $item){ $item = [ 'merchant_user_id' => $order->account_id, 'merchant_id' => $order->merchant_id, 'spread_merchant_id' => $extend->spread_merchant_id ?? 0, 'level_id' => $level->id, 'type' => $item->type ?? '', 'type_id' => $item->id ?? 0, 'order_id' => $order->id, 'created_at' => date('Y-m-d H:i:s',$time) ]; $where = [ ['merchant_user_id','=',$item['merchant_user_id']], ['type','=',$item['type']], ['type_id','=',$item['type_id']], ['level_id','=',$item['level_id']], ['order_id','=',$order->id], ]; $check = $model->where($where)->first(); if($check){ continue; } $data[] = $item; } $model->insert($data); } /** * 使用权益 * @param $type * @param $data * @return void */ public function useGain($type, $data) { if (empty($type)) { return null; } return $this->$type($data); } /** * 随机生成16位数,作为本地服务器的支付订单ID */ private function getTradeNO() { $dateline = time(); $mix_1 = rand(100, 999); $mix_2 = rand(100, 999); return $dateline . $mix_1 . $mix_2; } /** * 服务 * @param $data * @return void */ private function service($data) { $wechat_user = session('wechat.oauth_user.new'); $merchant_user = MerchantUsers::select('openid', 'mobile', 'nickname')->where('id', $data['merchant_user_id']) ->first(); if ($wechat_user) { $openid = $wechat_user->getId(); } else { $openid = $merchant_user->openid; } $result = CommunityActivity::where('id', $data['type_id'])->first(); $level_data = SaasMemberLevel::where('id',$data['level_id'])->first(); $gain = json_decode($level_data->gain,true); $sku_id = null; foreach ($gain as $item){ if($item['id'] == $data['type_id']){ $sku_id = $item['sku_id'] ?? null; break; } } $desc = $goods = $result['title']; if ($sku_id) { $skus = json_decode($result['sku'], true); $skus = array_column($skus, null, 'sku_id'); $sku = $skus[$sku_id] ?? []; $sku_name = $sku['name'] ?? '未知规格'; $desc = $result['title'] . '-' . $sku_name; $goods = $sku_name; } $level_order = TouristOrder::find($data['order_id']); $linkmen = $level_order->linkmen ? json_decode($level_order->linkmen,true) : []; $trade_no = $this->getTradeNO(); $tourist_order = new TouristOrder(); $tourist_order->open_id = $openid; $tourist_order->price = 0; $tourist_order->pay_type = 'vip_gain'; $tourist_order->type = 'community'; $tourist_order->type_id = $result->id; $tourist_order->trade_no = $trade_no; $tourist_order->desc = $desc ?? ''; $tourist_order->goods = $goods ?? ''; // $tourist_order->merchant_id = $data['spread_merchant_id']; $tourist_order->merchant_id = $result->merchant_id ?? $data['spread_merchant_id']; $tourist_order->account_id = $data['merchant_user_id']; $tourist_order->withdrawal_radio = 100; $tourist_order->alliance_id = null; $tourist_order->pay_status = 1; $tourist_order->linkmen = $level_order->linkmen ?? ''; $tourist_order->name = $linkmen['name'] ?? ''; $tourist_order->mobile = $linkmen['mobile'] ?? ''; $tourist_order->sku_id = $sku_id; $tourist_order->save(); $users = new UserMember(); $users->type = 'community'; $users->type_id = $data['type_id']; $users->m_id = $data['spread_merchant_id']; $users->m_user_id = $data['merchant_user_id']; $users->pay_type = 'wechat'; $users->save(); } /** * 测评 * @param $data * @return void */ private function evaluation($data) { $merchant_id = $data['spread_merchant_id']; $wechat_user = session('wechat.oauth_user.new'); $MerchantUser = MerchantUsers::select('openid', 'mobile', 'nickname')->where('id', $data['merchant_user_id']) ->first(); if ($wechat_user) { $open_id = $wechat_user->getId(); } else { $open_id = $MerchantUser->openid; } $merchant_evaluates = MerchantEvaluate::where('id', $data['type_id']) ->first(); // if($merchant_evaluates->type ==1){ // $result = EvaluateService::testDetails($data['type_id']); // }else{ $result = EvaluateDetail::where('test_item_id', $merchant_evaluates['test_item_id']) ->first(); // } $trade_no = $this->getTradeNO(); $level_order = TouristOrder::find($data['order_id']); $linkmen = $level_order->linkmen ? json_decode($level_order->linkmen,true) : []; $tourist_order = new TouristOrder(); $tourist_order->open_id = $open_id; $tourist_order->price = 0; $tourist_order->num = 1; $tourist_order->pay_type = 'vip_gain'; $tourist_order->type = 'evaluate'; $tourist_order->type_id = $merchant_evaluates->id; $tourist_order->goods = '评测_' . $result['title']; $tourist_order->trade_no = $trade_no; $tourist_order->withdrawal_radio = 100; //分成比例 $tourist_order->from_openid = null; $tourist_order->share_channel_id = null; $tourist_order->alliance_id = null; $tourist_order->name = $linkmen['name'] ?? '空'; $tourist_order->mobile = $linkmen['mobile'] ?? '空'; $tourist_order->account_id = $data['merchant_user_id']; // $tourist_order->merchant_id = $merchant_id; $tourist_order->merchant_id = $merchant_evaluates->merchant_id ?? $merchant_id; $tourist_order->channel = 0; $tourist_order->desc = $result['subtitle']; $tourist_order->area_code = null; $tourist_order->linkmen = $level_order->linkmen ?? ''; $tourist_order->pay_status = 1; $tourist_order->save(); } /** * 课程 * @param $data * @return void */ private function course($data) { $merchant_user_id = $data['merchant_user_id'];//用户id $wechat_user = session('wechat.oauth_user.new'); if ($wechat_user) { $openid = $wechat_user->getId(); } else { $merchant_user = MerchantUser::where('id', $merchant_user_id)->first(); $openid = $merchant_user->openid; } $course = Course::where('id', $data['type_id'])->first(); $anchor = Anchor::where('m_id',$data['spread_merchant_id'])->first(); $MerchantUsers = MerchantUser::where('id', $data['merchant_user_id'])->first(); $trade_no = \CommonUtilsService::getTradeNO(); $level_order = TouristOrder::find($data['order_id']); $linkmen = $level_order->linkmen ? json_decode($level_order->linkmen,true) : []; $tourist_order = new TouristOrder(); $tourist_order->open_id = $openid; $tourist_order->price = 0; $tourist_order->pay_type = 'vip_gain'; $tourist_order->type = 'course'; $tourist_order->goods = ''; $tourist_order->type_id = $data['type_id']; $tourist_order->trade_no = $trade_no; $tourist_order->desc = $course->title; $tourist_order->from_openid = null; $tourist_order->share_channel_id = null; // $tourist_order->merchant_id = $data['spread_merchant_id']; $tourist_order->merchant_id = $course->merchant_id ?? $data['spread_merchant_id']; $tourist_order->account_id = $data['merchant_user_id']; $tourist_order->name = $linkmen['name'] ?? '空'; $tourist_order->area_code = ''; $tourist_order->alliance_id = null; $tourist_order->mobile = $linkmen['mobile'] ?? '空'; $tourist_order->withdrawal_radio = 100; $tourist_order->pay_status = 1; $tourist_order->linkmen = $level_order->linkmen ?? ''; $user_course = new UserCourses(); $user_course->user_id = 0; $user_course->course_id = $data['type_id']; $user_course->type = 'business'; $user_course->trade_no = $trade_no; $user_course->open_id = $openid; $user_course->merchant_user_id = $merchant_user_id; $user_course->status = 1; $tourist_order->save(); $user_course->save(); } /** * 活动 * @param $data * @return void */ private function activity($data) { $wechat_user = session('wechat.oauth_user.new'); $merchant_user = MerchantUsers::select('openid', 'mobile', 'nickname')->where('id', $data['merchant_user_id']) ->first(); if ($wechat_user) { $openid = $wechat_user->getId(); } else { $openid = $merchant_user->openid; } $result = CommunityActivity::where('id', $data['type_id'])->first(); $level_data = SaasMemberLevel::where('id',$data['level_id'])->first(); $gain = json_decode($level_data->gain,true); $sku_id = null; foreach ($gain as $item){ if($item['id'] == $data['type_id']){ $sku_id = $item['sku_id'] ?? null; break; } } $desc = $goods = $result['title']; if ($sku_id) { $skus = json_decode($result['sku'], true); $skus = array_column($skus, null, 'sku_id'); $sku = $skus[$sku_id] ?? []; $sku_name = $sku['name'] ?? '未知规格'; $desc = $result['title'] . '-' . $sku_name; $goods = $sku_name; } $level_order = TouristOrder::find($data['order_id']); $linkmen = $level_order->linkmen ? json_decode($level_order->linkmen,true) : []; $trade_no = $this->getTradeNO(); $tourist_order = new TouristOrder(); $tourist_order->open_id = $openid; $tourist_order->price = 0; $tourist_order->pay_type = 'vip_gain'; $tourist_order->type = 'community'; $tourist_order->type_id = $result->id; $tourist_order->trade_no = $trade_no; $tourist_order->desc = $desc ?? ''; $tourist_order->goods = $goods ?? ''; // $tourist_order->merchant_id = $data['spread_merchant_id']; $tourist_order->merchant_id = $result->merchant_id ?? $data['spread_merchant_id']; $tourist_order->account_id = $data['merchant_user_id']; $tourist_order->withdrawal_radio = 100; $tourist_order->alliance_id = null; $tourist_order->pay_status = 1; $tourist_order->linkmen = $level_order->linkmen ?? ''; $tourist_order->name = $linkmen['name'] ?? ''; $tourist_order->mobile = $linkmen['mobile'] ?? ''; $tourist_order->sku_id = $sku_id; $tourist_order->save(); $users = new UserMember(); $users->type = 'community'; $users->type_id = $data['type_id']; $users->m_id = $data['spread_merchant_id']; $users->m_user_id = $data['merchant_user_id']; $users->pay_type = 'wechat'; $users->save(); } /** * 咨询 * @param $data * @return void */ private function consultation($data) { $wechat_user = session('wechat.oauth_user.new'); $openId = null; if ($wechat_user){ $openId = $wechat_user->getId(); } $config = Consultation::where('id', $data['type_id'])->first(); $trade_no = $this->getTradeNO(); $level_order = TouristOrder::find($data['order_id']); $linkmen = $level_order->linkmen ? json_decode($level_order->linkmen,true) : []; $consultation = new ConsultationRecords(); $consultation->anchor_id = $config->consult_account_id; $consultation->merchant_id = $data['spread_merchant_id']; $consultation->merchant_user_id = $data['merchant_user_id']; $consultation->consulation_id = $data['type_id']; $consultation->name = $linkmen['name'] ?? '空'; $consultation->phone = $linkmen['mobile'] ?? '空'; $consultation->price = 0; $consultation->num = 1; $consultation->type = 'voice'; $consultation->class = ''; $consultation->expect = ''; $consultation->desc = 'vip权益兑换'; $consultation->pay_status = 1;// $consultation->duration = $config->duration; $consultation->Remaining_duration = $config->duration * 60; $consultation->viewer_id = 0; $consultation->trade_no = $trade_no; $consultation->from_open_id = ''; $consultation->save(); $tourist_order = new TouristOrder(); $tourist_order->open_id = $openId; $tourist_order->price = 0; $tourist_order->type_id = $data['type_id']; $tourist_order->pay_type = 'vip_gain'; $tourist_order->type = 'consult'; $tourist_order->withdrawal_radio = 100; $tourist_order->pay_status = 1;// $tourist_order->trade_no = $trade_no; $tourist_order->group_id = null; $tourist_order->from_openid = null; $tourist_order->share_channel_id = null; $tourist_order->name = $linkmen['name'] ?? '空';; $tourist_order->desc = $config->title; $tourist_order->mobile = $linkmen['mobile'] ?? '空';; $tourist_order->merchant_id = $data['spread_merchant_id']; $tourist_order->account_id = $data['merchant_user_id']; $tourist_order->alliance_id = null; $tourist_order->linkmen = $level_order->linkmen ?? ''; $tourist_order->save(); } /** * 商品 */ private function shop($data) { $wechat_user = session('wechat.oauth_user.new'); $merchant_user_id = $data['merchant_user_id'];//用户id if ($wechat_user) { $openid = $wechat_user->getId(); } else { $openid = MerchantUsers::where('id', $merchant_user_id)->value('openid'); } $result = MerchantShop::where('id', $data['type_id'])->first(); $level_data = SaasMemberLevel::where('id',$data['level_id'])->first(); $gain = json_decode($level_data->gain,true); $sku_id = null; foreach ($gain as $item){ if($item['id'] == $data['type_id']){ $sku_id = $item['sku_id'] ?? null; break; } } $desc = $goods = $result['title']; if ($sku_id) { $skus = json_decode($result['sku'], true); $skus = array_column($skus, null, 'sku_id'); $sku = $skus[$sku_id] ?? []; $sku_name = $sku['name'] ?? '未知规格'; $desc = $result['title'] . '-' . $sku_name; $goods = $sku_name; } $level_order = TouristOrder::find($data['order_id']); $linkmen = $level_order->linkmen ? json_decode($level_order->linkmen,true) : []; $trade_no = $this->getTradeNo(); $tourist_order = new TouristOrder(); $tourist_order->open_id = $openid; $tourist_order->price = 0; $tourist_order->pay_type = 'vip_gain'; $tourist_order->type = 'shop'; $tourist_order->num = 1; $tourist_order->type_id = $data['type_id']; $tourist_order->trade_no = $trade_no; $tourist_order->group_id = null; $tourist_order->desc = $desc ?? ''; $tourist_order->from_openid = null; $tourist_order->share_channel_id = null; $tourist_order->merchant_id = $result->merchant_id ?? $data['spread_merchant_id']; $tourist_order->account_id = $data['merchant_user_id']; $tourist_order->name = $linkmen['name'] ?? '空'; $tourist_order->mobile = $linkmen['mobile'] ?? '空'; $tourist_order->withdrawal_radio = 100; $tourist_order->goods = $goods ?? ''; $tourist_order->alliance_id = null; $tourist_order->pay_status = 1; $tourist_order->address = $data['shop_data']['address'] ?? ''; $tourist_order->save(); $shop_recive = new ShopRecive(); $shop_recive->name = $data['shop_data']['name'] ?? ''; $shop_recive->mobile = $data['shop_data']['mobile'] ?? ''; $shop_recive->address = $data['shop_data']['address'] ?? ''; $shop_recive->order_status = 0; $shop_recive->account_id = $data['merchant_user_id']; $shop_recive->merchant_id = $result->merchant_id ?? $data['spread_merchant_id']; $shop_recive->order_id = $tourist_order->id; $shop_recive->save(); } }