You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
233 lines
8.0 KiB
233 lines
8.0 KiB
<?php
|
|
|
|
|
|
namespace app\api\logic;
|
|
|
|
|
|
use app\common\basics\Logic;
|
|
use app\common\model\content\Article;
|
|
use app\common\model\content\ArticleCategory;
|
|
use app\common\model\content\Resource;
|
|
use app\common\model\content\ResourceCategory;
|
|
use app\common\model\user\User;
|
|
use app\common\model\user\UserResource;
|
|
use app\common\server\AreaServer;
|
|
use app\common\server\UrlServer;
|
|
use think\Db;
|
|
|
|
class ResourceLogic extends Logic
|
|
{
|
|
/**
|
|
* @Notes: 资料分类
|
|
* @Author: 张无忌
|
|
* @param $get
|
|
* @return array
|
|
*/
|
|
public static function category($get)
|
|
{
|
|
try {
|
|
$model = new ResourceCategory();
|
|
$where = [];
|
|
if(isset($get['cate_type']) ){
|
|
if($get['cate_type'] == 0){
|
|
$where[] = ['id','not in',[17,18,19,20,21]];
|
|
}else{
|
|
$where[] = ['id','in',[17,18,19,20,21]];
|
|
}
|
|
}
|
|
|
|
return $model->field(['id', 'name'])
|
|
->where([
|
|
['del', '=', 0],
|
|
['is_show', '=', 1]
|
|
])->where($where)->select()->toArray();
|
|
|
|
} catch (\Exception $e) {
|
|
return ['error'=>$e->getMessage()];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @Notes: 文章列表
|
|
* @Author: 张无忌
|
|
* @param $get
|
|
* @return array
|
|
*/
|
|
public static function lists($get,$user_id=0)
|
|
{
|
|
try {
|
|
if(!isset($get['cid']) || !strstr($get['cid'],"my")){
|
|
|
|
$where = [
|
|
['a.del', '=', 0],
|
|
['a.is_show', '=', 1],
|
|
['c.del', '=', 0],
|
|
['c.is_show', '=', 1],
|
|
];
|
|
|
|
if(isset($get['keyword']) && $get['keyword']!=""){
|
|
$where[] = ['a.title', 'like', "%".$get['keyword']."%"];
|
|
}
|
|
|
|
if(isset($get['cid']) && !empty($get['cid']) && $get['cid']>0 && !strstr($get['cid'],"city_") ) {
|
|
$where[] = ['cid', '=', $get['cid']];
|
|
}
|
|
|
|
if(isset($get['cid']) && !empty($get['cid']) && strstr($get['cid'],"city_") ) {
|
|
$where[] = ['a.city_id', '=', str_replace("city_","",$get['cid'])];
|
|
}
|
|
|
|
if(isset($get['cid']) && $get['cid'] == 20 && isset($get['city_id']) && $get['city_id']>0){
|
|
$where[] = ['a.city_id', '=', $get['city_id']];
|
|
}
|
|
|
|
if(isset($get['cate_type']) ){
|
|
if($get['cate_type'] == 0){
|
|
$where[] = ['c.id','not in',[17,18,19,20,21]];
|
|
}else{
|
|
$where[] = ['c.id','in',[17,18,19,20,21]];
|
|
}
|
|
}
|
|
|
|
|
|
$order = [
|
|
'sort' => 'asc',
|
|
'id' => 'desc'
|
|
];
|
|
|
|
$model = new Resource();
|
|
|
|
$count = $model->alias('a')->join('resource_category c', 'c.id = a.cid')->where($where)->count();
|
|
|
|
$list = $model->alias('a')
|
|
->join('resource_category c', 'c.id = a.cid')
|
|
->field(['a.id', 'a.title', 'a.image', 'a.visit', 'a.likes','a.intro', 'a.content', 'a.create_time','a.price','a.type','a.province_id','a.city_id','a.district_id'])
|
|
->where($where)
|
|
->order($order)
|
|
->page($get['page_no'], $get['page_size'])
|
|
->select()
|
|
->toArray();
|
|
foreach ($list as &$item){
|
|
$item['price_str'] = $item['type']==0? "免费":($item['type']==1?"VIP会员免费":round($item['price'],2));
|
|
}
|
|
|
|
|
|
}else{
|
|
$where = [
|
|
['b.user_id', '=', $user_id],
|
|
['b.type', '=', $get['cid']=='my_buy'?1:0],
|
|
];
|
|
$order = [
|
|
'create_time' => 'desc'
|
|
];
|
|
|
|
$model = new UserResource();
|
|
|
|
$count = $model->alias('b')->join('resource a', 'b.resource_id = a.id')->join('resource_category c', 'c.id = a.cid')->where($where)->count();
|
|
|
|
$list = $model->alias('b')
|
|
->join('resource a', 'b.resource_id = a.id')
|
|
->join('resource_category c', 'c.id = a.cid')
|
|
->field(['a.id', 'a.title', 'a.image', 'a.visit', 'a.likes','a.intro', 'a.content', 'a.create_time','a.price','a.type','a.province_id','a.city_id','a.district_id'])
|
|
->where($where)
|
|
->order($order)
|
|
->page($get['page_no'], $get['page_size'])
|
|
->select()
|
|
->toArray();
|
|
foreach ($list as &$item){
|
|
$item['price_str'] = $item['type']==0? "免费":($item['type']==1?"VIP会员免费":round($item['price'],2));
|
|
}
|
|
}
|
|
$more = is_more($count, $get['page_no'], $get['page_size']);
|
|
$data = [
|
|
'list' => $list,
|
|
'page_no' => $get['page_no'],
|
|
'page_size' => $get['page_size'],
|
|
'count' => $count,
|
|
'more' => $more
|
|
];
|
|
return $data;
|
|
|
|
} catch (\Exception $e) {
|
|
return ['error'=>$e->getMessage()];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @Notes: 文章详细
|
|
* @Author: 张无忌
|
|
* @param $id
|
|
* @return array
|
|
*/
|
|
public static function detail($id,$uid)
|
|
{
|
|
$article = Resource::field('*')->where('id', $id)->findOrEmpty();
|
|
if($article->isEmpty()) {
|
|
$article = [];
|
|
}else{
|
|
$article->visit = $article->visit + 1;
|
|
$article->save();
|
|
$article = $article->toArray();
|
|
|
|
$article['price_str'] = $article['type']==0? "免费":($article['type']==1?"VIP会员免费":"¥".round($article['price'],2));
|
|
$goodsType = $article['type'];
|
|
if($uid){
|
|
if($goodsType==2){
|
|
$resmodel = new UserResource();
|
|
$count = $resmodel->where("resource_id",$id)->where("user_id",$uid)->where("type",1)->count();
|
|
if($count){
|
|
$goodsType=0;
|
|
}
|
|
}elseif ($goodsType==1){
|
|
$user = User::field('*')->findOrEmpty($uid)->toArray();;
|
|
if($user && $user['ship_id']>0 && ($user['exp_time']>time() || $user['exp_time'] == 0)){
|
|
$goodsType=0;
|
|
}
|
|
}
|
|
}
|
|
|
|
$article['goodsType'] = $goodsType;
|
|
$article['path'] = $article['path']?UrlServer::getFileUrl($article['path']):'';
|
|
|
|
$article['address'] = $article['province_id']?AreaServer::getAddress([
|
|
$article['province_id'],
|
|
$article['city_id'],
|
|
$article['district_id']]):'全国';
|
|
|
|
// 使用正则表达式进行替换
|
|
$pattern = '/<a[^>]+href=["\'](.*?\.(?:mp4|wav))["\'][^>]*>(.*?)<\/a>/i';
|
|
$replacement = '<video src="$1"></video>';
|
|
$article['content'] = preg_replace($pattern, $replacement, $article['content']);
|
|
}
|
|
|
|
return $article;
|
|
}
|
|
|
|
/**
|
|
* @Notes: 文章详细
|
|
* @Author: 张无忌
|
|
* @param $id
|
|
* @return int
|
|
*/
|
|
public static function downloadLog($id,$uid)
|
|
{
|
|
$article = Resource::field('*')->where('id', $id)->findOrEmpty();
|
|
if($article->isEmpty()) {
|
|
return 0;
|
|
}else{
|
|
$article->download = $article->download + 1;
|
|
$article->save();
|
|
|
|
//下载记录
|
|
$userResource = [];
|
|
$userResource['user_id'] = $uid;
|
|
$userResource['resource_id'] = $id;
|
|
$userResource['type'] = 0;
|
|
$userResource['create_time'] = time();
|
|
$userResourceModel = new UserResource();
|
|
$userResourceModel->insert($userResource);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
}
|