123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace app\common\model;
- use library\tools\Data;
- use think\Model;
- use function Symfony\Component\String\b;
- // 商品热搜
- class TopSearch extends Model
- {
- // 保存更新热搜数据
- public static function saveData($id,$module='')
- {
- $data = [];
- switch ($module)
- {
- case 'video':
- $info = VideoUrl::where('id',$id)->find()->toArray();
- if(!empty($info)) $data['series_id'] = $info['video_id'];
- break;
- case 'article':
- $info = ArticleItem::where('id',$id)->find()->toArray();
- if(!empty($info)) $data['series_id'] = $info['article_id'];
- break;
- case 'datum':
- $info = DatumUrl::where('id',$id)->find()->toArray();
- if(!empty($info)) $data['series_id'] = $info['datum_id'];
- break;
- case 'press':
- $info = Press::where('id',$id)->find()->toArray();
- break;
- case "forum":
- $info = UserForum::where('id',$id)->find()->toArray();
- break;
- case 'activity':
- $info = Activity::where('id',$id)->find()->toArray();
- break;
- case 'demand':
- $info = PlatformDemand::where('id',$id)->find()->toArray();
- break;
- case 'recruit':
- $info = Recruit::where('id',$id)->find()->toArray();
- break;
- case 'supplier_goods':
- $info = SupplierGoods::where('id',$id)->find()->toArray();
- break;
- case 'goods':
- $info = StoreGoods::where('id',$id)->find()->toArray();
- break;
- }
- if(empty($info)) return false;
- $data['title'] = isset($info['title']) ? $info['title'] : $info['name'];
- $data['status'] = isset($info['status']) ? $info['status'] : 1;
- $data['is_deleted'] = isset($info['is_deleted']) ? $info['is_deleted'] :0;
- if(isset($info['create_at'])) $data['create_at'] = $info['create_at'] ;
- if(isset($info['release_time'])) $data['release_time'] = $info['release_time'] ;
- if(isset($info['hot_time'])) $data['hot_time'] = $info['hot_time'] ;
- $data['hot_num'] = isset($info['hot_num']) ? $info['hot_num'] :0;
- $data['module'] = $module;
- $data['rel_id'] = $info['id'];
- Data::save('TopSearch',$data,'module',['module'=>$module,'rel_id'=>$data['rel_id']]);
- }
- // 增加热搜阅读量
- public static function seIncHotNum($rel_id,$module,$num = 1)
- {
- switch ($module) {
- case 'video':
- VideoUrl::where('id',$rel_id)->setInc('hot_num',$num);
- break;
- case 'article':
- ArticleItem::where('id',$rel_id)->setInc('hot_num',$num);
- break;
- case 'datum':
- DatumUrl::where('id',$rel_id)->setInc('hot_num',$num);
- break;
- case 'press':
- Press::where('id',$rel_id)->setInc('hot_num',$num);
- break;
- case "forum":
- UserForum::where('id',$rel_id)->setInc('hot_num',$num);
- break;
- case 'activity':
- Activity::where('id',$rel_id)->setInc('hot_num',$num);
- break;
- case 'demand':
- PlatformDemand::where('id',$rel_id)->setInc('hot_num',$num);
- break;
- case 'recruit':
- Recruit::where('id',$rel_id)->setInc('hot_num',$num);
- break;
- case 'supplier_goods':
- SupplierGoods::where('id',$rel_id)->setInc('hot_num',$num);
- break;
- case 'goods':
- StoreGoods::where('id',$rel_id)->setInc('hot_num',$num);
- break;
- }
- static::where(['rel_id'=>$rel_id,'module'=>$module])->setInc('hot_num',$num);
- }
- }
|