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); } }