public static function getAllGoods($moduleId) { if (empty($moduleId)) { return array(); } $ret = DB::getDB()->fetchAll('m_goods_module_glist', '*', array('module_id'), array($moduleId), false, array('sort'), array('desc')); return $ret === false ? array() : $ret; }
public static function newOne($orderId, $goodsId, $skuAttr, $skuValue, $amount, $price, $attach) { if (empty($orderId) || empty($goodsId) || empty($amount)) { return false; } $data = array('order_id' => $orderId, 'goods_id' => $goodsId, 'sku_attr' => $skuAttr, 'sku_value' => $skuValue, 'amount' => $amount, 'price' => $price, 'state' => self::ORDER_GOODS_ST_UN_DELIVER, 'commented' => 0, 'attach' => $attach, 'ctime' => CURRENT_TIME, 'mtime' => CURRENT_TIME, 'm_user' => 'sys'); $ret = DB::getDB('w')->insertOne('o_order_goods', $data); if ($ret === false || (int) $ret <= 0) { return false; } return true; }
public static function hadCommented($userId, $orderId, $goodsId) { $ck = Cache::CK_GOODS_HAD_COMMENT . $userId . ':' . $orderId . ':' . $goodsId; $ret = Cache::get($ck); if ($ret === false) { $ret = DB::getDB()->fetchCount('g_goods_comment', array('user_id', 'goods_id', 'order_id'), array($userId, $goodsId, $orderId), array('and', 'and')); if ($ret !== false) { Cache::setex($ck, Cache::CK_GOODS_HAD_COMMENT_EXPIRE, (string) $ret); } } return (int) $ret > 0; }
public static function hadLiked($userId, $commentId) { $ck = Cache::CK_GOODS_COMMENT_HAD_LIKE . $commentId . ':' . $userId; $ret = Cache::get($ck); if ($ret === false) { $ret = DB::getDB()->fetchCount('g_goods_comment_like', array('comment_id', 'user_id'), array($commentId, $userId), array('and')); if ($ret !== false) { Cache::setex($ck, Cache::CK_GOODS_COMMENT_HAD_LIKE_EXPIRE, (string) $ret); } } return (int) $ret > 0; }
public static function findSomeCouponsByIds($couponIds) { if (empty($couponIds)) { return array(); } ksort($couponIds, SORT_NUMERIC); $idSet = implode(',', $couponIds); $ck = Cache::CK_COUPON_CFG_LIST_INFO . $idSet; $ret = Cache::get($ck); if ($ret !== false) { $ret = json_decode($ret, true); } else { $sql = "select * from m_coupon_cfg where id in ({$idSet})"; $ret = DB::getDB()->rawQuery($sql); if ($ret !== false) { Cache::setex($ck, json_encode($ret), Cache::CK_COUPON_CFG_INFO_LIST_EXPIRE); } } return $ret === false ? array() : $ret; }
public static function findUserDetailById($userId, $fromDb = 'w') { if (empty($userId)) { return array(); } $ck = Cache::CK_USER_DETAIL_INFO . $userId; $ret = Cache::get($ck); if ($ret !== false) { $ret = json_decode($ret, true); } else { $ret = DB::getDB($fromDb)->fetchOne('u_user_detail', '*', array('user_id'), array($userId)); if ($ret !== false) { Cache::set($ck, json_encode($ret)); } } if (empty($ret)) { return array(); } return $ret; }
private static function genCategoryId($categoryId) { $level1 = (int) ($categoryId / 1000000); $level2 = (int) ((int) ($categoryId / 1000) % 1000); $level3 = (int) ($categoryId % 1000); if ($level1 == 0) { // 增加一级分类 $sql = 'select max(category_id) as m from g_category'; $ret = DB::getDB('w')->rawQuery($sql); if ($ret === false) { return false; } if (empty($ret) || empty($ret[0]['m'])) { return 100000000; // 初始以100000000开始,虽然会少用9个,但会整齐好看一些 } $max = (int) $ret[0]['m']; if ((int) ($max / 1000000) == 999) { Log::fatal('category_id ' . $categoryId . ' level1 max = 999, out of limit!'); return false; } return ((int) ($max / 1000000) + 1) * 1000000; } else { if ($level2 == 0 && $level3 == 0) { // 增加二级分类 $sql = 'select max(category_id) as m from g_category where' . ' category_id >= ' . $level1 * 1000000 . ' and category_id < ' . ($level1 + 1) * 1000000; $ret = DB::getDB('w')->rawQuery($sql); if ($ret === false) { return false; } if (empty($ret) || empty($ret[0]['m'])) { return $level1 * 1000000 + 1000; } $maxLevel2 = (int) ((int) $ret[0]['m'] / 1000) % 1000; if ($maxLevel2 == 999) { Log::fatal('category_id ' . $categoryId . ' level2 max = 999, out of limit!'); return false; } return $level1 * 1000000 + ($maxLevel2 + 1) * 1000; } else { if ($level3 == 0) { // 增加三级分类 $sql = 'select max(category_id) as m from g_category where' . ' category_id >= ' . ($level1 * 1000000 + $level2 * 1000) . ' and category_id < ' . ($level1 * 1000000 + ($level2 + 1) * 1000); $ret = DB::getDB('w')->rawQuery($sql); if ($ret === false) { return false; } if (empty($ret) || empty($ret[0]['m'])) { return $level1 * 1000000 + $level2 * 1000 + 1; } $maxLevel3 = (int) $ret[0]['m'] % 1000; if ($maxLevel3 == 999) { Log::fatal('category_id ' . $categoryId . ' level3 max = 999, out of limit!'); return false; } return $level1 * 1000000 + $level2 * 1000 + $maxLevel3 + 1; } } } Log::error('error category_id(' . $categoryId . ') when generate category id'); return false; }
public static function findAllValidBanner($beginTime, $endTime, $showArea) { $ret = DB::getDB()->fetchAll('m_banner', '*', array('begin_time >=', 'end_time <', 'show_area'), array($beginTime, $endTime, $showArea), array('and', 'and'), array('sort'), array('desc')); return $ret === false ? array() : $ret; }
public static function findUserByPhone($phone, $fromDb = 'w') { if (empty($phone)) { return array(); } $ck = Cache::CK_USER_INFO_FOR_PHONE . $phone; $ret = Cache::get($ck); if ($ret !== false) { $ret = json_decode($ret, true); } else { $ret = DB::getDB($fromDb)->fetchOne('u_user', '*', array('phone'), array($phone)); if ($ret !== false) { Cache::set($ck, json_encode($ret)); } } if (empty($ret)) { return array(); } $ret['nickname'] = Util::emojiDecode($ret['nickname']); return $ret; }
private static function getSomeCoupon($userId, $state, $page, $size) { if (empty($userId)) { return array(); } $page = $page > 0 ? $page - 1 : $page; $ret = DB::getDB()->fetchSome('u_coupon', '*', array('user_id', 'state'), array($userId, self::COUPON_ST_UNUSED), array('and'), array('begin_time'), array('asc'), array($page * $size, $size)); return $ret === false ? array() : $ret; }
public static function findAllValidActivity($beginTime, $endTime) { $ret = DB::getDB()->fetchAll('m_activity', '*', array('begin_time >=', 'end_time <'), array($beginTime, $endTime), array('and')); return $ret === false ? array() : $ret; }
public static function onActivateForGZH($openid) { if (empty($openid)) { return; } $ret = DB::getDB('w')->update('u_wx_user', array('atime' => CURRENT_TIME), array('openid'), array($openid)); self::onUpdateData($openid); }