db()->where($where)->select(); return $data; } # 获取商品信息 public function getInfo($pid) { $where['id'] = $pid; //$where['status'] = 1; //$where['is_deleted'] = 0; $data = $this->db()->where($where)->find(); return $data; } # 获取缓存 public function get($mid, $key, $get = true) { if (!$get) { return false; } $cache_key = 'productv2_' . $mid . '_' . $key; $data = !$get ? false : $this->cache($cache_key); if (!$data) { if (is_numeric($key) && $key > 0) { $data = $this->getInfo($key); if ($data) { $this->cache($cache_key, $data); } } else { $relation = MerchantRelationService::instance()->getInfo($mid, $key); if ($relation) { $data = $this->getInfo($relation['pid']); if ($data) { $this->cache($cache_key, $data); } } else { $this->cache($cache_key, 'del'); } } } if ($data) { if ($data['status'] != 1) { return false; } if ($data['is_deleted'] != 0) { return false; } } return $data; } # 获取商品信息 public function getInfoByKey($key, $id = false, $cids = '') { $where['key'] = $key; $where['status'] = 1; $where['is_deleted'] = 0; $db = $this->db()->where($where); $raw = array(); if ($id) { $raw[] = ' id != ' . $id; } if ($cids) { $raw[] = ' cid in('.$cids.')'; } if ($raw) { $raw = implode(' and ' , $raw); $db->whereRaw($raw); } $data = $db->order('sort desc,id desc')->select()->toArray(); return $data; } # 根据关键字获得 public function getByKey($key, $id, $cids = '') { return $this->getInfoByKey($key, $id, $cids); } }