public static function UseCard($order, $card_id) { if ($order['card_id']) { return self::ERR_ORDER; } $card = Table::Fetch('card', $card_id); if (!$card) { return self::ERR_NOCARD; } if ($card['consume'] == 'Y') { return self::ERR_USED; } $today = strtotime(date('Y-m-d')); if ($card['begin_time'] > $today || $card['end_time'] < $today) { return self::ERR_EXPIRE; } $team = Table::Fetch('team', $order['team_id']); if ($card['partner_id'] > 0 && $card['partner_id'] != $team['partner_id']) { return self::ERR_TEAM; } if ($team['card'] < $card['credit']) { return self::ERR_CREDIT; } $finalcard = $card['credit'] > $order['origin'] ? $order['origin'] : $card['credit']; Table::UpdateCache('order', $order['id'], array('card_id' => $card_id, 'card' => $finalcard, 'origin' => array("origin - {$finalcard}"))); Table::UpdateCache('card', $card_id, array('consume' => 'Y', 'team_id' => $team['id'], 'order_id' => $order['id'], 'ip' => Utility::GetRemoteIp())); return true; }
static public function Consume($coupon,$store_id,$doer_id,$verifytype=4) { if ( !$coupon['consume']=='N' ) return false; $u = array( 'ip' => Utility::GetRemoteIp(), 'consume_time' => time(), 'consume' => 'Y', 'verifytype'=>$verifytype, 'store_id'=>$store_id, 'doer_id'=>$doer_id, ); DB::Update('order',$coupon['order_id'],array('had_consume'=>1)); Table::UpdateCache('coupon', $coupon['id'], $u); //判断是否点评返利成功,点评并返利成功的订单的消费券可以继续返利 $orderdp=DB::LimitQuery('order_dp',array( 'condition'=>array('order_id'=>$coupon['order_id'],'has_return'=>1) )); if(!empty($orderdp)){ ZFlow::CreateFromCoupon($coupon); } ZCredit::CreateFromConsume($coupon); return true; }
function sms_coupon($coupon, $mobile = null) { global $INI; if ($coupon['consume'] == 'Y' || $coupon['expire_time'] < strtotime(date('Y-m-d'))) { return $INI['system']['couponname'] . '已失效'; } $user = Table::Fetch('user', $coupon['user_id']); $order = Table::Fetch('order', $coupon['order_id']); if (!Utility::IsMobile($mobile)) { $mobile = $order['mobile']; if (!Utility::IsMobile($mobile)) { $mobile = $user['mobile']; } } if (!Utility::IsMobile($mobile)) { return '请设置合法的手机号码,以便接受短信'; } $team = Table::Fetch('team', $coupon['team_id']); $partner = Table::Fetch('partner', $coupon['partner_id']); $coupon['end'] = date('Y-n-j', $coupon['expire_time']); $coupon['name'] = $team['product']; $content = render('manage_tpl_smscoupon', array('partner' => $partner, 'coupon' => $coupon, 'user' => $user)); if (true === ($code = sms_send($mobile, $content))) { Table::UpdateCache('coupon', $coupon['id'], array('sms' => array('`sms` + 1'), 'sms_time' => time())); return true; } return $code; }
public static function Create($user_row, $uc = true) { if (function_exists('zuitu_uc_register') && $uc) { $pp = $user_row['password']; $em = $user_row['email']; $un = $user_row['username']; $ret = zuitu_uc_register($em, $un, $pp); if (!$ret) { return false; } } $user_row['password'] = self::GenPassword($user_row['password']); $user_row['create_time'] = $user_row['login_time'] = time(); $user_row['ip'] = Utility::GetRemoteIp(); $user_row['secret'] = md5(rand(1000000, 9999999) . time() . $user_row['email']); $user_row['id'] = DB::Insert('user', $user_row); $_rid = abs(intval(cookieget('_rid'))); if ($_rid) { $r_user = Table::Fetch('user', $_rid); if ($r_user) { ZInvite::Create($r_user, $user_row); } } if ($user_row['id'] == 1) { Table::UpdateCache('user', $user_row['id'], array('manager' => 'Y', 'secret' => '')); } return $user_row['id']; }
public static function Secret($mobile, $secret = null) { $secret = $secret ? $secret : Utility::VerifyCode(); $sms = Table::Fetch('smssubscribe', $mobile, 'mobile'); if ($sms) { Table::UpdateCache('smssubscribe', $sms['id'], array('secret' => $secret)); } return $secret; }
public static function Consume($coupon) { if (!$coupon['consume'] == 'N') { return false; } $u = array('ip' => Utility::GetRemoteIp(), 'consume_time' => time(), 'consume' => 'Y'); Table::UpdateCache('coupon', $coupon['id'], $u); ZFlow::CreateFromCoupon($coupon); return true; }
public static function CashIt($order) { global $login_user_id; if (!$order['state'] == 'pay') { return 0; } //update order Table::UpdateCache('order', $order['id'], array('state' => 'pay', 'service' => 'cash', 'admin_id' => $login_user_id, 'money' => $order['origin'], 'pay_time' => time())); $order = Table::FetchForce('order', $order['id']); ZTeam::BuyOne($order); }
public static function Create($score, $user_id, $action = 'charge', $detail_id = 0) { if (!$score || !$user_id) { return 0; } //update user score; $user = Table::Fetch('user', $user_id); Table::UpdateCache('user', $user_id, array('score' => array("`score`+{$score}"))); $u = array('user_id' => $user_id, 'admin_id' => 0, 'score' => $score, 'action' => $action, 'detail_id' => $detail_id, 'create_time' => time()); return DB::Insert('credit', $u); }
public static function SetOrderState($team) { if ($team->close_time == 0) { return; } $c = array('team_id' => $team['id'], 'state' => 'unpay'); $os = DB::LimitQuery('order', array('condition' => $condition)); $ids = Utility::GetColumn($os, 'id'); foreach ($ids as $id) { Table::UpdateCache('order', $id, array('state' => 'expire')); } }
public static function CreateFromStore($user_id = 0, $money = 0) { $money = abs(intval($money)); if ($money <= 0 || $user_id <= 0) { return; } //update user money; $user = Table::Fetch('user', $user_id); Table::UpdateCache('user', $user_id, array('money' => array("money + {$money}"))); $u = array('user_id' => $user_id, 'money' => $money, 'direction' => 'income', 'action' => 'store', 'detail_id' => 0, 'create_time' => time()); return DB::Insert('flow', $u); }
public static function CashIt($order) { if (!$order['state'] == 'pay') { return 0; } //update user money; $user = Table::Fetch('user', $order['user_id']); Table::UpdateCache('user', $order['user_id'], array('money' => moneyit($user['money'] - $order['credit']))); //update order Table::UpdateCache('order', $order['id'], array('state' => 'pay', 'service' => 'cash', 'money' => $order['origin'])); $order = Table::FetchForce('order', $order['id']); ZTeam::BuyOne($order); }
static function Assign($order) { $ccon = array('order_id' => $order['id']); $count = Table::Count('voucher', $ccon); while ($count < $order['quantity']) { $voucher = self::GetValidVoucher($order['team_id']); if (!$voucher) { break; } Table::UpdateCache('voucher', $voucher['id'], array('user_id' => $order['user_id'], 'order_id' => $order['id'])); $count = Table::Count('voucher', $ccon); } }
public static function UsePayCard($paycard) { global $login_user_id; if (!$paycard['consume'] == 'N') { return false; } $u = array('user_id' => $login_user_id, 'recharge_time' => time(), 'consume' => 'Y'); Table::UpdateCache('paycard', $paycard['id'], $u); Table::UpdateCache('user', $login_user_id, array('money' => array("money + {$paycard['value']}"))); $l = array('user_id' => $login_user_id, 'admin_id' => 0, 'money' => $paycard['value'], 'direction' => 'income', 'action' => 'cardstore', 'detail_id' => $paycard['id'], 'create_time' => time()); DB::Insert('flow', $l); return true; }
function uc_api_updatepw($get, $post) { $username = $get['username']; $password = ZUser::GenPassword($get['password']); if (strtolower(UC_CHARSET) != 'utf-8') { $username = mb_convert_encoding($username, 'UTF-8', UC_CHARSET); } $u = Table::Fetch('user', $username, 'username'); if ($u && $u['password'] != $password) { Table::UpdateCache('user', $u['id'], array('password' => $password)); if ($_SESSION['user_id'] && $_SESSION['user_id'] == $u['id']) { unset($_SESSION['user_id']); } } return API_RETURN_SUCCEED; }
public static function BuyOne($order) { $order = Table::FetchForce('order', $order['id']); $team = Table::FetchForce('team', $order['team_id']); $plus = $team['conduser'] == 'Y' ? 1 : $order['quantity']; $team['now_number'] += $plus; if ($team['max_number'] > 0 && $team['now_number'] >= $team['max_number']) { $team['close_time'] = time(); } Table::UpdateCache('team', $team['id'], array('close_time' => $team['close_time'], 'now_number' => array("`now_number` + {$plus}"))); /* cash flow */ ZFlow::CreateFromOrder($order); /* order : send coupon ? */ ZCoupon::CheckOrder($order); /* order : invite buy */ ZInvite::CheckInvite($order); }
static public function CashIt($order) { global $login_user_id; if (! $order['state']=='pay' ) return 0; //update order Table::UpdateCache('order', $order['id'], array( 'state' => 'pay', 'service' => 'cash', 'admin_id' => $login_user_id, 'money' => $order['origin'], 'pay_time' => time(), )); /* cash flow */ $order = Table::FetchForce('order', $order['id']); ZFlow::CreateFromStore($order['user_id'], $order['origin']); ZTeam::BuyOne($order); }
public static function Create($user_row) { $user_row['password'] = self::GenPassword($user_row['password']); $user_row['create_time'] = $user_row['login_time'] = time(); $user_row['ip'] = Utility::GetRemoteIp(); $user_row['secret'] = md5(Utility::GenSecret(12)); $user_row['id'] = DB::Insert('user', $user_row); if ($_COOKIE['_rid']) { $r_user = Table::Fetch('user', $_COOKIE['_rid']); if ($r_user) { ZInvite::Create($r_user, $user_row); } } if ($user_row['id'] == 1) { Table::UpdateCache('user', $user_row['id'], array('manager' => 'Y', 'secret' => '')); } return $user_row['id']; }
static public function BuyOne($order) { $order = Table::FetchForce('order', $order['id']); $order_id = abs(intval($order['id'])); $team_id = abs(intval($order['team_id'])); $team = Table::FetchForce('team', $order['team_id']); $plus = $team['conduser']=='Y' ? 1 : $order['quantity']; $team['now_number'] += $plus; /* close time */ if ( $team['max_number']>0 && $team['now_number'] >= $team['max_number'] ) { $team['close_time'] = time(); } /* reach time */ if ( $team['now_number']>=$team['min_number'] && $team['reach_time'] == 0 ) { $team['reach_time'] = time(); } Table::UpdateCache('team', $team['id'], array( 'close_time' => $team['close_time'], 'reach_time' => $team['reach_time'], 'now_number' => array( "`now_number` + {$plus}", ), )); //UPDATE buy_id $SQL = "UPDATE `order` o,(SELECT max(buy_id)+1 AS c FROM `order` WHERE state = 'pay' and team_id = '{$team_id}') AS c SET o.buy_id = c.c, o.luky_id = 100000 + floor(rand()*100000) WHERE o.id = '{$order_id}' AND buy_id = 0;"; DB::Query($SQL); /* send sms Immediately */ if(option_yes('buycouponsms')) sms_buy($order); /* cash flow */ ZFlow::CreateFromOrder($order); /* order : send coupon ? */ ZCoupon::CheckOrder($order); /* order : send voucher ? */ ZVoucher::CheckOrder($order); /* order : send express sms ? */ ZExpress::CheckOrder($order); /* order : invite buy */ ZInvite::CheckInvite($order); ZCredit::UpdateFromOrder($order); }
public static function Enable($mobile, $enable = false, $user_id = '') { $condition = array('tools' => $mobile, 'enable' => 'Y'); $remove = DB::GetTableRow('toolsbind', $condition); if ($remove) { Table::Delete('toolsbind', $remove['id']); } $havecondition = array('user_id' => $user_id, 'enable' => 'Y'); $removeold = DB::GetTableRow('toolsbind', $havecondition); if ($removeold) { Table::Delete('toolsbind', $removeold['id']); } $sms = Table::Fetch('toolsbind', $mobile, 'tools'); $time = time(); if ($sms) { Table::UpdateCache('toolsbind', $sms['id'], array('enable' => 'Y', 'create_time' => $time)); Table::UpdateCache('user', $sms['user_id'], array('mobile' => $mobile, 'mobilecode' => 'yes', 'enable' => 'Y')); } }
public static function Create($user_row, $uc = true) { $user_row['password'] = self::GenPassword($user_row['password']); $user_row['create_time'] = $user_row['login_time'] = time(); $user_row['ip'] = Utility::GetRemoteIp(); $user_row['secret'] = md5(rand(1000000, 9999999) . time() . $user_row['email']); $user_row['id'] = DB::Insert('user', $user_row); $_rid = abs(intval(cookieget('_rid'))); if ($_rid) { $r_user = Table::Fetch('user', $_rid); if ($r_user) { ZInvite::Create($r_user, $user_row); } } if ($user_row['id'] == 1) { Table::UpdateCache('user', $user_row['id'], array('manager' => 'Y', 'secret' => '')); } return $user_row['id']; }
static public function CreateFromConsume($coupon){ $team = Table::Fetch('team',$coupon['team_id']); $user = Table::Fetch('user',$coupon['user_id']); $ubi = intval($team['team_price']/10); Table::UpdateCache('user', $coupon['user_id'], array( 'score' => array( "`score`+{$ubi}" ), )); $u = array( 'user_id' => $coupon['user_id'], 'admin_id' => 0, 'score' => $ubi, 'action' => 'consume', 'detail_id' => $coupon['id'], 'create_time' => time(), ); return DB::Insert('credit', $u); }
function zuitu_uc_login($email, $pass) { if (!function_exists('uc_user_login')) { return array(); } if (!defined('UC_API')) { return array(); } $isuid = strpos($email, '@') ? 2 : 0; if (strtolower(UC_CHARSET) != 'utf-8') { $email = mb_convert_encoding($email, UC_CHARSET, 'UTF-8'); } $ucresult = uc_user_login($email, $pass, $isuid, 0); $uckey = array('uid', 'username', 'password', 'email', 'duplicate'); $ucresult = array_combine($uckey, $ucresult); $ucresult = zuitu_encode_array($ucresult); $ucresult = zuitu_encode_detect($ucresult); DB::Query('SET NAMES UTF8;'); if ($ucresult['uid'] > 0 && $ucresult['email']) { $eu = Table::Fetch('user', $ucresult['email'], 'email'); if ($eu) { if ($eu['username'] != $ucresult['username']) { $epass = ZUser::GenPassword($ucresult['password']); Table::UpdateCache('user', $eu['id'], array('username' => $ucresult['username'], 'password' => $epass)); return Table::FetchForce('user', $eu['id']); } return $eu; } unset($ucresult['uid']); unset($ucresult['duplicate']); zuitu_encode_array($ucresult); zuitu_encode_detect($ucresult); $newuser_id = ZUser::Create($ucresult, false); if ($newuser_id) { return Table::Fetch('user', $newuser_id); } } return array(); }
public static function CheckInvite($order) { if ($order['state'] == 'unpay') { return; } global $INI; $invitecredit = abs(intval($INI['system']['invitecredit'])); if (!$invitecredit) { return; } $user = Table::Fetch('user', $order['user_id']); if (!$user || $user['newbie'] != 'Y') { return; } $invite = Table::Fetch('invite', $order['user_id'], 'other_user_id'); if (!$invite || $invite['credit'] > 0 || $invite['pay'] != 'N') { return; } Table::UpdateCache('invite', $invite['id'], array('credit' => $invitecredit, 'team_id' => $order['team_id'], 'buy_time' => time())); Table::UpdateCache('user', $order['user_id'], array('newbie' => 'N')); return true; }
function sms_coupon($coupon) { global $INI; $coupon_user = Table::Fetch('user', $coupon['user_id']); if ($coupon['consume'] == 'Y' || $coupon['expire_time'] < strtotime(date('Y-m-d'))) { return $INI['system']['couponname'] . '已失效'; } else { if (!Utility::IsMobile($coupon_user['mobile'])) { return '请设置合法的手机号码,以便接受短信'; } } $team = Table::Fetch('team', $coupon['team_id']); $user = Table::Fetch('user', $coupon['user_id']); $coupon['end'] = date('Y-n-j', $coupon['expire_time']); $coupon['name'] = $team['product']; $content = render('manage_tpl_smscoupon', array('coupon' => $coupon, 'user' => $user)); $content = trim(preg_replace("/[\\s]+/", '', $content)); if (true === ($code = sms_send($coupon_user['mobile'], $content))) { Table::UpdateCache('coupon', $coupon['id'], array('sms' => array('`sms` + 1'))); return true; } return $code; }
static function Assign($order) { $ccon = array('order_id' => $order['id']); $count = Table::Count('voucher', $ccon); //send_goods_confirm_by_platform if( ($order['service']=='alipay') && ($INI['alipay']['autosendgoods']='Y') && ($INI['alipay']['guarantee']!='Y') ) { alipay_send_goods($order['trade_no']); } while($count<$order['quantity']) { $voucher = self::GetValidVoucher($order['team_id']); if (!$voucher) break; $flag = Table::UpdateCache('voucher', $voucher['id'], array( 'user_id' => $order['user_id'], 'order_id' => $order['id'], )); if($flag){ $voucher = Table::Fetch('voucher', $voucher['id']); global $INI; if ($INI['sms']['auto']=='1') sms_voucher($voucher); } $count = Table::Count('voucher', $ccon); } }
public static function CheckInvite($order) { if ($order['state'] == 'unpay') { return; } $user = Table::Fetch('user', $order['user_id']); $team = Table::Fetch('team', $order['team_id']); if (!$user || $user['newbie'] != 'Y') { return; } Table::UpdateCache('user', $order['user_id'], array('newbie' => 'N')); global $INI; $invite = Table::Fetch('invite', $order['user_id'], 'other_user_id'); $invitecredit = abs(intval($team['bonus'])); /* 无邀请记录 或 已返利或取消 */ if (!$invite || $invite['credit'] > 0 || $invite['pay'] != 'N') { return; } if (time() - $invite['create_time'] > 7 * 86400) { return; } Table::UpdateCache('invite', $invite['id'], array('credit' => $invitecredit, 'team_id' => $order['team_id'], 'buy_time' => time())); return true; }
<?php require_once dirname(dirname(__FILE__)) . '/app.php'; $id = abs(intval($_GET['id'])); $order = Table::Fetch('order', $id); if (!$order) { Session::Set('error', '订单不存在!'); redirect('index.php'); } $team = Table::Fetch('team', $order['team_id']); $team['state'] = team_state($team); if ($team['close_time']) { redirect("team.php?id={$id}"); } /* generator unique pay_id */ if (!($order['pay_id'] && (preg_match('#-(\\d+)-(\\d+)-#', $order['pay_id'], $m) && ($m[1] == $order['id'] && $m[2] == $order['quantity'])))) { $randid = strtolower(Utility::GenSecret(4, Utility::CHAR_WORD)); $pay_id = "go-{$order['id']}-{$order['quantity']}-{$randid}"; Table::UpdateCache('order', $order['id'], array('pay_id' => $pay_id)); } /* end */ include template('wap_check');
public static function Check_alifast($alipay_id, $alipay_name, $alipay_email = null) { $aliuser = DB::GetTableRow('user', array('alipay_id' => $alipay_id)); if ($aliuser) { if (!empty($alipay_email)) { $email_user = DB::GetTableRow('user', array('email' => $alipay_email)); if (!$email_user) { Table::UpdateCache('user', $aliuser['id'], array('email' => $alipay_email)); } } return $aliuser; } $user['username'] = $alipay_id; $user['realname'] = $alipay_name; $user['alipay_id'] = $alipay_id; if ($alipay_email) { $email_user = DB::GetTableRow('user', array('email' => $alipay_email)); if (!$email_user) { $user['email'] = $alipay_email; } } $user['create_time'] = $user['login_time'] = time(); $user['ip'] = Utility::GetRemoteIp(); $ali_user['id'] = DB::Insert('user', $user); $aliuser = DB::GetTableRow('user', array('id' => $ali_user['id'])); return $aliuser; }
$wwwlink = mail_zd($email); die(include template('account_verify')); } else { if (strpos($secret, '@')) { Session::Set('unemail', $secret); mail_sign_email($secret); redirect(WEB_ROOT . '/account/verify.php'); } } $user = Table::Fetch('user', $secret, 'secret'); if ($user['enable'] == 'Y') { Session::Set('error', '你的账户已经验通过,请直接登录!'); if (isset($_SESSION['user_id'])) { unset($_SESSION['user_id']); ZLogin::NoRemember(); ZUser::SynLogout(); } redirect(WEB_ROOT . '/account/login.php'); } if ($user) { if (option_yes('mobilecode')) { Table::UpdateCache('user', $user['id'], array('emailable' => 'Y')); die(include template('account_signmobile')); } else { Table::UpdateCache('user', $user['id'], array('emailable' => 'Y', 'enable' => 'Y')); Session::Set('notice', '恭喜!你的帐户已经通过Email验证'); ZLogin::Login($user['id']); redirect(get_loginpage(WEB_ROOT . '/index.php')); } } redirect(WEB_ROOT . '/index.php');
$table->image = upload_image('upload_image', $team['image'], 'team', true); $table->image1 = upload_image('upload_image1', $team['image1'], 'team'); $table->image2 = upload_image('upload_image2', $team['image2'], 'team'); //team_type == goods if ($table->team_type == 'goods') { $table->min_number = 1; } $error_tip = array(); if (!$error_tip) { if ($table->update($insert)) { print $table->title; $field = strtoupper($table->conduser) == 'Y' ? null : 'quantity'; $now_number = Table::Count('order', array('team_id' => $table->id, 'state' => 'pay'), $field); $need_update = array('now_number' => $now_number); /* 增加了总数,未卖完状态 */ if ($table->max_number > $table->now_number) { $need_update['close_time'] = 0; } Table::UpdateCache('team', $table->id, $need_update); Session::Set('notice', '团购修改成功'); Utility::Redirect(WEB_ROOT . "/biz/index.php"); } else { Session::Set('error', '修改团信息失败,请检查系统环境?'); } } } $groups = DB::LimitQuery('category', array('condition' => array('zone' => 'group'))); $groups = Utility::OptionArray($groups, 'id', 'name'); $partners = DB::LimitQuery('partner', array('order' => 'ORDER BY id DESC')); $partners = Utility::OptionArray($partners, 'id', 'title'); include template('biz_coupon_edit');