0) {
$key = 'cate_child_id';
}
} else {
$key = 'channel_id';
}
$where = [$key => $cate['id'], 'status' => 1];
$search = Dever::input('search');
if ($search) {
$where['name'] = ['like', $search];
}
$set = ['col' => 'id,sku_id,cate_child_id,name,info,price,pic,type,view,num_sell'];
if ($limit) {
$set['limit'] = $limit;
}
if ($page) {
$set['num'] = $page;
}
$order = Dever::input('order');
if ($order == 1) {
# 销量排序
$set['order'] = 'num_sell desc';
} elseif ($order == 3) {
# 价格正序
$set['order'] = 'price asc';
} elseif ($order == 4) {
# 价格倒序
$set['order'] = 'price desc';
}
$data = Dever::db('psource/info')->select($where, $set);
if ($data) {
foreach ($data as &$v) {
$v = $this->get($v, $cate);
}
}
return $data;
}
# 获取资源信息
public function get($info, $cate = [])
{
if (is_numeric($info)) {
$info = Dever::db('psource/info')->find(['id' => $info, 'status' => 1], ['col' => 'id,name,pic,price,cate_id']);
}
if ($info) {
if (!$cate) {
$cate = Dever::load(Cate::class)->getInfo($info['cate_id']);
}
# 获取封面
$info['cover'] = '';
$pic = explode(',', $info['pic']);
unset($info['pic']);
if (isset($pic[0])) {
$info['cover'] = $pic[0];
}
$info = Dever::load(Price::class)->get($info, $cate, -1);
}
return $info;
}
# 获取资源详细信息
public function getInfo($uid, $id)
{
$info = Dever::db('psource/info')->find(['id' => $id, 'status' => 1], ['col' => 'id,name,info,price,sku_id,pic,content,channel_id,cate_parent_id,cate_id,have_vip,num_sell']);
if (!$info) {
Dever::error('资源不存在');
}
# 分类
$cate = Dever::load(Cate::class)->getInfo($info['cate_id']);
# 价格
$info = Dever::load(Price::class)->get($info, $cate, -1);
$info['pic'] = explode(',', $info['pic']);
$info['content'] = htmlspecialchars_decode($info['content']);
if ($info['content'] == '
') {
$info['content'] = '';
}
# 获取sku基本信息
$sku = Dever::db('psource/sku')->find($info['sku_id']);
if ($sku) {
$info['sku_name'] = Dever::load(\Api\Lib\Sku::class)->getName($sku['key'], 'psource');
}
# 查看是否专享
$info['have_vip'] = Dever::load(Price::class)->getHave($info);
# 展示说明
$info['help'] = Dever::load(Help::class)->getList($cate['help_cate_id']);
# 是否收藏
$info['collect'] = false;
if ($uid) {
$act = Act::load('collect', $uid, 1, $info['id']);
if ($act->getInfo()) {
$info['collect'] = true;
}
}
return $info;
}
# 获取资源sku信息
public function getSku($id)
{
$info = Dever::db('psource/info')->find(['id' => $id, 'status' => 1], ['col' => 'id,sku_id,cate_id']);
if (!$info) {
Dever::error('资源不存在');
}
# 分类
$cate = Dever::load(Cate::class)->getInfo($info['cate_id']);
$sku = Dever::load(\Api\Lib\Sku::class)->getList(['info_id' => $info['id']], $info['sku_id'], 'psource');
if ($sku['info']) {
$sku['info'] = Dever::load(Price::class)->get($sku['info'], $cate, -1);
}
if ($sku['price']) {
foreach ($sku['price'] as &$price) {
$price = Dever::load(Price::class)->get($price, $cate, -1);
}
}
return $sku;
}
# 获取资源基本信息
public function getBaseInfo($source_id)
{
$info = Dever::db('psource/info')->find($source_id, ['col' => 'id,name,info,channel_id,cate_parent_id']);
if (!$info) {
Dever::error('资源不存在');
}
return $info;
}
# 获取资源编号或者ID
public function getCode($id, $encode = true)
{
if (Dever::getData('muser')) {
$salt = Dever::getData('muser')['select']['data_id'];//品牌id
$xorkey = Dever::getData('muser')['id'];//当前登录的管理员id
} else {
$place = Dever::load(\Place::class);
$salt = $place['info']['id'];//品牌id
$xorkey = $place['uid'];//当前登录的管理员id
}
return \Dever\Helper\Str::uid($id, $encode, $salt, $xorkey);
}
# 根据$cate获取where条件
public function getWhereByCate($cate, $prefix = '')
{
if ($cate) {
$cate = explode(',', $cate);
if (isset($cate[2]) && $cate[2]) {
$where = [$prefix . 'cate_child_id' => $cate[2]];
} elseif (isset($cate[1]) && $cate[1]) {
$where = [$prefix . 'cate_parent_id' => $cate[1]];
} else {
$where = [$prefix . 'channel_id' => $cate[0]];
}
}
$where[$prefix . 'status'] = 1;
return $where;
}
# 根据$cate获取资源列表
public function getListByCate($cate)
{
$where = $this->getWhereByCate($cate);
return Dever::db('psource/info')->select($where);
}
# 根据$cate获取资源sku列表
public function getSkuByCate($cate)
{
$set['join'] = array
(
array
(
'table' => 'psource_info',
'type' => 'left join',
'on' => 'main.info_id=t0.id',
),
);
$set['col'] = 'main.id,main.info_id,main.key,main.pic,main.price,main.code';
$set['order'] = 'main.id asc';
$where = $this->getWhereByCate($cate, 't0.');
$where['main.state'] = 1;
return Dever::db('psource/sku')->select($where, $set);
}
}