Пример #1
0
function uni_group_check()
{
    global $_W;
    $uniacid = $_W['uniacid'];
    $settings = uni_setting($uniacid, array('groupdata'));
    $groupdata = $settings['groupdata'] ? $settings['groupdata'] : array();
    if ($_W['account']['groupid'] != 0 && $groupdata['isexpire'] == 1 && $groupdata['endtime'] < TIMESTAMP) {
        pdo_update('uni_account', array('groupid' => 0), array('uniacid' => $uniacid));
        pdo_update('uni_settings', array('groupdata' => iserializer(array('isexpire' => 1, 'endtime' => $groupdata['endtime'], 'oldgroupid' => $_W['account']['groupid']))), array('uniacid' => $uniacid));
        $_W['account']['groupid'] = 0;
        load()->model('module');
        module_build_privileges();
        return true;
    }
    return false;
}
Пример #2
0
 $multi['styleid'] = $styleid;
 pdo_insert('site_multi', $multi);
 $multi_id = pdo_insertid();
 $unisettings['creditnames'] = array('credit1' => array('title' => '积分', 'enabled' => 1), 'credit2' => array('title' => '余额', 'enabled' => 1));
 $unisettings['creditnames'] = iserializer($unisettings['creditnames']);
 $unisettings['creditbehaviors'] = array('activity' => 'credit1', 'currency' => 'credit2');
 $unisettings['creditbehaviors'] = iserializer($unisettings['creditbehaviors']);
 $unisettings['uniacid'] = $uniacid;
 $unisettings['default_site'] = $multi_id;
 $unisettings['sync'] = iserializer(array('switch' => 0, 'acid' => ''));
 pdo_insert('uni_settings', $unisettings);
 pdo_insert('mc_groups', array('uniacid' => $uniacid, 'title' => '默认会员组', 'isdefault' => 1));
 $account_users = array('uniacid' => $uniacid, 'uid' => 1, 'role' => 'manager');
 pdo_insert('uni_account_users', $account_users);
 load()->model('module');
 module_build_privileges();
 $insert['account'] = trim($_GPC['account']);
 $insert['name'] = trim($_GPC['name']);
 $insert['level'] = 1;
 $insert['type'] = 1;
 if (empty($account)) {
     $acid = account_create($uniacid, $insert);
     if (!empty($_FILES['qrcode']['tmp_name'])) {
         $_W['uploadsetting'] = array();
         $_W['uploadsetting']['image']['folder'] = $acid;
         //file be save in attachment/$acid
         $_W['uploadsetting']['image']['extentions'] = array('jpg', 'jpeg', 'png');
         $_W['uploadsetting']['image']['limit'] = $_W['config']['upload']['image']['limit'];
         $upload = file_upload($_FILES['qrcode'], 'image', "qrcode_{$acid}");
     }
     if (!empty($_FILES['headimg']['tmp_name'])) {
Пример #3
0
function buy_package($user, $package_id, $total = 1)
{
    if (empty($user) || empty($user["uid"])) {
        return error(-1, "用户不存在");
    }
    if ($total <= 0) {
        return error(-1, "购买数必须大于1");
    }
    if (empty($user["credit2"]) || doubleval($user["credit2"]) < 0) {
        return error(-1, "用户余额为0无法购买套餐.");
    }
    $group = kim_get_uni_group($package_id);
    if (empty($group)) {
        return error(-1, "模块不存在.");
    }
    $price = doubleval($group["price"]);
    if (intval($user['groupid']) > 0) {
        list($price, $discount) = check_price($price, intval($user['groupid']));
    }
    if (doubleval($user["credit2"]) < $price * $total) {
        return error(-1, "用户余额不足.");
    }
    $st = get_settings();
    $day = 30;
    if (intval($st[package_day]) > 0) {
        $day = intval($st[package_day]);
    }
    $package_price = $price * $total;
    $package_time = $total * $day * 24 * 60 * 60;
    load()->model("account");
    $account = uni_fetch();
    if (empty($account)) {
        return error(-1, "公众号不存在.");
    }
    $settings = uni_setting($account["uniacid"], array('groupdata'));
    $groupData = $settings['groupdata'] ? $settings['groupdata'] : array("endtime" => TIMESTAMP);
    $package_endTime = $package_time;
    if ($groupData["endtime"] - TIMESTAMP > 0) {
        $package_endTime = $groupData["endtime"] - TIMESTAMP + $package_time;
    }
    $old_package = kim_get_uni_group($account["groupid"]);
    try {
        pdo_begin();
        $endtime = date("Y-m-d", TIMESTAMP + $package_endTime);
        load()->model('user');
        $record = array();
        $record['uid'] = $user["uid"];
        $record['endtime'] = $endtime;
        user_update($record);
        $order_record = array("uniacid" => $account["uniacid"], "uid" => $user["uid"], "package" => $package_id, "buy_time" => TIMESTAMP, "expiration_time" => TIMESTAMP + $package_endTime);
        pdo_insert("users_packages", $order_record);
        $record_id = pdo_insertid();
        if ($record_id <= 0) {
            throw new Exception("保存记录失败");
        }
        //VIP时间同步
        $groupData["endtime"] = $groupData["endtime"] < TIMESTAMP ? TIMESTAMP : $groupData["endtime"];
        $old_over_time = date("Y-m-d", $groupData["endtime"]);
        $new_over_time = date("Y-m-d", TIMESTAMP + $package_endTime);
        $log = array(0, sprintf("自动续费: %s 套餐续费,续费前:%s 到期; 续费后:%s 到期", $group["name"], $old_over_time, $new_over_time));
        if (intval($account["groupid"]) != intval($package_id)) {
            $surplus_price = $old_package["price"] * round(($groupData["endtime"] - TIMESTAMP) / 86400);
            $surplus_price = $surplus_price / $day;
            $surplus_time = round($surplus_price / $group["price"]) * $day;
            $package_endTime = $surplus_time * 24 * 60 * 60 + $package_time;
            $new_over_time = date("Y-m-d", TIMESTAMP + $package_endTime);
            $log_text = sprintf("套餐变更: &lt;p&gt;A、原套餐: %s , %s 到期&lt;/p&gt;&lt;p&gt;B、变更后: %s , %s 到期.&lt;/p&gt;", $old_package["name"], $old_over_time, $group["name"], $new_over_time);
            $log = array(0, $log_text);
            if (pdo_update('uni_account', array('groupid' => $package_id), array('uniacid' => $account["uniacid"])) <= 0) {
                throw new Exception("更新套餐失败.");
            }
        }
        $new_groupdata = array('groupdata' => iserializer(array('isexpire' => 1, 'endtime' => TIMESTAMP + $package_endTime, 'oldgroupid' => $old_package['id'], 'is_auto' => 1)));
        if (pdo_update('uni_settings', $new_groupdata, array('uniacid' => $account["uniacid"])) <= 0) {
            throw new Exception("更新套餐失败!");
        }
        $result = user_credits_update($user["uid"], "credit2", -$package_price, $log);
        if (is_error($result)) {
            throw new Exception($result["message"]);
        }
        $_W['account']['groupid'] = $account["uniacid"];
        load()->model('module');
        module_build_privileges();
        pdo_update("users_packages", array("record_id" => $record_id, "status" => 1), array("id" => $record_id));
        pdo_commit();
        return true;
    } catch (Exception $e) {
        pdo_rollback();
        return error(-1, $e->getMessage());
    }
    return error(-1, "错误操作.");
}