DataDownload.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\material;
  12. use think\Db;
  13. use traits\ModelTrait;
  14. use basic\ModelBasic;
  15. use app\wap\model\material\DataDownloadCategpry;
  16. /**资料 model
  17. * Class DataDownload
  18. * @package app\wap\model\material
  19. */
  20. class DataDownload extends ModelBasic
  21. {
  22. use ModelTrait;
  23. public static function PreWhere($alias = '', $model = null)
  24. {
  25. if (is_null($model)) $model = new self();
  26. if ($alias) {
  27. $model = $model->alias($alias);
  28. $alias .= '.';
  29. }
  30. return $model->where([$alias . 'is_show' => 1, $alias . 'status' => 1, $alias . 'is_del' => 0]);
  31. }
  32. /**列表
  33. * @param int $page
  34. * @param int $limit
  35. * @param $tid
  36. * @return array
  37. */
  38. public static function getDataDownloadExercisesList($page, $limit, $pid, $cate_id, $search)
  39. {
  40. $model = self::PreWhere();
  41. if ($pid && $cate_id) {
  42. $model = $model->where(['cate_id' => $cate_id]);
  43. } else if ($pid && !$cate_id) {
  44. $cate_ids = DataDownloadCategpry::where('pid', $pid)->column('id');
  45. $model = $model->where('cate_id', 'in', $cate_ids);
  46. }
  47. if ($search) $model = $model->where('title', 'LIKE', "%$search%");
  48. $list = $model->order('sort desc,id desc')->page($page, $limit)->select();
  49. $list = count($list) ? $list->toArray() : [];
  50. return $list;
  51. }
  52. /**
  53. * 获取单个资料的详细信息
  54. * @param $uid 用户id
  55. * @param $id 资料id
  56. * */
  57. public static function getOneDataDownload($uid, $id)
  58. {
  59. $data = self::PreWhere()->find($id);
  60. if (!$data) return self::setErrorInfo('您要查看的资料不存在!');
  61. if ($data->is_show == 0) return self::setErrorInfo('您要查看的资料已下架!');
  62. $title = $data->title;
  63. $data->collect = self::getDb('special_relation')->where(['link_id' => $id, 'type' => 1, 'uid' => $uid, 'category' => 1])->count() ? true : false;
  64. $data->abstract = htmlspecialchars_decode($data->abstract);
  65. $data = json_encode($data->toArray());
  66. return compact('data', 'title');
  67. }
  68. /**讲师名下资料
  69. * @param $mer_id
  70. * @param $page
  71. * @param $limit
  72. */
  73. public static function getLecturerDataDownloadList($mer_id, $page, $limit)
  74. {
  75. if ($mer_id) {
  76. $model = self::PreWhere();
  77. $model = $model->where(['mer_id' => $mer_id])->order('sort desc,id desc');
  78. $list = $model->page($page, $limit)->select();
  79. $list = count($list) ? $list->toArray() : [];
  80. } else {
  81. $list = [];
  82. }
  83. return $list;
  84. }
  85. }