function sunkSubscriberServices()
{
    global $link;
    # MB ID => IPTV ID
    $usersMB2IPTV = array();
    # MB ID => IPTV ID
    $servicesMB2IPTV = array();
    $servicesIPTV = getServicesIPTV();
    $addSubscriberPackets = array();
    $IPTVnames = array();
    foreach ($servicesIPTV as $k => $v) {
        $servicesMB2IPTV[intval($v[1])] = $v[0];
    }
    $activeServicesMB = getActiveServicesMB();
    $activeServicesIPTV = getActiveServicesIPTV();
    $usersMikBiLL = getUsersWithServices($link);
    $usersIPTV = getUsersIPTV();
    foreach ($usersIPTV as $user) {
        $IPTVnames[$user[1]] = $user[0];
    }
    # UID => ID
    # преобразуем через логин UID в subscriber_id
    foreach ($usersMikBiLL as $uid => $user) {
        $usersMB2IPTV[$uid] = $IPTVnames[$user['user']];
    }
    foreach ($activeServicesMB as $uid => $user) {
        foreach ($user as $serviceid => $v) {
            if (isset($usersMB2IPTV[$uid]) and !isset($activeServicesIPTV[$usersMB2IPTV[$uid]][$servicesMB2IPTV[$serviceid]])) {
                $addSubscriberPackets[] = array($usersMB2IPTV[$uid], $servicesMB2IPTV[$serviceid], true);
            }
        }
    }
    #print_r($addSubscriberPackets);
    if (!empty($addSubscriberPackets)) {
        # добавление пакетов
        $res = jsonRequest("insert", array("into" => "subscriber_package", "columns" => array("subscriber_id", "package_id", "enabled"), "values" => $addSubscriberPackets, "returning" => "package_id"));
        echo 'insert cmd result: ';
        #print_r($res);
    }
}
示例#2
0
}
$usersMikBiLLLogin = array();
$usersIPTV = array();
$addUsers = array();
$deleteUsers = array();
$currentUsers = array();
# синхронищзация пакетов (услуг)
syncServicesIPTV($link);
$usersMikBiLL = getUsersWithServices($link);
foreach ($usersMikBiLL as $user) {
    $usersMikBiLLLogin[$user['user']] = 0;
}
//print_r($usersMikBiLL);
# по каждому абоненту выберем оборудование и услуги
# выборка списка абонентов
$usersIPTVList = getUsersIPTV();
//echo 'select users: ';
//print_r($usersIPTVList);
//print_r($usersMikBiLL);
foreach ($usersIPTVList as $user) {
    $usersIPTV[$user[1]] = $user;
}
foreach ($usersMikBiLL as $user) {
    if (!isset($usersIPTV[$user['user']])) {
        # новый
        $addUsers[] = $user;
    } else {
        # уже есть - обновить
        $currentUsers[] = $user;
    }
}
function syncSubscriberServices()
{
    global $link;
    # MB ID => IPTV ID
    $usersMB2IPTV = array();
    # MB ID => IPTV ID
    $servicesMB2IPTV = array();
    $servicesIPTV = getServicesIPTV();
    $addSubscriberPackets = array();
    $deleteSubscriberPackets = array();
    /**
     * @var array $IPTVnames сопоставление [логин] => ID в IPTV
     */
    $IPTVnames = array();
    foreach ($servicesIPTV as $k => $v) {
        $servicesMB2IPTV[intval($v[1])] = $v[0];
    }
    $activeServicesMB = getActiveServicesMB();
    $activeServicesIPTV = getActiveServicesIPTV();
    $usersMikBiLL = getUsersWithServices($link);
    $usersIPTV = getUsersIPTV();
    foreach ($usersIPTV as $user) {
        $IPTVnames[$user[1]] = $user[0];
    }
    # UID => ID
    # преобразуем через логин UID в subscriber_id
    foreach ($usersMikBiLL as $uid => $user) {
        $usersMB2IPTV[$uid] = $IPTVnames[$user['user']];
    }
    foreach ($activeServicesMB as $uid => $user) {
        foreach ($user as $serviceid => $expiredOn) {
            if (isset($usersMB2IPTV[$uid]) and !isset($activeServicesIPTV[$usersMB2IPTV[$uid]][$servicesMB2IPTV[$serviceid]])) {
                $addSubscriberPackets[] = array($usersMB2IPTV[$uid], $servicesMB2IPTV[$serviceid], true);
                //				var_dump($expiredOn);
            } else {
                # существует - удалить
                unset($activeServicesIPTV[$usersMB2IPTV[$uid]][$servicesMB2IPTV[$serviceid]]);
            }
        }
    }
    //	print_r($addSubscriberPackets);
    if (!empty($addSubscriberPackets)) {
        # добавление пакетов
        jsonsql_call("insert", array("into" => "subscriber_package", "columns" => array("subscriber_id", "package_id", "enabled"), "values" => $addSubscriberPackets, "returning" => "package_id"));
    }
    //	$deleteSubscriberPackets = array(
    //		array(
    //			1205153,
    //			1990
    //		),
    //		array(
    //			1205153,
    //			1989
    //		),
    //	);
    foreach ($activeServicesIPTV as $user) {
        foreach ($user as $activeService) {
            //			var_dump($activeService);
            $deleteSubscriberPackets[] = array($activeService[0], $activeService[1]);
        }
        //		var_dump($activeService);
    }
    deleteIPTVPacketFromUser($deleteSubscriberPackets);
    //	deleteIPTVPacketFromUser(1205153, 1990);
    //	$deleteSubscriberPackets = array(
    //		"and" => array(
    //			array("eq" => array("package_id", "1990")),
    //			array("eq" => array("subscriber_id", "1205153"))
    //		)
    ////		"subscriber_id" => "1205153",
    //
    ////	    array("subscriber_id", "1205153"),
    ////		array("package_id", "1990"),
    //	);
    //
    ////	if (count($deleteSubscriberPackets) > 1) {
    //		jsonsql_call("delete", array(
    //				"from"  => "subscriber_package",
    //				"where" =>
    //					$deleteSubscriberPackets
    ////					"eq" => $deleteSubscriberPackets
    ////					"and" => array(
    ////						"eq" => array(),
    ////						"eq" => array(),
    ////					)
    //			)
    //		);
    //	}
}