123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php namespace Psource\Lib;
- use Dever;
- use Pact\Lib\Core as Act;
- class Info
- {
- # 获取资源列表
- public function getList($cate, $limit, $page = false)
- {
- if (isset($cate['parent_id'])) {
- $key = 'cate_parent_id';
- if ($cate['parent_id'] > 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'] == '<p><br></p>') {
- $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);
- }
- }
|