TopSearch.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\common\model;
  3. use library\tools\Data;
  4. use think\Model;
  5. use function Symfony\Component\String\b;
  6. // 商品热搜
  7. class TopSearch extends Model
  8. {
  9. // 保存更新热搜数据
  10. public static function saveData($id,$module='')
  11. {
  12. $data = [];
  13. switch ($module)
  14. {
  15. case 'video':
  16. $info = VideoUrl::where('id',$id)->find()->toArray();
  17. if(!empty($info)) $data['series_id'] = $info['video_id'];
  18. break;
  19. case 'article':
  20. $info = ArticleItem::where('id',$id)->find()->toArray();
  21. if(!empty($info)) $data['series_id'] = $info['article_id'];
  22. break;
  23. case 'datum':
  24. $info = DatumUrl::where('id',$id)->find()->toArray();
  25. if(!empty($info)) $data['series_id'] = $info['datum_id'];
  26. break;
  27. case 'press':
  28. $info = Press::where('id',$id)->find()->toArray();
  29. break;
  30. case "forum":
  31. $info = UserForum::where('id',$id)->find()->toArray();
  32. break;
  33. case 'activity':
  34. $info = Activity::where('id',$id)->find()->toArray();
  35. break;
  36. case 'demand':
  37. $info = PlatformDemand::where('id',$id)->find()->toArray();
  38. break;
  39. case 'recruit':
  40. $info = Recruit::where('id',$id)->find()->toArray();
  41. break;
  42. case 'supplier_goods':
  43. $info = SupplierGoods::where('id',$id)->find()->toArray();
  44. break;
  45. case 'goods':
  46. $info = StoreGoods::where('id',$id)->find()->toArray();
  47. break;
  48. }
  49. if(empty($info)) return false;
  50. $data['title'] = isset($info['title']) ? $info['title'] : $info['name'];
  51. $data['status'] = isset($info['status']) ? $info['status'] : 1;
  52. $data['is_deleted'] = isset($info['is_deleted']) ? $info['is_deleted'] :0;
  53. if(isset($info['create_at'])) $data['create_at'] = $info['create_at'] ;
  54. if(isset($info['release_time'])) $data['release_time'] = $info['release_time'] ;
  55. if(isset($info['hot_time'])) $data['hot_time'] = $info['hot_time'] ;
  56. $data['hot_num'] = isset($info['hot_num']) ? $info['hot_num'] :0;
  57. $data['module'] = $module;
  58. $data['rel_id'] = $info['id'];
  59. Data::save('TopSearch',$data,'module',['module'=>$module,'rel_id'=>$data['rel_id']]);
  60. }
  61. // 增加热搜阅读量
  62. public static function seIncHotNum($rel_id,$module,$num = 1)
  63. {
  64. switch ($module) {
  65. case 'video':
  66. VideoUrl::where('id',$rel_id)->setInc('hot_num',$num);
  67. break;
  68. case 'article':
  69. ArticleItem::where('id',$rel_id)->setInc('hot_num',$num);
  70. break;
  71. case 'datum':
  72. DatumUrl::where('id',$rel_id)->setInc('hot_num',$num);
  73. break;
  74. case 'press':
  75. Press::where('id',$rel_id)->setInc('hot_num',$num);
  76. break;
  77. case "forum":
  78. UserForum::where('id',$rel_id)->setInc('hot_num',$num);
  79. break;
  80. case 'activity':
  81. Activity::where('id',$rel_id)->setInc('hot_num',$num);
  82. break;
  83. case 'demand':
  84. PlatformDemand::where('id',$rel_id)->setInc('hot_num',$num);
  85. break;
  86. case 'recruit':
  87. Recruit::where('id',$rel_id)->setInc('hot_num',$num);
  88. break;
  89. case 'supplier_goods':
  90. SupplierGoods::where('id',$rel_id)->setInc('hot_num',$num);
  91. break;
  92. case 'goods':
  93. StoreGoods::where('id',$rel_id)->setInc('hot_num',$num);
  94. break;
  95. }
  96. static::where(['rel_id'=>$rel_id,'module'=>$module])->setInc('hot_num',$num);
  97. }
  98. }