本文整理汇总了PHP中vmc::database方法的典型用法代码示例。如果您正苦于以下问题:PHP vmc::database方法的具体用法?PHP vmc::database怎么用?PHP vmc::database使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vmc
的用法示例。
在下文中一共展示了vmc::database方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: counter
/**
* 不破坏缓存情况下的商品统计
*/
public function counter($args = array())
{
$args = array_merge((array) $args, $this->req_params);
$mdl_goods = app::get('b2c')->model('goods');
$gid = $args['goods_id'];
if (!$gid) {
return false;
}
$db = vmc::database();
$kv = base_kvstore::instance('b2c_counter');
foreach ($args as $key => $value) {
$value = intval($value);
$update_sql = false;
if ($value < 1) {
$value = 1;
}
switch ($key) {
case 'view_count':
$this->history($gid);
//UV型统计 24小时同一IP记录一次
$c_key = 'view_count_uv_' . $gid . '_' . base_request::get_remote_addr();
cacheobject::get($c_key, $time);
$kv->fetch('view_w_count_time', $vw_last_update);
if (!$time || strtotime('+1 day', $time) < time()) {
//获得周标记
if ($vw_last_update > strtotime('-1 week')) {
$update_sql = "UPDATE vmc_b2c_goods SET view_count=view_count+{$value},view_w_count=view_w_count+{$value} WHERE goods_id={$gid}";
} else {
$update_sql = "UPDATE vmc_b2c_goods SET view_count=view_count+{$value},view_w_count={$value} WHERE goods_id={$gid}";
$kv->store('view_w_count_time', time());
}
cacheobject::set($c_key, time(), 86400 + time());
}
break;
case 'buy_count':
//验证
if (md5($gid . 'buy_count' . $value * 1024) != $args['buy_count_sign']) {
break;
}
//获得周标记
$kv->fetch('buy_w_count_time', $bw_last_update);
if ($bw_last_update > strtotime('-1 week')) {
$update_sql = "UPDATE vmc_b2c_goods SET buy_count=buy_count+{$value},buy_w_count=buy_w_count+{$value} WHERE goods_id={$gid}";
} else {
$update_sql = "UPDATE vmc_b2c_goods SET buy_count=buy_count+{$value},buy_w_count={$value} WHERE goods_id={$gid}";
$kv->store('buy_w_count_time', time());
}
break;
case 'comment_count':
if (md5($gid . 'comment_count' . $value * 1024) == $args['comment_count_sign']) {
$update_sql = "UPDATE vmc_b2c_goods SET comment_count=comment_count+{$value} WHERE goods_id={$gid}";
}
break;
}
if ($update_sql) {
logger::info($update_sql);
$db->exec($update_sql, true);
}
}
}
示例2: _init_config
/**
* 初始化商品促销过滤.
*
* @param array $aGoodsId // array(xxx,xxx,xxx);
*/
private function _init_config($goods_id_arr, $filter = array())
{
if (empty($goods_id_arr)) {
return false;
}
$filter['goods_id'] = $goods_id_arr;
$current_member = vmc::singleton('b2c_cart_stage')->get_member();
if (!$filter['member_lv']) {
$filter['member_lv'] = $current_member['member_lv'] ? $current_member['member_lv'] : -1;
}
//开启的促销
$where[] = "pref.status = 'true'";
//一定商品范围的促销
$where[] = 'pref.goods_id IN (' . implode(',', $filter['goods_id']) . ')';
//一定会员级别的促销
$where[] = ' (find_in_set(\'' . $filter['member_lv'] . '\', pref.member_lv_ids))';
//促销时间限制
if (!empty($filter['current_time'])) {
$where[] = sprintf('(%s >= pref.from_time or pref.from_time=0)', $filter['current_time']);
$where[] = sprintf('(%s <= pref.to_time or pref.to_time=0)', $filter['current_time']);
}
$SQL = 'SELECT pref.*,srg.name,srg.s_template
FROM vmc_b2c_sales_rule_goods AS srg
JOIN vmc_b2c_goods_promotion_ref AS pref ON pref.rule_id = srg.rule_id
WHERE ' . implode(' AND ', $where) . '
ORDER BY pref.sort_order ASC,pref.ref_id DESC';
$res = vmc::database()->select($SQL);
if (empty($res)) {
return false;
}
return utils::array_change_key($res, 'goods_id', true);
}
示例3: member_avatar
private function member_avatar($content)
{
$blocks = preg_split('/%AVATAR_([0-9a-z]*)_S_([a-z0-9\\:]*)_AVATAR%/', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
$c = count($blocks);
$block_lib = array();
$block = array();
for ($i = 0; $i < $c; $i++) {
switch ($i % 3) {
case 1:
$mid = $blocks[$i];
$block[$mid][$i] = array($blocks[$i + 1]);
$blocks[$i] =& $block[$mid][$i][0];
break;
case 2:
$block[$mid][$i - 1][1] = $blocks[$i];
$blocks[$i] = '';
break;
}
}
if ($block) {
$db = vmc::database();
foreach ($db->select('select avatar,member_id from vmc_b2c_members where member_id in(\'' . implode("','", array_keys($block)) . '\')') as $r) {
$block_lib[$r['member_id']] = $r;
}
foreach ($block as $mid => $sizes) {
foreach ($sizes as $i => $item) {
$block[$mid][$i][0] = '%IMG_' . $block_lib[$mid]['avatar'] . '_S_' . $item[0] . '_IMG%';
}
}
}
return implode('', $blocks);
}
示例4: end
public function end($result = true, $message = null, $url_params = null, $params = array())
{
if (!$this->transaction_start) {
trigger_error('The transaction has not started yet', E_USER_ERROR);
}
$this->transaction_start = false;
$db = vmc::database();
restore_error_handler();
if (is_null($url_params)) {
$url = $this->_action_url;
} elseif (is_array($url_params)) {
$url = $this->app->router()->gen_url($url_params);
} else {
$url = $url_params;
}
if ($result) {
$db->commit($this->transaction_status);
$status = 'success';
$message = $message == '' ? '操作成功!' : $message;
} else {
$db->rollback();
$status = 'error';
$message = $message ? $message : '操作失败!';
}
$this->_end_message = $message;
$this->_end_status = $status;
$this->splash($status, $url, $message, 'redirect', $params);
}
示例5: getupdatesql
public static function getupdatesql($table_name, &$data, $whereClause)
{
$db = vmc::database();
if (!$table_name) {
trigger_error('getupdatesql UNKNOW TABLE_NAME', E_USER_WARNING);
return false;
}
foreach ($data as $key => $value) {
$data[strtolower($key)] = $value;
}
$table_fields = $db->fetch_colum('DESCRIBE ' . $table_name, 0);
$table_fields_type = $db->fetch_colum('DESCRIBE ' . $table_name, 1);
$table_fields = array_combine($table_fields, $table_fields_type);
$ready_update_str_arr = array();
foreach ($table_fields as $key => $type) {
if (isset($data[$key])) {
$ready_update_str_arr[] = '`' . $key . '`=' . self::quotevalue($db, $data[$key], $type);
}
}
if (count($ready_update_str_arr) > 0) {
$update_str = implode(',', $ready_update_str_arr);
$sql = 'UPDATE ' . $table_name . ' SET ' . $update_str;
if (strlen($whereClause) > 0) {
$sql .= ' WHERE ' . $whereClause;
} else {
logger::warning('全表更新被拦截' . $sql);
return '';
}
return $sql;
} else {
return '';
}
}
示例6: get_mysql_status
function get_mysql_status()
{
$aResult = array('mysql.server_host' => DB_HOST, 'mysql.server_dbname' => DB_NAME, 'mysql.server_user' => DB_USER);
foreach (vmc::database()->select("show status") as $row) {
$aResult['mysql.' . strtolower($row["Variable_name"])] = $row["Value"];
}
return $aResult;
}
示例7: __construct
public function __construct()
{
$sql = 'select * from vmc_dbeav_meta_register';
$arr_rows = vmc::database()->select($sql);
foreach ($arr_rows as $row) {
$this->_meta_columns[$row['tbl_name']][$row['col_name']] = $row;
}
}
示例8: get_data
public function get_data()
{
$pri_settings = vmc::database()->select('select app, `key`, value from vmc_base_setting');
$settings = array();
foreach ($pri_settings as $setting) {
$settings['setting/' . $setting['app'] . '-' . $setting['key']] = unserialize($setting['value']);
}
return $settings;
}
示例9: table_name
public function table_name($real = false)
{
$class_name = get_class($this);
$table_name = substr($class_name, 5 + strpos($class_name, '_mdl_'));
if ($real) {
return vmc::database()->prefix . $this->app->app_id . '_' . $table_name;
} else {
return $table_name;
}
}
示例10: drop
public function drop($table, $col)
{
$mrId = vmc::database()->selectrow('SELECT mr_id FROM vmc_dbeav_meta_register WHERE tbl_name = "' . $table . '" AND col_name = "' . $col . '"');
if (!$mrId) {
return true;
}
$mrId = $mrId['mr_id'];
$this->delete(array('mr_id' => $mrId));
return vmc::database()->exec('DELETE FROM vmc_dbeav_meta_register WHERE mr_id = ' . $mrId);
}
示例11: fetch
public function fetch($key, &$value, $timeout_version = null)
{
$rows = vmc::database()->select(sprintf("SELECT * FROM `vmc_base_kvstore` WHERE `prefix` = %s AND `key` = %s", vmc::database()->quote($this->prefix), vmc::database()->quote($key)), true);
if ($rows[0]['id'] > 0 && $timeout_version < $rows[0]['dateline']) {
if ($rows[0]['ttl'] > 0 && $rows[0]['dateline'] + $rows[0]['ttl'] < time()) {
return false;
}
$value = unserialize($rows[0]['value']);
return true;
}
return false;
}
示例12: save
public function save($type = 'comment')
{
extract($_POST);
$redirect = $this->gen_url(array('app' => 'b2c', 'ctl' => 'site_member', 'act' => 'orders', 'args0' => 's4'));
if ($reply) {
$comment['for_comment_id'] = $comment['member_id'];
$redirect = $this->gen_url(array('app' => 'seller', 'ctl' => 'site_seller', 'act' => 'orders', 'args0' => 's4'));
}
$comment['comment_id'] = $this->mComment->apply_id($type);
$comment['content'] = trim($comment['content']);
$comment['goods_id'] = $goods_id;
$comment['createtime'] = time();
if (is_numeric($comment_id)) {
//追评
$comment['comment_num'] = 2;
if (!$this->mComment->save($comment)) {
$this->splash('error', $redirect, '提交失败!');
}
$comment_type = array('order_id' => $comment['order_id'], 'comment_type' => '2');
if (!$this->app->model('orders')->save($comment_type)) {
$db->rollback();
$this->_send('error', '提交失败!');
}
$this->splash('success', $redirect, '评论成功!');
$this->comment_count($goods_id);
} else {
//第一次评论
$db = vmc::database();
$db->beginTransaction();
$comment['comment_id'] = $this->mComment->apply_id($type);
$comment['comment_num'] = 1;
if (!$this->mComment->save($comment)) {
$db->rollback();
$this->splash('error', $redirect, '提交失败!');
}
$mark['comment_id'] = $comment['comment_id'];
$mark['goods_id'] = $goods_id;
if (!$this->app->model('goods_mark')->save($mark)) {
$db->rollback();
$this->_send('error', '提交失败!');
}
$comment_type = array('order_id' => $comment['order_id'], 'comment_type' => '1');
if (!$this->app->model('orders')->save($comment_type)) {
$db->rollback();
$this->_send('error', '提交失败!');
}
$this->comment_count($goods_id);
$db->commit();
$this->splash('success', $redirect, '评论成功');
}
}
示例13: getMysqlStatus
public function getMysqlStatus()
{
$db = vmc::database();
$aStatus = $db->select("show status");
$aShowStaus = array_keys($this->_mysql_status);
$aResult = array();
// 可以进行分组咯
foreach ($aStatus as $row) {
if (in_array($row["Variable_name"], $aShowStaus)) {
$aResult[$row["Variable_name"]] = $row["Value"];
}
}
return $aResult;
}
示例14: get_html
function get_html($from, $to)
{
$render = $this->render;
$mdl_order = app::get('b2c')->model('orders');
$where_ft = $mdl_order->_filter(array('createtime|between' => array($from, $to)));
$SQL_amount = "SELECT sum(`order_total`) as amount_sum FROM vmc_b2c_orders WHERE (pay_status='1' OR is_cod='Y') AND " . $where_ft;
$SQL_avg_amount = "SELECT avg(`order_total`) as amount_avg FROM vmc_b2c_orders WHERE (pay_status='1' OR is_cod='Y') AND " . $where_ft;
$SQL_ordercount = "SELECT count(`order_id`) as order_count FROM vmc_b2c_orders WHERE (pay_status='1' OR is_cod='Y') AND " . $where_ft;
$render->pagedata['amount_sum'] = $mdl_order->db->select($SQL_amount);
$render->pagedata['amount_avg'] = $mdl_order->db->select($SQL_avg_amount);
$render->pagedata['order_count'] = $mdl_order->db->select($SQL_ordercount);
$render->pagedata['gview_count'] = vmc::database()->select("SELECT sum(view_count) as gview_count FROM vmc_b2c_goods");
//TODO
return $render->fetch('desktop/widgets/stats.html');
}
示例15: __construct
/**
* 构造函数.
*
* @param $object $app // service 调用必须的
*/
public function __construct()
{
$this->app = app::get('b2c');
$this->session = vmc::singleton('base_session');
$this->session->start();
$this->member_info = vmc::singleton('b2c_cart_stage')->get_member();
$this->mdl_cartobjects = $this->app->model('cart_objects');
$this->mdl_goods = $this->app->model('goods');
$this->mdl_products = $this->app->model('products');
if (!empty($this->member_info)) {
$this->member_id = $this->member_info['member_id'];
$this->member_discout = $this->member_info['lv_discount'];
}
$this->member_discout = $this->member_discout ? $this->member_discout : 1;
$this->db = vmc::database();
$this->obj_math = vmc::singleton('ectools_math');
}