12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2022/3/16
- * Time: 16:39
- */
- namespace App\Service;
- use App\Log;
- use App\Models\AdqAccountBindPidConf;
- use App\Models\AdqUser;
- use App\Models\CapacityUser;
- use App\Models\CorpMapping;
- use App\Models\Customer;
- use App\Models\CustomerDetails;
- use App\Models\DjDirectInvestmentOrder;
- use App\Models\DjOrder;
- use App\Models\DjUser;
- use App\Models\MassPopularizData;
- use App\Models\OfficialAccount;
- use App\Models\OfficialWebUserActionSetId;
- use App\Models\PlatformApp;
- use App\Models\Tencent\TxClickRecord;
- use App\Models\Tencent\YxOrder;
- use App\Models\TencentAdConf;
- use App\RedisModel;
- use App\Service\Order\YingKeService;
- use App\Support\EmailQueue;
- class DjOrderService
- {
- # 杭州猎豆 | 剧有戏 - 柚子 - 订单数据保存
- public static function youziOrderSave($orderPay, $source, $status, $platformType, $type = 1)
- {
- // 根据企业id映射关系表查询自己的企业id
- $corpList = CorpMapping::getCorpList($platformType);
- $systemCorpid = isset($corpList[$orderPay['mpAppId']]['corpid']) ? $corpList[$orderPay['mpAppId']]['corpid'] : '';
- $orderPay['system_corpid'] = $systemCorpid;
- $orderPay['self_order_type'] = 1;
- // 数据源ID不为空时,根据数据源ID查询公众号APPID,柚子平台不直接返回公众号APPID
- if(!empty($orderPay['userActionSetId'])) {
- $appList = TencentAdConf::getAppList();
- $bindAppId = isset($appList[$orderPay['userActionSetId']]['app_id']) ? $appList[$orderPay['userActionSetId']]['app_id'] : '';
- $orderPay['bind_app_id'] = $bindAppId;
- }
- if(empty($orderPay['bind_app_id'])) {
- $accountInfo = OfficialAccount::query()->where('mp_app_id', $orderPay['mpAppId'])->first();
- $orderPay['bind_app_id'] = $accountInfo->mp_name ?? null;
- }
- // 企微id为空并且公众号APPID不为空,则根据公众号APPID查询对应的企微id
- if(empty($orderPay['system_corpid']) && !empty($orderPay['bind_app_id'])) {
- $systemCorpid = self::getSystemCorpidByAppId($orderPay['bind_app_id']);
- $orderPay['system_corpid'] = $systemCorpid;
- }
- // 默认运营带来的订单(非系统企微用户)
- $externalUserId = null;
- $userId = null;
- $params = $orderPay['params'] ?? ($orderPay['channelId'] ?? null);
- if(!empty($params)) {
- $params = urldecode($params);
- if(strstr($params, '|')) {
- $paramsData = explode('|', $params);
- $corpid = $paramsData[0] ?? null;
- $userId = $paramsData[1] ?? null;
- $externalUserId = $paramsData[2] ?? null;
- // 如果接收到了透传回来的企微ID,则覆盖之前根据公众号查询到的企微id
- if(!empty($corpid)) {
- $orderPay['system_corpid'] = $corpid;
- }
- } else {
- $externalUserId = $params;
- }
- }
- # 当此参数为空时,柚子就不给返回了,因此这里做一下兼容处理
- $orderPay['selfUnionId'] = $orderPay['selfUnionId'] ?? null;
- // 查询企微用户相关信息
- $responseData = Customer::getCustomerRegisterTime($orderPay['system_corpid'], $orderPay['selfUnionId'], $externalUserId, $userId);
- $registerTime = $responseData['register_time'];
- $userActionSetId = $responseData['user_action_set_id'];
- $accountId = $responseData['account_id'];
- $unionid = $responseData['unionid'];
- $joinType = $responseData['join_type'];
- $adType = $responseData['ad_type'];
- $selfExternalUserId = $responseData['external_userid'];
- $selfUserId = $responseData['self_user_id'];
- if(empty($registerTime)) {
- $orderPay['is_ad_user'] = 0;
- // 系统中没有查询到对应的注册时间,直接使用柚子返回的注册时间,此订单为运营订单
- } else {
- // 可以查询到用户的企微关注时间,就用企微关注时间作为用户的注册时间,并且认为是企微用户,此订单为投放订单
- $orderPay['mpUserRegisterTime'] = $registerTime * 1000;
- $orderPay['is_ad_user'] = 1;
- }
- // 查询到的adq投放账号对应的web数据源ID不为空,将查询出来的数据源ID写入订单表中(覆盖柚子回传回来的数据源ID),为之后的adq订单上报做准备
- if(!empty($userActionSetId)) {
- $orderPay['userActionSetId'] = $userActionSetId;
- }
- // 查询到的用户unionid不为空,那么将我们自己的unionid写入订单表中(覆盖柚子返回的数据),为之后的mp订单上报做准备
- if(!empty($unionid)) {
- $orderPay['selfUnionId'] = $unionid;
- }
- if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId) {
- Log::logInfo('柚子平台-回传客服ID与系统查询客服ID不一致', [
- 'order_id' => $orderPay['orderId'],
- 'self_user_id' => $selfUserId,
- 'corp_user_id' => $userId,
- ], 'callBackOrderParamsError');
- }
- if(!empty($externalUserId) && 0 == $orderPay['is_ad_user'] && 1 == $type) {
- Log::logInfo('柚子平台-接收到透传参数后找不到企微用户', [
- 'order_id' => $orderPay['orderId'],
- 'params' => $params
- ], 'callBackOrderParamsError');
- }
- $orderPay['adq_account_id'] = $accountId;// adq投放账号,主要是为了可以在adq回传时使用
- $orderPay['join_type'] = $joinType;// 用户添加渠道(最新一次添加客服的渠道,由企微返回,这里是为了之后统计数据冗余)
- $orderPay['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;// 用户外部联系人ID
- $orderPay['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;// 企微客服user_id
- $orderPay['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 1mp 2adq,获取失败时归属到mp非运营回收中
- // 推广数据检测区分新老客户-当月下单是新客户
- if (isset($orderPay['playletActivityId']) && !empty($orderPay['playletActivityId'])) {
- if (
- isset($orderPay['mpUserRegisterTime'], $orderPay['createdTs'])
- &&
- (!empty($orderPay['mpUserRegisterTime']) && !empty($orderPay['createdTs']))
- ) {
- $curMonth = date('Y-m-01 00:00:00', intval($orderPay['createdTs'] / 1000));
- $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
- $regTime = date('Y-m-d H:i:s', ($orderPay['mpUserRegisterTime'] / 1000));
- if ($regTime >= $curMonth && $regTime < $aftMonth) {
- $orderPay['pCustomerType'] = 1;// 下单时间在注册时间的自然月内,新用户
- } else {
- $orderPay['pCustomerType'] = 2;// 老用户
- }
- }
- }
- if(2 == $type) {
- # 剧有戏订单 使用小程序openid赋值给unionid字段
- $orderPay['selfUnionId'] = $orderPay['mpOpenid'];
- $orderPay['external_userid'] = empty($orderPay['external_userid']) ? $orderPay['selfUnionId'] : $orderPay['external_userid'];
- if(1 == $orderPay['self_order_type']) {
- // 柚子平台自己做adq回传逻辑
- $webUserActionSetIdList = OfficialWebUserActionSetId::WEB_USER_SET_ID_LIST;
- if(!empty($orderPay['userActionSetId']) && in_array($orderPay['userActionSetId'], $webUserActionSetIdList)) {
- $orderPay['self_order_type'] = 2;
- }
- }
- $orderPay['is_ad_user'] = 1;
- if((1 == $orderPay['self_order_type'] && empty($orderPay['bind_app_id'])) ||
- (2 == $orderPay['self_order_type']) && empty($orderPay['adq_account_id'])) {
- $orderPay['is_ad_user'] = 0;
- }
- }
- $payType = 1;// 安卓(小程序虚拟支付)
- # 获取订单金额分成比例(不区分安卓还是ios)
- // $shareInProportionArr = OrderService::getOrderShareInProportion(1);
- $playletName = $orderPay['playletName'] ?? null;
- $shareInProportionArr = OrderService::getOrderShareInProportionNew($source, $playletName, $orderPay['sys_group_id']);
- $shareInProportion = $shareInProportionArr[$payType] ?? 1;
- # 计算分成后的金额
- $orderPay['origin_pay_money'] = $orderPay['payMoney'];
- if(3 == $orderPay['sys_group_id']) {
- $orderPay['payMoney'] = $orderPay['origin_pay_money'] * $shareInProportion;
- }
- DjOrder::orderDataSaveFromYouzi($orderPay, $source, $status, $platformType);
- }
- # 杭州猎豆 - 冰甜剧场(嘉书小程序) - 订单数据保存
- public static function jiashuOrderSave($orderPay, $appId)
- {
- // 根据渠道channel获取公众号appid
- $channelList = TencentAdConf::getChannelList();
- $bindAppId = isset($channelList[$orderPay['channel']]['app_id']) ? $channelList[$orderPay['channel']]['app_id'] : '';
- $orderPay['bind_app_id'] = $bindAppId;
- $orderPay['system_corpid'] = null;
- $orderPay['selfUnionId'] = null;
- // 根据公众号appid反查企业corpid
- if(!empty($bindAppId)) {
- $systemCorpid = self::getSystemCorpidByAppId($bindAppId);
- $orderPay['system_corpid'] = $systemCorpid;
- }
- // 将openid写入mp_open_id字段
- $orderPay['mpOpenId'] = $orderPay['openid'];
- $orderPay['maAppId'] = $orderPay['miniAppid'] ?? null;
- $orderPay['is_ad_user'] = 0;
- $userId = null;
- $externalUserId = null;
- $params = $orderPay['params'] ?? null;
- if(!empty($params)) {
- $params = urldecode($params);
- if(strstr($params, '|')) {
- $paramsData = explode('|', $params);
- $corpid = $paramsData[0] ?? null;
- $userId = $paramsData[1] ?? null;
- $externalUserId = $paramsData[2] ?? null;
- // 如果接收到了透传回来的企微ID,则覆盖之前根据公众号查询到的企微id
- if(!empty($corpid)) {
- $orderPay['system_corpid'] = $corpid;
- }
- } else {
- $externalUserId = $params;
- }
- }
- // 查询用户最早注册时间
- $responseData = Customer::getCustomerRegisterTime($orderPay['system_corpid'], $orderPay['selfUnionId'], $externalUserId, $userId);
- $registerTime = $responseData['register_time'];
- $userActionSetId = $responseData['user_action_set_id'];
- $accountId = $responseData['account_id'];
- $unionid = $responseData['unionid'];
- $joinType = $responseData['join_type'];
- $adType = $responseData['ad_type'];
- $selfExternalUserId = $responseData['external_userid'];
- $selfUserId = $responseData['self_user_id'];
- if(!empty($registerTime)) {
- $orderPay['mpUserRegisterTime'] = $registerTime;
- $orderPay['is_ad_user'] = 1;
- } else {
- $orderPay['mpUserRegisterTime'] = strtotime($orderPay['userCreateTs']);
- }
- if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId) {
- Log::logInfo('嘉书小程序-回传客服ID与系统查询客服ID不一致', [
- 'order_id' => $orderPay['orderId'],
- 'self_user_id' => $selfUserId,
- 'corp_user_id' => $userId,
- ], 'callBackOrderParamsError');
- }
- if(!empty($externalUserId) && 0 == $orderPay['is_ad_user']) {
- Log::logInfo('嘉书小程序-接收到透传参数后找不到企微用户', [
- 'order_id' => $orderPay['orderId'],
- 'params' => $params
- ], 'callBackOrderParamsError');
- }
- $channelArr = config('jiashu.channel');
- $orderPay['userActionSetId'] = $userActionSetId;
- $orderPay['selfUnionId'] = $unionid;
- $orderPay['adq_account_id'] = $accountId;
- $orderPay['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
- $orderPay['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
- $orderPay['self_order_type'] = !empty($adType) ? $adType : 1;// 订单类型 为空时归属为mp订单 1mp 2adq
- $orderPay['join_type'] = $joinType;
- $orderPay['login_account'] = isset($channelArr[$orderPay['channel']]) ? 'liedou' : null;// 第三方平台登录账号
- // 推广数据检测区分新老客户-当月下单是新客户
- if (isset($orderPay['article']) && !empty($orderPay['article'])) {
- if (
- isset($orderPay['userCreateTs'], $orderPay['updateTs'])
- &&
- (!empty($orderPay['userCreateTs']) && !empty($orderPay['updateTs']))
- ) {
- $curMonth = date('Y-m-01 00:00:00', strtotime($orderPay['updateTs']));
- $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
- $regTime = $orderPay['userCreateTs'];
- if ($regTime >= $curMonth && $regTime < $aftMonth) {
- $orderPay['pCustomerType'] = 1;
- } else {
- $orderPay['pCustomerType'] = 2;
- }
- }
- }
- if(!isset($channelArr[$orderPay['channel']])) {
- EmailQueue::rPush('嘉书平台-未知渠道号', '渠道号:'.$orderPay['channel'], ['song.shen@kuxuan-inc.com'], '猎羽');
- }
- $payType = 1;// 安卓(小程序虚拟支付)
- # 获取订单金额分成比例(不区分安卓还是ios)
- // $shareInProportionArr = OrderService::getOrderShareInProportion(2);
- $playletName = $orderPay['productName'] ?? null;
- $shareInProportionArr = OrderService::getOrderShareInProportionNew(2, $playletName, $orderPay['sys_group_id']);
- $shareInProportion = $shareInProportionArr[$payType] ?? 1;
- # 计算分成后的金额
- $orderPay['origin_pay_money'] = $orderPay['price'];
- if(3 == $orderPay['sys_group_id']) {
- $orderPay['price'] = $orderPay['origin_pay_money'] * $shareInProportion;
- }
- DjOrder::orderDataSaveFromJiashu($orderPay, $appId);
- }
- # 杭州猎豆 | 剧有戏 - 中文在线(迈步) - 订单数据保存
- public static function unifyOrderSave($orderPay, $platformId)
- {
- // 小程序openid写入mp_open_id字段
- $orderPay['mpOpenid'] = $orderPay['mp_openid'] ?? null;
- // 根据公众号appid反查企微id
- $systemCorpid = self::getSystemCorpidByAppId($orderPay['gzh_appid']);
- $orderPay['corpid'] = $systemCorpid;
- $orderPay['gzh_unionid'] = $orderPay['gzh_unionid'] ?? null;
- // 默认非系统用户,即非投放订单
- $orderPay['is_ad_user'] = 0;
- $externalUserId = null;
- $userId = null;
- $params = $orderPay['params'] ?? ($orderPay['user_id'] ?? null);
- if(!empty($params)) {
- $params = urldecode($params);
- if(strstr($params, "|")) {
- $paramsData = explode('|', $params);
- $systemCorpid = $paramsData[0] ?? null;
- $userId = $paramsData[1] ?? null;
- $externalUserId = $paramsData[2] ?? null;
- // 如果接收到了透传回来的企微ID,则覆盖之前根据公众号查询到的企微id
- if(!empty($systemCorpid)) {
- $orderPay['corpid'] = $systemCorpid;
- }
- } else {
- $externalUserId = $params;
- $userId = null;
- }
- }
- $responseData = Customer::getCustomerRegisterTime($orderPay['corpid'], $orderPay['gzh_unionid'], $externalUserId, $userId);
- $registerTime = $responseData['register_time'];
- $userActionSetId = $responseData['user_action_set_id'];
- $accountId = $responseData['account_id'];
- $unionid = $responseData['unionid'];
- $joinType = $responseData['join_type'];
- $adType = $responseData['ad_type'];
- $selfExternalUserId = $responseData['external_userid'];
- $selfUserId = $responseData['self_user_id'];
- if(empty($registerTime)) {
- // 系统中没有查询到对应的注册时间,直接使用迈步返回的时间
- $orderPay['register_time'] = strtotime($orderPay['follow_time']);
- } else {
- $orderPay['register_time'] = $registerTime;
- $orderPay['is_ad_user'] = 1;
- }
- // 查询出的用户unionid不为空,则将查询结果替换接收到的unionid
- if(!empty($unionid)){
- $orderPay['gzh_unionid'] = $unionid;
- }
- if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId) {
- Log::logInfo('迈步平台-回传客服ID与系统查询客服ID不一致', [
- 'order_id' => $orderPay['orderId'],
- 'self_user_id' => $selfUserId,
- 'corp_user_id' => $userId,
- ], 'callBackOrderParamsError');
- }
- if(!empty($externalUserId) && 0 == $orderPay['is_ad_user']) {
- Log::logInfo('迈步平台-接收到透传参数后找不到企微用户', [
- 'order_id' => $orderPay['orderId'],
- 'params' => $params
- ], 'callBackOrderParamsError');
- }
- $orderPay['userActionSetId'] = $userActionSetId;
- $orderPay['adq_account_id'] = $accountId;
- $orderPay['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
- $orderPay['join_type'] = $joinType;
- $orderPay['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
- $orderPay['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
- $loginAccountConf = config('maiBu.login_account');// 第三方平台登录账号
- $orderPay['login_account'] = !empty($orderPay['partner_id']) ? (isset($loginAccountConf[$orderPay['partner_id']]) ?
- $loginAccountConf[$orderPay['partner_id']] : null) : null;
- // 推广数据检测区分新老客户-当月下单是新客户
- if (isset($orderPay['promotion_id']) && !empty($orderPay['promotion_id'])) {
- if (
- isset($orderPay['register_time'], $orderPay['order_pay_time'])
- &&
- (!empty($orderPay['register_time']) && !empty($orderPay['order_pay_time']))
- ) {
- $curMonth = date('Y-m-01 00:00:00', strtotime($orderPay['order_pay_time']));
- $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
- $regTime = date('Y-m-d H:i:s', $orderPay['register_time']);
- if ($regTime >= $curMonth && $regTime < $aftMonth) {
- $orderPay['pCustomerType'] = 1;// 推广数据新用户
- } else {
- $orderPay['pCustomerType'] = 2;// 推广数据老用户
- }
- }
- }
- if(38 == $orderPay['sys_group_id']) {
- $orderPay['is_ad_user'] = 1;
- $orderPay['self_order_type'] = 2;
- $orderPay['selfUnionId'] = $orderPay['mpOpenid'];
- $orderPay['external_userid'] = empty($orderPay['external_userid']) ? $orderPay['selfUnionId'] : $orderPay['external_userid'];
- if((1 == $orderPay['self_order_type'] && empty($orderPay['gzh_appid'])) ||
- (2 == $orderPay['self_order_type']) && empty($orderPay['adq_account_id'])) {
- $orderPay['is_ad_user'] = 0;
- }
- }
- $payType = 1;
- # 获取对应的支付类型
- $orderPay['pay_type'] = $orderPay['pay_type'] ?? 0;
- $orderPay['order_pay_type'] = MaiBuService::getOrderPayType($orderPay['pay_type']);
- if(1 != $orderPay['order_pay_type']) $payType = 2;
- # 获取订单金额分成比例
- // $shareInProportionArr = OrderService::getOrderShareInProportion(3);
- $playletName = $orderPay['product_name'] ?? null;
- $shareInProportionArr = OrderService::getOrderShareInProportionNew(3, $playletName, $orderPay['sys_group_id']);
- $shareInProportion = $shareInProportionArr[$payType] ?? 1;// 不能区分是否为安卓还是ios之前先统一按照安卓处理
- # 计算分成后的金额
- $orderPay['origin_pay_money'] = $orderPay['amount'];
- if(3 == $orderPay['sys_group_id']) {
- $orderPay['amount'] = $orderPay['origin_pay_money'] * $shareInProportion;
- }
- DjOrder::orderDataSaveFromUnify($orderPay, $platformId, 3);
- }
- public static function getSystemCorpidByAppId($appId)
- {
- $officialAccountList = OfficialAccount::lists();
- $corpid = isset($officialAccountList[$appId]['corp_id']) ? $officialAccountList[$appId]['corp_id'] : '';
- return $corpid;
- }
- /*
- * 汇总指定账号对应时间段内的累计充值人数【unionId去重】
- * @param $accountData array 待汇总的账号信息集合 array(['app_id' => *, 'start_date' => *, 'end_date' => *],……)
- * */
- public static function getChargeUserTotalUnique($accountData)
- {
- if(empty($accountData)) return 0;
- $externalUserIdList = array();
- try {
- foreach ($accountData as $datum) {
- $appId = $datum['app_id'] ?? '';
- $startDate = $datum['start_date'] ?? '';
- $endDate = $datum['end_date'] ?? '';
- $accountId = $datum['account_id'] ?? '';
- if((empty($appId) && empty($accountId)) || !$startDate || !$endDate) {
- Log::logError('汇总去重后的累计充值人数参数缺失', [
- 'app_id' => $appId,
- 'start_date' => $startDate,
- 'end_date' => $endDate,
- 'param' => $accountData
- ], 'ChargeUserTotalUnique');
- continue;
- }
- if(!empty($appId)) {
- # 查询公众号在这段时间范围内下单用户的external_userid
- $externalUserIds = DjOrder::query()
- ->select(['external_userid'])->where('bind_app_id', $appId)
- ->where('mp_user_register_time', '>=', strtotime($startDate . ' 00:00:00') * 1000)
- ->where('mp_user_register_time', '<=', strtotime($endDate.' 23:59:59') * 1000)
- ->where('pay_status', 1)
- ->where('is_ad_user', 1)
- ->where('order_type', 1)
- ->distinct()
- ->pluck('external_userid');
- if(!empty($externalUserIds))
- $externalUserIds = $externalUserIds->toArray();
- $externalUserIdList = array_merge($externalUserIdList, $externalUserIds);
- } else {
- # 查询公众号在这段时间范围内下单用户的unionId
- $externalUserIds = DjOrder::query()
- ->select(['external_userid'])->where('adq_account_id', $accountId)
- ->where('mp_user_register_time', '>=', strtotime($startDate . ' 00:00:00') * 1000)
- ->where('mp_user_register_time', '<=', strtotime($endDate.' 23:59:59') * 1000)
- ->where('pay_status', 1)
- ->where('is_ad_user', 1)
- ->where('order_type', 2)
- ->distinct()
- ->pluck('external_userid');
- if(!empty($externalUserIds))
- $externalUserIds = $externalUserIds->toArray();
- $externalUserIdList = array_merge($externalUserIdList, $externalUserIds);
- }
- }
- } catch (\Exception $e) {
- Log::logError('汇总去重后的累计充值人数过程发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage(),
- 'param' => $accountData
- ], 'ChargeUserTotalUnique-Exception');
- }
- return count(array_unique($externalUserIdList));
- }
- # 杭州猎豆 - 东方小剧场(嘉书H5) - 订单数据保存
- public static function jiashuWebOrderSave($dataList)
- {
- # 嘉书h5一次请求数据会包含多条数据,需要遍历数据,逐条判断是否为下单类型
- foreach($dataList as $orderPay) {
- $dataType = isset($orderPay['datatype']) ? $orderPay['datatype'] : '';
- switch($dataType) {
- case 'register': #注册,新激活
- break;
- case 'active': # 活跃
- break;
- case 'pay': #支付
- // 根据公众号appid反查企微id
- $systemCorpid = self::getSystemCorpidByAppId($orderPay['app_id']);
- $orderPay['corpid'] = $systemCorpid;
- // 根据返回的外部联系人id查询用户的unionid以及注册时间
- $params = $orderPay['params'] ?? null;
- $params = ('undefined' == $params) ? null : $params;
- $userId = null;
- $externalUserId = null;
- if(!empty($params)){
- $params = urldecode($params);
- if(strstr($params, '|')) {
- $paramsData = explode('|', $params);
- $systemCorpid = $paramsData[0] ?? null;
- $userId = $paramsData[1] ?? null;
- $externalUserId = $paramsData[2] ?? null;
- // 如果接收到了透传回来的企微ID,则覆盖之前根据公众号查询到的企微id
- if(!empty($systemCorpid)) {
- $orderPay['corpid'] = $systemCorpid;
- }
- } else {
- $externalUserId = $params;
- }
- }
- //TODO 通过platform_id来查询,当剧有戏或者其他团队想要使用该逻辑时,需要重新提供请求接口,在连接上带上平台ID参数
- $orderPay['sys_group_id'] = 3;//杭州猎豆账号
- // 查询用户最早注册时间
- $orderPay['is_ad_user'] = 0;
- $responseData = Customer::getCustomerRegisterTime($orderPay['corpid'], null, $externalUserId, $userId);
- $registerTime = $responseData['register_time'];
- $userActionSetId = $responseData['user_action_set_id'];
- $accountId = $responseData['account_id'];
- $unionid = $responseData['unionid'];
- $joinType = $responseData['join_type'];
- $adType = $responseData['ad_type'];
- $selfExternalUserId = $responseData['external_userid'];
- $selfUserId = $responseData['self_user_id'];
- if(empty($registerTime)) {
- // 系统中没有查询到对应的注册时间,直接使用嘉书返回的时间
- $orderPay['register_time'] = strtotime($orderPay['register_ts']);
- } else {
- $orderPay['register_time'] = $registerTime;
- // $orderPay['register_time'] = strtotime($orderPay['register_ts']);
- $orderPay['is_ad_user'] = 1;
- }
- if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId) {
- Log::logInfo('嘉书web平台-回传客服ID与系统查询客服ID不一致', [
- 'order_id' => $orderPay['order_id'],
- 'self_user_id' => $selfUserId,
- 'corp_user_id' => $userId,
- ], 'callBackOrderParamsError');
- }
- if(!empty($externalUserId) && 0 == $orderPay['is_ad_user']) {
- Log::logInfo('嘉书web平台-接收到透传参数后找不到企微用户', [
- 'order_id' => $orderPay['order_id'],
- 'params' => $params
- ], 'callBackOrderParamsError');
- }
- $channelArr = config('jiashu.channel');
- $orderPay['userActionSetId'] = $userActionSetId;
- $orderPay['adq_account_id'] = $accountId;
- $orderPay['self_unionid'] = $unionid;
- $orderPay['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
- $orderPay['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
- $orderPay['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
- $orderPay['join_type'] = $joinType;
- $orderPay['login_account'] = isset($channelArr[$orderPay['channel']]) ? 'hzliedou' : null;
- if(!isset($channelArr[$orderPay['channel']])) {
- EmailQueue::rPush('嘉书平台-未知渠道号', '渠道号:'.$orderPay['channel'], ['song.shen@kuxuan-inc.com'], '猎羽');
- }
- // 判断订单来源
- $orderPay['plat_order_type'] = (0 == $orderPay['app_type']) ? 1 : 0;// app_type为0时表示H5来源,其他为小程序来源
- $payType = 1;// 安卓(小程序虚拟支付)
- # 获取订单金额分成比例(不用区分是否为小程序虚拟支付)
- // $shareInProportionArr = OrderService::getOrderShareInProportion(2);
- $playletName = $orderPay['product_name'] ?? null;
- $shareInProportionArr = OrderService::getOrderShareInProportionNew(2, $playletName, $orderPay['sys_group_id']);
- $shareInProportion = $shareInProportionArr[$payType] ?? 1;
- # 计算分成后的金额
- $orderPay['origin_pay_money'] = $orderPay['amount'];
- if(3 == $orderPay['sys_group_id']) {
- $orderPay['amount'] = $orderPay['origin_pay_money'] * $shareInProportion;
- }
- DjOrder::jiashuWebOrderSave($orderPay);
- break;
- case 'shortcut': # 加桌
- break;
- case 'ad': # 广告活跃
- break;
- case 'play': # 播放记录
- break;
- case 'fans': # 关注/取关粉丝
- break;
- case 'refund': # 退款
- break;
- case 'subscribe': # 订阅消息
- break;
- case 'buy': # 购买记录
- break;
- case 'pay_report': # 支付回传数据
- break;
- default:
- Log::logError('嘉书H5回调数据类型异常', ['order_pay' => $orderPay], 'callBackOrderError');
- break;
- }
- }
- }
- # 杭州猎豆 - 点众阳光 - 订单数据保存
- public static function platformOrderCallBack($orderPay)
- {
- $params = $orderPay['params'] ?? ($orderPay['user_id'] ?? null);
- $params = ('null' == $params) ? null : $params;
- $userId = null;
- $externalUserId = null;
- if(!empty($params)) {
- $params = urldecode($params);
- if(strstr($params, "|")) {
- $paramsData = explode('|', $params);
- $systemCorpid = $paramsData[0] ?? null;
- $userId = $paramsData[1] ?? null;
- $externalUserId = $paramsData[2] ?? null;
- // 如果接收到了透传回来的企微ID,则覆盖之前根据公众号查询到的企微id
- if(!empty($systemCorpid)) {
- $orderPay['corpid'] = $systemCorpid;
- }
- } else {
- $externalUserId = $params;
- $userId = null;
- }
- }
- $orderPay['gzh_unionid'] = $orderPay['gzh_unionid'] ?? null;
- $orderPay['corpid'] = $orderPay['corpid'] ?? null;
- $responseData = Customer::getCustomerRegisterTime($orderPay['corpid'], $orderPay['gzh_unionid'], $externalUserId, $userId);
- $registerTime = $responseData['register_time'];
- $userActionSetId = $responseData['user_action_set_id'];
- $accountId = $responseData['account_id'];
- $unionid = $responseData['unionid'];
- $joinType = $responseData['join_type'];
- $adType = $responseData['ad_type'];
- $selfExternalUserId = $responseData['external_userid'];
- $selfUserId = $responseData['self_user_id'];
- if(empty($registerTime)) {
- // 系统中没有查询到对应的注册时间,直接使用迈步返回的时间
- $orderPay['register_time'] = null;
- $orderPay['is_ad_user'] = 0;
- } else {
- $orderPay['register_time'] = $registerTime;
- $orderPay['is_ad_user'] = 1;
- }
- // 查询出的用户unionid不为空,则将查询结果替换接收到的unionid
- if(!empty($unionid)){
- $orderPay['gzh_unionid'] = $unionid;
- }
- if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId) {
- Log::logInfo('点众阳光平台-回传客服ID与系统查询客服ID不一致', [
- 'order_id' => $orderPay['orderId'],
- 'self_user_id' => $selfUserId,
- 'corp_user_id' => $userId,
- ], 'callBackOrderParamsError');
- }
- if(!empty($externalUserId) && 0 == $orderPay['is_ad_user']) {
- Log::logInfo('点众阳光平台-接收到透传参数后找不到企微用户', [
- 'order_id' => $orderPay['orderId'],
- 'params' => $params
- ], 'callBackOrderParamsError');
- }
- $orderPay['userActionSetId'] = $userActionSetId;
- $orderPay['adq_account_id'] = $accountId;
- $orderPay['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
- $orderPay['join_type'] = $joinType;
- $orderPay['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
- $orderPay['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
- // 推广数据检测区分新老客户-当月下单是新客户
- if (isset($orderPay['promotion_id']) && !empty($orderPay['promotion_id'])) {
- if (
- isset($orderPay['register_time'], $orderPay['order_pay_time'])
- &&
- (!empty($orderPay['register_time']) && !empty($orderPay['order_pay_time']))
- ) {
- $curMonth = date('Y-m-01 00:00:00', strtotime($orderPay['order_pay_time']));
- $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
- $regTime = date('Y-m-d H:i:s', $orderPay['register_time']);
- if ($regTime >= $curMonth && $regTime < $aftMonth) {
- $orderPay['pCustomerType'] = 1;// 推广数据新用户
- } else {
- $orderPay['pCustomerType'] = 2;// 推广数据老用户
- }
- }
- }
- $payType = 1; // 安卓(小程序虚拟支付)
- # 获取订单金额分成比例(不用区分是否为小程序虚拟支付)
- // $shareInProportionArr = OrderService::getOrderShareInProportion(4);
- $productName = $orderPay['product_name'] ?? null;
- $shareInProportionArr = OrderService::getOrderShareInProportionNew($orderPay['order_source'], $productName, $orderPay['sys_group_id']);
- $shareInProportion = $shareInProportionArr[$payType] ?? 1;
- # 计算分成后的金额
- $orderPay['origin_pay_money'] = $orderPay['amount'];
- if(3 == $orderPay['sys_group_id']) {
- $orderPay['amount'] = $orderPay['origin_pay_money'] * $shareInProportion;
- }
- $os = self::sunshineDeviceType($orderPay);
- $orderPay['os'] = $os;
- DjOrder::orderDataSaveFromPlatform($orderPay);
- }
- public static function sunshineDeviceType($order) {
- if(!isset($order['os'])) {
- // EmailQueue::rPush('第三方平台设备类型异常', json_encode([
- // 'platform' => '点众阳光', 'msg' => '设备类型字段不存在', 'order_data' => $order
- // ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
- return 0;
- }
- switch($order['os']) {
- case 0:# 安卓
- $os = 1;break;
- case 1:# ios
- $os = 2;break;
- default:
- EmailQueue::rPush('第三方平台设备类型异常', json_encode([
- 'platform' => '点众阳光', 'msg' => '设备类型字段值不符合预期', 'order_data' => $order
- ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
- $os = 0;break;
- }
- return $os;
- }
- # 杭州猎豆 - 容量 - 订单数据保存
- public static function saveCapacityOrder($order)
- {
- $order['order_source'] = 6;
- $order['order_type'] = 0;// 默认小程序
- $order['corpId'] = $order['corpId'] ?? null;
- $order['qyOpenId'] = $order['qyOpenId'] ?? null;
- $order['qyUserId'] = $order['qyUserId'] ?? null;
- # 查询公众号对应的用户openid
- $userInfo = CapacityUser::getUserInfo($order['productUserId'], $order['spreadChannelId'], $order['corpId']
- , $order['qyOpenId'], $order['qyUserId'], $order['id'], $order['createTime'], $order['platform_id']);
- $order['maOpenId'] = !empty($userInfo['maOpenId']) ? $userInfo['maOpenId'] : null;
- $order['mpOpenId'] = !empty($userInfo['mpOpenId']) ? $userInfo['mpOpenId'] : null;
- $order['corpId'] = !empty($userInfo['corpId']) ? $userInfo['corpId'] : $order['corpId'];
- $order['qyOpenId'] = !empty($userInfo['qyOpenId']) ? $userInfo['qyOpenId'] : $order['qyOpenId'];
- $order['qyUserId'] = !empty($userInfo['qyUserId']) ? $userInfo['qyUserId'] : $order['qyUserId'];
- if(isset($order['spreadChannelId']) && !empty($order['spreadChannelId'])){
- // 根据渠道ID获取对应的公众号app_id
- $order['gzh_appid'] = PlatformApp::query()->where('channel', $order['spreadChannelId'])
- ->where('enable', 1)->where('platform_id', 6)->value('app_id');
- if(!empty($order['gzh_appid']) && !empty($order['authorisedAppId']) && ($order['gzh_appid'] != $order['authorisedAppId'])
- && (time()*1000 <= $order['createTime']+300000)) {
- Log::logInfo('容量平台-已授权的公众号appid与渠道ID对应公众号不一致', [
- 'order_id' => $order['id'],
- 'gzh_appid' => $order['gzh_appid'],
- 'spreadChannelId' => $order['spreadChannelId'],
- 'authorisedAppId' => $order['authorisedAppId']
- ], 'callBackOrderParamsError');
- }
- if(!isset($order['authorisedAppId'])) {
- $order['authorisedAppId'] = $order['gzh_appid'];
- }
- }
- $corpid = $order['corpId'] ?? null;
- $externalUserId = $order['qyOpenId'] ?? null;
- $userId = $order['qyUserId'] ?? null;
- $order['authorisedAppId'] = $order['authorisedAppId'] ?? null;
- // 当透传回来的企微ID为空时,根据公众号app_id再次查询一次绑定的企微ID
- if(empty($order['corpId']) && !empty($order['authorisedAppId'])) {
- $corpid = DjOrderService::getSystemCorpidByAppId($order['authorisedAppId']);
- $order['corpId'] = $corpid;
- }
- $responseData = Customer::getCustomerRegisterTime($corpid, null, $externalUserId, $userId);
- $registerTime = $responseData['register_time'];
- $userActionSetId = $responseData['user_action_set_id'];
- $accountId = $responseData['account_id'];
- $unionid = $responseData['unionid'];
- $joinType = $responseData['join_type'];
- $adType = $responseData['ad_type'];
- $selfExternalUserId = $responseData['external_userid'];
- $selfUserId = $responseData['self_user_id'];
- $order['is_ad_user'] = 0;
- if(empty($registerTime)) {
- // 系统中没有查询到对应的注册时间,直接使用第三方返回的时间
- $order['register_time'] = $order['userRegisterTime'];
- } else {
- $order['register_time'] = $registerTime * 1000;
- $order['is_ad_user'] = 1;
- }
- # 判断系统查询得到的客服id和透传回来的客服id是否一致(订单获取到5分钟之内报警,因为同一个订单在当天会不停的获取到)
- if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId && (time()*1000 <= $order['createTime']+300000)) {
- Log::logInfo('容量平台回传客服ID与系统查询客服ID不一致', [
- 'order_info' => $order,
- 'response' => $responseData,
- ], 'callBackOrderUserIdError');
- EmailQueue::rPush('容量平台回传客服ID与系统查询客服ID不一致', json_encode([
- 'order_info' => $order,
- 'response' => $responseData,
- ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
- }
- if($accountId) {
- $accountRelationAppList = AdqUser::getAppIdList([$accountId]);
- $accountRelationAppId = $accountRelationAppList->where('account_id', $accountId)->first();
- $accountRelationAppId = $accountRelationAppId->app_id ?? null;
- # 当投放账号绑定的公众号与订单中渠道号对应的公众号不一致时,更新为非投放
- if($accountRelationAppId != $order['authorisedAppId'] && date('Y-m-d', $order['createTime']/1000) >= '2023-04-25') {
- $order['is_ad_user'] = 0;
- $order['register_time'] = $order['userRegisterTime'];
- Log::logInfo('容量平台需归结为非投放订单', [
- 'order_id' => $order['id'],
- 'relation_app_id' => $accountRelationAppId,
- 'bind_app_id' => $order['authorisedAppId']
- ], 'CapacityOrderTest');
- } else {
- $order['userActionSetId'] = $userActionSetId;
- $order['adq_account_id'] = $accountId;
- $order['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
- $order['join_type'] = $joinType;
- $order['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
- $order['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
- $order['self_unionid'] = $unionid;
- }
- }
- if(!empty($externalUserId) && 0 == $order['is_ad_user'] && (time()*1000 <= $order['createTime']+300000)) {
- Log::logInfo('容量平台-接收到透传参数后找不到企微用户', [
- 'order_id' => $order['id'],
- 'corpId' => $order['corpId'],
- 'qyOpenId' => $order['qyOpenId'],
- 'qyUserId' => $order['qyUserId']
- ], 'callBackOrderParamsError');
- }
- // 处理支付相关信息
- $order = CapacityService::dealPayInfo($order);
- # 判断是否为直投订单
- $order['promotion_id'] = $order['batchId'] ?? null;
- // 推广数据检测区分新老客户-当月下单是新客户
- if (isset($order['promotion_id']) && !empty($order['promotion_id'])) {
- if (
- isset($order['register_time'], $order['createTime'])
- &&
- (!empty($order['register_time']) && !empty($order['createTime']))
- ) {
- $curMonth = date('Y-m-01 00:00:00', $order['createTime']/1000);
- $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
- $regTime = date('Y-m-d H:i:s', $order['register_time']/1000);
- if ($regTime >= $curMonth && $regTime < $aftMonth) {
- $order['pCustomerType'] = 1;// 推广数据新用户
- } else {
- $order['pCustomerType'] = 2;// 推广数据老用户
- }
- }
- }
- # 查询推广ID对应的链接名称
- $order['promotion_title'] = MassPopularizData::query()->where('pid', strval($order['promotion_id']))
- ->where('platType', 6)->value('popularizTitle');
- $order['is_direct_investment'] = false;
- if(!empty($order['promotion_id'])) {
- $adqAccountIds = AccountConfService::getAccountIdByPid($order['sys_group_id'], $order['promotion_id'], 1);
- if(!empty($adqAccountIds)) {
- if(count($adqAccountIds) > 1) {
- EmailQueue::rPush('根据推广计划id查询投放账号结果异常(容量平台)', 'sys_group_id:' . $order['sys_group_id']
- . '; pid:' . $order['promotion_id'], ['song.shen@kuxuan-inc.com'], '猎羽');
- }
- $order['is_direct_investment'] = true;
- $adqAccountId = $adqAccountIds[0];
- $officialWebUserActionInfo = OfficialWebUserActionSetId::query()
- ->where('account_id', $adqAccountId)
- ->first();
- $userActionSetId = $officialWebUserActionInfo->web_user_action_set_id ?? null;
- $order['adq_account_id'] = $adqAccountId; # adq投放账号id
- $order['self_order_type'] = 2; # 指定为adq投放
- $order['userActionSetId'] = $userActionSetId;# 投放账号绑定的数据源id
- DjDirectInvestmentOrder::saveCapacityOrder($order);
- return true;
- }
- }
- $userAgent = $order['userAgent'] ?? '';
- # 从userAgent中提取设备信息
- $deviceType = CapacityService::getDeviceType($userAgent);
- $order['os'] = $deviceType;
- DjOrder::saveCapacityOrder($order);
- return true;
- }
- # 杭州猎豆 - 花生 - 订单数据保存
- public static function savePeanutOrder($order)
- {
- $order['sys_group_id'] = 3;
- $order['platform_id'] = 'rrTkwItVplaezpb5';
- $order['order_source'] = 5;
- $order['kuxuan_corp_id'] = $order['kuxuan_corp_id'] == '-' ? null : $order['kuxuan_corp_id'];
- $order['kuxuan_ex_user_id'] = $order['kuxuan_ex_user_id'] == '-' ? null : $order['kuxuan_ex_user_id'];
- $order['kuxuan_customer_id'] = $order['kuxuan_customer_id'] == '-' ? null : $order['kuxuan_customer_id'];
- $corpid = $order['kuxuan_corp_id'];
- $externalUserId = $order['kuxuan_ex_user_id'];
- $userId = $order['kuxuan_customer_id'];
- // 当透传回来的企微ID为空时,根据公众号app_id再次查询一次绑定的企微ID
- if(empty($corpid) && !empty($order['mpAppId'])) {
- $corpid = DjOrderService::getSystemCorpidByAppId($order['mpAppId']);
- $order['kuxuan_corp_id'] = $corpid;
- }
- $responseData = Customer::getCustomerRegisterTime($corpid, null, $externalUserId, $userId);
- $registerTime = $responseData['register_time'];
- $userActionSetId = $responseData['user_action_set_id'];
- $accountId = $responseData['account_id'];
- $unionid = $responseData['unionid'];
- $joinType = $responseData['join_type'];
- $adType = $responseData['ad_type'];
- $selfExternalUserId = $responseData['external_userid'];
- $selfUserId = $responseData['self_user_id'];
- $order['is_ad_user'] = 0;
- if(empty($registerTime)) {
- // 系统中没有查询到对应的注册时间,直接使用迈步返回的时间
- $order['register_time'] = strtotime($order['join_at']) * 1000;
- } else {
- $order['register_time'] = $registerTime * 1000;
- $order['is_ad_user'] = 1;
- }
- if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId && (time() <= strtotime($order['request_at'])+300)) {
- Log::logInfo('花生平台回传客服ID与系统查询客服ID不一致', [
- 'order_info' => $order,
- 'response' => $responseData,
- ], 'callBackOrderUserIdError');
- EmailQueue::rPush('花生平台回传客服ID与系统查询客服ID不一致', json_encode([
- 'order_info' => $order,
- 'response' => $responseData,
- ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
- }
- $order['userActionSetId'] = $userActionSetId;
- $order['adq_account_id'] = $accountId;
- $order['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
- $order['join_type'] = $joinType;
- $order['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
- $order['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
- $order['self_unionid'] = $unionid;
- $order['promotion_id'] = $order['spread_id'] ?? null;
- // 推广数据检测区分新老客户-当月下单是新客户
- if (isset($order['promotion_id']) && !empty($order['promotion_id'])) {
- if (
- isset($order['register_time'], $order['pay_at'])
- &&
- (!empty($order['register_time']) && !empty($order['pay_at']))
- ) {
- $curMonth = date('Y-m-01 00:00:00', strtotime($order['pay_at']));
- $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
- $regTime = date('Y-m-d H:i:s', $order['register_time']/1000);
- if ($regTime >= $curMonth && $regTime < $aftMonth) {
- $order['pCustomerType'] = 1;// 推广数据新用户
- } else {
- $order['pCustomerType'] = 2;// 推广数据老用户
- }
- }
- }
- if(!empty($externalUserId) && 0 == $order['is_ad_user'] && (time() <= strtotime($order['pay_at'])+300)) {
- Log::logInfo('花生平台-接收到透传参数后找不到企微用户', [
- 'order_id' => $order['order_num'],
- 'corpId' => $order['kuxuan_corp_id'],
- 'qyOpenId' => $order['kuxuan_ex_user_id'],
- 'qyUserId' => $order['kuxuan_customer_id']
- ], 'callBackOrderParamsError');
- }
- $payType = 1; // 安卓 小程序虚拟支付
- $way = $order['way'] ?? 0;
- $order['order_pay_type'] = HuaShengService::getOrderPayType($way);
- if(1 != $order['order_pay_type']) { $payType = 2; }
- # 获取订单金额分成比例(不用区分是否为小程序虚拟支付)
- // $shareInProportionArr = OrderService::getOrderShareInProportion(5);
- $playletName = $order['book_name'] ?? null;
- $shareInProportionArr = OrderService::getOrderShareInProportionNew($order['order_source'], $playletName, $order['sys_group_id']);
- $shareInProportion = $shareInProportionArr[$payType] ?? 1;
- # 计算分成后的金额
- $order['origin_pay_money'] = $order['total_charge_amount'];
- if(3 == $order['sys_group_id']) {
- $order['total_charge_amount'] = $order['origin_pay_money'] * $shareInProportion;
- }
- $order = HuaShengService::getOrderOs($order);
- DjOrder::savePeanutOrder($order);
- }
- # 星橙优品 - 花生 - 订单数据保存
- public static function savePeanutOrderSecond($order)
- {
- $order['sys_group_id'] = 51;
- $order['platform_id'] = '8TCtA8fHsIpbnlun';
- $order['order_source'] = 5;
- $order['enterprise_corp_id'] = !isset($order['enterprise_corp_id']) || $order['enterprise_corp_id'] == '-' ? null : $order['enterprise_corp_id'];
- $order['enterprise_ex_user_id'] = !isset($order['enterprise_ex_user_id']) || $order['enterprise_ex_user_id'] == '-' ? null : $order['enterprise_ex_user_id'];
- $order['enterprise_customer_id'] = !isset($order['enterprise_customer_id']) || $order['enterprise_customer_id'] == '-' ? null : $order['enterprise_customer_id'];
- $corpid = $order['enterprise_corp_id'];
- $externalUserId = $order['enterprise_ex_user_id'];
- $userId = $order['enterprise_customer_id'];
- // 当透传回来的企微ID为空时,根据公众号app_id再次查询一次绑定的企微ID
- if(empty($corpid) && !empty($order['mpAppId'])) {
- $corpid = DjOrderService::getSystemCorpidByAppId($order['mpAppId']);
- $order['enterprise_corp_id'] = $corpid;
- }
- $responseData = Customer::getCustomerRegisterTime($corpid, null, $externalUserId, $userId);
- $registerTime = $responseData['register_time'];
- $userActionSetId = $responseData['user_action_set_id'];
- $accountId = $responseData['account_id'];
- $unionid = $responseData['unionid'];
- $joinType = $responseData['join_type'];
- $adType = $responseData['ad_type'];
- $selfExternalUserId = $responseData['external_userid'];
- $selfUserId = $responseData['self_user_id'];
- $order['is_ad_user'] = 0;
- if(empty($registerTime)) {
- // 系统中没有查询到对应的注册时间,直接使用第三方返回的时间
- $order['register_time'] = strtotime($order['join_at']) * 1000;
- } else {
- $order['register_time'] = $registerTime * 1000;
- $order['is_ad_user'] = 1;
- }
- if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId) {
- Log::logInfo('花生平台回传客服ID与系统查询客服ID不一致', [
- 'order_info' => $order,
- 'response' => $responseData,
- ], 'callBackOrderUserIdError');
- EmailQueue::rPush('花生平台回传客服ID与系统查询客服ID不一致', json_encode([
- 'order_info' => $order,
- 'response' => $responseData,
- ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
- }
- $order['userActionSetId'] = $userActionSetId;
- $order['adq_account_id'] = $accountId;
- $order['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
- $order['join_type'] = $joinType;
- $order['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
- $order['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
- $order['self_unionid'] = $unionid;
- $order['promotion_id'] = $order['spread_id'] ?? null;
- // 推广数据检测区分新老客户-当月下单是新客户
- if (isset($order['promotion_id']) && !empty($order['promotion_id'])) {
- if (
- isset($order['register_time'], $order['pay_at'])
- &&
- (!empty($order['register_time']) && !empty($order['pay_at']))
- ) {
- $curMonth = date('Y-m-01 00:00:00', strtotime($order['pay_at']));
- $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
- $regTime = date('Y-m-d H:i:s', $order['register_time']/1000);
- if ($regTime >= $curMonth && $regTime < $aftMonth) {
- $order['pCustomerType'] = 1;// 推广数据新用户
- } else {
- $order['pCustomerType'] = 2;// 推广数据老用户
- }
- }
- }
- if(!empty($externalUserId) && 0 == $order['is_ad_user']) {
- Log::logInfo('花生平台-接收到透传参数后找不到企微用户', [
- 'order_id' => $order['order_num'],
- 'corpId' => $order['enterprise_corp_id'],
- 'qyOpenId' => $order['enterprise_ex_user_id'],
- 'qyUserId' => $order['enterprise_customer_id']
- ], 'callBackOrderParamsError');
- }
- $order['kuxuan_corp_id'] = $order['enterprise_corp_id'];
- $order['origin_pay_money'] = $order['total_charge_amount'];
- $way = $order['way'] ?? 0;
- $order['order_pay_type'] = HuaShengService::getOrderPayType($way);
- $order = HuaShengService::getOrderOs($order);
- DjOrder::savePeanutOrder($order);
- }
- # 星橙优品|猎豆优选 - 九州 - 订单数据保存
- public static function saveJiuZhouOrder($order) {
- $order['platform_id'] = '';
- $order['order_source'] = 7;
- $order['plat_order_type'] = 0;
- # 解析透传参数
- $msgId = $order['msg_id'];
- $msgData = explode('|', $msgId);
- $suffix = $msgData[0] ?? null;
- $dataId = $msgData[1] ?? null;
- $corpid = null;
- $externalUserId = null;
- $userId = null;
- if(!empty($suffix) && !empty($dataId)) {
- $row = CustomerDetails::suffix(intval($suffix))->where('id', $dataId)->select(['corpid', 'user_id', 'external_userid'])
- ->first();
- $corpid = $row->corpid ?? null;
- $userId = $row->user_id ?? null;
- $externalUserId = $row->external_userid ?? null;
- }
- // 当透传回来的企微ID为空时,根据公众号app_id再次查询一次绑定的企微ID
- if(empty($corpid) && !empty($order['gzh_id'])) {
- $corpid = DjOrderService::getSystemCorpidByAppId($order['gzh_id']);
- }
- // 通过透传参数查找系统客户信息以及投放账号信息
- $responseData = Customer::getCustomerRegisterTime($corpid, null, $externalUserId, $userId);
- $registerTime = $responseData['register_time'];
- $userActionSetId = $responseData['user_action_set_id'];
- $accountId = $responseData['account_id'];
- $unionid = $responseData['unionid'];
- $joinType = $responseData['join_type'];
- $adType = $responseData['ad_type'];
- $selfExternalUserId = $responseData['external_userid'];
- $selfUserId = $responseData['self_user_id'];
- $order['is_ad_user'] = 0;
- if(empty($registerTime)) {
- // 系统中没有查询到对应的注册时间,直接使用第三方返回的时间
- $order['register_time'] = strtotime($order['user_register_time']) * 1000;
- } else {
- $order['register_time'] = $registerTime * 1000;
- $order['is_ad_user'] = 1;
- }
- $order['userActionSetId'] = $userActionSetId;
- $order['adq_account_id'] = $accountId;
- $order['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
- $order['join_type'] = $joinType;
- $order['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
- $order['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
- $order['self_unionid'] = $unionid;
- $order['system_corpid'] = $corpid;
- $order['promotion_id'] = $order['link_id'] ?? null;
- // 推广数据检测区分新老客户-当月下单是新客户(数据看板 - 推广数据报表 中使用)
- if (isset($order['promotion_id']) && !empty($order['promotion_id'])) {
- if (
- isset($order['register_time'], $order['payDate'])
- &&
- (!empty($order['register_time']) && !empty($order['payDate']))
- ) {
- $curMonth = $order['payDate'];
- $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", $curMonth));
- $regTime = date('Y-m-d H:i:s', $order['register_time']/1000);
- if ($regTime >= $curMonth && $regTime < $aftMonth) {
- $order['pCustomerType'] = 1;// 推广数据新用户
- } else {
- $order['pCustomerType'] = 2;// 推广数据老用户
- }
- }
- }
- if(!empty($externalUserId) && 0 == $order['is_ad_user']) {
- Log::logInfo('九州平台-接收到透传参数后找不到企微用户', [
- 'order_id' => $order['orderId'],
- 'corpId' => $corpid,
- 'qyOpenId' => $externalUserId,
- 'qyUserId' => $userId
- ], 'saveJiuZhouOrderError');
- }
- # 订单金额分成比例
- if(substr_count($order['orderId'], "Virtual") >= 1) {
- $payType = 1;
- $order['device_type'] = 1;
- } else {
- $payType = 2;
- $order['device_type'] = 0;
- }
- // $shareInProportionArr = OrderService::getOrderShareInProportion(7);
- $playletName = $order['theater_name'] ?? null;
- $shareInProportionArr = OrderService::getOrderShareInProportionNew($order['order_source'], $playletName, $order['sys_group_id']);
- $shareInProportion = $shareInProportionArr[$payType] ?? 1;
- $order['origin_pay_money'] = $order['payNotifyAmount'];
- if(3 == $order['sys_group_id']) {
- $order['payNotifyAmount'] = $order['origin_pay_money'] * $shareInProportion;
- }
- DjOrder::saveJiuZhouOrder($order);
- }
- # 杭州猎豆 映客
- public static function saveYingKeOrder($order) {
- $order['platform_id'] = '';
- $order['order_source'] = 8;
- $order['plat_order_type'] = 0;
- $corpid = null;
- # 根据小程序名称获取小程序app_id
- list($order['ma_app_id'], $order['sys_group_id']) = YingKeService::getMaAppIdByName($order['appName']);
- if('龙王剧场' == $order['appName']) {
- $order['plat_order_type'] = 1;
- }
- // 当透传回来的企微ID为空时,根据公众号app_id再次查询一次绑定的企微ID
- if(empty($corpid) && !empty($order['gzhId'])) {
- $corpid = DjOrderService::getSystemCorpidByAppId($order['gzhId']);
- }
- $order['is_ad_user'] = 0;
- $order['system_corpid'] = $corpid;
- # 通过推广链接ID查询投放账号
- $promotionId = $order['linkId'];
- $bindAccountDataList = AdqAccountBindPidConf::search([
- 'sys_group_id' => $order['sys_group_id'], 'pid' => $promotionId, 'status' => 1
- ]);
- if($bindAccountDataList->isNotEmpty()) {
- $accountData = $bindAccountDataList->first();
- $accountId = $accountData->account_id ?? null;
- if(!empty($accountId)) {
- $officialWebUserActionInfo = OfficialWebUserActionSetId::query()
- ->where('account_id', $accountId)
- ->first();
- $userActionSetId = $officialWebUserActionInfo->web_user_action_set_id ?? null;
- $order['adq_account_id'] = $accountId;
- $order['userActionSetId'] = $userActionSetId;
- $order['self_order_type'] = 2;
- }
- }
- $deviceType = $order['deviceType'];// 1:android 2:ios
- $playletName = $order['movieName'] ?? null;
- $shareInProportionArr = OrderService::getOrderShareInProportionNew($order['order_source'], $playletName, $order['sys_group_id']);
- $shareInProportion = $shareInProportionArr[$deviceType] ?? 1;
- $order['origin_pay_money'] = $order['payNotifyAmount'];
- if(3 == $order['sys_group_id']) {
- $order['payNotifyAmount'] = $order['origin_pay_money'] * $shareInProportion;
- }
- DjOrder::saveYingKeOrder($order);
- }
- # 杭州猎豆 触摸
- public static function saveChuMoOrder($order) {
- $order['platform_id'] = '';
- $order['order_source'] = 9;
- $order['plat_order_type'] = 0;
- # 解析透传参数
- $msgId = $order['qw_params'];
- $msgData = explode('|', $msgId);
- $suffix = $msgData[0] ?? null;
- $dataId = $msgData[1] ?? null;
- $corpid = null;
- $externalUserId = null;
- $userId = null;
- if(!empty($suffix) && !empty($dataId)) {
- $row = CustomerDetails::suffix(intval($suffix))->where('id', $dataId)->select(['corpid', 'user_id', 'external_userid'])
- ->first();
- $corpid = $row->corpid ?? null;
- $userId = $row->user_id ?? null;
- $externalUserId = $row->external_userid ?? null;
- }
- # 通过订单中返回的渠道号来查询对应的公众号app_id
- if(isset($order['channel_id']) && !empty($order['channel_id'])){
- // 根据渠道ID获取对应的公众号app_id
- $order['gzh_appid'] = PlatformApp::query()->where('channel', $order['channel_id'])
- ->where('enable', 1)->where('platform_id', $order['order_source'])->value('app_id');
- }
- // 当透传回来的企微ID为空时,根据公众号app_id再次查询一次绑定的企微ID
- if(empty($corpid) && !empty($order['gzh_appid'])) {
- $corpid = DjOrderService::getSystemCorpidByAppId($order['gzh_appid']);
- }
- # 通过透传参数来查找企微中的用户信息以及投放账号信息
- $responseData = Customer::getCustomerRegisterTime($corpid, null, $externalUserId, $userId);
- $registerTime = $responseData['register_time'];
- $userActionSetId = $responseData['user_action_set_id'];
- $accountId = $responseData['account_id'];
- $unionid = $responseData['unionid'];
- $joinType = $responseData['join_type'];
- $adType = $responseData['ad_type'];
- $selfExternalUserId = $responseData['external_userid'];
- $selfUserId = $responseData['self_user_id'];
- $order['is_ad_user'] = 0;
- if(empty($registerTime)) {
- // 系统中没有查询到对应的注册时间,直接使用第三方返回的时间
- $order['register_time'] = strtotime($order['user_reg_date']) * 1000;
- } else {
- $order['register_time'] = $registerTime * 1000;
- $order['is_ad_user'] = 1;
- }
- $order['userActionSetId'] = $userActionSetId;
- $order['adq_account_id'] = $accountId;
- $order['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
- $order['join_type'] = $joinType;
- $order['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
- $order['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
- $order['self_unionid'] = $unionid;
- $order['system_corpid'] = $corpid;
- if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId && (time() <= strtotime($order['order_create_date'])+300)) {
- Log::logInfo('触摸平台回传客服ID与系统查询客服ID不一致', [
- 'order_info' => $order,
- 'response' => $responseData,
- ], 'callBackOrderUserIdError');
- EmailQueue::rPush('触摸平台回传客服ID与系统查询客服ID不一致', json_encode([
- 'order_info' => $order,
- 'response' => $responseData,
- ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
- }
- if($accountId) {
- $accountRelationAppList = AdqUser::getAppIdList([$accountId]);
- $accountRelationAppId = $accountRelationAppList->where('account_id', $accountId)->first();
- $accountRelationAppId = $accountRelationAppId->app_id ?? null;
- # 当投放账号绑定的公众号与订单中渠道号对应的公众号不一致时,更新为非投放
- if(isset($order['authorisedAppId']) && $accountRelationAppId != $order['authorisedAppId']) {
- $order['is_ad_user'] = 0;
- $order['register_time'] = $order['userRegisterTime'];
- } else {
- $order['userActionSetId'] = $userActionSetId;
- $order['adq_account_id'] = $accountId;
- $order['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
- $order['join_type'] = $joinType;
- $order['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
- $order['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
- $order['self_unionid'] = $unionid;
- }
- }
- if(!empty($externalUserId) && 0 == $order['is_ad_user'] && (time() <= strtotime($order['order_create_date'])+300)) {
- Log::logInfo('触摸平台-接收到透传参数后找不到企微用户', [
- 'order_id' => $order['id'],
- 'corpId' => $order['corpId'],
- 'qyOpenId' => $order['qyOpenId'],
- 'qyUserId' => $order['qyUserId']
- ], 'callBackOrderParamsError');
- }
- # 处理订单支付类型(安卓还是ios)
- $payType = 1;
- switch($order['platform']) {
- case 'ios':
- $payType = 2;
- break;
- case 'other':
- $payType = 1;
- break;
- }
- $order['deviceType'] = $payType;
- # 处理订单金额分成比例
- $playletName = $order['video_name'] ?? null;
- $shareInProportionArr = OrderService::getOrderShareInProportionNew($order['order_source'], $playletName, $order['sys_group_id']);
- $shareInProportion = $shareInProportionArr[$payType] ?? 1;
- $order['origin_pay_money'] = $order['total_fee'];
- if(3 == $order['sys_group_id']) {
- $order['payNotifyAmount'] = $order['origin_pay_money'] * $shareInProportion;
- }
- DjOrder::saveChuMoOrder($order);
- }
- public static function saveFanQieOrder($order) {
- $order['platform_id'] = '';
- $order['order_source'] = 10;
- $order['plat_order_type'] = 0;
- # 通过推广链接ID查询投放账号
- $promotionId = $order['promotion_id'];
- $bindAccountDataList = AdqAccountBindPidConf::search([
- 'sys_group_id' => $order['sys_group_id'], 'pid' => $promotionId, 'status' => 1
- ]);
- if($bindAccountDataList->isNotEmpty()) {
- $accountData = $bindAccountDataList->first();
- $accountId = $accountData->account_id ?? null;
- if(!empty($accountId)) {
- $officialWebUserActionInfo = OfficialWebUserActionSetId::query()
- ->where('account_id', $accountId)
- ->first();
- $userActionSetId = $officialWebUserActionInfo->web_user_action_set_id ?? null;
- $order['adq_account_id'] = $accountId;
- $order['userActionSetId'] = $userActionSetId;
- $order['self_order_type'] = 2;
- }
- }
- $deviceType = $order['order_type'];// 1:android 2:ios
- $playletName = null;
- $shareInProportionArr = OrderService::getOrderShareInProportionNew($order['order_source'], $playletName, $order['sys_group_id']);
- $shareInProportion = $shareInProportionArr[$deviceType] ?? 1;
- $order['origin_pay_money'] = $order['pay_fee']*100;
- if(3 == $order['sys_group_id']) {
- $order['payNotifyAmount'] = $order['origin_pay_money'] * $shareInProportion;
- }
- DjOrder::saveFanQieOrder($order);
- }
- public static function saveYunXuanOrder($order) {
- // 自定义推广参数(投放账户)
- $order['tx_cps_id'] = $order['goods_info'][0]['chan_info'][0]['tx_cps_id'] ?? null;
- if(empty($order['tx_cps_id'])) {
- EmailQueue::rPush('云选联盟订单匹配投放账户失败', json_encode($order, 256), ['song.shen@kuxuan-inc.com'], '电商直投');
- }
- # 数据格式化
- $order['order_create_time'] = date('Y-m-d H:i:s', $order['create_time'] / 1000);
- unset($order['create_time']);
- $order['status_change_time'] = date('Y-m-d H:i:s', $order['status_change_time'] / 1000);
- $order['payed_time'] = !empty($order['payed_time']) ? date('Y-m-d H:i:s', $order['payed_time'] / 1000) : null;
- $order['send_time'] = !empty($order['send_time']) ? date('Y-m-d H:i:s', $order['send_time'] / 1000) : null;
- $order['received_time'] = !empty($order['received_time']) ? date('Y-m-d H:i:s', $order['received_time'] / 1000) : null;
- $order['finish_time'] = !empty($order['finish_time']) ? date('Y-m-d H:i:s', $order['finish_time'] / 1000) : null;
- $order['settle_confirm_time'] = !empty($order['settle_confirm_time']) ? date('Y-m-d H:i:s', $order['settle_confirm_time'] / 1000) : null;
- $order['goods_info'] = !empty($order['goods_info']) ? json_encode($order['goods_info'], 256) : '[]';
- $order['category_info'] = !empty($order['category_info']) ? json_encode($order['category_info'], 256) : '[]';
- # 数据映射
- $order['order_source'] = YxOrder::getOrderSource($order['order_source']);
- $order['order_status'] = YxOrder::getOrderStatus($order['order_status']);
- $order['distribute_sale_trace_type'] = YxOrder::getDistributeSaleTraceType($order['distribute_sale_trace_type']);
- YxOrder::saveData($order);
- }
- }
|