<?php
class companyAction
{	
	public function __construct()
	{
		$Params = mvc::$URL_PARAMS;
		LibTpl::Set('UNIAPP',$Params['uniapp'] ?? 0);
	}
	//跑街令广告链接
	function info()
	{
		$Params = mvc::$URL_PARAMS;
	
		$showRows = [];
		if(isset($Params['ads_id']) && $Params['ads_id'] > 0)
		{
		    $ads = new AdsBase();
			$B2cBase = new B2cBase();
		    $res = $ads->get("pj_user_ads",['ads_topimg','ads_title','ads_url_data'],sprintf(" and ads_id=%d",$Params['ads_id']),true);
			$adsArr = $res['data'];
		    $adsArr['ads_url_data'] = json_decode($adsArr['ads_url_data'], true);
			$sort = [];
			foreach($adsArr['ads_url_data'] as $v)
			{
				$sort[] = $v['sort'];
			}
			array_multisort($sort, SORT_ASC, $adsArr['ads_url_data']);
			//image 组合
			$lastType = '';
			$lastrow = -1;
			foreach($adsArr['ads_url_data'] as $v)
			{
				if($v['type'] == 'image')
				{
					if($lastType == '' || $lastType != 'image')
					{
						$lastrow++;
						$showRows[$lastrow] = ['type'=>'image', 'rows'=>[$v]];
					}
					else if($v['type'] == $lastType)
					{
						$showRows[$lastrow]['rows'][] = $v;
					}
				}
				elseif($v['type'] == 'mulu')
				{	
					$res = $B2cBase->get('sh_super',['ssu_pjl_user'],sprintf(" AND ssu_shop_id=%d",$v['key']),true);
					
					$v['pjl_user'] = $res['data']['ssu_pjl_user'];
					
					$v['txt_rows'] = explode('@',$v['value']);
					$lastrow++;
					$showRows[$lastrow] = $v;
				}
				else
				{
					$lastrow++;
					$showRows[$lastrow] = $v;
				}
				$lastType = $v['type'];
			}
        }
		LibTpl::Set('title', $adsArr['ads_title']);
		LibTpl::Set('url_data', $showRows);
		LibTpl::Set('Params', $Params);
		LibTpl::Set('adsArr', $adsArr);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}
}