1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540 |
- <?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;
- }
- /*
- * 汇总指定账号对应时间段内的累计充值人数【externalUserId去重】
- * @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']);
- // Log::logInfo('番茄平台-订单金额分成配置', [
- // 'order_source' => $order['order_source'],
- // 'sys_group_id' => $order['sys_group_id'],
- // 'config' => $shareInProportionArr
- // ], 'saveFanQieOrder');
- $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);
- }
- }
|