public static function get($name) { $key = self::key($name); if (!isset(self::$c_cache[$key])) { self::$c_cache[$key] = self::$c_instance->get($key); } return self::$c_cache[$key]; }
/** * Handles the validate export event. Searches into the cache if the this * table is known and has a number of lines that are exported. If this number * is equal to the number of lines we want to export this time, there's no * modifications and thus no need for a new export. * * @param ValidateExportEvent $event */ public function onValidateExport(ValidateExportEvent $event) { if ($this->cache === null || !$this->cache instanceof ICache) { $message = Yii::t('export.cache_exported_file_behavior', 'Autovalidation due to invalid cache value.'); Yii::log($message, CLogger::LEVEL_WARNING, 'export.cache_exported_file_behavior'); $event->validate = true; return; } $policy = $event->getPolicy(); $count = $policy->getCount($event->getCriteriaBuilder()); $this->_count = $count; $key = $this->buildKey($policy, $event->getCriteriaBuilder()); $cachedCount = $this->cache->get($key); if ($cachedCount === null || $cachedCount === false || (int) $count !== (int) $cachedCount) { $event->validate = true; return; } $event->validate = false; }
static function goods_category() { //获取商品分类缓存 $cacheObj = new ICache('file'); $catResult = $cacheObj->get('goodsCategory'); if ($catResult) { return $catResult; } $catResult = array(); $catObj = new IModel('category'); $catFirst = $catObj->query('parent_id = 0', 'id,name,parent_id,visibility', 'sort', 'asc'); $catOther = $catObj->query('parent_id != 0', 'id,name,parent_id,visibility', 'sort', 'asc'); foreach ($catFirst as $first_key => $first) { foreach ($catOther as $other_key => $other_val) { if ($first['id'] == $other_val['parent_id']) { //拼接二级分类 $first['second'][$other_key] = $other_val; //拼接二级以下所有分类 $catMore = array(); self::recursion_goods_category($other_val, $catOther, $catObj, $catMore); $first['second'][$other_key]['more'] = $catMore; } } $catResult[] = $first; } //写入缓存 $cacheObj->set('goodsCategory', $catResult); return $catResult; }
/** * @brief 商品分类列表 */ function category_list() { $isCache = false; $tb_category = new IModel('category'); $cacheObj = new ICache('file'); $data = $cacheObj->get('sortdata'); if (!$data) { $goods = new goods_class(); $data = $goods->sortdata($tb_category->query(false, '*', 'sort', 'asc')); $isCache ? $cacheObj->set('sortdata', $data) : ""; } $this->data['category'] = $data; $this->setRenderData($this->data); $this->redirect('category_list', false); }
/** * @brief 【重要】支付回调[异步] */ function server_callback() { //从URL中获取支付方式 $payment_id = IFilter::act(IReq::get('_id'), 'int'); $paymentInstance = Payment::createPaymentInstance($payment_id); if (!is_object($paymentInstance)) { die('fail'); } //初始化参数 $money = ''; $message = '支付失败'; $orderNo = ''; //执行接口回调函数 $callbackData = array_merge($_POST, $_GET); unset($callbackData['controller']); unset($callbackData['action']); unset($callbackData['_id']); $return = $paymentInstance->serverCallback($callbackData, $payment_id, $money, $message, $orderNo); //支付成功 if ($return == 1) { //充值方式 if (stripos($orderNo, 'recharge') !== false) { $tradenoArray = explode('recharge', $orderNo); $recharge_no = isset($tradenoArray[1]) ? $tradenoArray[1] : 0; if (payment::updateRecharge($recharge_no)) { $paymentInstance->notifyStop(); exit; } } else { //读取批量订单付款 $cacheObj = new ICache('file'); $moreOrder = $cacheObj->get($orderNo); $moreOrder = $moreOrder ? explode(",", $moreOrder) : array($orderNo); foreach ($moreOrder as $key => $item) { $order_id = Order_Class::updateOrderStatus($item); if (!$order_id) { throw new IException("异步支付回调修改状态错误,订单ID:" . $order_id); } } $paymentInstance->notifyStop(); exit; } } else { $paymentInstance->notifyStop(); exit; } }