1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558 |
- <?php
- namespace App\Console\Commands;
- use App\EsModel;
- use App\Log;
- use App\Models\AdqPlayletTrendData;
- use App\Models\AdqUser;
- use App\Models\AuthorizeCorp;
- use App\Models\BlackListRecord;
- use App\Models\ChatGroupMassMsg;
- use App\Models\ChatGroupMassMsgLog;
- use App\Models\Customer;
- use App\Models\CustomerDetails;
- use App\Models\DjDirectInvestmentOrder;
- use App\Models\DjOrder;
- use App\Models\DjUser;
- use App\Models\DramaSeries;
- use App\Models\DramaUserRela;
- use App\Models\Es\ChatGroupMassMsgLogEs;
- use App\Models\Es\CustomerInformationRecord;
- use App\Models\Es\MassMsgSendDetailEs;
- use App\Models\Es\PlayletAccountDataTrend;
- use App\Models\MassMsg;
- use App\Models\MassMsgRecord;
- use App\Models\MassMsgSendDetail;
- use App\Models\MassMsgSendNotice;
- use App\Models\MassPopularizData;
- use App\Models\MomentRecord;
- use App\Models\MomentTask;
- use App\Models\MpPlayletTrendData;
- use App\Models\OfficialAccount;
- use App\Models\OfficialWebUserActionSetId;
- use App\Models\PlatformOrderConf;
- use App\Models\Report\DjRegUserRangeReport;
- use App\Models\Report\PlayletDataTrend;
- use App\Models\System\AdminManageCorp;
- use App\Models\System\Users;
- use App\Models\Tencent\YxOrder;
- use App\Models\TencentAdAuth;
- use App\Models\UserOpinionFeedback;
- use App\RedisModel;
- use App\Service\Admin\AdminService;
- use App\Service\Admin\PermissionService;
- use App\Service\Admin\RoleService;
- use App\Service\CustomerTagService;
- use App\Service\DjOrderService;
- use App\Service\HttpService;
- use App\Service\JiuZhouService;
- use App\Service\MassMsgService;
- use App\Service\PitcherService;
- use App\Service\wechatWorkService;
- use App\Service\JiaShuService;
- use App\Service\MassMsgRuleService;
- use App\Support\qyApi\QyCommon;
- use App\Support\tencentAdSDK\ReportsOpenApi;
- use App\Support\tencentAdSDK\UserActionsOpenApi;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Hash;
- class Test extends Command
- {
- protected $signature = 'test {startId?}';
- protected $description = '测试脚本';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- try{
- // $this->getOrderCustomerInformation();
- # 手动回传22年部分未回传订单
- // $type = !empty($this->argument('type')) ? $this->argument('type') : 1;
- // if(1 == $type) {
- // # 生产
- // $this->adqUserActionUploadToRds();
- // } else {
- // # 消费
- // $this->adqUserActionUploadTest();
- // }
- // $this->xingchengAdqUserActionUploadTest();
- // $orderInfo = DjOrder::query()->where('order_id', $type)->first();
- // TencentAdAuth::intoActionAddList($orderInfo->toArray());
- // $this->updateMassMsgNoticeSendStatus();
- // $this->test();
- // $this->dealDepartUserRelation();
- // $startId = !empty($this->argument('startId')) ? $this->argument('startId') : 0;
- // $this->chatGroupMassMsgLogToEsTest($startId);
- // $this->dealBlackListCustomerTag();
- // $this->checkCustomerTag();
- // $this->sysCorpCustomerListTest();
- // $this->quitStaffRelationDel();
- $this->ECommerceUserActionsDataUpload();
- // $this->delRelationData();
- // $this->updateDataRecord();
- // // 获取所有已激活客服列表
- // $followUserList = DjUser::getUserIdList($corpid);
- // $followUserList = json_decode(json_encode($followUserList), 1);
- //
- // // 循环处理配置了客户联系功能的员工,拉取对应的客户信息
- // // 如果使用没有配置联系我的内部员工id来请求数据的话,接口会返回user_id异常的错误信息
- // $followUserListArr = array_chunk($followUserList, 100);
- // foreach ($followUserListArr as $userArr) {
- // $value['corpid'] = $corpid;
- // $value['user_list'] = $userArr;
- // print_r(json_encode($value));
- //// RedisModel::lPush(AuthorizeCorp::SYNC_CORP_CUSTOMER, json_encode($value));
- // }
- } catch (\Exception $exception) {
- $this->error('文件'.$exception->getFile().' 在 ' . $exception->getLine() . '行发生异常: ' . $exception->getMessage());
- }
- }
- public function ECommerceUserActionsDataUpload() {
- $orderList = YxOrder::query()->where('order_create_time', '>=', '2024-11-24')
- ->where('order_create_time', '<', '2024-11-25')->where('order_status', 1)->get();
- foreach($orderList as $orderInfo) {
- TencentAdAuth::intoActionAddListSecond($orderInfo->toArray());
- }
- }
- public function quitStaffRelationDel() {
- }
- public function delRelationData() {
- for($i = 0; $i < 50; $i++) {
- $relationList = CustomerDetails::suffix($i)->where('enable', 1)->whereIn('loss_status', [0, 1])->groupBy(['con_user_cus'])
- ->selectRaw('con_user_cus, count(1) as count')->having('count', '>', 1)->get();
- $this->info("下标 $i 查询数据 ".$relationList->count().' 条');
- if($relationList->isNotEmpty()) {
- $delIdArr = [];
- foreach($relationList as $relationInfo) {
- $dataList = CustomerDetails::suffix($i)->where('enable', 1)->whereIn('loss_status', [0, 1])
- ->where('con_user_cus', $relationInfo->con_user_cus)->get();
- $dataIdList = array_column($dataList->toArray(), 'id');
- $maxId = $dataList->min('id');
- $delIdList = array_diff($dataIdList, [$maxId]);
- if(!empty($delIdList)) {
- $delIdArr = array_merge($delIdArr, $delIdList);
- }
- }
- if(!empty($delIdArr)) {
- $this->info("下标 $i 需删除数据 ".count($delIdArr));
- Log::logInfo('删除数据记录', ['i' => $i, 'data' => $delIdArr], 'delRelationData');
- CustomerDetails::suffix($i)->whereIn('id', $delIdArr)->update(['enable' => 0]);
- }
- }
- }
- }
- public function updateDataRecord() {
- $corpid = 'ww7cfbe30100a1ba87';
- $userId = 'HuaMei';
- $externalUserId = 'wmGUoUCAAAa25mzyGEdL8XhsRMLJ1lMQ';
- $customerInfo = CustomerDetails::suffix($corpid)->where('corpid', $corpid)->where('user_id', $userId)->where('external_userid', $externalUserId)->first();
- $this->info('更新前时间为'.$customerInfo->updated_at);
- CustomerDetails::suffix($corpid)->updateOrCreate([
- 'corpid' => $corpid,
- 'user_id' => $userId,
- 'external_userid' => $externalUserId,
- ],[
- 'remark' => $customerInfo->remark,
- 'description' => $customerInfo->description,
- 'createtime' => $customerInfo->createtime,
- 'remark_corp_name' => $customerInfo->remark_corp_name,
- 'remark_mobiles' => $customerInfo->remark_mobiles,
- 'add_way' => $customerInfo->add_way,
- 'wechat_channels' => $customerInfo->wechat_channels,
- 'oper_userid' => $customerInfo->oper_userid,
- 'state' => $customerInfo->state,
- 'enable' => $customerInfo->enable,
- 'customer_id' => $customerInfo->customer_id,
- 'name' => $customerInfo->name,
- 'is_new_customer' => $customerInfo->is_new_customer,
- 'is_new_customer_no_loss' => $customerInfo->is_new_customer_no_loss,
- 'tag_list' => $customerInfo->tag_list,
- 'gender' => $customerInfo->gender,
- 'con_user_cus' => $customerInfo->con_user_cus,
- 'uni_customer_label' => $customerInfo->uni_customer_label,
- ]);
- $NewCustomerInfo = CustomerDetails::suffix($corpid)->where('corpid', $corpid)->where('user_id', $userId)->where('external_userid', $externalUserId)->first();
- $this->info('更新前时间为'.$NewCustomerInfo->updated_at);
- }
- public function sysCorpCustomerListTest() {
- $sysGroupId = 38;
- //todo 其他账号优先处理阿菜还有大浪淘沙,最后处理星橙优品
- # 查询杭州猎豆下的所有企微列表
- $corpIdList = AdminManageCorp::getSysGroupCorpList($sysGroupId);
- $corpDataList = AuthorizeCorp::getCorpIdList($corpIdList);
- # 按照企微来获取企微可见范围下的客服数据
- $corpDataList = json_decode(json_encode($corpDataList), 1);
- foreach($corpDataList as $corpid) {
- # 查询企微对应的客服
- // list($userList, $errcode) = wechatWorkService::followUserList($corpid);
- $userList = DjUser::getUserIdList($corpid);
- $userList = json_decode(json_encode($userList), 1);
- $count = count($userList);
- Log::logInfo('获取可见范围内客服列表', ['corpid' => $corpid, 'user_list' => $userList, 'user_count' => $count], 'sysCorpCustomerListTest');
- if(empty($userList)) {
- $this->info('企微【' . $corpid . '】暂无客服信息');
- continue;
- }
- $this->info(date('H:i') . ' 企微 ' . $corpid . ' 共查询客服 ' . $count . ' 个');
- foreach ($userList as $userid) {
- $customerCount = self::getUserCustomerCount($corpid, $userid);
- Log::logInfo('获取企微下的客户总数', ['corpid' => $corpid, 'user_id' => $userid, 'customer_count' => $customerCount], 'sysCorpCustomerListTest');
- $systemCustomerCount = CustomerDetails::suffix($corpid)->where('corpid', $corpid)->where('enable', 1)
- ->where('user_id', $userid)->count();
- Log::logInfo('获取系统内的客户总数', ['corpid' => $corpid, 'user_id' => $userid, 'customer_count' => $systemCustomerCount], 'sysCorpCustomerListTest');
- if($customerCount != false && $customerCount > $systemCustomerCount) {
- $this->info('企微【'.$corpid.'】下的客服【'.$userid.'】企微返回客户总数为'.$customerCount.',系统当前客户总数为'.$systemCustomerCount);
- }
- }
- }
- # 依次拉取客服的客户列表,获取客户总数并对比系统中的客户数与企微客户总数大小
- # 少于企微客户总数的客服放入待同步客户数据队列当中
- $this->info('处理完成');
- }
- public function getUserCustomerCount($corpid, $userId, $retry = 0) {
- $accessToken = AuthorizeCorp::getAccessToken($corpid);
- $url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list?access_token=$accessToken&userid=$userId";
- $response = HttpService::httpGet($url);
- if(empty($response) && $retry < 5) {
- $retry++;
- sleep(1);
- return self::getUserCustomerCount($corpid, $userId, $retry);
- }
- $response = json_decode($response, 1);
- if(isset($response['errcode']) && 0 != $response['errcode']) {
- if(in_array($response['errcode'], [701008, 84061])) {
- # 客服没有许可,客服下没有客户,
- return 0;
- }
- if(in_array($response['errcode'], [-1])) {
- $retry++;
- sleep(1);
- return self::getUserCustomerCount($corpid, $userId, $retry);
- }
- $this->error('请求企微可见客户列表失败,响应数据: '.json_encode($response));
- return false;
- }
- return count($response['external_userid']);
- }
- public function checkCustomerTag() {
- for($i = 0; $i < 50; $i++) {
- $totalCount = CustomerDetails::suffix($i)->count();
- $matchCount = CustomerDetails::suffix($i)->whereRaw('match(`tag_list`) against ("+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" in boolean mode)')->count();
- if($matchCount != $totalCount) {
- $this->error('suffix: '.$i.' , total_count: '.$totalCount.', match_count: '.$matchCount);
- } else {
- $this->info('suffix: '.$i.' , total_count: '.$totalCount.', match_count: '.$matchCount);
- }
- }
- }
- public function dealBlackListCustomerTag() {
- $blackListCustomerList = BlackListRecord::query()->where('enable', 1)->get();
- foreach($blackListCustomerList as $blackListCustomerInfo) {
- RedisModel::lPush(CustomerTagService::CUSTOMER_TAG_MARK_RDS, json_encode([
- 'corpid' => $blackListCustomerInfo->corpid, 'user_id' => $blackListCustomerInfo->user_id
- , 'external_userid' => $blackListCustomerInfo->external_userid,
- 'type' => 2, 'tag_group_name' => '猎羽', 'tag_name_list' => ['黑名单客户']
- ], 256));
- }
- $feedBackCustomerList = UserOpinionFeedback::query()->select(['corpid', 'user_id', 'external_userid'])
- ->where('enable', 1)->groupBy(['corpid', 'user_id', 'external_userid'])->get();
- foreach($feedBackCustomerList as $feedBackCustomerInfo) {
- RedisModel::lPush(CustomerTagService::CUSTOMER_TAG_MARK_RDS, json_encode([
- 'corpid' => $feedBackCustomerInfo->corpid, 'user_id' => $feedBackCustomerInfo->user_id
- , 'external_userid' => $feedBackCustomerInfo->external_userid,
- 'type' => 2, 'tag_group_name' => '猎羽', 'tag_name_list' => ['投诉客户']
- ], 256));
- }
- }
- public function chatGroupMassMsgLogToEsTest($startId) {
- $monthArr = ['2024-02'];
- foreach($monthArr as $month) {
- $start = date('Y-m-01 00:00:00', strtotime($month));
- $end = date('Y-m-01 00:00:00', strtotime($month.' +1 month'));
- while(true) {
- $msgList = ChatGroupMassMsg::query()->where('send_time', '>=', $start)
- ->where('send_time', '<', $end)
- ->where('id', '>', $startId)->orderBy('id', 'asc')->limit(100)->get();
- if($msgList->isEmpty()) {
- if($month == '2024-03') {
- break 2;
- } else {
- break;
- }
- }
- $startId = $msgList->max('id');
- $this->info('本次查询最大ID为:'.$startId);
- $ruleIdList = array_column($msgList->toArray(), 'id');
- $list = ChatGroupMassMsgLog::query()->whereIn('rule_id', $ruleIdList)->get();
- $listArr = array_chunk($list->toArray(), 500);
- foreach($listArr as $item) {
- ChatGroupMassMsgLogEs::repairData($item, $month);
- }
- }
- }
- }
- public function dealDepartUserRelation() {
- # 获取企微列表
- $corpList = AuthorizeCorp::query()->where('enable', 1)->where('id', '>=', 19)->get();
- foreach($corpList as $corpInfo) {
- $this->info('开始处理企微 '.$corpInfo->corp_name.' 数据');
- # 通过企微接口查询待分配的成员以及客户列表
- $cursor = "";
- while(1) {
- $responseData = QyCommon::getUnassignedList($corpInfo->corpid, $cursor);
- if(isset($responseData['errcode']) && $responseData['errcode'] == 0) {
- # 处理返回的数据
- $newList = array_map(function($value) {
- return '("'.$value['handover_userid'].'","'.$value['external_userid'].'")';
- }, $responseData['info']);
- if(!empty($newList)) {
- CustomerDetails::suffix($corpInfo->corpid)->where('corpid', $corpInfo->corpid)
- ->whereRaw("(`user_id`, `external_userid`) in (".implode(',', $newList).')')
- ->update(['enable' => 0]);
- }
- if(empty($responseData['next_cursor'])) {
- // 本企微处理完成,开始处理下一个企微的数据
- break;
- } else {
- $cursor = $responseData['next_cursor'];
- }
- } else {
- $this->error('返回数据异常,错误码:'.$responseData['errcode']);
- break;
- }
- }
- }
- }
- public function updateMassMsgNoticeSendStatus() {
- $startId = 0;
- while(true) {
- $list = MassMsgSendNotice::query()->where('enable', 1)->where('id', '>', $startId)
- ->orderBy('id', 'asc')->limit(100)->get();
- if($list->isEmpty()) {
- break;
- }
- $startId = $list->max('id');
- foreach($list as $value) {
- $corpid = $value->corpid;
- $ruleId = $value->rule_id;
- $userId = $value->user_id;
- $this->info(date('H:i:s') . ' 开始处理规则id: '.$ruleId.' 的数据');
- # 防止同一个群发多个msg_id,其中某n条未执行的情况
- $count = MassMsgRecord::query()->where('corpid', $corpid)->where('rule_id', $ruleId)
- ->where('sender', $userId)->where('status', 1)->where('msg_id', '>', '')
- ->count();
- if(0 == $count) {
- MassMsgSendNotice::query()->where('corpid', $corpid)->where('rule_id', $ruleId)
- ->where('user_id', $userId)->where('msg_type', 1)->update(['send_status' => 2]);
- }
- }
- }
- $this->info('处理完成');
- }
- public function xingchengAdqUserActionUploadTest() {
- $accountId = '35574856';
- $userActionSetId = '1201835985';
- $accessToken = '91f6de2a626add78b141d8ea8a99e864';
- $platformArr = config('platform.base');
- $interface = 'user_actions/add';
- $url = 'https://api.e.qq.com/v1.3/' . $interface;
- $orderList = DjOrder::query()->selectRaw('order_id, ma_app_id, ma_open_id, playlet_id, playlet_name,'
- .'order_source, pay_money')->where('sys_group_id', 51)->where('pay_status', 1)->where('ma_app_id', '>', '')
- ->where('ma_open_id', '>', '')->where('order_source', 7)->orderBy('id', 'asc')->limit(500)->get();
- foreach($orderList as $orderInfo) {
- $orderInfo = $orderInfo->toArray();
- $wechat_app_id = $orderInfo['ma_app_id'];
- $wechat_openid = $orderInfo['ma_open_id'];
- // 用户标识
- $userId = array_filter([
- 'wechat_app_id' => $wechat_app_id,
- 'wechat_openid' => $wechat_openid,
- ]);
- $platform = $platformArr[$orderInfo['order_source']];
- $parameters = [
- 'account_id' => $accountId,
- 'user_action_set_id' => $userActionSetId,
- 'actions' => [
- [
- 'action_time' => time(),
- 'user_id' => $userId,
- 'action_type' => 'PURCHASE',
- 'action_param' => [
- 'value' => round($orderInfo['pay_money'] / 100),
- 'object' => 1,
- 'product_name' => empty($orderInfo['playlet_name']) ? "充值活动-{$platform}" : "{$orderInfo['playlet_name']}-{$platform}",
- ],
- 'channel' => 'TENCENT',
- ]
- ]
- ];
- if(!empty($orderInfo['playlet_id'])) {
- $parameters['actions'][0]['action_param']['product_id'] = $orderInfo['playlet_id'];
- }
- $parameters = json_encode($parameters);
- $retry = 2;
- do {
- $common_parameters = [
- 'access_token' => $accessToken,
- 'timestamp' => time(),
- 'nonce' => md5(uniqid('', true))
- ];
- $request_url = $url . '?' . http_build_query($common_parameters);
- try {
- $res = HttpService::httpPost($request_url, $parameters, true);
- } catch (\Throwable $e) {
- Log::logError('数据回传接口请求异常', [
- 'params' => json_encode($parameters),
- 'msg' => $e->getTraceAsString()
- ], 'xingchengAdqUserActionUploadTest');
- }
- $resArr = json_decode($res, true);
- // 记录日志
- Log::logInfo('数据上报API:' . $interface, [
- 'order_id' => $orderInfo['order_id'],
- 'url' => $request_url,
- 'params' => $parameters,
- 'response' => $res,
- ], 'xingchengAdqUserActionUploadTest');
- } while(($resArr['code'] != 0) && (--$retry > 0));
- }
- }
- public function adqUserActionUploadToRds() {
- $this->info('开始查询22年用户数据');
- $id = 2268597;
- $key = 'Playlet::adqUserActionUploadTest';
- while(true) {
- $orderList = DjOrder::query()->selectRaw('max(id) as id, ma_app_id, ma_open_id, pay_money, playlet_id, playlet_name, order_source, order_id')
- ->where('ma_app_id', '>', '')->where('ma_open_id', '>', '')
- ->whereRaw("`ma_user_register_time` >=(unix_timestamp('2022-01-01 00:00:00')*1000) and `ma_user_register_time` <(unix_timestamp('2023-01-01 00:00:00')*1000)" )
- ->where('sys_group_id', 3)->where('pay_status', 1)->where('id', '>', $id)
- ->groupBy('ma_open_id')->orderBy('id', 'asc')->limit(1000)->get();
-
- if($orderList->isNotEmpty()){
- $id = $orderList->max('id');
- foreach($orderList as $orderInfo) {
- $value = [
- 'order_id' => $orderInfo->order_id,
- 'ma_app_id' => $orderInfo->ma_app_id,
- 'ma_open_id' => $orderInfo->ma_open_id,
- 'playlet_id' => $orderInfo->playlet_id,
- 'playlet_name' => $orderInfo->playlet_name,
- 'order_source' => $orderInfo->order_source,
- 'pay_money' => $orderInfo->pay_money,
- ];
- RedisModel::lPush($key, json_encode($value, 256));
- }
- } else {
- break;
- }
- }
- $this->info('22年用户数据查询完成,开始查询23年用户数据');
- $id = 0;
- for($i = 1;$i<=140;$i++) {
- $orderList = DjOrder::query()->selectRaw('max(id) as id, ma_app_id, ma_open_id, pay_money, playlet_id, playlet_name, order_source, order_id')
- ->where('ma_app_id', '>', '')->where('ma_open_id', '>', '')
- ->whereRaw("`ma_user_register_time` >=(unix_timestamp('2023-01-01 00:00:00')*1000)" )
- ->where('sys_group_id', 3)->where('pay_status', 1)->where('id', '>', $id)
- ->groupBy('ma_open_id')->orderBy('id', 'asc')->limit(1000)->get();
- $id = $orderList->max('id');
- foreach($orderList as $orderInfo) {
- $value = [
- 'order_id' => $orderInfo->order_id,
- 'ma_app_id' => $orderInfo->ma_app_id,
- 'ma_open_id' => $orderInfo->ma_open_id,
- 'playlet_id' => $orderInfo->playlet_id,
- 'playlet_name' => $orderInfo->playlet_name,
- 'order_source' => $orderInfo->order_source,
- 'pay_money' => $orderInfo->pay_money,
- ];
- RedisModel::lPush($key, json_encode($value, 256));
- }
- }
- $this->info('23年用户查询完成');
- }
- public static function adqUserActionUploadTest() {
- # 批量查询22年未回传订单数据
- $accountList = [
- ['account_id' => '30155755', 'user_action_set_id' => '1201286910', 'access_token' => '672fc653e5b227f5faeefb88b9409ed5'],
- ['account_id' => '30156032', 'user_action_set_id' => '1201282364', 'access_token' => '49147257a4843bc8937ae315f1269fab'],
- ['account_id' => '28262322', 'user_action_set_id' => '1201136782', 'access_token' => '3439ff7e13cd061732b09bbeac495b13'],
- ['account_id' => '30155755', 'user_action_set_id' => '1201286910', 'access_token' => '672fc653e5b227f5faeefb88b9409ed5'],
- ];
- // $accountId = '24605135';
- // $userActionSetId = '1201834449';
- // $accessToken = 'cd3a5ab5fb0ef69340e27856cee6a41e';
- $platformArr = config('platform.base');
- $interface = 'user_actions/add';
- $url = 'https://api.e.qq.com/v1.3/' . $interface;
- $startTime = time();
- $key = 'Playlet::adqUserActionUploadTest';
- while(true) {
- if(time() - $startTime >= 600) {
- break;
- }
- $value = RedisModel::rPop($key);
- if(empty($value)) {
- sleep(1);
- continue;
- }
- $orderInfo = json_decode($value, 1);
- foreach ($accountList as $accountInfo) {
- $accountId = $accountInfo['account_id'];
- $accessToken = $accountInfo['access_token'];
- $userActionSetId = $accountInfo['user_action_set_id'];
-
- $wechat_app_id = $orderInfo['ma_app_id'];
- $wechat_openid = $orderInfo['ma_open_id'];
- // 用户标识
- $userId = array_filter([
- 'wechat_app_id' => $wechat_app_id,
- 'wechat_openid' => $wechat_openid,
- ]);
- $platform = $platformArr[$orderInfo['order_source']];
- $parameters = [
- 'account_id' => $accountId,
- 'user_action_set_id' => $userActionSetId,
- 'actions' => [
- [
- 'action_time' => time(),
- 'user_id' => $userId,
- 'action_type' => 'PURCHASE',
- 'action_param' => [
- 'value' => round($orderInfo['pay_money'] / 100),
- 'object' => 1,
- 'product_name' => empty($orderInfo['playlet_name']) ? "充值活动-{$platform}" : "{$orderInfo['playlet_name']}-{$platform}",
- ],
- 'channel' => 'TENCENT',
- ]
- ]
- ];
- if(!empty($orderInfo['playlet_id'])) {
- $parameters['actions'][0]['action_param']['product_id'] = $orderInfo['playlet_id'];
- }
- $parameters = json_encode($parameters);
- $retry = 2;
- do {
- $common_parameters = [
- 'access_token' => $accessToken,
- 'timestamp' => time(),
- 'nonce' => md5(uniqid('', true))
- ];
- $request_url = $url . '?' . http_build_query($common_parameters);
- try {
- $res = HttpService::httpPost($request_url, $parameters, true);
- } catch (\Throwable $e) {
- Log::logError('数据回传接口请求异常', [
- 'params' => json_encode($parameters),
- 'msg' => $e->getTraceAsString()
- ], 'adqUserActionUploadTest');
- }
- $resArr = json_decode($res, true);
- // 记录日志
- Log::logInfo('数据上报API:' . $interface, [
- 'order_id' => $orderInfo['order_id'],
- 'url' => $request_url,
- 'params' => $parameters,
- 'response' => $res,
- ], 'adqUserActionUploadTest');
- } while(($resArr['code'] != 0) && (--$retry > 0));
- }
- }
- }
- public function test() {
- try{
- $massMsgList = MassMsg::query()->where('send_time', '>=', '2023-12-01')->get();
- foreach ($massMsgList as $massMsgInfo) {
- $this->info('mass_msg rule_id : ' . $massMsgInfo->id);
- MassMsgRecord::query()->where('rule_id', $massMsgInfo->id)->update(['create_time' => $massMsgInfo->send_time]);
- }
- $this->info('开始处理客户朋友圈消息');
- $momentList = MomentTask::query()->where('send_time', '>=', '2023-12-01')->get();
- foreach($momentList as $momentInfo) {
- $this->info('moment rule_id : ' . $momentInfo->id);
- MomentRecord::query()->where('rule_id', $momentInfo->id)->update(['create_time' => $momentInfo->send_time]);
- }
- } catch (\Exception $exception) {
- echo $exception->getFile().'('.$exception->getLine().'):'.$exception->getMessage();
- }
- }
- public function writeCustomerInformationToOrder()
- {
- $date = $startDate = "2023-03-05";
- $endDate = "2023-03-13";
- while($date <= $endDate) {
- $filePath = storage_path('playlet/03-20/OrderUserInformationGet-'.$date.'.log');
- $content = file_get_contents($filePath);
- $list = explode(' []', $content);
- foreach($list as $k => $str) {
- if(empty($str)) {
- $this->info($date.'日数据处理完成');
- break ;
- }
- $newStr = substr($str, 64);
- $arr = json_decode($newStr, 1);
- DjOrder::query()->where('order_id', $arr['order_id'])->update([
- 'corp_user_id' => $arr['self_user_id']
- ]);
- }
- $date = date('Y-m-d', strtotime('+1 days'));
- }
- }
- public function updateOrderTest()
- {
- $this->info(date('H:i:s') . ' 开始处理');
- $id = 4119077;
- $num = 1;
- while(true) {
- $orderList = DjOrder::query()->select(['id', 'order_id', 'pay_money', 'origin_pay_money'])
- ->where('order_source', '7')
- ->where('id', '>', $id)
- ->where('sys_group_id', 3)
- ->orderBy('id', 'asc')
- ->limit(1000)->get();
- if($orderList->isNotEmpty()) {
- $id = $orderList->max('id');
- echo $num++;
- foreach($orderList as $orderInfo) {
- if(substr_count($orderInfo->order_id, "Virtual") >= 1) {
- $updateData['pay_type'] = 1;
- $updateData['pay_money'] = $orderInfo->origin_pay_money * 0.8;
- } else {
- $updateData['pay_type'] = 0;
- $updateData['pay_money'] = $orderInfo->origin_pay_money * 0.85;
- }
- DjOrder::query()->where('id', $orderInfo->id)->update($updateData);
- }
- } else {
- break;
- }
- sleep(1);
- }
- $this->info(date('H:i:s') . ' 处理完成');
- }
- public function getOrderCustomerInformation()
- {
- $startDate = '2023-03-15';
- $endDate = '2023-03-16';
- $date = $startDate;
- while($date<=$endDate) {
- $this->info('开始处理 ' . $date . ' 日的数据');
- $orderList = DjOrder::query()->selectRaw('id, order_id, mp_open_id, mp_user_register_time,'
- .' system_corpid, bind_app_id, corp_user_id, external_userid, order_pay_time')->where('is_ad_user', 1)
- ->where('create_time', '>=', $date . ' 00:00:00')->where('create_time', '<=', $date . ' 23:59:59')
- ->orderBy('id', 'asc')->get();
- if($orderList->isNotEmpty()) {
- foreach ($orderList as $orderInfo) {
- // 根据企微以及外部联系人ID查询客服ID,如果有多个客服,则将加粉时间和关注时间对比,全部对比失败时找到下单时间之前最后一个关注的客服
- if(empty($orderInfo->system_corpid) || empty($orderInfo->external_userid) || empty($orderInfo->mp_user_register_time)){
- Log::logError('缺失必要参数', json_decode(json_encode($orderInfo), 1), 'getOrderCustomerInformationTrace');
- continue;
- }
- $customerDetailsList = CustomerDetails::suffix($orderInfo->system_corpid)->where('corpid', $orderInfo->system_corpid)
- ->where('external_userid', $orderInfo->external_userid)->orderBy('createtime', 'desc')->get();
- if($customerDetailsList->isEmpty()) {
- Log::logError('查询客户详情列表为空', [
- 'order_info' => json_decode(json_encode($orderInfo), 1),
- 'customer_list' => $customerDetailsList->toArray(),
- ], 'getOrderCustomerInformationTrace');
- continue;
- }
- $selfUserId = null;
- foreach($customerDetailsList as $customerDetails) {
- if($customerDetails->createtime <= $orderInfo->mp_user_register_time/1000) {
- $selfUserId = $customerDetails->user_id;
- break;
- }
- }
- if(empty($selfUserId)) {
- Log::logError('获取企微客服失败', [
- 'order_info' => json_decode(json_encode($orderInfo), 1),
- 'customer_list' => $customerDetailsList->toArray(),
- ], 'getOrderCustomerInformationTrace');
- continue;
- }
- if(!empty($orderInfo->corp_user_id) && $orderInfo->corp_user_id != $selfUserId) {
- $this->error(date('H:i:s') . ' 查询客服信息与透传客服信息不一致,订单ID为:' . $orderInfo->order_id);
- Log::logInfo('查询客服信息与透传客服信息不一致', [
- 'self_user_id' => $selfUserId,
- 'corpid' => $orderInfo->system_corpid,
- 'external_userid' => $orderInfo->external_userid,
- 'mp_user_register_time' => $orderInfo->mp_user_register_time,
- 'corp_user_id' => $orderInfo->corp_user_id,
- 'order_id' => $orderInfo->order_id,
- ], 'getOrderCustomerInformationTrace');
- }
- Log::logInfo('', [
- 'order_id' => $orderInfo->order_id,
- 'bind_app_id' => $orderInfo->bind_app_id,
- 'mp_open_id' => $orderInfo->mp_open_id,
- 'mp_user_register_time' => $orderInfo->mp_user_register_time,
- 'self_user_id' => $selfUserId,
- 'system_corpid' => $orderInfo->system_corpid,
- ], 'OrderUserInformationGet-'.$date);
- }
- }
- $date = date('Y-m-d', strtotime($date . ' +1 days'));
- }
- }
- public function jiashuOrderUserRegisterTimeRepair()
- {
- $startId = 0;
- $orderPayTime = strtotime('2022-12-01 00:00:00') * 1000;
- $this->info(date('H:i') . ' 开始处理');
- while(true){
- $orderList = DjOrder::query()->where('sys_group_id', 3)->where('order_source', 2)
- ->where('order_pay_time', '>=', $orderPayTime)->where('id', '>', $startId)
- ->where('is_ad_user', 1)->orderBy('id', 'asc')->limit(1000)->get();
- if(empty($orderList)){
- $this->info(date('H:i') . ' 执行完成');
- break;
- }
- $this->info(date('H:i') . ' 本次查询数据共:' . $orderList->count() . '条');
- foreach($orderList as $orderInfo) {
- $responseData = Customer::getCustomerRegisterTime($orderInfo->system_corpid, null,
- $orderInfo->external_userid, null);
- $registerTime = $responseData['register_time'];
- if(!empty($registerTime)) {
- // 系统中没有查询到对应的注册时间,直接使用嘉书返回的时间
- DjOrder::query()->where('id', $orderInfo->id)->update([
- 'mp_user_register_time' => $registerTime * 1000
- ]);
- }
- $startId = $orderInfo->id;
- }
- }
- }
- public function dealTempData()
- {
- $data = \DB::table('temp')->get();
- $data = json_decode(json_encode($data), 1);
- $this->info(date('Y-m-d H:i') . ' 开始处理,本次共需要处理数据'.count($data).'条');
- $start = time();
- foreach($data as $value) {
- MassPopularizData::query()
- ->updateOrCreate([
- 'pid' => strval($value['pid'])
- ],[
- 'platType' => 4,
- 'mpAppId' => $value['maAppId'],
- 'popularizTitle' => $value['popularizTitle'],
- 'playletTitle' => $value['playletTitle']
- ]);
- }
- $this->info(date('Y-m-d H:i') . ' 处理完成,耗时'. (time() - $start) . '秒');
- }
- public function jiashuApiTest()
- {
- $apiKey = '5eb24c607326536d412eba0bc21018c4';
- $customerId = 111;
- # 获取产品列表信息
- $res = JiaShuService::getAppList($apiKey, $customerId);
- print_r($res);
- die;
- # 获取短剧列表
- $appId = '';
- $dramaList = JiaShuService::getContentList($apiKey, $customerId, 1, $appId);
- print_r($dramaList);
- # 获取剧集列表
- $videoId = '';
- $sectionList = JiaShuService::getSectionList($apiKey, $customerId, $appId, $videoId);
- print_r($sectionList);
- # 生成推广链接
- $dramaSort = '';
- $res = JiaShuService::savePromotion($apiKey, $customerId, $appId, $videoId, $dramaSort);
- print_r($res);
- // $this->historyOrderSave();
- }
- public function customerListSync()
- {
- $corpid = 'wwa93b0e23b7c5fe91';
- // $userList = DjUser::query()
- // ->where('corpid', $corpid)
- // ->get();
- // foreach($userList as $userInfo) {
- $userList = [
- 'XingDaiLu'
- ];
- wechatWorkService::getCustomerListByUserId($corpid,$userList);
- // }
- }
- public function historyOrderSave()
- {
- $startId = 0;
- while(true){
- $orderList = \DB::table('order_10_10')->where('id', '>', $startId)
- ->orderBy('id', 'asc')->limit(1000)->get();
- if($orderList->isEmpty()){
- return ;
- }
- $orderList = json_decode(json_encode($orderList), 1);
- $insertData = [];
- foreach($orderList as $orderInfo) {
- $item = [];
- $strArr = explode('_', $orderInfo['商户单号']);
- $str = $strArr[0];
- $str = trim($str);
- $orderId = substr($str, 3);
- $startId = $orderInfo['id'];
- $row = DjOrder::query()
- ->where('order_id', $orderId)
- ->where('order_source', 4)
- ->first();
- if(!empty($row)) {
- DjOrder::query()->where('id', $row->id)->update(['pay_status' => 1]);
- continue;
- }
- $item['order_id'] = $orderId;
- $item['mp_user_register_time'] = strtotime($orderInfo['用户注册时间'])*1000;
- $item['pay_money'] = $orderInfo['充值金额']*10000;
- $item['pay_status'] = 1;
- $item['order_source'] = 4;
- $item['is_ad_user'] = 0;
- $item['created_ts'] = strtotime($orderInfo['下单时间'])*1000;
- $item['order_pay_time'] = strtotime($orderInfo['完成时间'])*1000;
- $item['pid'] = $orderInfo['推广链接id'];
- $item['platform_id'] = 'test';
- $item['sys_group_id'] = 3;
- $insertData[] = $item;
- }
- DjOrder::query()->insert($insertData);
- }
- }
- public function playletDataDeal()
- {
- $this->info('开始处理mp数据');
- $mpNum = 0;
- $startId = 0;
- $startTime = time();
- while(true){
- $list = MpPlayletTrendData::query()
- ->select(['id', 'playlet_id', 'expense_date', 'ref_date', 'days_type', 'plat_order_type'
- , 'scan_follow_count', 'follow_cost', 'first_roi', 'paid', 'active_fans', 'pay_count', 'pay_user'
- , 'pay_money', 'pay_count_total', 'pay_user_total', 'pay_money_total', 'day_cost_cover_rate'
- , 'enable'])
- ->where('enable', 1)
- ->where('id', '>', $startId)
- ->orderBy('id', 'asc')
- ->limit(1000)
- ->get();
- if($list->isNotEmpty()){
- $startId = $list->max('id');
- $mpNum += count($list->toArray());
- $this->info('已处理'.$mpNum.'条mp数据');
- $insertData = [];
- foreach($list->toArray() as $key=>$item) {
- $insertData[$key] = $item;
- $insertData[$key]['ad_type'] = 1;
- unset($insertData[$key]['id']);
- }
- PlayletDataTrend::query()->insert($insertData);
- } else {
- break;
- }
- if((time() - $startTime)%60 == 0) {
- sleep(1);
- $this->info('休息一下');
- }
- }
- $this->info('开始处理adq数据');
- $adqNum = 0;
- $startId = 0;
- $startTime = time();
- while(true){
- $list = AdqPlayletTrendData::query()
- ->select(['id', 'playlet_id', 'expense_date', 'ref_date', 'days_type', 'plat_order_type'
- , 'scan_follow_count', 'follow_cost', 'first_roi', 'paid', 'active_fans', 'pay_count', 'pay_user'
- , 'pay_money', 'pay_count_total', 'pay_user_total', 'pay_money_total', 'day_cost_cover_rate'
- , 'enable'])
- ->where('enable', 1)
- ->where('id', '>', $startId)
- ->orderBy('id', 'asc')
- ->limit(1000)
- ->get();
- if($list->isNotEmpty()){
- $startId = $list->max('id');
- $adqNum += count($list->toArray());
- $this->info('已处理'.$adqNum.'条adq数据');
- $insertData = [];
- foreach($list->toArray() as $key=>$item) {
- $insertData[$key] = $item;
- $insertData[$key]['ad_type'] = 2;
- unset($insertData[$key]['id']);
- }
- PlayletDataTrend::query()->insert($insertData);
- } else {
- break;
- }
- if((time() - $startTime)%60 == 0) {
- sleep(1);
- $this->info('休息一下');
- }
- }
- }
- public function userActionsUpload()
- {
- $orderList = DjOrder::query()
- ->whereRaw("adq_account_id ='35509830' and mp_user_register_time >= (unix_timestamp('2024-01-19 00:00:00')*1000) and pay_status =1")->get();
- foreach($orderList as $orderInfo) {
- $this->info('开始处理订单 '.$orderInfo->order_id.' 的数据');
- $orderData = $orderInfo->toArray();
- $orderData['ignore_black'] = 1;
- TencentAdAuth::intoActionAddList($orderData);
- }
- }
- public function adqActionUploadSecond()
- {
- $orderList = DjDirectInvestmentOrder::query()
- ->whereRaw("order_id in ('116334145')")
- ->orderBy('id' , 'desc')
- ->get();
- foreach($orderList->toArray() as $orderInfo) {
- $this->info('处理'.$orderInfo['id'].'的数据');
- TencentAdAuth::intoActionAddList(array_merge($orderInfo, ['is_direct_investment' => 1]));
- }
- }
- public function adqActionUpload()
- {
- $orderList = DjOrder::query()
- ->where('sys_group_id', 3)
- ->whereIn('order_source', [3])
- ->where('is_ad_user', 0)
- ->where('external_userid', '>', '')
- ->where('pay_status', 1)
- ->get();
- $orderList = $orderList->toArray();
- foreach($orderList as $orderInfo) {
- $orderPay = [];
- $params = $orderInfo['external_userid'];
- $params = urldecode($params);
- $externalUserId = null;
- $userId = null;
- if(strstr($params, '|')) {
- $paramsData = explode('|', $params);
- $systemCorpid = $paramsData[0] ?? null;
- $userId = $paramsData[1] ?? null;
- $externalUserId = $paramsData[2] ?? null;
- } else {
- continue;
- }
- $responseData = Customer::getCustomerRegisterTime($orderInfo['system_corpid'], $orderInfo['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'];
- if(empty($registerTime)) {
- $orderPay['mp_user_register_time'] = $orderInfo['mp_user_register_time'];
- } else {
- $orderPay['mp_user_register_time'] = $registerTime * 1000;
- $orderPay['is_ad_user'] = 1;
- }
- // 查询出的用户unionid不为空,则将查询结果替换接收到的unionid
- if(!empty($unionid)){
- $orderPay['unionid'] = $unionid;
- }
- $orderPay['bind_user_action_set_id']= $userActionSetId;
- $orderPay['adq_account_id'] = $accountId;
- $orderPay['corp_user_id'] = $userId;
- $orderPay['join_type'] = $joinType;
- $orderPay['order_type'] = empty($adType) ? 1 : $adType;// 订单类型 为空时归属为mp订单 1mp 2adq
- $orderPay['external_userid'] = !empty($externalUserId) ? $externalUserId : $selfExternalUserId;
- // 推广数据检测区分新老客户-当月下单是新客户
- if (isset($orderInfo['pid']) && !empty($orderInfo['pid'])) {
- if (
- isset($orderPay['mp_user_register_time'], $orderInfo['order_pay_time'])
- &&
- (!empty($orderPay['mp_user_register_time']) && !empty($orderInfo['order_pay_time']))
- ) {
- $curMonth = date('Y-m-01 00:00:00', strtotime($orderInfo['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['mp_user_register_time']);
- if ($regTime >= $curMonth && $regTime < $aftMonth) {
- $orderPay['p_customer_type'] = 1;// 推广数据新用户
- } else {
- $orderPay['p_customer_type'] = 2;// 推广数据老用户
- }
- }
- }
- DjOrder::query()
- ->where('id', $orderInfo['id'])
- ->update($orderPay);
- $this->info('订单'.$orderInfo['order_id'].'处理完成');
- if($orderPay['order_type'] != $orderInfo['order_type']) {
- $orderInfo['mp_user_register_time'] = $orderPay['mp_user_register_time'];
- $orderInfo['bind_user_action_set_id'] = $orderPay['bind_user_action_set_id'];
- $orderInfo['adq_account_id'] = $orderPay['adq_account_id'];
- $orderInfo['order_type'] = $orderPay['order_type'];
- TencentAdAuth::intoActionAddList($orderInfo);
- }
- }
- }
- public function getAdqDailyReports()
- {
- $stDate = '2022-12-14';
- $enDate = '2022-12-14';
- $list = TencentAdAuth::query()
- ->where('enable', 1)
- ->whereNull('wechat_account_id')
- ->where('account_id', '26010505')
- ->orderBy('id', 'ASC')
- ->get();
- foreach($list as $accountInfo) {
- $data = [
- 'account_id' => $accountInfo->account_id,
- 'start_date' => $stDate,
- 'end_date' => $enDate,
- 'level' => 'REPORT_LEVEL_ADVERTISER',
- ];
- $res = ReportsOpenApi::dailyReportsGet($data);
- Log::logInfo('getAdqDailyReports', [
- 'params' => $data,
- 'response' => (array) $res,
- ], 'test');
- }
- }
- public function ActionsUpload()
- {
- $upData = [
- "action_time" =>1660712576,
- "wechat_openid" =>"o8aSs5JC3EMDuQBx9meWk08tBvbQ",
- "wechat_app_id" =>"wx1bbc441b0d86bd38",
- "value" =>1990,
- "product_name" =>"\u80a1\u738b\u5e9f\u5a7f-\u67da\u5b50-\u7b2c34\u96c6",
- "account_id" =>"24614521",
- "bind_app_id" =>"wxe56b997561a0eef3",
- "user_action_set_id"=>1200707475,
- "action_type" =>"PURCHASE",
- "object" =>1,
- "access_token" =>'23a203d24ce6ca193d187bfd5e3e9841',
- ];
- $res = UserActionsOpenApi::add($upData);
- if ($res['status'] == 'fail') {
- Log::logError('ADQ数据回传失败', [
- 'actionType' => "PURCHASE",
- 'parm' => json_encode($upData),
- 'msg' => json_encode($res)
- ], 'AdqUserActionsDataUpload');
- return false;
- } else {
- Log::logInfo('ADQ数据回传成功', [
- 'actionType' => "PURCHASE",
- 'parm' => json_encode($upData),
- 'msg' => json_encode($res)
- ], 'AdqUserActionsDataUpload');
- return true;
- }
- }
- public function update_old_report(){
- for ($check_date = strtotime("2021-11-01");$check_date<= strtotime("2022-02-01");$check_date+=86400){
- $check_date_str = date("Y-m-d",$check_date);
- RedisModel::lPush('Playlet::count_user_range_report',"$check_date_str|");
- }
- print "添加成功";
- }
- public function convertToOpenId($corpid)
- {
- $accessToken = AuthorizeCorp::getAccessToken($corpid, '测试外部联系人id转openid');
- $url = 'https://qyapi.weixin.qq.com/cgi-bin/externalcontact/convert_to_openid?access_token='.$accessToken;
- $params['external_userid'] = 'wmVZsnRgAA4Kv6AeVmZZvoF4DszKyK2w';
- $result = HttpService::httpPost($url, json_encode($params), 1);
- $result = json_decode($result);
- dd($result);
- }
- public function generator($idx, $idMin, $ruleId)
- {
- $limit = 500;
- $idMax = MassMsgSendDetail::suffix($idx)
- ->where('rule_id', $ruleId)
- ->where('enable', 1)
- ->max('id') ?? 0;
- echo $idx.'@@'.$ruleId.'@@'.$idMax.PHP_EOL;
- while ($idMin < $idMax) {
- $list = MassMsgSendDetail::suffix($idx)
- ->where('enable', 1)
- ->where('rule_id', $ruleId)
- ->where('id', '>', $idMin)
- ->where('id', '<=', $idMax)
- ->orderBy('id', 'ASC')
- ->limit(500)
- ->get();
- $count = $list->count();
- if ($count == 0) break;
- yield $list->toArray();
- if ($count < $limit) break;
- $idMin = $list->max('id');
- }
- }
- public function dataToEs($listGenerator, $massMsgInfo)
- {
- foreach ($listGenerator as $dataList) {
- // 获取客服信息
- $senderIds = array_unique(array_column($dataList, 'sender'));
- $userList = DjUser::query()
- ->where('corpid', $massMsgInfo->corpid)
- ->whereIn('user_id', $senderIds)
- ->pluck('name', 'user_id');
- // 获取客户信息
- $externalUserids = array_unique(array_column($dataList, 'external_userid'));
- $customerList = Customer::suffix($massMsgInfo->corpid)
- ->select(['external_userid', 'name', 'avatar'])
- ->whereIn('external_userid', $externalUserids)
- ->get()->keyBy('external_userid');
- MassMsgSendDetailEs::repairData($dataList, $massMsgInfo, $userList, $customerList);
- }
- }
- public function updateOrderPCustomerType()
- {
- $listGenerator = $this->orderGenerator();
- foreach ($listGenerator as $list) {
- foreach ($list as $value) {
- echo '更新开始:id:'.$value->id.PHP_EOL;
- $mp_user_register_time = $value->mp_user_register_time;
- $order_pay_time = $value->order_pay_time;
- $cur_month = date('Y-m-01 00:00:00', intval($order_pay_time / 1000));
- $aft_month = date('Y-m-01 00:00:00', strtotime("+1 months", strtotime($cur_month)));
- $reg_time = date('Y-m-d H:i:s', ($mp_user_register_time / 1000));
- echo 'cur_month:'.$cur_month.PHP_EOL;
- echo 'aft_month:'.$aft_month.PHP_EOL;
- echo 'reg_time:'.$reg_time.PHP_EOL;
- if ($reg_time >= $cur_month && $reg_time < $aft_month) {
- echo '更新结束:p_customer_type:1'.PHP_EOL;
- $value->update(['p_customer_type' => 1]);
- } else {
- echo '更新结束:p_customer_type:2'.PHP_EOL;
- $value->update(['p_customer_type' => 2]);
- }
- }
- }
- }
- public function orderGenerator()
- {
- $limit = 500;
- $idMin = 0;
- $idMax = DjOrder::query()->whereNotNull('pid')->max('id');
- while ($idMin < $idMax) {
- $list = DjOrder::query()
- ->whereNotNull('pid')
- ->where('id', '>', $idMin)
- ->where('id', '<=', $idMax)
- ->orderBy('id', 'ASC')
- ->limit($limit)
- ->get();
- $count = $list->count();
- if ($count == 0) break;
- yield $list;
- if ($count < $limit) break;
- $idMin = $list->max('id');
- }
- }
- public function repairData()
- {
- $massMsgRuleList = MassMsg::query()->where('send_time', '>=', date('Y-m-d 00:00:00'))
- ->where('estimated_user', 0)->where('operate_type', 1)->get();
- foreach ($massMsgRuleList as $massMsgRuleInfo) {
- if(2 == $massMsgRuleInfo->operate_type){
- RedisModel::lPush(MassMsg::MASS_MSG_ESTIMATED_MULTIPLE_CORP_USER_COUNT_RDS, $massMsgRuleInfo->id);
- } else {
- RedisModel::lPush(MassMsg::MASS_MSG_ESTIMATED_USER_COUNT_RDS, $massMsgRuleInfo->id);
- }
- }
- }
- public function repairData2($listGenerator)
- {
- foreach ($listGenerator as $list) {
- foreach ($list as $item) {
- echo 'id:'.$item->id.PHP_EOL;
- $dataJson = $item->attachments;
- if (empty($dataJson)) continue;
- $data = json_decode($dataJson, true);
- if (!is_array($data)) {
- Log::logError('存储的数据格式不合法', $data, 'test');
- continue;
- }
- $pid = null;
- $res = $this->drawPid($data, $pid, 'test');
- if ($res) {
- if (!is_null($pid)) {
- $upDb['pids'] = $pid;
- $item->update($upDb);
- }
- }
- }
- }
- }
- public function massGenerator()
- {
- $limit = 500;
- $idMin = 0;
- $idMax = MassMsg::query()->where('is_draw', 1)->max('id');
- while ($idMin < $idMax) {
- $list = MassMsg::query()
- ->where('is_draw', 1)
- ->where('id', '>', $idMin)
- ->where('id', '<=', $idMax)
- ->orderBy('id', 'ASC')
- ->limit($limit)
- ->get();
- $count = $list->count();
- if ($count == 0) break;
- yield $list;
- if ($count < $limit) break;
- $idMin = $list->max('id');
- }
- }
- public function momentGenerator()
- {
- $limit = 500;
- $idMin = 0;
- $idMax = MomentTask::query()->where('is_draw', 1)->max('id');
- while ($idMin < $idMax) {
- $list = MomentTask::query()
- ->where('is_draw', 1)
- ->where('id', '>', $idMin)
- ->where('id', '<=', $idMax)
- ->orderBy('id', 'ASC')
- ->limit($limit)
- ->get();
- $count = $list->count();
- if ($count == 0) break;
- yield $list;
- if ($count < $limit) break;
- $idMin = $list->max('id');
- }
- }
- public function drawPid($attachments, &$pid, $logName)
- {
- Log::logInfo('提取开始', $attachments, $logName);
- $drawPids = [];
- foreach ($attachments as $datum) {
- if (isset($datum['msgtype'])) {
- $url = null;
- // 小程序
- if (
- ($datum['msgtype'] == 'miniprogram')
- &&
- isset($datum['miniprogram']['page'])
- &&
- !empty($datum['miniprogram']['page'])
- ) {
- $url = $datum['miniprogram']['page'];
- }
- // 链接
- if (
- ($datum['msgtype'] == 'link')
- &&
- isset($datum['link']['url'])
- &&
- !empty($datum['link']['url'])
- ) {
- $url = $datum['link']['url'];
- }
- // H5推广
- if (
- ($datum['msgtype'] == 'promote')
- &&
- isset($datum['promote']['jump_url'])
- &&
- !empty($datum['promote']['jump_url'])
- ) {
- $url = $datum['promote']['jump_url'];
- }
- // 欢迎语中的H5推广会被转换成普通链接方式
- if (
- ($datum['msgtype'] == 'link')
- &&
- isset($datum['link']['jump_url'])
- &&
- !empty($datum['link']['jump_url'])
- ) {
- $url = $datum['link']['jump_url'];
- }
- // 属于其他类型
- if (is_null($url)) continue;
- Log::logInfo('提取URL', [
- 'url' => $url
- ], $logName);
- // 处理url
- $filedExistNum = 0;
- $this->dealUrl($url, $filedExistNum, $drawPids, $logName);
- if ($filedExistNum > 1) {
- Log::logError('提取推广链接PID存在多个字段', $datum, $logName);
- return false;
- }
- }
- // if (count($drawPids) > 1) {
- // Log::logError('提取推广链接PID存在多个值', $datum, $logName);
- // return false;
- // }
- if (!empty($drawPids)) $pid = json_encode(array_filter($drawPids));
- Log::logInfo('提取结束', $attachments, $logName);
- }
- return true;
- }
- public function dealUrl($url, &$filedExistNum, &$drawPids, $logName)
- {
- $url = str_replace("%25", "%", $url);
- $url = str_replace("&", "&", $url);
- $url = urldecode($url);
- $urlArr = parse_url($url);
- if (!isset($urlArr['query']) && empty($urlArr['query'])) return false;
- Log::logInfo('提取url', [
- 'url' => $url,
- 'filedExistNum' => $filedExistNum,
- 'drawPids' => $drawPids
- ], $logName);
- parse_str($urlArr['query'], $query);
- // 柚子 pathId
- if (isset($query['pathId']) && !empty($query['pathId'])) {
- $filedExistNum ++;
- $drawPids[] = $query['pathId'];
- }
- // 嘉书 article
- if (isset($query['article']) && !empty($query['article'])) {
- $filedExistNum ++;
- $drawPids[] = $query['article'];
- }
- // 迈步 pid
- if (isset($query['pid']) && !empty($query['pid'])) {
- $filedExistNum ++;
- $drawPids[] = $query['pid'];
- }
- // 点众阳光 referral_id
- if (isset($query['referral_id']) && !empty($query['referral_id'])) {
- $filedExistNum ++;
- $drawPids[] = $query['referral_id'];
- }
- foreach ($query as $urlVal) {
- $this->dealUrl($urlVal, $filedExistNum, $drawPids, $logName);
- }
- Log::logInfo('提取url结果', [
- 'url' => $url,
- 'filedExistNum' => $filedExistNum,
- 'drawPids' => $drawPids
- ], $logName);
- }
- }
|