企微短剧业务系统

DjOrderService.php 74KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2022/3/16
  6. * Time: 16:39
  7. */
  8. namespace App\Service;
  9. use App\Log;
  10. use App\Models\AdqAccountBindPidConf;
  11. use App\Models\AdqUser;
  12. use App\Models\CapacityUser;
  13. use App\Models\CorpMapping;
  14. use App\Models\Customer;
  15. use App\Models\CustomerDetails;
  16. use App\Models\DjDirectInvestmentOrder;
  17. use App\Models\DjOrder;
  18. use App\Models\DjUser;
  19. use App\Models\MassPopularizData;
  20. use App\Models\OfficialAccount;
  21. use App\Models\OfficialWebUserActionSetId;
  22. use App\Models\PlatformApp;
  23. use App\Models\Tencent\TxClickRecord;
  24. use App\Models\Tencent\YxOrder;
  25. use App\Models\TencentAdConf;
  26. use App\RedisModel;
  27. use App\Service\Order\YingKeService;
  28. use App\Support\EmailQueue;
  29. class DjOrderService
  30. {
  31. # 杭州猎豆 | 剧有戏 - 柚子 - 订单数据保存
  32. public static function youziOrderSave($orderPay, $source, $status, $platformType, $type = 1)
  33. {
  34. // 根据企业id映射关系表查询自己的企业id
  35. $corpList = CorpMapping::getCorpList($platformType);
  36. $systemCorpid = isset($corpList[$orderPay['mpAppId']]['corpid']) ? $corpList[$orderPay['mpAppId']]['corpid'] : '';
  37. $orderPay['system_corpid'] = $systemCorpid;
  38. $orderPay['self_order_type'] = 1;
  39. // 数据源ID不为空时,根据数据源ID查询公众号APPID,柚子平台不直接返回公众号APPID
  40. if(!empty($orderPay['userActionSetId'])) {
  41. $appList = TencentAdConf::getAppList();
  42. $bindAppId = isset($appList[$orderPay['userActionSetId']]['app_id']) ? $appList[$orderPay['userActionSetId']]['app_id'] : '';
  43. $orderPay['bind_app_id'] = $bindAppId;
  44. }
  45. if(empty($orderPay['bind_app_id'])) {
  46. $accountInfo = OfficialAccount::query()->where('mp_app_id', $orderPay['mpAppId'])->first();
  47. $orderPay['bind_app_id'] = $accountInfo->mp_name ?? null;
  48. }
  49. // 企微id为空并且公众号APPID不为空,则根据公众号APPID查询对应的企微id
  50. if(empty($orderPay['system_corpid']) && !empty($orderPay['bind_app_id'])) {
  51. $systemCorpid = self::getSystemCorpidByAppId($orderPay['bind_app_id']);
  52. $orderPay['system_corpid'] = $systemCorpid;
  53. }
  54. // 默认运营带来的订单(非系统企微用户)
  55. $externalUserId = null;
  56. $userId = null;
  57. $params = $orderPay['params'] ?? ($orderPay['channelId'] ?? null);
  58. if(!empty($params)) {
  59. $params = urldecode($params);
  60. if(strstr($params, '|')) {
  61. $paramsData = explode('|', $params);
  62. $corpid = $paramsData[0] ?? null;
  63. $userId = $paramsData[1] ?? null;
  64. $externalUserId = $paramsData[2] ?? null;
  65. // 如果接收到了透传回来的企微ID,则覆盖之前根据公众号查询到的企微id
  66. if(!empty($corpid)) {
  67. $orderPay['system_corpid'] = $corpid;
  68. }
  69. } else {
  70. $externalUserId = $params;
  71. }
  72. }
  73. # 当此参数为空时,柚子就不给返回了,因此这里做一下兼容处理
  74. $orderPay['selfUnionId'] = $orderPay['selfUnionId'] ?? null;
  75. // 查询企微用户相关信息
  76. $responseData = Customer::getCustomerRegisterTime($orderPay['system_corpid'], $orderPay['selfUnionId'], $externalUserId, $userId);
  77. $registerTime = $responseData['register_time'];
  78. $userActionSetId = $responseData['user_action_set_id'];
  79. $accountId = $responseData['account_id'];
  80. $unionid = $responseData['unionid'];
  81. $joinType = $responseData['join_type'];
  82. $adType = $responseData['ad_type'];
  83. $selfExternalUserId = $responseData['external_userid'];
  84. $selfUserId = $responseData['self_user_id'];
  85. if(empty($registerTime)) {
  86. $orderPay['is_ad_user'] = 0;
  87. // 系统中没有查询到对应的注册时间,直接使用柚子返回的注册时间,此订单为运营订单
  88. } else {
  89. // 可以查询到用户的企微关注时间,就用企微关注时间作为用户的注册时间,并且认为是企微用户,此订单为投放订单
  90. $orderPay['mpUserRegisterTime'] = $registerTime * 1000;
  91. $orderPay['is_ad_user'] = 1;
  92. }
  93. // 查询到的adq投放账号对应的web数据源ID不为空,将查询出来的数据源ID写入订单表中(覆盖柚子回传回来的数据源ID),为之后的adq订单上报做准备
  94. if(!empty($userActionSetId)) {
  95. $orderPay['userActionSetId'] = $userActionSetId;
  96. }
  97. // 查询到的用户unionid不为空,那么将我们自己的unionid写入订单表中(覆盖柚子返回的数据),为之后的mp订单上报做准备
  98. if(!empty($unionid)) {
  99. $orderPay['selfUnionId'] = $unionid;
  100. }
  101. if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId) {
  102. Log::logInfo('柚子平台-回传客服ID与系统查询客服ID不一致', [
  103. 'order_id' => $orderPay['orderId'],
  104. 'self_user_id' => $selfUserId,
  105. 'corp_user_id' => $userId,
  106. ], 'callBackOrderParamsError');
  107. }
  108. if(!empty($externalUserId) && 0 == $orderPay['is_ad_user'] && 1 == $type) {
  109. Log::logInfo('柚子平台-接收到透传参数后找不到企微用户', [
  110. 'order_id' => $orderPay['orderId'],
  111. 'params' => $params
  112. ], 'callBackOrderParamsError');
  113. }
  114. $orderPay['adq_account_id'] = $accountId;// adq投放账号,主要是为了可以在adq回传时使用
  115. $orderPay['join_type'] = $joinType;// 用户添加渠道(最新一次添加客服的渠道,由企微返回,这里是为了之后统计数据冗余)
  116. $orderPay['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;// 用户外部联系人ID
  117. $orderPay['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;// 企微客服user_id
  118. $orderPay['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 1mp 2adq,获取失败时归属到mp非运营回收中
  119. // 推广数据检测区分新老客户-当月下单是新客户
  120. if (isset($orderPay['playletActivityId']) && !empty($orderPay['playletActivityId'])) {
  121. if (
  122. isset($orderPay['mpUserRegisterTime'], $orderPay['createdTs'])
  123. &&
  124. (!empty($orderPay['mpUserRegisterTime']) && !empty($orderPay['createdTs']))
  125. ) {
  126. $curMonth = date('Y-m-01 00:00:00', intval($orderPay['createdTs'] / 1000));
  127. $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
  128. $regTime = date('Y-m-d H:i:s', ($orderPay['mpUserRegisterTime'] / 1000));
  129. if ($regTime >= $curMonth && $regTime < $aftMonth) {
  130. $orderPay['pCustomerType'] = 1;// 下单时间在注册时间的自然月内,新用户
  131. } else {
  132. $orderPay['pCustomerType'] = 2;// 老用户
  133. }
  134. }
  135. }
  136. if(2 == $type) {
  137. # 剧有戏订单 使用小程序openid赋值给unionid字段
  138. $orderPay['selfUnionId'] = $orderPay['mpOpenid'];
  139. $orderPay['external_userid'] = empty($orderPay['external_userid']) ? $orderPay['selfUnionId'] : $orderPay['external_userid'];
  140. if(1 == $orderPay['self_order_type']) {
  141. // 柚子平台自己做adq回传逻辑
  142. $webUserActionSetIdList = OfficialWebUserActionSetId::WEB_USER_SET_ID_LIST;
  143. if(!empty($orderPay['userActionSetId']) && in_array($orderPay['userActionSetId'], $webUserActionSetIdList)) {
  144. $orderPay['self_order_type'] = 2;
  145. }
  146. }
  147. $orderPay['is_ad_user'] = 1;
  148. if((1 == $orderPay['self_order_type'] && empty($orderPay['bind_app_id'])) ||
  149. (2 == $orderPay['self_order_type']) && empty($orderPay['adq_account_id'])) {
  150. $orderPay['is_ad_user'] = 0;
  151. }
  152. }
  153. $payType = 1;// 安卓(小程序虚拟支付)
  154. # 获取订单金额分成比例(不区分安卓还是ios)
  155. // $shareInProportionArr = OrderService::getOrderShareInProportion(1);
  156. $playletName = $orderPay['playletName'] ?? null;
  157. $shareInProportionArr = OrderService::getOrderShareInProportionNew($source, $playletName, $orderPay['sys_group_id']);
  158. $shareInProportion = $shareInProportionArr[$payType] ?? 1;
  159. # 计算分成后的金额
  160. $orderPay['origin_pay_money'] = $orderPay['payMoney'];
  161. if(3 == $orderPay['sys_group_id']) {
  162. $orderPay['payMoney'] = $orderPay['origin_pay_money'] * $shareInProportion;
  163. }
  164. DjOrder::orderDataSaveFromYouzi($orderPay, $source, $status, $platformType);
  165. }
  166. # 杭州猎豆 - 冰甜剧场(嘉书小程序) - 订单数据保存
  167. public static function jiashuOrderSave($orderPay, $appId)
  168. {
  169. // 根据渠道channel获取公众号appid
  170. $channelList = TencentAdConf::getChannelList();
  171. $bindAppId = isset($channelList[$orderPay['channel']]['app_id']) ? $channelList[$orderPay['channel']]['app_id'] : '';
  172. $orderPay['bind_app_id'] = $bindAppId;
  173. $orderPay['system_corpid'] = null;
  174. $orderPay['selfUnionId'] = null;
  175. // 根据公众号appid反查企业corpid
  176. if(!empty($bindAppId)) {
  177. $systemCorpid = self::getSystemCorpidByAppId($bindAppId);
  178. $orderPay['system_corpid'] = $systemCorpid;
  179. }
  180. // 将openid写入mp_open_id字段
  181. $orderPay['mpOpenId'] = $orderPay['openid'];
  182. $orderPay['maAppId'] = $orderPay['miniAppid'] ?? null;
  183. $orderPay['is_ad_user'] = 0;
  184. $userId = null;
  185. $externalUserId = null;
  186. $params = $orderPay['params'] ?? null;
  187. if(!empty($params)) {
  188. $params = urldecode($params);
  189. if(strstr($params, '|')) {
  190. $paramsData = explode('|', $params);
  191. $corpid = $paramsData[0] ?? null;
  192. $userId = $paramsData[1] ?? null;
  193. $externalUserId = $paramsData[2] ?? null;
  194. // 如果接收到了透传回来的企微ID,则覆盖之前根据公众号查询到的企微id
  195. if(!empty($corpid)) {
  196. $orderPay['system_corpid'] = $corpid;
  197. }
  198. } else {
  199. $externalUserId = $params;
  200. }
  201. }
  202. // 查询用户最早注册时间
  203. $responseData = Customer::getCustomerRegisterTime($orderPay['system_corpid'], $orderPay['selfUnionId'], $externalUserId, $userId);
  204. $registerTime = $responseData['register_time'];
  205. $userActionSetId = $responseData['user_action_set_id'];
  206. $accountId = $responseData['account_id'];
  207. $unionid = $responseData['unionid'];
  208. $joinType = $responseData['join_type'];
  209. $adType = $responseData['ad_type'];
  210. $selfExternalUserId = $responseData['external_userid'];
  211. $selfUserId = $responseData['self_user_id'];
  212. if(!empty($registerTime)) {
  213. $orderPay['mpUserRegisterTime'] = $registerTime;
  214. $orderPay['is_ad_user'] = 1;
  215. } else {
  216. $orderPay['mpUserRegisterTime'] = strtotime($orderPay['userCreateTs']);
  217. }
  218. if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId) {
  219. Log::logInfo('嘉书小程序-回传客服ID与系统查询客服ID不一致', [
  220. 'order_id' => $orderPay['orderId'],
  221. 'self_user_id' => $selfUserId,
  222. 'corp_user_id' => $userId,
  223. ], 'callBackOrderParamsError');
  224. }
  225. if(!empty($externalUserId) && 0 == $orderPay['is_ad_user']) {
  226. Log::logInfo('嘉书小程序-接收到透传参数后找不到企微用户', [
  227. 'order_id' => $orderPay['orderId'],
  228. 'params' => $params
  229. ], 'callBackOrderParamsError');
  230. }
  231. $channelArr = config('jiashu.channel');
  232. $orderPay['userActionSetId'] = $userActionSetId;
  233. $orderPay['selfUnionId'] = $unionid;
  234. $orderPay['adq_account_id'] = $accountId;
  235. $orderPay['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
  236. $orderPay['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
  237. $orderPay['self_order_type'] = !empty($adType) ? $adType : 1;// 订单类型 为空时归属为mp订单 1mp 2adq
  238. $orderPay['join_type'] = $joinType;
  239. $orderPay['login_account'] = isset($channelArr[$orderPay['channel']]) ? 'liedou' : null;// 第三方平台登录账号
  240. // 推广数据检测区分新老客户-当月下单是新客户
  241. if (isset($orderPay['article']) && !empty($orderPay['article'])) {
  242. if (
  243. isset($orderPay['userCreateTs'], $orderPay['updateTs'])
  244. &&
  245. (!empty($orderPay['userCreateTs']) && !empty($orderPay['updateTs']))
  246. ) {
  247. $curMonth = date('Y-m-01 00:00:00', strtotime($orderPay['updateTs']));
  248. $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
  249. $regTime = $orderPay['userCreateTs'];
  250. if ($regTime >= $curMonth && $regTime < $aftMonth) {
  251. $orderPay['pCustomerType'] = 1;
  252. } else {
  253. $orderPay['pCustomerType'] = 2;
  254. }
  255. }
  256. }
  257. if(!isset($channelArr[$orderPay['channel']])) {
  258. EmailQueue::rPush('嘉书平台-未知渠道号', '渠道号:'.$orderPay['channel'], ['song.shen@kuxuan-inc.com'], '猎羽');
  259. }
  260. $payType = 1;// 安卓(小程序虚拟支付)
  261. # 获取订单金额分成比例(不区分安卓还是ios)
  262. // $shareInProportionArr = OrderService::getOrderShareInProportion(2);
  263. $playletName = $orderPay['productName'] ?? null;
  264. $shareInProportionArr = OrderService::getOrderShareInProportionNew(2, $playletName, $orderPay['sys_group_id']);
  265. $shareInProportion = $shareInProportionArr[$payType] ?? 1;
  266. # 计算分成后的金额
  267. $orderPay['origin_pay_money'] = $orderPay['price'];
  268. if(3 == $orderPay['sys_group_id']) {
  269. $orderPay['price'] = $orderPay['origin_pay_money'] * $shareInProportion;
  270. }
  271. DjOrder::orderDataSaveFromJiashu($orderPay, $appId);
  272. }
  273. # 杭州猎豆 | 剧有戏 - 中文在线(迈步) - 订单数据保存
  274. public static function unifyOrderSave($orderPay, $platformId)
  275. {
  276. // 小程序openid写入mp_open_id字段
  277. $orderPay['mpOpenid'] = $orderPay['mp_openid'] ?? null;
  278. // 根据公众号appid反查企微id
  279. $systemCorpid = self::getSystemCorpidByAppId($orderPay['gzh_appid']);
  280. $orderPay['corpid'] = $systemCorpid;
  281. $orderPay['gzh_unionid'] = $orderPay['gzh_unionid'] ?? null;
  282. // 默认非系统用户,即非投放订单
  283. $orderPay['is_ad_user'] = 0;
  284. $externalUserId = null;
  285. $userId = null;
  286. $params = $orderPay['params'] ?? ($orderPay['user_id'] ?? null);
  287. if(!empty($params)) {
  288. $params = urldecode($params);
  289. if(strstr($params, "|")) {
  290. $paramsData = explode('|', $params);
  291. $systemCorpid = $paramsData[0] ?? null;
  292. $userId = $paramsData[1] ?? null;
  293. $externalUserId = $paramsData[2] ?? null;
  294. // 如果接收到了透传回来的企微ID,则覆盖之前根据公众号查询到的企微id
  295. if(!empty($systemCorpid)) {
  296. $orderPay['corpid'] = $systemCorpid;
  297. }
  298. } else {
  299. $externalUserId = $params;
  300. $userId = null;
  301. }
  302. }
  303. $responseData = Customer::getCustomerRegisterTime($orderPay['corpid'], $orderPay['gzh_unionid'], $externalUserId, $userId);
  304. $registerTime = $responseData['register_time'];
  305. $userActionSetId = $responseData['user_action_set_id'];
  306. $accountId = $responseData['account_id'];
  307. $unionid = $responseData['unionid'];
  308. $joinType = $responseData['join_type'];
  309. $adType = $responseData['ad_type'];
  310. $selfExternalUserId = $responseData['external_userid'];
  311. $selfUserId = $responseData['self_user_id'];
  312. if(empty($registerTime)) {
  313. // 系统中没有查询到对应的注册时间,直接使用迈步返回的时间
  314. $orderPay['register_time'] = strtotime($orderPay['follow_time']);
  315. } else {
  316. $orderPay['register_time'] = $registerTime;
  317. $orderPay['is_ad_user'] = 1;
  318. }
  319. // 查询出的用户unionid不为空,则将查询结果替换接收到的unionid
  320. if(!empty($unionid)){
  321. $orderPay['gzh_unionid'] = $unionid;
  322. }
  323. if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId) {
  324. Log::logInfo('迈步平台-回传客服ID与系统查询客服ID不一致', [
  325. 'order_id' => $orderPay['orderId'],
  326. 'self_user_id' => $selfUserId,
  327. 'corp_user_id' => $userId,
  328. ], 'callBackOrderParamsError');
  329. }
  330. if(!empty($externalUserId) && 0 == $orderPay['is_ad_user']) {
  331. Log::logInfo('迈步平台-接收到透传参数后找不到企微用户', [
  332. 'order_id' => $orderPay['orderId'],
  333. 'params' => $params
  334. ], 'callBackOrderParamsError');
  335. }
  336. $orderPay['userActionSetId'] = $userActionSetId;
  337. $orderPay['adq_account_id'] = $accountId;
  338. $orderPay['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
  339. $orderPay['join_type'] = $joinType;
  340. $orderPay['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
  341. $orderPay['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
  342. $loginAccountConf = config('maiBu.login_account');// 第三方平台登录账号
  343. $orderPay['login_account'] = !empty($orderPay['partner_id']) ? (isset($loginAccountConf[$orderPay['partner_id']]) ?
  344. $loginAccountConf[$orderPay['partner_id']] : null) : null;
  345. // 推广数据检测区分新老客户-当月下单是新客户
  346. if (isset($orderPay['promotion_id']) && !empty($orderPay['promotion_id'])) {
  347. if (
  348. isset($orderPay['register_time'], $orderPay['order_pay_time'])
  349. &&
  350. (!empty($orderPay['register_time']) && !empty($orderPay['order_pay_time']))
  351. ) {
  352. $curMonth = date('Y-m-01 00:00:00', strtotime($orderPay['order_pay_time']));
  353. $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
  354. $regTime = date('Y-m-d H:i:s', $orderPay['register_time']);
  355. if ($regTime >= $curMonth && $regTime < $aftMonth) {
  356. $orderPay['pCustomerType'] = 1;// 推广数据新用户
  357. } else {
  358. $orderPay['pCustomerType'] = 2;// 推广数据老用户
  359. }
  360. }
  361. }
  362. if(38 == $orderPay['sys_group_id']) {
  363. $orderPay['is_ad_user'] = 1;
  364. $orderPay['self_order_type'] = 2;
  365. $orderPay['selfUnionId'] = $orderPay['mpOpenid'];
  366. $orderPay['external_userid'] = empty($orderPay['external_userid']) ? $orderPay['selfUnionId'] : $orderPay['external_userid'];
  367. if((1 == $orderPay['self_order_type'] && empty($orderPay['gzh_appid'])) ||
  368. (2 == $orderPay['self_order_type']) && empty($orderPay['adq_account_id'])) {
  369. $orderPay['is_ad_user'] = 0;
  370. }
  371. }
  372. $payType = 1;
  373. # 获取对应的支付类型
  374. $orderPay['pay_type'] = $orderPay['pay_type'] ?? 0;
  375. $orderPay['order_pay_type'] = MaiBuService::getOrderPayType($orderPay['pay_type']);
  376. if(1 != $orderPay['order_pay_type']) $payType = 2;
  377. # 获取订单金额分成比例
  378. // $shareInProportionArr = OrderService::getOrderShareInProportion(3);
  379. $playletName = $orderPay['product_name'] ?? null;
  380. $shareInProportionArr = OrderService::getOrderShareInProportionNew(3, $playletName, $orderPay['sys_group_id']);
  381. $shareInProportion = $shareInProportionArr[$payType] ?? 1;// 不能区分是否为安卓还是ios之前先统一按照安卓处理
  382. # 计算分成后的金额
  383. $orderPay['origin_pay_money'] = $orderPay['amount'];
  384. if(3 == $orderPay['sys_group_id']) {
  385. $orderPay['amount'] = $orderPay['origin_pay_money'] * $shareInProportion;
  386. }
  387. DjOrder::orderDataSaveFromUnify($orderPay, $platformId, 3);
  388. }
  389. public static function getSystemCorpidByAppId($appId)
  390. {
  391. $officialAccountList = OfficialAccount::lists();
  392. $corpid = isset($officialAccountList[$appId]['corp_id']) ? $officialAccountList[$appId]['corp_id'] : '';
  393. return $corpid;
  394. }
  395. /*
  396. * 汇总指定账号对应时间段内的累计充值人数【unionId去重】
  397. * @param $accountData array 待汇总的账号信息集合 array(['app_id' => *, 'start_date' => *, 'end_date' => *],……)
  398. * */
  399. public static function getChargeUserTotalUnique($accountData)
  400. {
  401. if(empty($accountData)) return 0;
  402. $externalUserIdList = array();
  403. try {
  404. foreach ($accountData as $datum) {
  405. $appId = $datum['app_id'] ?? '';
  406. $startDate = $datum['start_date'] ?? '';
  407. $endDate = $datum['end_date'] ?? '';
  408. $accountId = $datum['account_id'] ?? '';
  409. if((empty($appId) && empty($accountId)) || !$startDate || !$endDate) {
  410. Log::logError('汇总去重后的累计充值人数参数缺失', [
  411. 'app_id' => $appId,
  412. 'start_date' => $startDate,
  413. 'end_date' => $endDate,
  414. 'param' => $accountData
  415. ], 'ChargeUserTotalUnique');
  416. continue;
  417. }
  418. if(!empty($appId)) {
  419. # 查询公众号在这段时间范围内下单用户的external_userid
  420. $externalUserIds = DjOrder::query()
  421. ->select(['external_userid'])->where('bind_app_id', $appId)
  422. ->where('mp_user_register_time', '>=', strtotime($startDate . ' 00:00:00') * 1000)
  423. ->where('mp_user_register_time', '<=', strtotime($endDate.' 23:59:59') * 1000)
  424. ->where('pay_status', 1)
  425. ->where('is_ad_user', 1)
  426. ->where('order_type', 1)
  427. ->distinct()
  428. ->pluck('external_userid');
  429. if(!empty($externalUserIds))
  430. $externalUserIds = $externalUserIds->toArray();
  431. $externalUserIdList = array_merge($externalUserIdList, $externalUserIds);
  432. } else {
  433. # 查询公众号在这段时间范围内下单用户的unionId
  434. $externalUserIds = DjOrder::query()
  435. ->select(['external_userid'])->where('adq_account_id', $accountId)
  436. ->where('mp_user_register_time', '>=', strtotime($startDate . ' 00:00:00') * 1000)
  437. ->where('mp_user_register_time', '<=', strtotime($endDate.' 23:59:59') * 1000)
  438. ->where('pay_status', 1)
  439. ->where('is_ad_user', 1)
  440. ->where('order_type', 2)
  441. ->distinct()
  442. ->pluck('external_userid');
  443. if(!empty($externalUserIds))
  444. $externalUserIds = $externalUserIds->toArray();
  445. $externalUserIdList = array_merge($externalUserIdList, $externalUserIds);
  446. }
  447. }
  448. } catch (\Exception $e) {
  449. Log::logError('汇总去重后的累计充值人数过程发生异常', [
  450. 'line' => $e->getLine(),
  451. 'msg' => $e->getMessage(),
  452. 'param' => $accountData
  453. ], 'ChargeUserTotalUnique-Exception');
  454. }
  455. return count(array_unique($externalUserIdList));
  456. }
  457. # 杭州猎豆 - 东方小剧场(嘉书H5) - 订单数据保存
  458. public static function jiashuWebOrderSave($dataList)
  459. {
  460. # 嘉书h5一次请求数据会包含多条数据,需要遍历数据,逐条判断是否为下单类型
  461. foreach($dataList as $orderPay) {
  462. $dataType = isset($orderPay['datatype']) ? $orderPay['datatype'] : '';
  463. switch($dataType) {
  464. case 'register': #注册,新激活
  465. break;
  466. case 'active': # 活跃
  467. break;
  468. case 'pay': #支付
  469. // 根据公众号appid反查企微id
  470. $systemCorpid = self::getSystemCorpidByAppId($orderPay['app_id']);
  471. $orderPay['corpid'] = $systemCorpid;
  472. // 根据返回的外部联系人id查询用户的unionid以及注册时间
  473. $params = $orderPay['params'] ?? null;
  474. $params = ('undefined' == $params) ? null : $params;
  475. $userId = null;
  476. $externalUserId = null;
  477. if(!empty($params)){
  478. $params = urldecode($params);
  479. if(strstr($params, '|')) {
  480. $paramsData = explode('|', $params);
  481. $systemCorpid = $paramsData[0] ?? null;
  482. $userId = $paramsData[1] ?? null;
  483. $externalUserId = $paramsData[2] ?? null;
  484. // 如果接收到了透传回来的企微ID,则覆盖之前根据公众号查询到的企微id
  485. if(!empty($systemCorpid)) {
  486. $orderPay['corpid'] = $systemCorpid;
  487. }
  488. } else {
  489. $externalUserId = $params;
  490. }
  491. }
  492. //TODO 通过platform_id来查询,当剧有戏或者其他团队想要使用该逻辑时,需要重新提供请求接口,在连接上带上平台ID参数
  493. $orderPay['sys_group_id'] = 3;//杭州猎豆账号
  494. // 查询用户最早注册时间
  495. $orderPay['is_ad_user'] = 0;
  496. $responseData = Customer::getCustomerRegisterTime($orderPay['corpid'], null, $externalUserId, $userId);
  497. $registerTime = $responseData['register_time'];
  498. $userActionSetId = $responseData['user_action_set_id'];
  499. $accountId = $responseData['account_id'];
  500. $unionid = $responseData['unionid'];
  501. $joinType = $responseData['join_type'];
  502. $adType = $responseData['ad_type'];
  503. $selfExternalUserId = $responseData['external_userid'];
  504. $selfUserId = $responseData['self_user_id'];
  505. if(empty($registerTime)) {
  506. // 系统中没有查询到对应的注册时间,直接使用嘉书返回的时间
  507. $orderPay['register_time'] = strtotime($orderPay['register_ts']);
  508. } else {
  509. $orderPay['register_time'] = $registerTime;
  510. // $orderPay['register_time'] = strtotime($orderPay['register_ts']);
  511. $orderPay['is_ad_user'] = 1;
  512. }
  513. if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId) {
  514. Log::logInfo('嘉书web平台-回传客服ID与系统查询客服ID不一致', [
  515. 'order_id' => $orderPay['order_id'],
  516. 'self_user_id' => $selfUserId,
  517. 'corp_user_id' => $userId,
  518. ], 'callBackOrderParamsError');
  519. }
  520. if(!empty($externalUserId) && 0 == $orderPay['is_ad_user']) {
  521. Log::logInfo('嘉书web平台-接收到透传参数后找不到企微用户', [
  522. 'order_id' => $orderPay['order_id'],
  523. 'params' => $params
  524. ], 'callBackOrderParamsError');
  525. }
  526. $channelArr = config('jiashu.channel');
  527. $orderPay['userActionSetId'] = $userActionSetId;
  528. $orderPay['adq_account_id'] = $accountId;
  529. $orderPay['self_unionid'] = $unionid;
  530. $orderPay['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
  531. $orderPay['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
  532. $orderPay['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
  533. $orderPay['join_type'] = $joinType;
  534. $orderPay['login_account'] = isset($channelArr[$orderPay['channel']]) ? 'hzliedou' : null;
  535. if(!isset($channelArr[$orderPay['channel']])) {
  536. EmailQueue::rPush('嘉书平台-未知渠道号', '渠道号:'.$orderPay['channel'], ['song.shen@kuxuan-inc.com'], '猎羽');
  537. }
  538. // 判断订单来源
  539. $orderPay['plat_order_type'] = (0 == $orderPay['app_type']) ? 1 : 0;// app_type为0时表示H5来源,其他为小程序来源
  540. $payType = 1;// 安卓(小程序虚拟支付)
  541. # 获取订单金额分成比例(不用区分是否为小程序虚拟支付)
  542. // $shareInProportionArr = OrderService::getOrderShareInProportion(2);
  543. $playletName = $orderPay['product_name'] ?? null;
  544. $shareInProportionArr = OrderService::getOrderShareInProportionNew(2, $playletName, $orderPay['sys_group_id']);
  545. $shareInProportion = $shareInProportionArr[$payType] ?? 1;
  546. # 计算分成后的金额
  547. $orderPay['origin_pay_money'] = $orderPay['amount'];
  548. if(3 == $orderPay['sys_group_id']) {
  549. $orderPay['amount'] = $orderPay['origin_pay_money'] * $shareInProportion;
  550. }
  551. DjOrder::jiashuWebOrderSave($orderPay);
  552. break;
  553. case 'shortcut': # 加桌
  554. break;
  555. case 'ad': # 广告活跃
  556. break;
  557. case 'play': # 播放记录
  558. break;
  559. case 'fans': # 关注/取关粉丝
  560. break;
  561. case 'refund': # 退款
  562. break;
  563. case 'subscribe': # 订阅消息
  564. break;
  565. case 'buy': # 购买记录
  566. break;
  567. case 'pay_report': # 支付回传数据
  568. break;
  569. default:
  570. Log::logError('嘉书H5回调数据类型异常', ['order_pay' => $orderPay], 'callBackOrderError');
  571. break;
  572. }
  573. }
  574. }
  575. # 杭州猎豆 - 点众阳光 - 订单数据保存
  576. public static function platformOrderCallBack($orderPay)
  577. {
  578. $params = $orderPay['params'] ?? ($orderPay['user_id'] ?? null);
  579. $params = ('null' == $params) ? null : $params;
  580. $userId = null;
  581. $externalUserId = null;
  582. if(!empty($params)) {
  583. $params = urldecode($params);
  584. if(strstr($params, "|")) {
  585. $paramsData = explode('|', $params);
  586. $systemCorpid = $paramsData[0] ?? null;
  587. $userId = $paramsData[1] ?? null;
  588. $externalUserId = $paramsData[2] ?? null;
  589. // 如果接收到了透传回来的企微ID,则覆盖之前根据公众号查询到的企微id
  590. if(!empty($systemCorpid)) {
  591. $orderPay['corpid'] = $systemCorpid;
  592. }
  593. } else {
  594. $externalUserId = $params;
  595. $userId = null;
  596. }
  597. }
  598. $orderPay['gzh_unionid'] = $orderPay['gzh_unionid'] ?? null;
  599. $orderPay['corpid'] = $orderPay['corpid'] ?? null;
  600. $responseData = Customer::getCustomerRegisterTime($orderPay['corpid'], $orderPay['gzh_unionid'], $externalUserId, $userId);
  601. $registerTime = $responseData['register_time'];
  602. $userActionSetId = $responseData['user_action_set_id'];
  603. $accountId = $responseData['account_id'];
  604. $unionid = $responseData['unionid'];
  605. $joinType = $responseData['join_type'];
  606. $adType = $responseData['ad_type'];
  607. $selfExternalUserId = $responseData['external_userid'];
  608. $selfUserId = $responseData['self_user_id'];
  609. if(empty($registerTime)) {
  610. // 系统中没有查询到对应的注册时间,直接使用迈步返回的时间
  611. $orderPay['register_time'] = null;
  612. $orderPay['is_ad_user'] = 0;
  613. } else {
  614. $orderPay['register_time'] = $registerTime;
  615. $orderPay['is_ad_user'] = 1;
  616. }
  617. // 查询出的用户unionid不为空,则将查询结果替换接收到的unionid
  618. if(!empty($unionid)){
  619. $orderPay['gzh_unionid'] = $unionid;
  620. }
  621. if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId) {
  622. Log::logInfo('点众阳光平台-回传客服ID与系统查询客服ID不一致', [
  623. 'order_id' => $orderPay['orderId'],
  624. 'self_user_id' => $selfUserId,
  625. 'corp_user_id' => $userId,
  626. ], 'callBackOrderParamsError');
  627. }
  628. if(!empty($externalUserId) && 0 == $orderPay['is_ad_user']) {
  629. Log::logInfo('点众阳光平台-接收到透传参数后找不到企微用户', [
  630. 'order_id' => $orderPay['orderId'],
  631. 'params' => $params
  632. ], 'callBackOrderParamsError');
  633. }
  634. $orderPay['userActionSetId'] = $userActionSetId;
  635. $orderPay['adq_account_id'] = $accountId;
  636. $orderPay['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
  637. $orderPay['join_type'] = $joinType;
  638. $orderPay['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
  639. $orderPay['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
  640. // 推广数据检测区分新老客户-当月下单是新客户
  641. if (isset($orderPay['promotion_id']) && !empty($orderPay['promotion_id'])) {
  642. if (
  643. isset($orderPay['register_time'], $orderPay['order_pay_time'])
  644. &&
  645. (!empty($orderPay['register_time']) && !empty($orderPay['order_pay_time']))
  646. ) {
  647. $curMonth = date('Y-m-01 00:00:00', strtotime($orderPay['order_pay_time']));
  648. $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
  649. $regTime = date('Y-m-d H:i:s', $orderPay['register_time']);
  650. if ($regTime >= $curMonth && $regTime < $aftMonth) {
  651. $orderPay['pCustomerType'] = 1;// 推广数据新用户
  652. } else {
  653. $orderPay['pCustomerType'] = 2;// 推广数据老用户
  654. }
  655. }
  656. }
  657. $payType = 1; // 安卓(小程序虚拟支付)
  658. # 获取订单金额分成比例(不用区分是否为小程序虚拟支付)
  659. // $shareInProportionArr = OrderService::getOrderShareInProportion(4);
  660. $productName = $orderPay['product_name'] ?? null;
  661. $shareInProportionArr = OrderService::getOrderShareInProportionNew($orderPay['order_source'], $productName, $orderPay['sys_group_id']);
  662. $shareInProportion = $shareInProportionArr[$payType] ?? 1;
  663. # 计算分成后的金额
  664. $orderPay['origin_pay_money'] = $orderPay['amount'];
  665. if(3 == $orderPay['sys_group_id']) {
  666. $orderPay['amount'] = $orderPay['origin_pay_money'] * $shareInProportion;
  667. }
  668. $os = self::sunshineDeviceType($orderPay);
  669. $orderPay['os'] = $os;
  670. DjOrder::orderDataSaveFromPlatform($orderPay);
  671. }
  672. public static function sunshineDeviceType($order) {
  673. if(!isset($order['os'])) {
  674. // EmailQueue::rPush('第三方平台设备类型异常', json_encode([
  675. // 'platform' => '点众阳光', 'msg' => '设备类型字段不存在', 'order_data' => $order
  676. // ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
  677. return 0;
  678. }
  679. switch($order['os']) {
  680. case 0:# 安卓
  681. $os = 1;break;
  682. case 1:# ios
  683. $os = 2;break;
  684. default:
  685. EmailQueue::rPush('第三方平台设备类型异常', json_encode([
  686. 'platform' => '点众阳光', 'msg' => '设备类型字段值不符合预期', 'order_data' => $order
  687. ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
  688. $os = 0;break;
  689. }
  690. return $os;
  691. }
  692. # 杭州猎豆 - 容量 - 订单数据保存
  693. public static function saveCapacityOrder($order)
  694. {
  695. $order['order_source'] = 6;
  696. $order['order_type'] = 0;// 默认小程序
  697. $order['corpId'] = $order['corpId'] ?? null;
  698. $order['qyOpenId'] = $order['qyOpenId'] ?? null;
  699. $order['qyUserId'] = $order['qyUserId'] ?? null;
  700. # 查询公众号对应的用户openid
  701. $userInfo = CapacityUser::getUserInfo($order['productUserId'], $order['spreadChannelId'], $order['corpId']
  702. , $order['qyOpenId'], $order['qyUserId'], $order['id'], $order['createTime'], $order['platform_id']);
  703. $order['maOpenId'] = !empty($userInfo['maOpenId']) ? $userInfo['maOpenId'] : null;
  704. $order['mpOpenId'] = !empty($userInfo['mpOpenId']) ? $userInfo['mpOpenId'] : null;
  705. $order['corpId'] = !empty($userInfo['corpId']) ? $userInfo['corpId'] : $order['corpId'];
  706. $order['qyOpenId'] = !empty($userInfo['qyOpenId']) ? $userInfo['qyOpenId'] : $order['qyOpenId'];
  707. $order['qyUserId'] = !empty($userInfo['qyUserId']) ? $userInfo['qyUserId'] : $order['qyUserId'];
  708. if(isset($order['spreadChannelId']) && !empty($order['spreadChannelId'])){
  709. // 根据渠道ID获取对应的公众号app_id
  710. $order['gzh_appid'] = PlatformApp::query()->where('channel', $order['spreadChannelId'])
  711. ->where('enable', 1)->where('platform_id', 6)->value('app_id');
  712. if(!empty($order['gzh_appid']) && !empty($order['authorisedAppId']) && ($order['gzh_appid'] != $order['authorisedAppId'])
  713. && (time()*1000 <= $order['createTime']+300000)) {
  714. Log::logInfo('容量平台-已授权的公众号appid与渠道ID对应公众号不一致', [
  715. 'order_id' => $order['id'],
  716. 'gzh_appid' => $order['gzh_appid'],
  717. 'spreadChannelId' => $order['spreadChannelId'],
  718. 'authorisedAppId' => $order['authorisedAppId']
  719. ], 'callBackOrderParamsError');
  720. }
  721. if(!isset($order['authorisedAppId'])) {
  722. $order['authorisedAppId'] = $order['gzh_appid'];
  723. }
  724. }
  725. $corpid = $order['corpId'] ?? null;
  726. $externalUserId = $order['qyOpenId'] ?? null;
  727. $userId = $order['qyUserId'] ?? null;
  728. $order['authorisedAppId'] = $order['authorisedAppId'] ?? null;
  729. // 当透传回来的企微ID为空时,根据公众号app_id再次查询一次绑定的企微ID
  730. if(empty($order['corpId']) && !empty($order['authorisedAppId'])) {
  731. $corpid = DjOrderService::getSystemCorpidByAppId($order['authorisedAppId']);
  732. $order['corpId'] = $corpid;
  733. }
  734. $responseData = Customer::getCustomerRegisterTime($corpid, null, $externalUserId, $userId);
  735. $registerTime = $responseData['register_time'];
  736. $userActionSetId = $responseData['user_action_set_id'];
  737. $accountId = $responseData['account_id'];
  738. $unionid = $responseData['unionid'];
  739. $joinType = $responseData['join_type'];
  740. $adType = $responseData['ad_type'];
  741. $selfExternalUserId = $responseData['external_userid'];
  742. $selfUserId = $responseData['self_user_id'];
  743. $order['is_ad_user'] = 0;
  744. if(empty($registerTime)) {
  745. // 系统中没有查询到对应的注册时间,直接使用第三方返回的时间
  746. $order['register_time'] = $order['userRegisterTime'];
  747. } else {
  748. $order['register_time'] = $registerTime * 1000;
  749. $order['is_ad_user'] = 1;
  750. }
  751. # 判断系统查询得到的客服id和透传回来的客服id是否一致(订单获取到5分钟之内报警,因为同一个订单在当天会不停的获取到)
  752. if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId && (time()*1000 <= $order['createTime']+300000)) {
  753. Log::logInfo('容量平台回传客服ID与系统查询客服ID不一致', [
  754. 'order_info' => $order,
  755. 'response' => $responseData,
  756. ], 'callBackOrderUserIdError');
  757. EmailQueue::rPush('容量平台回传客服ID与系统查询客服ID不一致', json_encode([
  758. 'order_info' => $order,
  759. 'response' => $responseData,
  760. ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
  761. }
  762. if($accountId) {
  763. $accountRelationAppList = AdqUser::getAppIdList([$accountId]);
  764. $accountRelationAppId = $accountRelationAppList->where('account_id', $accountId)->first();
  765. $accountRelationAppId = $accountRelationAppId->app_id ?? null;
  766. # 当投放账号绑定的公众号与订单中渠道号对应的公众号不一致时,更新为非投放
  767. if($accountRelationAppId != $order['authorisedAppId'] && date('Y-m-d', $order['createTime']/1000) >= '2023-04-25') {
  768. $order['is_ad_user'] = 0;
  769. $order['register_time'] = $order['userRegisterTime'];
  770. Log::logInfo('容量平台需归结为非投放订单', [
  771. 'order_id' => $order['id'],
  772. 'relation_app_id' => $accountRelationAppId,
  773. 'bind_app_id' => $order['authorisedAppId']
  774. ], 'CapacityOrderTest');
  775. } else {
  776. $order['userActionSetId'] = $userActionSetId;
  777. $order['adq_account_id'] = $accountId;
  778. $order['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
  779. $order['join_type'] = $joinType;
  780. $order['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
  781. $order['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
  782. $order['self_unionid'] = $unionid;
  783. }
  784. }
  785. if(!empty($externalUserId) && 0 == $order['is_ad_user'] && (time()*1000 <= $order['createTime']+300000)) {
  786. Log::logInfo('容量平台-接收到透传参数后找不到企微用户', [
  787. 'order_id' => $order['id'],
  788. 'corpId' => $order['corpId'],
  789. 'qyOpenId' => $order['qyOpenId'],
  790. 'qyUserId' => $order['qyUserId']
  791. ], 'callBackOrderParamsError');
  792. }
  793. // 处理支付相关信息
  794. $order = CapacityService::dealPayInfo($order);
  795. # 判断是否为直投订单
  796. $order['promotion_id'] = $order['batchId'] ?? null;
  797. // 推广数据检测区分新老客户-当月下单是新客户
  798. if (isset($order['promotion_id']) && !empty($order['promotion_id'])) {
  799. if (
  800. isset($order['register_time'], $order['createTime'])
  801. &&
  802. (!empty($order['register_time']) && !empty($order['createTime']))
  803. ) {
  804. $curMonth = date('Y-m-01 00:00:00', $order['createTime']/1000);
  805. $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
  806. $regTime = date('Y-m-d H:i:s', $order['register_time']/1000);
  807. if ($regTime >= $curMonth && $regTime < $aftMonth) {
  808. $order['pCustomerType'] = 1;// 推广数据新用户
  809. } else {
  810. $order['pCustomerType'] = 2;// 推广数据老用户
  811. }
  812. }
  813. }
  814. # 查询推广ID对应的链接名称
  815. $order['promotion_title'] = MassPopularizData::query()->where('pid', strval($order['promotion_id']))
  816. ->where('platType', 6)->value('popularizTitle');
  817. $order['is_direct_investment'] = false;
  818. if(!empty($order['promotion_id'])) {
  819. $adqAccountIds = AccountConfService::getAccountIdByPid($order['sys_group_id'], $order['promotion_id'], 1);
  820. if(!empty($adqAccountIds)) {
  821. if(count($adqAccountIds) > 1) {
  822. EmailQueue::rPush('根据推广计划id查询投放账号结果异常(容量平台)', 'sys_group_id:' . $order['sys_group_id']
  823. . '; pid:' . $order['promotion_id'], ['song.shen@kuxuan-inc.com'], '猎羽');
  824. }
  825. $order['is_direct_investment'] = true;
  826. $adqAccountId = $adqAccountIds[0];
  827. $officialWebUserActionInfo = OfficialWebUserActionSetId::query()
  828. ->where('account_id', $adqAccountId)
  829. ->first();
  830. $userActionSetId = $officialWebUserActionInfo->web_user_action_set_id ?? null;
  831. $order['adq_account_id'] = $adqAccountId; # adq投放账号id
  832. $order['self_order_type'] = 2; # 指定为adq投放
  833. $order['userActionSetId'] = $userActionSetId;# 投放账号绑定的数据源id
  834. DjDirectInvestmentOrder::saveCapacityOrder($order);
  835. return true;
  836. }
  837. }
  838. $userAgent = $order['userAgent'] ?? '';
  839. # 从userAgent中提取设备信息
  840. $deviceType = CapacityService::getDeviceType($userAgent);
  841. $order['os'] = $deviceType;
  842. DjOrder::saveCapacityOrder($order);
  843. return true;
  844. }
  845. # 杭州猎豆 - 花生 - 订单数据保存
  846. public static function savePeanutOrder($order)
  847. {
  848. $order['sys_group_id'] = 3;
  849. $order['platform_id'] = 'rrTkwItVplaezpb5';
  850. $order['order_source'] = 5;
  851. $order['kuxuan_corp_id'] = $order['kuxuan_corp_id'] == '-' ? null : $order['kuxuan_corp_id'];
  852. $order['kuxuan_ex_user_id'] = $order['kuxuan_ex_user_id'] == '-' ? null : $order['kuxuan_ex_user_id'];
  853. $order['kuxuan_customer_id'] = $order['kuxuan_customer_id'] == '-' ? null : $order['kuxuan_customer_id'];
  854. $corpid = $order['kuxuan_corp_id'];
  855. $externalUserId = $order['kuxuan_ex_user_id'];
  856. $userId = $order['kuxuan_customer_id'];
  857. // 当透传回来的企微ID为空时,根据公众号app_id再次查询一次绑定的企微ID
  858. if(empty($corpid) && !empty($order['mpAppId'])) {
  859. $corpid = DjOrderService::getSystemCorpidByAppId($order['mpAppId']);
  860. $order['kuxuan_corp_id'] = $corpid;
  861. }
  862. $responseData = Customer::getCustomerRegisterTime($corpid, null, $externalUserId, $userId);
  863. $registerTime = $responseData['register_time'];
  864. $userActionSetId = $responseData['user_action_set_id'];
  865. $accountId = $responseData['account_id'];
  866. $unionid = $responseData['unionid'];
  867. $joinType = $responseData['join_type'];
  868. $adType = $responseData['ad_type'];
  869. $selfExternalUserId = $responseData['external_userid'];
  870. $selfUserId = $responseData['self_user_id'];
  871. $order['is_ad_user'] = 0;
  872. if(empty($registerTime)) {
  873. // 系统中没有查询到对应的注册时间,直接使用迈步返回的时间
  874. $order['register_time'] = strtotime($order['join_at']) * 1000;
  875. } else {
  876. $order['register_time'] = $registerTime * 1000;
  877. $order['is_ad_user'] = 1;
  878. }
  879. if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId && (time() <= strtotime($order['request_at'])+300)) {
  880. Log::logInfo('花生平台回传客服ID与系统查询客服ID不一致', [
  881. 'order_info' => $order,
  882. 'response' => $responseData,
  883. ], 'callBackOrderUserIdError');
  884. EmailQueue::rPush('花生平台回传客服ID与系统查询客服ID不一致', json_encode([
  885. 'order_info' => $order,
  886. 'response' => $responseData,
  887. ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
  888. }
  889. $order['userActionSetId'] = $userActionSetId;
  890. $order['adq_account_id'] = $accountId;
  891. $order['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
  892. $order['join_type'] = $joinType;
  893. $order['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
  894. $order['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
  895. $order['self_unionid'] = $unionid;
  896. $order['promotion_id'] = $order['spread_id'] ?? null;
  897. // 推广数据检测区分新老客户-当月下单是新客户
  898. if (isset($order['promotion_id']) && !empty($order['promotion_id'])) {
  899. if (
  900. isset($order['register_time'], $order['pay_at'])
  901. &&
  902. (!empty($order['register_time']) && !empty($order['pay_at']))
  903. ) {
  904. $curMonth = date('Y-m-01 00:00:00', strtotime($order['pay_at']));
  905. $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
  906. $regTime = date('Y-m-d H:i:s', $order['register_time']/1000);
  907. if ($regTime >= $curMonth && $regTime < $aftMonth) {
  908. $order['pCustomerType'] = 1;// 推广数据新用户
  909. } else {
  910. $order['pCustomerType'] = 2;// 推广数据老用户
  911. }
  912. }
  913. }
  914. if(!empty($externalUserId) && 0 == $order['is_ad_user'] && (time() <= strtotime($order['pay_at'])+300)) {
  915. Log::logInfo('花生平台-接收到透传参数后找不到企微用户', [
  916. 'order_id' => $order['order_num'],
  917. 'corpId' => $order['kuxuan_corp_id'],
  918. 'qyOpenId' => $order['kuxuan_ex_user_id'],
  919. 'qyUserId' => $order['kuxuan_customer_id']
  920. ], 'callBackOrderParamsError');
  921. }
  922. $payType = 1; // 安卓 小程序虚拟支付
  923. $way = $order['way'] ?? 0;
  924. $order['order_pay_type'] = HuaShengService::getOrderPayType($way);
  925. if(1 != $order['order_pay_type']) { $payType = 2; }
  926. # 获取订单金额分成比例(不用区分是否为小程序虚拟支付)
  927. // $shareInProportionArr = OrderService::getOrderShareInProportion(5);
  928. $playletName = $order['book_name'] ?? null;
  929. $shareInProportionArr = OrderService::getOrderShareInProportionNew($order['order_source'], $playletName, $order['sys_group_id']);
  930. $shareInProportion = $shareInProportionArr[$payType] ?? 1;
  931. # 计算分成后的金额
  932. $order['origin_pay_money'] = $order['total_charge_amount'];
  933. if(3 == $order['sys_group_id']) {
  934. $order['total_charge_amount'] = $order['origin_pay_money'] * $shareInProportion;
  935. }
  936. $order = HuaShengService::getOrderOs($order);
  937. DjOrder::savePeanutOrder($order);
  938. }
  939. # 星橙优品 - 花生 - 订单数据保存
  940. public static function savePeanutOrderSecond($order)
  941. {
  942. $order['sys_group_id'] = 51;
  943. $order['platform_id'] = '8TCtA8fHsIpbnlun';
  944. $order['order_source'] = 5;
  945. $order['enterprise_corp_id'] = !isset($order['enterprise_corp_id']) || $order['enterprise_corp_id'] == '-' ? null : $order['enterprise_corp_id'];
  946. $order['enterprise_ex_user_id'] = !isset($order['enterprise_ex_user_id']) || $order['enterprise_ex_user_id'] == '-' ? null : $order['enterprise_ex_user_id'];
  947. $order['enterprise_customer_id'] = !isset($order['enterprise_customer_id']) || $order['enterprise_customer_id'] == '-' ? null : $order['enterprise_customer_id'];
  948. $corpid = $order['enterprise_corp_id'];
  949. $externalUserId = $order['enterprise_ex_user_id'];
  950. $userId = $order['enterprise_customer_id'];
  951. // 当透传回来的企微ID为空时,根据公众号app_id再次查询一次绑定的企微ID
  952. if(empty($corpid) && !empty($order['mpAppId'])) {
  953. $corpid = DjOrderService::getSystemCorpidByAppId($order['mpAppId']);
  954. $order['enterprise_corp_id'] = $corpid;
  955. }
  956. $responseData = Customer::getCustomerRegisterTime($corpid, null, $externalUserId, $userId);
  957. $registerTime = $responseData['register_time'];
  958. $userActionSetId = $responseData['user_action_set_id'];
  959. $accountId = $responseData['account_id'];
  960. $unionid = $responseData['unionid'];
  961. $joinType = $responseData['join_type'];
  962. $adType = $responseData['ad_type'];
  963. $selfExternalUserId = $responseData['external_userid'];
  964. $selfUserId = $responseData['self_user_id'];
  965. $order['is_ad_user'] = 0;
  966. if(empty($registerTime)) {
  967. // 系统中没有查询到对应的注册时间,直接使用第三方返回的时间
  968. $order['register_time'] = strtotime($order['join_at']) * 1000;
  969. } else {
  970. $order['register_time'] = $registerTime * 1000;
  971. $order['is_ad_user'] = 1;
  972. }
  973. if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId) {
  974. Log::logInfo('花生平台回传客服ID与系统查询客服ID不一致', [
  975. 'order_info' => $order,
  976. 'response' => $responseData,
  977. ], 'callBackOrderUserIdError');
  978. EmailQueue::rPush('花生平台回传客服ID与系统查询客服ID不一致', json_encode([
  979. 'order_info' => $order,
  980. 'response' => $responseData,
  981. ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
  982. }
  983. $order['userActionSetId'] = $userActionSetId;
  984. $order['adq_account_id'] = $accountId;
  985. $order['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
  986. $order['join_type'] = $joinType;
  987. $order['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
  988. $order['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
  989. $order['self_unionid'] = $unionid;
  990. $order['promotion_id'] = $order['spread_id'] ?? null;
  991. // 推广数据检测区分新老客户-当月下单是新客户
  992. if (isset($order['promotion_id']) && !empty($order['promotion_id'])) {
  993. if (
  994. isset($order['register_time'], $order['pay_at'])
  995. &&
  996. (!empty($order['register_time']) && !empty($order['pay_at']))
  997. ) {
  998. $curMonth = date('Y-m-01 00:00:00', strtotime($order['pay_at']));
  999. $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($curMonth)));
  1000. $regTime = date('Y-m-d H:i:s', $order['register_time']/1000);
  1001. if ($regTime >= $curMonth && $regTime < $aftMonth) {
  1002. $order['pCustomerType'] = 1;// 推广数据新用户
  1003. } else {
  1004. $order['pCustomerType'] = 2;// 推广数据老用户
  1005. }
  1006. }
  1007. }
  1008. if(!empty($externalUserId) && 0 == $order['is_ad_user']) {
  1009. Log::logInfo('花生平台-接收到透传参数后找不到企微用户', [
  1010. 'order_id' => $order['order_num'],
  1011. 'corpId' => $order['enterprise_corp_id'],
  1012. 'qyOpenId' => $order['enterprise_ex_user_id'],
  1013. 'qyUserId' => $order['enterprise_customer_id']
  1014. ], 'callBackOrderParamsError');
  1015. }
  1016. $order['kuxuan_corp_id'] = $order['enterprise_corp_id'];
  1017. $order['origin_pay_money'] = $order['total_charge_amount'];
  1018. $way = $order['way'] ?? 0;
  1019. $order['order_pay_type'] = HuaShengService::getOrderPayType($way);
  1020. $order = HuaShengService::getOrderOs($order);
  1021. DjOrder::savePeanutOrder($order);
  1022. }
  1023. # 星橙优品|猎豆优选 - 九州 - 订单数据保存
  1024. public static function saveJiuZhouOrder($order) {
  1025. $order['platform_id'] = '';
  1026. $order['order_source'] = 7;
  1027. $order['plat_order_type'] = 0;
  1028. # 解析透传参数
  1029. $msgId = $order['msg_id'];
  1030. $msgData = explode('|', $msgId);
  1031. $suffix = $msgData[0] ?? null;
  1032. $dataId = $msgData[1] ?? null;
  1033. $corpid = null;
  1034. $externalUserId = null;
  1035. $userId = null;
  1036. if(!empty($suffix) && !empty($dataId)) {
  1037. $row = CustomerDetails::suffix(intval($suffix))->where('id', $dataId)->select(['corpid', 'user_id', 'external_userid'])
  1038. ->first();
  1039. $corpid = $row->corpid ?? null;
  1040. $userId = $row->user_id ?? null;
  1041. $externalUserId = $row->external_userid ?? null;
  1042. }
  1043. // 当透传回来的企微ID为空时,根据公众号app_id再次查询一次绑定的企微ID
  1044. if(empty($corpid) && !empty($order['gzh_id'])) {
  1045. $corpid = DjOrderService::getSystemCorpidByAppId($order['gzh_id']);
  1046. }
  1047. // 通过透传参数查找系统客户信息以及投放账号信息
  1048. $responseData = Customer::getCustomerRegisterTime($corpid, null, $externalUserId, $userId);
  1049. $registerTime = $responseData['register_time'];
  1050. $userActionSetId = $responseData['user_action_set_id'];
  1051. $accountId = $responseData['account_id'];
  1052. $unionid = $responseData['unionid'];
  1053. $joinType = $responseData['join_type'];
  1054. $adType = $responseData['ad_type'];
  1055. $selfExternalUserId = $responseData['external_userid'];
  1056. $selfUserId = $responseData['self_user_id'];
  1057. $order['is_ad_user'] = 0;
  1058. if(empty($registerTime)) {
  1059. // 系统中没有查询到对应的注册时间,直接使用第三方返回的时间
  1060. $order['register_time'] = strtotime($order['user_register_time']) * 1000;
  1061. } else {
  1062. $order['register_time'] = $registerTime * 1000;
  1063. $order['is_ad_user'] = 1;
  1064. }
  1065. $order['userActionSetId'] = $userActionSetId;
  1066. $order['adq_account_id'] = $accountId;
  1067. $order['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
  1068. $order['join_type'] = $joinType;
  1069. $order['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
  1070. $order['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
  1071. $order['self_unionid'] = $unionid;
  1072. $order['system_corpid'] = $corpid;
  1073. $order['promotion_id'] = $order['link_id'] ?? null;
  1074. // 推广数据检测区分新老客户-当月下单是新客户(数据看板 - 推广数据报表 中使用)
  1075. if (isset($order['promotion_id']) && !empty($order['promotion_id'])) {
  1076. if (
  1077. isset($order['register_time'], $order['payDate'])
  1078. &&
  1079. (!empty($order['register_time']) && !empty($order['payDate']))
  1080. ) {
  1081. $curMonth = $order['payDate'];
  1082. $aftMonth = date('Y-m-01 00:00:00', strtotime("+1 months", $curMonth));
  1083. $regTime = date('Y-m-d H:i:s', $order['register_time']/1000);
  1084. if ($regTime >= $curMonth && $regTime < $aftMonth) {
  1085. $order['pCustomerType'] = 1;// 推广数据新用户
  1086. } else {
  1087. $order['pCustomerType'] = 2;// 推广数据老用户
  1088. }
  1089. }
  1090. }
  1091. if(!empty($externalUserId) && 0 == $order['is_ad_user']) {
  1092. Log::logInfo('九州平台-接收到透传参数后找不到企微用户', [
  1093. 'order_id' => $order['orderId'],
  1094. 'corpId' => $corpid,
  1095. 'qyOpenId' => $externalUserId,
  1096. 'qyUserId' => $userId
  1097. ], 'saveJiuZhouOrderError');
  1098. }
  1099. # 订单金额分成比例
  1100. if(substr_count($order['orderId'], "Virtual") >= 1) {
  1101. $payType = 1;
  1102. $order['device_type'] = 1;
  1103. } else {
  1104. $payType = 2;
  1105. $order['device_type'] = 0;
  1106. }
  1107. // $shareInProportionArr = OrderService::getOrderShareInProportion(7);
  1108. $playletName = $order['theater_name'] ?? null;
  1109. $shareInProportionArr = OrderService::getOrderShareInProportionNew($order['order_source'], $playletName, $order['sys_group_id']);
  1110. $shareInProportion = $shareInProportionArr[$payType] ?? 1;
  1111. $order['origin_pay_money'] = $order['payNotifyAmount'];
  1112. if(3 == $order['sys_group_id']) {
  1113. $order['payNotifyAmount'] = $order['origin_pay_money'] * $shareInProportion;
  1114. }
  1115. DjOrder::saveJiuZhouOrder($order);
  1116. }
  1117. # 杭州猎豆 映客
  1118. public static function saveYingKeOrder($order) {
  1119. $order['platform_id'] = '';
  1120. $order['order_source'] = 8;
  1121. $order['plat_order_type'] = 0;
  1122. $corpid = null;
  1123. # 根据小程序名称获取小程序app_id
  1124. list($order['ma_app_id'], $order['sys_group_id']) = YingKeService::getMaAppIdByName($order['appName']);
  1125. if('龙王剧场' == $order['appName']) {
  1126. $order['plat_order_type'] = 1;
  1127. }
  1128. // 当透传回来的企微ID为空时,根据公众号app_id再次查询一次绑定的企微ID
  1129. if(empty($corpid) && !empty($order['gzhId'])) {
  1130. $corpid = DjOrderService::getSystemCorpidByAppId($order['gzhId']);
  1131. }
  1132. $order['is_ad_user'] = 0;
  1133. $order['system_corpid'] = $corpid;
  1134. # 通过推广链接ID查询投放账号
  1135. $promotionId = $order['linkId'];
  1136. $bindAccountDataList = AdqAccountBindPidConf::search([
  1137. 'sys_group_id' => $order['sys_group_id'], 'pid' => $promotionId, 'status' => 1
  1138. ]);
  1139. if($bindAccountDataList->isNotEmpty()) {
  1140. $accountData = $bindAccountDataList->first();
  1141. $accountId = $accountData->account_id ?? null;
  1142. if(!empty($accountId)) {
  1143. $officialWebUserActionInfo = OfficialWebUserActionSetId::query()
  1144. ->where('account_id', $accountId)
  1145. ->first();
  1146. $userActionSetId = $officialWebUserActionInfo->web_user_action_set_id ?? null;
  1147. $order['adq_account_id'] = $accountId;
  1148. $order['userActionSetId'] = $userActionSetId;
  1149. $order['self_order_type'] = 2;
  1150. }
  1151. }
  1152. $deviceType = $order['deviceType'];// 1:android 2:ios
  1153. $playletName = $order['movieName'] ?? null;
  1154. $shareInProportionArr = OrderService::getOrderShareInProportionNew($order['order_source'], $playletName, $order['sys_group_id']);
  1155. $shareInProportion = $shareInProportionArr[$deviceType] ?? 1;
  1156. $order['origin_pay_money'] = $order['payNotifyAmount'];
  1157. if(3 == $order['sys_group_id']) {
  1158. $order['payNotifyAmount'] = $order['origin_pay_money'] * $shareInProportion;
  1159. }
  1160. DjOrder::saveYingKeOrder($order);
  1161. }
  1162. # 杭州猎豆 触摸
  1163. public static function saveChuMoOrder($order) {
  1164. $order['platform_id'] = '';
  1165. $order['order_source'] = 9;
  1166. $order['plat_order_type'] = 0;
  1167. # 解析透传参数
  1168. $msgId = $order['qw_params'];
  1169. $msgData = explode('|', $msgId);
  1170. $suffix = $msgData[0] ?? null;
  1171. $dataId = $msgData[1] ?? null;
  1172. $corpid = null;
  1173. $externalUserId = null;
  1174. $userId = null;
  1175. if(!empty($suffix) && !empty($dataId)) {
  1176. $row = CustomerDetails::suffix(intval($suffix))->where('id', $dataId)->select(['corpid', 'user_id', 'external_userid'])
  1177. ->first();
  1178. $corpid = $row->corpid ?? null;
  1179. $userId = $row->user_id ?? null;
  1180. $externalUserId = $row->external_userid ?? null;
  1181. }
  1182. # 通过订单中返回的渠道号来查询对应的公众号app_id
  1183. if(isset($order['channel_id']) && !empty($order['channel_id'])){
  1184. // 根据渠道ID获取对应的公众号app_id
  1185. $order['gzh_appid'] = PlatformApp::query()->where('channel', $order['channel_id'])
  1186. ->where('enable', 1)->where('platform_id', $order['order_source'])->value('app_id');
  1187. }
  1188. // 当透传回来的企微ID为空时,根据公众号app_id再次查询一次绑定的企微ID
  1189. if(empty($corpid) && !empty($order['gzh_appid'])) {
  1190. $corpid = DjOrderService::getSystemCorpidByAppId($order['gzh_appid']);
  1191. }
  1192. # 通过透传参数来查找企微中的用户信息以及投放账号信息
  1193. $responseData = Customer::getCustomerRegisterTime($corpid, null, $externalUserId, $userId);
  1194. $registerTime = $responseData['register_time'];
  1195. $userActionSetId = $responseData['user_action_set_id'];
  1196. $accountId = $responseData['account_id'];
  1197. $unionid = $responseData['unionid'];
  1198. $joinType = $responseData['join_type'];
  1199. $adType = $responseData['ad_type'];
  1200. $selfExternalUserId = $responseData['external_userid'];
  1201. $selfUserId = $responseData['self_user_id'];
  1202. $order['is_ad_user'] = 0;
  1203. if(empty($registerTime)) {
  1204. // 系统中没有查询到对应的注册时间,直接使用第三方返回的时间
  1205. $order['register_time'] = strtotime($order['user_reg_date']) * 1000;
  1206. } else {
  1207. $order['register_time'] = $registerTime * 1000;
  1208. $order['is_ad_user'] = 1;
  1209. }
  1210. $order['userActionSetId'] = $userActionSetId;
  1211. $order['adq_account_id'] = $accountId;
  1212. $order['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
  1213. $order['join_type'] = $joinType;
  1214. $order['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
  1215. $order['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
  1216. $order['self_unionid'] = $unionid;
  1217. $order['system_corpid'] = $corpid;
  1218. if(!empty($userId) && !empty($selfUserId) && $userId != $selfUserId && (time() <= strtotime($order['order_create_date'])+300)) {
  1219. Log::logInfo('触摸平台回传客服ID与系统查询客服ID不一致', [
  1220. 'order_info' => $order,
  1221. 'response' => $responseData,
  1222. ], 'callBackOrderUserIdError');
  1223. EmailQueue::rPush('触摸平台回传客服ID与系统查询客服ID不一致', json_encode([
  1224. 'order_info' => $order,
  1225. 'response' => $responseData,
  1226. ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
  1227. }
  1228. if($accountId) {
  1229. $accountRelationAppList = AdqUser::getAppIdList([$accountId]);
  1230. $accountRelationAppId = $accountRelationAppList->where('account_id', $accountId)->first();
  1231. $accountRelationAppId = $accountRelationAppId->app_id ?? null;
  1232. # 当投放账号绑定的公众号与订单中渠道号对应的公众号不一致时,更新为非投放
  1233. if(isset($order['authorisedAppId']) && $accountRelationAppId != $order['authorisedAppId']) {
  1234. $order['is_ad_user'] = 0;
  1235. $order['register_time'] = $order['userRegisterTime'];
  1236. } else {
  1237. $order['userActionSetId'] = $userActionSetId;
  1238. $order['adq_account_id'] = $accountId;
  1239. $order['corp_user_id'] = empty($selfUserId) ? $userId : $selfUserId;
  1240. $order['join_type'] = $joinType;
  1241. $order['self_order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
  1242. $order['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
  1243. $order['self_unionid'] = $unionid;
  1244. }
  1245. }
  1246. if(!empty($externalUserId) && 0 == $order['is_ad_user'] && (time() <= strtotime($order['order_create_date'])+300)) {
  1247. Log::logInfo('触摸平台-接收到透传参数后找不到企微用户', [
  1248. 'order_id' => $order['id'],
  1249. 'corpId' => $order['corpId'],
  1250. 'qyOpenId' => $order['qyOpenId'],
  1251. 'qyUserId' => $order['qyUserId']
  1252. ], 'callBackOrderParamsError');
  1253. }
  1254. # 处理订单支付类型(安卓还是ios)
  1255. $payType = 1;
  1256. switch($order['platform']) {
  1257. case 'ios':
  1258. $payType = 2;
  1259. break;
  1260. case 'other':
  1261. $payType = 1;
  1262. break;
  1263. }
  1264. $order['deviceType'] = $payType;
  1265. # 处理订单金额分成比例
  1266. $playletName = $order['video_name'] ?? null;
  1267. $shareInProportionArr = OrderService::getOrderShareInProportionNew($order['order_source'], $playletName, $order['sys_group_id']);
  1268. $shareInProportion = $shareInProportionArr[$payType] ?? 1;
  1269. $order['origin_pay_money'] = $order['total_fee'];
  1270. if(3 == $order['sys_group_id']) {
  1271. $order['payNotifyAmount'] = $order['origin_pay_money'] * $shareInProportion;
  1272. }
  1273. DjOrder::saveChuMoOrder($order);
  1274. }
  1275. public static function saveFanQieOrder($order) {
  1276. $order['platform_id'] = '';
  1277. $order['order_source'] = 10;
  1278. $order['plat_order_type'] = 0;
  1279. # 通过推广链接ID查询投放账号
  1280. $promotionId = $order['promotion_id'];
  1281. $bindAccountDataList = AdqAccountBindPidConf::search([
  1282. 'sys_group_id' => $order['sys_group_id'], 'pid' => $promotionId, 'status' => 1
  1283. ]);
  1284. if($bindAccountDataList->isNotEmpty()) {
  1285. $accountData = $bindAccountDataList->first();
  1286. $accountId = $accountData->account_id ?? null;
  1287. if(!empty($accountId)) {
  1288. $officialWebUserActionInfo = OfficialWebUserActionSetId::query()
  1289. ->where('account_id', $accountId)
  1290. ->first();
  1291. $userActionSetId = $officialWebUserActionInfo->web_user_action_set_id ?? null;
  1292. $order['adq_account_id'] = $accountId;
  1293. $order['userActionSetId'] = $userActionSetId;
  1294. $order['self_order_type'] = 2;
  1295. }
  1296. }
  1297. $deviceType = $order['order_type'];// 1:android 2:ios
  1298. $playletName = null;
  1299. $shareInProportionArr = OrderService::getOrderShareInProportionNew($order['order_source'], $playletName, $order['sys_group_id']);
  1300. $shareInProportion = $shareInProportionArr[$deviceType] ?? 1;
  1301. $order['origin_pay_money'] = $order['pay_fee']*100;
  1302. if(3 == $order['sys_group_id']) {
  1303. $order['payNotifyAmount'] = $order['origin_pay_money'] * $shareInProportion;
  1304. }
  1305. DjOrder::saveFanQieOrder($order);
  1306. }
  1307. public static function saveYunXuanOrder($order) {
  1308. // 自定义推广参数(投放账户)
  1309. $order['tx_cps_id'] = $order['goods_info'][0]['chan_info'][0]['tx_cps_id'] ?? null;
  1310. if(empty($order['tx_cps_id'])) {
  1311. EmailQueue::rPush('云选联盟订单匹配投放账户失败', json_encode($order, 256), ['song.shen@kuxuan-inc.com'], '电商直投');
  1312. }
  1313. # 数据格式化
  1314. $order['order_create_time'] = date('Y-m-d H:i:s', $order['create_time'] / 1000);
  1315. unset($order['create_time']);
  1316. $order['status_change_time'] = date('Y-m-d H:i:s', $order['status_change_time'] / 1000);
  1317. $order['payed_time'] = !empty($order['payed_time']) ? date('Y-m-d H:i:s', $order['payed_time'] / 1000) : null;
  1318. $order['send_time'] = !empty($order['send_time']) ? date('Y-m-d H:i:s', $order['send_time'] / 1000) : null;
  1319. $order['received_time'] = !empty($order['received_time']) ? date('Y-m-d H:i:s', $order['received_time'] / 1000) : null;
  1320. $order['finish_time'] = !empty($order['finish_time']) ? date('Y-m-d H:i:s', $order['finish_time'] / 1000) : null;
  1321. $order['settle_confirm_time'] = !empty($order['settle_confirm_time']) ? date('Y-m-d H:i:s', $order['settle_confirm_time'] / 1000) : null;
  1322. $order['goods_info'] = !empty($order['goods_info']) ? json_encode($order['goods_info'], 256) : '[]';
  1323. $order['category_info'] = !empty($order['category_info']) ? json_encode($order['category_info'], 256) : '[]';
  1324. # 数据映射
  1325. $order['order_source'] = YxOrder::getOrderSource($order['order_source']);
  1326. $order['order_status'] = YxOrder::getOrderStatus($order['order_status']);
  1327. $order['distribute_sale_trace_type'] = YxOrder::getDistributeSaleTraceType($order['distribute_sale_trace_type']);
  1328. YxOrder::saveData($order);
  1329. }
  1330. }