Пример #1
0
 public function index()
 {
     header('Location:index.php?app=b2c&ctl=admin_setting&act=index');
     die;
     $dashboard_from = $this->_request->get_post('f');
     $dashboard_to = $this->_request->get_post('t');
     $default_enter = true;
     if (!$dashboard_to) {
         $dashboard_to = strtotime(date('Y-m-d'));
     } else {
         $default_enter = false;
     }
     if (!$dashboard_from) {
         $dashboard_from = strtotime('-1 week', $dashboard_to);
     } else {
         $default_enter = false;
     }
     //权限带入
     $user = vmc::singleton('desktop_user');
     $is_super = $user->is_super();
     $group = $user->group();
     $group = (array) $group;
     //统一时间格式
     if (strpos($dashboard_from, ':')) {
         $dashboard_from = strtotime($dashboard_from);
         $dashboard_to = strtotime($dashboard_to);
     }
     if ($dashboard_from > $dashboard_to) {
         $tmp_t = $dashboard_to;
         $dashboard_to = $dashboard_from;
         $dashboard_from = $tmp_t;
     }
     //桌面挂件排序,用户自定义
     if ($default_enter && cacheobject::get('desktop.dashboard.widgets' . $dashboard_to, $cache_data) && isset($cache_data['data'])) {
         $this->pagedata['cached_time'] = $cache_data['cached_time'];
         $widgets = $cache_data['data'];
     } else {
         foreach (vmc::servicelist('desktop.widgets') as $key => $obj) {
             if ($is_super || in_array(get_class($obj), $group)) {
                 $item = array('title' => $obj->get_title(), 'layout' => $obj->get_layout(), 'html' => $obj->get_html($dashboard_from, $dashboard_to), 'order' => $obj->get_order());
                 if (method_exists($obj, 'get_classname')) {
                     $item['classname'] = $obj->get_classname();
                 }
                 $widgets[$item['layout']][] = $item;
             }
         }
         if ($default_enter) {
             $cache_data = array('cached_time' => time(), 'data' => $widgets);
             cacheobject::set('desktop.dashboard.widgets' . $dashboard_to, $cache_data, time() + 86400);
             //缓存24小时
         }
     }
     $this->pagedata['widgets'] = $widgets;
     $this->pagedata['dashboard_from'] = $dashboard_from;
     $this->pagedata['dashboard_to'] = $dashboard_to;
     //快捷
     $this->pagedata['tody'] = date('Y-m-d H:i', strtotime(date('Y-m-d')));
     $this->pagedata['from_arr'] = array('w' => date('Y-m-d H:i', strtotime('-1 week', strtotime($this->pagedata['tody']))), 'm' => date('Y-m-d H:i', strtotime('-1 month', strtotime($this->pagedata['tody']))), 'q' => date('Y-m-d H:i', strtotime('-3 month', strtotime($this->pagedata['tody']))));
     $this->display('dashboard.html');
 }
Пример #2
0
 private function _set_session($value, $ttl)
 {
     if (WITHOUT_CACHE === true) {
         return base_kvstore::instance('sessions')->store($this->_get_cache_key(), $value, $ttl);
     } else {
         return cacheobject::set($this->_get_cache_key(), $value, $ttl + time());
     }
 }
Пример #3
0
 private function __setKvArea()
 {
     base_kvstore::instance('ecos')->store('areaFileContents', $this->areaFileContents);
     if (config::get('cache.enabled', true)) {
         cacheobject::set('areaKvdata', array());
     }
     return true;
 }
Пример #4
0
 private function _set_session($value, $ttl)
 {
     if (!config::get('cache.enabled', true)) {
         return base_kvstore::instance('sessions')->store($this->_get_cache_key(), $value, $ttl);
     } else {
         return cacheobject::set($this->_get_cache_key(), $value, $ttl + time());
     }
 }
Пример #5
0
 function verify_key($key)
 {
     $sess_id = kernel::single('base_session')->sess_id();
     $key = $key . $sess_id;
     if (defined('WITHOUT_CACHE') && !constant('WITHOUT_CACHE')) {
         cacheobject::set($key, $this->obj->get_code());
     } else {
         base_kvstore::instance('vcode')->store($key, $this->obj->get_code());
     }
 }
Пример #6
0
 /**
  * Compile the view at the given path.
  *
  * @param  string  $path
  * @return string
  */
 public function compile(base_view_object_interface $object)
 {
     $this->setObject($object);
     $contents = $this->compileString($object->get());
     if (config::get('cache.enabled', false) == true) {
         $cache = ['lastModified' => time(), 'contents' => $contents];
         cacheobject::set($this->getCompiledCacheKey($object), $cache);
     }
     return $contents;
 }
Пример #7
0
 static function verify($key, $value)
 {
     $value = strtolower($value);
     $sess_id = kernel::single('base_session')->sess_id();
     $vcodekey = $key . $sess_id;
     if (config::get('cache.enabled', true)) {
         cacheobject::get($vcodekey, $vcode);
         //使用后则是过期
         cacheobject::set($vcodekey, $vcode, time() - 1);
     } else {
         base_kvstore::instance('vcode')->fetch($vcodekey, $vcode);
         //使用后则是过期
         base_kvstore::instance('vcode')->store($vcodekey, $vcode, 1);
     }
     if ($vcode == strval($value)) {
         return true;
     }
     return false;
 }
Пример #8
0
 public function get_access_token($bind_id = false, $app_define = false)
 {
     if ($app_define) {
         $app_id = $app_define['app_id'];
         $app_secret = $app_define['app_secret'];
     } else {
         $bind = app::get('wechat')->model('bind')->dump($bind_id);
         $app_id = $bind['appid'];
         $app_secret = $bind['appsecret'];
     }
     $http_client = vmc::singleton('base_httpclient');
     if (!cacheobject::get('wechat_access_token_' . $app_id, $access_token) || !$access_token) {
         $access_token_action = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$app_id}&secret={$app_secret}";
         $respnese = $http_client->get($access_token_action);
         $respnese = json_decode($respnese, 1);
         $access_token = $respnese['access_token'];
         if ($access_token) {
             cacheobject::set('wechat_access_token_' . $app_id, $access_token, time() + $respnese['expires_in']);
         }
     }
     return $access_token;
 }
Пример #9
0
 public function delete_vcode($account, $type, $vcodeData)
 {
     $vcode = $this->randomkeys(6);
     $vcodeData['vcode'] = $vcode;
     $key = $this->get_vcode_key($account, $type);
     if (WITHOUT_CACHE === true) {
         base_kvstore::instance('vcode/account')->store($key, $vcodeData, $this->ttl);
     } else {
         cacheobject::set($key, $vcodeData, $this->ttl + time());
     }
     return $vcodeData;
 }
Пример #10
0
 /**
  * 获得子类.
  */
 public function children($parent_id)
 {
     $cache_expired = $this->touch_cache();
     if (cacheobject::get('b2c-gcat-tree-cache-' . $parent_id, $children) && $children && $cache_expired > 0) {
         return $children;
     } else {
         $children = $this->getList('*', array('parent_id' => $parent_id), 0, -1, ' p_order ASC');
         $children = utils::array_change_key($children, 'cat_id');
         cacheobject::set('b2c-gcat-tree-cache-' . $parent_id, $children, time() + 60 * 60 * 24 * 30);
         return $children;
     }
 }
Пример #11
0
 public function send_email($type, $email, $content)
 {
     if (!($tmpl = $this->sendtypeToTmpl($type))) {
         return false;
     }
     $vcodeData = $this->checkVcode($email, $type);
     $vcode = $this->randomkeys(6);
     $vcodeData['account'] = $email;
     $vcodeData['vcode'] = $vcode;
     $vcodeData['count'] = 1;
     $vcodeData['createtime'] = date('Ymd');
     $vcodeData['lastmodify'] = time();
     $data['shopname'] = app::get('sysconf')->getConf('site.name');
     $data['vcode'] = $content . "&vcode=" . $vcode;
     $key = $this->getVcodeKey($email, $type);
     $result = messenger::sendEmail($email, $tmpl, $data);
     if ($result['rsp'] == "fail") {
         throw new \LogicException(app::get('system')->_('邮件发送失败,请检查邮箱格式是否正确!'));
     }
     if (defined('WITHOUT_CACHE') && !constant('WITHOUT_CACHE')) {
         cacheobject::set($key, $vcodeData, 3600 * 24);
     } else {
         base_kvstore::instance('vcode/account')->store($key, $vcodeData, 3600 * 24);
     }
     return true;
 }
Пример #12
0
 private function get_access_token($action_url)
 {
     if (!cacheobject::get('b2c_sms_platform_access_token_' . md5($action_url), $access_token) || !$access_token) {
         $res = $this->net->post($action_url);
         $res = json_decode($res, 1);
         $access_token = $res['access_token'];
         if ($access_token) {
             cacheobject::set('b2c_sms_platform_access_token_' . md5($action_url), $access_token, time() + $res['expires_in']);
         }
     }
     return $access_token;
 }
Пример #13
0
 /**
  * 不破坏缓存情况下的商品统计
  */
 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);
         }
     }
 }