<?php

/**
 * @method 跑街令CRM基本操作
 * @author soul
 * @copyright 2016/3/31
 */
class CrmAds extends CrmBase
{
    public function __construct()
    {
		parent::__construct();
		LibFc::useMainDb();
    }

	public function getTsAdsPlace()
	{	
		$ads = new BaseDb(mvc::$cfg['DB']['B2COTH']);
		$res = $ads->get('yp_province_city', ['pc_id as id, pc_name as name'], ' AND pc_pid = 0 ORDER BY pc_seq, pc_id');
		$provinceArr = array_column($res['data'], null, 'id');
		
		$Ypc2Base = new Ypc2Base();
		$brandArr = [];
		$brandArr = [];
		$res =$Ypc2Base->Get('bc_brand join bc_model2 on brand_id = mod2_brand_id', ['brand_id as id, brand_name as name', 'mod2_pc', 'mod2_cv'], ' order by brand_initial');
		
		foreach ($res['data'] as $item)
        {
            if (!isset($brandArr[$item['id']]))
            {
                $brandArr[$item['id']] = [
                    'id' => $item['id'],
                    'name' => $item['name'],
                    'mod2_pc' => 0,
                    'mod2_cv' => 0,
                ];
            }

            if ($item['mod2_pc'] && !$brandArr[$item['id']]['mod2_pc']) {
                $brandArr[$item['id']]['mod2_pc'] = 1;
            }

            if ($item['mod2_cv'] && !$brandArr[$item['id']]['mod2_cv']) {
                $brandArr[$item['id']]['mod2_cv'] = 1;
            }
        }

		

		$worldArr = [['id'=>0, 'name'=>'独家']];

		//按省或者品牌合并规整
		$groupArr = ['province'=>$provinceArr, 'brand'=>$brandArr, 'world'=>$worldArr];
		
		$pres = $ads->get('pj_place', ['pa_id, pa_name, pa_is_area, pa_is_keyword, pa_keyword_type, pa_max'], ' AND pa_status = 1 ORDER BY pa_seq');
		$placeArr = [];
		$now = time();
		//先计算每个广告位的适用情况
		foreach($pres['data'] as $v)
		{
			if($v['pa_is_area'] && $v['pa_is_keyword']) continue;
			$v['adsuse'] = [];
			$v['group'] = $v['pa_keyword_type'];
			if($v['pa_is_area'])
			{
				$v['group'] = 'province';
				foreach($provinceArr as $pk=>$pv)
				{
					$v['adsuse'][$pk]['all'] = array_merge($pv, ['has'=>0, 'can'=>$v['pa_max'], 'cantime'=>date('Y-m-d', $now), 'candate'=>0]);
				}
			}
			else if($v['pa_is_keyword'])
			{	
				foreach($brandArr as $pk=>$pv)
				{	
					//区分乘用车、商用车
					if ($pv['mod2_pc'])
                    {
                        $v['adsuse'][$pk]['pc'] = array_merge($pv, ['has'=>0, 'can'=>$v['pa_max'], 'cantime'=>date('Y-m-d', $now), 'candate'=>0]);
                    }

                    if ($pv['mod2_cv'])
                    {
                        $v['adsuse'][$pk]['cv'] = array_merge($pv, ['has'=>0, 'can'=>$v['pa_max'], 'cantime'=>date('Y-m-d', $now), 'candate'=>0]);
                    }
					
				}
			}
			else
			{
				$v['group'] = 'world';
				$v['adsuse'][0]['all'] = array_merge($worldArr[0], ['has'=>0, 'can'=>$v['pa_max'], 'cantime'=>date('Y-m-d', $now), 'candate'=>0]);
			}

			//已有的
			$adsTime = [];
			$res = $ads->get('pj_place_ads_time JOIN pj_place_ads ON pla_id = pat_pla_id', ['pat_keyword, pat_pc_id, pat_btime, pat_etime,pat_modpc,pat_modcv'], sprintf(" and pal_shoufei = 1 and pla_pa_id = %d and pat_etime >= %d order by pat_etime asc", $v['pa_id'], $now));
			foreach($res['data'] as $tvv)
			{
				if($tvv['pat_btime'] < $now) $tvv['pat_btime'] = $now;
				if($v['pa_is_area'])
				{
					$adsTime[$tvv['pat_pc_id']]['all'][] = ['btime'=>$tvv['pat_btime'], 'etime'=>$tvv['pat_etime']];
				}
				else if($v['pa_is_keyword'])
				{
					if($v['pa_keyword_type'] == 'brand'){

						if ($tvv['pat_modpc'] && isset($brandArr[$tvv['pat_keyword']]) && $brandArr[$tvv['pat_keyword']]['mod2_pc']) {
                            $adsTime[$tvv['pat_keyword']]['pc'][] = ['btime'=>$tvv['pat_btime'], 'etime'=>$tvv['pat_etime']];
                        }

                        if ($tvv['pat_modcv'] && isset($brandArr[$tvv['pat_keyword']]) && $brandArr[$tvv['pat_keyword']]['mod2_cv']) {
                            $adsTime[$tvv['pat_keyword']]['cv'][] = ['btime'=>$tvv['pat_btime'], 'etime'=>$tvv['pat_etime']];
                        }
					}	
				}
				else
				{
					$adsTime[0]['all'][] = ['btime'=>$tvv['pat_btime'], 'etime'=>$tvv['pat_etime']];
				}
			}
			foreach($adsTime as $tkk=>$tvv)
			{	
				foreach ($tvv as $ttkk => $ttvv) {
					$v['adsuse'][$tkk][$ttkk]['has'] = count($ttvv);
					$v['adsuse'][$tkk][$ttkk]['can'] = $v['pa_max'] - count($ttvv);
					//已全部售完
					if($v['adsuse'][$tkk][$ttkk]['has'] >= $v['pa_max'])
					{
						$v['adsuse'][$tkk][$ttkk]['can'] = 0;
						$endKey = $v['adsuse'][$tkk][$ttkk]['has'] - $v['pa_max'];
						$v['adsuse'][$tkk][$ttkk]['cantime'] = date('Y-m-d', $ttvv[$endKey]['etime']+3600*24);
						$v['adsuse'][$tkk][$ttkk]['candate'] = (int) ceil(($ttvv[$endKey]['etime'] - $now)/3600/24);
					}
				}
				
			}
			$placeArr[$v['pa_id']] = $v;
		}
		$brandLinkTypeArr = [];//提取车型的类型 all:全 pc:乘 cv:商
		// 省份、品牌
		foreach($groupArr as $style=>$gv)
		{
			foreach($gv as $gvid=>$gvval)
			{		
				if($style == 'brand'){	

					if($gvval['mod2_pc'] && $gvval['mod2_cv']){
						$brandLinkTypeArr['all'][] = $gvid;
					}elseif(!$gvval['mod2_pc'] && $gvval['mod2_cv']){
						$brandLinkTypeArr['onlycv'][] = $gvid;
					}elseif($gvval['mod2_pc'] && !$gvval['mod2_cv']){
						$brandLinkTypeArr['onlypc'][] = $gvid;
					}
					//需要判断当前品牌是否有乘用车、商用车
					if($gvval['mod2_pc']){
						$gvval['pc']['plas'] = [];
						foreach($placeArr as $paid=>$pav)
						{
							if($pav['group'] == $style && !empty($pav['adsuse'][$gvid]['pc']))
								$gvval['pc']['plas'][] = [
									'id'=>$paid,
									'name'=>$pav['pa_name'],
									'has'=>$pav['adsuse'][$gvid]['pc']['has'],
									'can'=>$pav['adsuse'][$gvid]['pc']['can'],
									'cantime'=>$pav['adsuse'][$gvid]['cantime'],
									'candate'=> (int) ceil((strtotime($pav['adsuse'][$gvid]['pc']['cantime']) - $now)/3600/24)
								];
						}
					}
					if($gvval['mod2_cv']){
						$gvval['cv']['plas'] = [];
						foreach($placeArr as $paid=>$pav)
						{
							if($pav['group'] == $style && !empty($pav['adsuse'][$gvid]['cv']))
								$gvval['cv']['plas'][] = [
									'id'=>$paid,
									'name'=>$pav['pa_name'],
									'has'=>$pav['adsuse'][$gvid]['cv']['has'],
									'can'=>$pav['adsuse'][$gvid]['cv']['can'],
									'cantime'=>$pav['adsuse'][$gvid]['cv']['cantime'],
									'candate'=> (int) ceil((strtotime($pav['adsuse'][$gvid]['cv']['cantime']) - $now)/3600/24)
								];
						}
					}
					$gv[$gvid] = $gvval;
				}else{
		
					$gvval['all']['plas'] = [];
					foreach($placeArr as $paid=>$pav)
					{
						if($pav['group'] == $style && !empty($pav['adsuse'][$gvid]['all']))
							$gvval['all']['plas'][] = [
								'id'=>$paid,
								'name'=>$pav['pa_name'],
								'has'=>$pav['adsuse'][$gvid]['all']['has'],
								'can'=>$pav['adsuse'][$gvid]['all']['can'],
								'cantime'=>$pav['adsuse'][$gvid]['all']['cantime'],
								'candate'=> (int) ceil((strtotime($pav['adsuse'][$gvid]['all']['cantime']) - $now)/3600/24)
							];
					}
					$gv[$gvid] = $gvval;
				}
			}
			$groupArr[$style] = array_values($gv);
		}
		return ['data'=>$groupArr,'brandLinkType'=>$brandLinkTypeArr];
	}

	/**
	 * @method 推送广告位给客户
	 * @author zhengweihua 
	 * @copyright 2026-05-18
	 */
	public function tsAdsPlaceToUser()
	{
		$ypwBase = new YpwBase();
		$tsreg = $ypwBase->getKeyVal('tsreg_pjlads');
		$tsreg = json_decode($tsreg['data'], true);
		if (!$tsreg) {
			return LibFc::ReturnData(false, '没有配置');
		}


		$tsAllArr = [];
        // 1. 获取所有启用的跑街令广告模板
        $res = $this->get('ts_msg_tpl', ['*'], " and tm_type='pjlads' and tm_status = 1");
        if(empty($res['data'])) {
            return LibFc::ReturnData(false, '无可用推送模板');
        }
        //存在多模板的情况
		$tsTplArr = [];
		foreach ($res['data'] as  $val) {
			$tsTplArr[$val['tm_dataid']][] = $val;
		}

        // 2. 获取需要忽略的用户列表 (冷却期内)
        // 同用户最近 mindate_user 天推送过任何 pjlads 类型
        $res = $this->get('ts_msg_history', ['distinct tmh_u_id'], sprintf(" and tmh_unikey like 'pjlads_%%' and tmh_status>=0 and tmh_atime>%d", strtotime('-'.$tsreg['mindate_user']['val'].' day')));
        $ignorUid = array_column($res['data'], 'tmh_u_id');

        // 同用户最近 mindate_place 天推送过特定位置 (unikey: pjlads_{pa_id})
        $res = $this->get('ts_msg_history', ['tmh_unikey, tmh_u_id'], sprintf(" and tmh_unikey like 'pjlads_%%' and tmh_status>=0 and tmh_atime>%d group by tmh_unikey, tmh_u_id", strtotime('-'.$tsreg['mindate_place']['val'].' day')));
        $ignorUniKeyUid = [];
        foreach($res['data'] as $v) {
            $ignorUniKeyUid[$v['tmh_u_id']][] = $v['tmh_unikey'];
        }

        // 3. 获取当天各位置各品牌的已推送次数
        // maxkey format: pjlads_{pa_id}_{type}_{brand_id}
        $res = $this->get('ts_msg_history', ["CONCAT(tmh_unikey, '_', JSON_UNQUOTE(tmh_para->'$.id')) as maxkey, COUNT(*) as total"], sprintf(" and tmh_unikey like 'pjlads_%%' and tmh_status>=0 and tmh_atime>=%d GROUP BY maxkey", strtotime(date('Y-m-d'))));
        $tsCountArr = array_column($res['data'], 'total', 'maxkey');


        // 4. 获取广告位可售情况
        $plres = $this->getTsAdsPlace();

		if($plres['data'])
		{	
			$YpwBase = new YpwBase();
			//获取符合推送条件的人-省份
			if($plres['data']['province']){
				$res = $YpwBase->get('yp_user_act join yp_user on ua_uid = u_id and u_status = 1 JOIN yp_user_ext ON ui_uid =ua_uid', ['ui_province id'], " and ui_province > 0 GROUP BY ui_province HAVING SUM(ua_pv) > 1000 ORDER BY SUM(ua_pv) DESC");
				$tsIdArr['province']['all'] = array_column($res['data'],'id');
			}
			//获取符合推送条件的人-品牌
			if($plres['data']['brand']){
				//如果品牌是全类型,那么就把乘用车、商用车区分开来；
				//如果品牌只有乘用车，但是统计数据包含商用车，则全部统计；反之同理
				if($plres['brandLinkType']['all']){

					$brandIds = implode(',',$plres['brandLinkType']['all']);

					$res = $YpwBase->get('yp_user_act_brand join yp_user on uab_uid = u_id and u_status = 1', ['uab_brand_id id'], sprintf(" and uab_modtype='pc' and uab_brand_id>0 and uab_brand_id IN (%s) GROUP BY uab_brand_id,uab_modtype HAVING SUM(uab_count) > 100 ORDER BY SUM(uab_count) DESC",$brandIds));
					$tsIdArr['brand']['pc'] = array_column($res['data'],'id');

					$res = $YpwBase->get('yp_user_act_brand join yp_user on uab_uid = u_id and u_status = 1', ['uab_brand_id id'], sprintf(" and uab_modtype='cv' and uab_brand_id>0 and uab_brand_id IN (%s) GROUP BY uab_brand_id,uab_modtype HAVING SUM(uab_count) > 100 ORDER BY SUM(uab_count) DESC",$brandIds));
					$tsIdArr['brand']['cv'] = array_column($res['data'],'id');
					
				}
				if ($plres['brandLinkType']['onlypc']) {
					$brandIds = implode(',',$plres['brandLinkType']['onlypc']);
					$res = $YpwBase->get('yp_user_act_brand join yp_user on uab_uid = u_id and u_status = 1', ['uab_brand_id id'], sprintf(" and uab_brand_id > 0 and uab_brand_id IN (%s) GROUP BY uab_brand_id HAVING SUM(uab_count) > 100 ORDER BY SUM(uab_count) DESC",$brandIds));
					$tsIdArr['brand']['onlypc'] = array_column($res['data'],'id');
					
				}
				
				if ($plres['brandLinkType']['onlycv']) {
					$brandIds = implode(',',$plres['brandLinkType']['onlycv']);
					$res = $YpwBase->get('yp_user_act_brand join yp_user on uab_uid = u_id and u_status = 1', ['uab_brand_id id'], sprintf(" and uab_brand_id > 0 and uab_brand_id IN (%s) GROUP BY uab_brand_id HAVING SUM(uab_count) > 100 ORDER BY SUM(uab_count) DESC",$brandIds));
					$tsIdArr['brand']['onlycv'] = array_column($res['data'],'id');
				}
				
			}
		
			foreach ($plres['data']  as $style=>$gvals) {
				
				//用属性ID作为键
				$gvals = array_column($gvals, null, 'id');

				if(!$tsIdArr[$style]) continue;
				//$type是统计类型,品牌只有乘用车或者只有商用车则统计全部
				foreach($tsIdArr[$style] as $type=>$typeArr)
				{	
					foreach ($typeArr as $toid) {
						if(empty($gvals[$toid])) continue;
						$gval = $gvals[$toid];
						$remsgArr = [];

						$toUsers = [];
						if($style == 'province')
						{//此省份的活跃用户
							$remsgArr = ['#省份#'=>$gval['name']];
							$where = sprintf(" and ui_province = %d GROUP BY ui_uid HAVING SUM(ua_pv) > %d ORDER BY SUM(ua_pv) DESC limit 1000", $toid,$tsreg['minpv']['val']?:100);
							$res = $YpwBase->get('yp_user_act join yp_user on ua_uid = u_id and u_status = 1 JOIN yp_user_ext ON ui_uid =ua_uid', ['ui_uid u_id', 'SUM(ua_pv) pv'], $where);
							$toUsers = $res['data'];

						}
						else if($style == 'brand')
						{//此品牌的活跃用户
							if ($type == 'pc') {
								$remsgArr = ['#品牌#'=>$gval['name'],'#车辆类型#'=>'乘用车'];
								$where = sprintf(" and uab_modtype='pc' and uab_brand_id = %d GROUP BY uab_uid HAVING SUM(uab_count) > %d ORDER BY SUM(uab_count) DESC limit 500", $toid,$tsreg['minpv']['val']?:100);
								$res = $YpwBase->get('yp_user_act_brand join yp_user on uab_uid = u_id and u_status = 1', ['uab_uid u_id', 'SUM(uab_count) pv'], $where);
								$toUsers = $res['data'];
							}elseif ($type == 'cv') {
								$remsgArr = ['#品牌#'=>$gval['name'],'#车辆类型#'=>'商用车'];
								$where = sprintf(" and uab_modtype='cv' and uab_brand_id = %d GROUP BY uab_uid HAVING SUM(uab_count) > %d ORDER BY SUM(uab_count) DESC limit 500", $toid,$tsreg['minpv']['val']?:100);
								$res = $YpwBase->get('yp_user_act_brand join yp_user on uab_uid = u_id and u_status = 1', ['uab_uid u_id', 'SUM(uab_count) pv'], $where);
								$toUsers = $res['data'];
							}else{
								$remsgArr = ['#品牌#'=>$gval['name'],'#车辆类型#'=>$type=='onlypc'?'乘用车':'商用车'];
								$where = sprintf(" and uab_brand_id = %d GROUP BY uab_uid HAVING SUM(uab_count) > %d ORDER BY SUM(uab_count) DESC limit 500", $toid,$tsreg['minpv']['val']?:100);
								$res = $YpwBase->get('yp_user_act_brand join yp_user on uab_uid = u_id and u_status = 1', ['uab_uid u_id', 'SUM(uab_count) pv'], $where);
								$toUsers = $res['data'];
							}
						}
						//查询crm客户信息
						$ctrArr = [];
						$uidstr = implode(',',array_column($toUsers,'u_id'));
						if($uidstr){
							$ctrRes = $this->get('crm_customer left join crm_customer_admin on ctr_id=cca_ctr_id',['ctr_id','ctr_uid','cca_au_uid'],sprintf(" and ctr_uid in (%s) and cca_end_time > %d ",$uidstr,time()));
							if($ctrRes) $ctrArr = array_column($ctrRes['data'],null,'ctr_uid');
						}
					
						
						foreach($toUsers as $uval)
						{
							$uid = $uval['u_id'];

							//在忽略推送里或者已经在本次推送
							if(in_array($uid, $ignorUid) || $tsAllArr[$uid]) continue;

							$curtype = $type;
							if($style == 'brand' && in_array($type ,['onlypc','onlycv'])) 
							$reason = '';
							if($style=='province'){
								$reason = sprintf('访问%s%d次', $gval['name'],$uval['pv']);
							}elseif($style=='brand'){
								if(in_array($type ,['onlypc','onlycv'])){
									$curtype = $type=='onlypc'?'pc':'cv';
									$reason = sprintf('访问%s%s%d次', $gval['name'],$type=='onlypc'?'乘用车':'商用车',$uval['pv']);
								}else{
									$reason = sprintf('访问%s%s%d次', $gval['name'],$type=='pc'?'乘用车':'商用车',$uval['pv']);
								}
							}
							shuffle($gval[$curtype]['plas']);//随机
							foreach($gval[$curtype]['plas'] as $pa)
							{
								//有推送模板，并且30天内有空位的
								$unikey = 'pjlads_'.$pa['id'].'_'.$curtype;
								$maxkey = $unikey.'_'.$toid;
								if(empty($tsTplArr[$pa['id']]) || $pa['candate'] > 30 || $tsCountArr[$maxkey] >= $tsreg['max']['val'])  continue;
								if(!empty($ignorUniKeyUid[$uid]) && in_array($unikey, $ignorUniKeyUid[$uid])) continue;
								//随机取一个推送模板
								$useTsTpl = count($tsTplArr[$pa['id']])==1?$tsTplArr[$pa['id']][0]:$tsTplArr[$pa['id']][rand(0,count($tsTplArr[$pa['id']])-1)];
								$msg = strtr($useTsTpl['tm_tpl'], $remsgArr);
								$tsAllArr[$uid] = [
									'tmh_u_id'=>$uid,
									'tmh_tm_id'=>$useTsTpl['tm_id'],
									'tmh_unikey'=>$unikey,
									'tmh_msg_type'=>$useTsTpl['tm_msg_type'],
									'tmh_para'=>json_encode(['id'=>$gval['id'],'name'=>$gval['name'],'reason'=>$reason], JSON_UNESCAPED_UNICODE),
									'tmh_msg'=>$msg,
									'tmh_atime'=>time(),
									'tmh_add_u_id'=>8,
									'tmh_au_id'=>$ctrArr[$uid]['cca_au_uid']??0,
									'tmh_ctr_id'=>$ctrArr[$uid]['ctr_id']??0
								];
								$tsCountArr[$maxkey]++;
							}
						}
					}
				}
			}
			if(!empty($tsAllArr))
			{
				$tsAllArr = array_values($tsAllArr);
				$this->addAny('ts_msg_history', array_keys($tsAllArr[0]), $tsAllArr);
			}
		}

		return LibFc::ReturnData(true);
	}


	/**
	  * @method 机器人推送给横向件用户
	  * @author zhengweihua
	  * @copyright 2026/5/18
	  * @return	
	  */
	public function tsRobotToUser()
	{
		$ypwBase = new YpwBase();
		$reg = $ypwBase->getKeyVal('tsreg_robot');
		$reg = json_decode($reg['data'], true);
		if (!$reg) {
			return LibFc::ReturnData(false, '没有配置');
		}

		$YpwBase = new YpwBase();
		
		$tmtype = 'robot';
		$res = $this->get('ts_msg_tpl', ['*'], " and tm_type='robot' and tm_status = 1");
		$tsTplArr = $res['data'];
		if(empty($tsTplArr)) return LibFc::ReturnData(false, '机器人推送模板不存在！');
		
		//同用户最近mindate_user天推送的过不再推送
		$res = $this->get('ts_msg_history', ['distinct tmh_u_id'], sprintf(" and tmh_unikey='%s' and tmh_status>=0 and tmh_atime>%d", $tmtype, strtotime('-'.$reg['mindate_user']['val'].' day')));
		$ignorUid = array_column($res['data'], 'tmh_u_id');

		//需要推送的所有记录，单用户只推送一条
		$tsAllArr = [];
		
		//当天已推送的次数
		$res = $this->get('ts_msg_history', ["COUNT(*) total"], sprintf(" and tmh_unikey='%s' and tmh_status>=0 and tmh_atime>=%d", $tmtype, strtotime(date('Y-m-d'))));
		$tsCountArr = $res['data']['total'];
		if($tsCountArr >= $reg['max']['val']) return LibFc::ReturnData(true);
		
		$toUsers = [];
		$res = $YpwBase->get('yp_user_act_part join yp_user on uap_uid = u_id and u_status = 1', ['uap_uid u_id', 'SUM(uap_count) pv'], " and uap_count > 5 GROUP BY uap_uid HAVING COUNT(DISTINCT uap_part) <= 5 AND SUM(uap_count) > 100 ORDER BY SUM(uap_count) DESC");
		$toUsers = $res['data'];

		//查询crm客户信息
		$uidstr = implode(',',array_column($toUsers,'u_id'));
		$ctrRes = $this->get('crm_customer left join crm_customer_admin on ctr_id=cca_ctr_id',['ctr_id','ctr_uid','cca_au_uid'],sprintf(" and ctr_uid in (%s) and cca_end_time > %d ",$uidstr,time()));
		if($ctrRes) $ctrArr = array_column($ctrRes['data'],null,'ctr_uid');
		foreach($toUsers as $uval)
		{
			$uid = $uval['u_id'];
			$reason = '最近查询配件达'.$uval['pv'].'次';
			//在忽略推送里或者已经在本次推送
			if(in_array($uid, $ignorUid) || $tsAllArr[$uid]) continue;
			$unikey = $tmtype;
			if($tsCountArr >= $reg['max']['val'])  continue;
			$useTsTpl = count($tsTplArr)==1?$tsTplArr[0]:$tsTplArr[rand(0,count($tsTplArr)-1)];
			$msg = $useTsTpl['tm_tpl'];
			$tsAllArr[$uid] = [
				'tmh_u_id'=>$uid,
				'tmh_tm_id'=>$useTsTpl['tm_id'],
				'tmh_unikey'=>$unikey,
				'tmh_para'=>json_encode(['reason'=>$reason], JSON_UNESCAPED_UNICODE),
				'tmh_msg_type'=>$useTsTpl['tm_msg_type'],
				'tmh_msg'=>$msg,
				'tmh_atime'=>time(),
				'tmh_add_u_id'=>8,
				'tmh_au_id'=>$ctrArr[$uid]['au_uid']??0,
				'tmh_ctr_id'=>$ctrArr[$uid]['ctr_id']??0
			];
			$tsCountArr++;
		}
		if(!empty($tsAllArr))
		{
			$tsAllArr = array_values($tsAllArr);
			$this->addAny('ts_msg_history', array_keys($tsAllArr[0]), $tsAllArr);
		}
		return LibFc::ReturnData(true);
	}
}
