function cookie($name = null, $value = null, $expire = 0) { if ($value) { return Cookie::set($name, $value, $expire); } return Cookie::get($name); }
/** * 催单 */ public function order_hurry() { $v = new \Model\Validation(); $order_id = \Core\URI::kv('id'); $order = \Db\Trade\Order::row(array('order_id' => $order_id, 'user_id' => $this->user->user_id)); $time_start = \Core\Cookie::get('time_start'); $v->required($order)->message('订单不存在', 1000); if (!$v->has_error()) { if (empty($time_start)) { \Core\Cookie::set('time_start', W_START_TIME); //@todo 更新催单时间 $order->hurry_status = 1; $order->hurry_time = W_START_TIME; $order->update(); $v->set_data(\Core\URI::a2p(array('trade' => 'order', 'id' => $order->id))); } else { if (W_START_TIME - $time_start > 600) { //@todo 更新催单时间 $order->hurry_status = 1; $order->hurry_time = W_START_TIME; $order->update(); $v->set_data(\Core\URI::a2p(array('trade' => 'order', 'id' => $order->id))); } $v->required(false)->message('已经收到,正在加急处理', 1000); } } $v->send(); }
public function set_cart_id() { // Check cookie for existance of the cart $hash = Cookie::get('cart'); if (!$hash) { return $this->create_cart(); } // Remove old cart rows DB::delete('carts')->where('created_at', '<=', time() - 3600)->execute(); // Check if our cookie not bad $cart = DB::select()->from('carts')->where('hash', '=', $hash)->as_object()->execute()->current(); if (!$cart) { return $this->create_cart(); } // Set cart_id $this->_cart_id = $cart->id; return true; }
public function getViewedIDs() { $ids = Cookie::get('viewed'); if (!$ids) { $ids = array(); } else { $ids = base64_decode($ids); $ids = json_decode($ids); if (!$ids) { $ids = array(); } else { if (!is_array($ids)) { $ids = array(); } } } return $ids; }
public function vote($post_title, $type) { $article = $this->where(['stitle', $post_title]); $value = 0; if (!Cookie::exists("votes-{$post_title}")) { $value = 1; } else { if (Cookie::get("votes-{$post_title}") != $type) { $value = 2; } } if ($type === 1) { $votes = sprintf("%+d", $article->first()->votes + $value); } else { $votes = sprintf("%+d", $article->first()->votes - $value); } $article->update(['votes' => $votes]); echo $votes; return Cookie::put("votes-{$post_title}", $type, 63113904); }