RecommendRelation.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\system;
  12. use app\admin\model\article\Article;
  13. use app\admin\model\special\Special;
  14. use app\admin\model\special\SpecialTask;
  15. use traits\ModelTrait;
  16. use basic\ModelBasic;
  17. use app\admin\model\store\StoreProduct;
  18. use app\admin\model\system\Recommend;
  19. /**
  20. * Class SystemAdmin
  21. * @package app\admin\model\system
  22. */
  23. class RecommendRelation extends ModelBasic
  24. {
  25. use ModelTrait;
  26. protected $insert = ['add_time'];
  27. public static function setAddTimeAttr($value)
  28. {
  29. return time();
  30. }
  31. public static function setWhere($id){
  32. $recommend=Recommend::where('id', $id)->find();
  33. $model=self::where('r.recommend_id', $id)->alias('r')->order('r.add_time desc');
  34. switch ($recommend['type']){
  35. case 0:
  36. $model=$model->join('Special s','r.link_id=s.id')->field('r.*,s.id,s.is_show,s.is_del')->where(['s.is_show'=>1,'s.is_del'=>0]);
  37. break;
  38. case 1:
  39. $model=$model->join('Article a','r.link_id=a.id')->field('r.*,a.id,a.is_show')->where(['a.is_show'=>1]);
  40. break;
  41. case 4:
  42. $model=$model->join('StoreProduct p','r.link_id=p.id')->field('r.*,p.id,p.is_show,p.is_del')->where(['p.is_show'=>1,'p.is_del'=>0]);
  43. break;
  44. }
  45. return $model;
  46. }
  47. public static function getAll($where, $id)
  48. {
  49. $data=self::setWhere($id)->page((int)$where['page'], (int)$where['limit'])->select();
  50. foreach ($data as &$itme) {
  51. if ($itme['type'] == 0) {
  52. $itme['type_name'] = '专题';
  53. $link = Special::PreWhere()->where('id', $itme['link_id'])->find();
  54. $itme['count'] = SpecialTask::getTaskCount($itme['link_id']);
  55. $itme['title'] = $link['title'];
  56. } else if ($itme['type'] == 1) {
  57. $itme['type_name'] = '图文';
  58. $link = Article::PreWhere()->where('id', $itme['link_id'])->find();
  59. $itme['count'] = 0;
  60. $itme['title'] = $link['title'];
  61. }else if ($itme['type'] == 4) {
  62. $itme['type_name'] = '商品';
  63. $link = StoreProduct::PreWhere()->where('id', $itme['link_id'])->find();
  64. $itme['count'] = 0;
  65. $itme['title'] = $link['store_name'];
  66. }
  67. }
  68. $count = self::setWhere($id)->count();
  69. return compact('data', 'count');
  70. }
  71. }