DataDownload.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\merchant\model\download;
  12. use think\Db;
  13. use traits\ModelTrait;
  14. use basic\ModelBasic;
  15. use app\merchant\model\download\DataDownloadCategpry;
  16. /**资料 model
  17. * Class DataDownload
  18. * @package app\admin\model\download
  19. */
  20. class DataDownload extends ModelBasic
  21. {
  22. use ModelTrait;
  23. /**字段过滤
  24. * @param string $alias
  25. * @param null $model
  26. * @return DataDownload
  27. */
  28. public static function PreWhere($alias = '', $model = null)
  29. {
  30. if (is_null($model)) $model = new self();
  31. if ($alias) {
  32. $model = $model->alias($alias);
  33. $alias .= '.';
  34. }
  35. return $model->where([$alias . 'is_show' => 1, $alias . 'is_del' => 0, $alias . 'status' => 1]);
  36. }
  37. /**条件处理
  38. * @param $where
  39. * @return DataDownload
  40. */
  41. public static function setWhere($where)
  42. {
  43. $model = new self();
  44. $model = $model->alias('d');
  45. $time['data'] = '';
  46. if (isset($where['start_time']) && isset($where['end_time']) && $where['start_time'] != '' && $where['end_time'] != '') {
  47. $time['data'] = $where['start_time'] . ' - ' . $where['end_time'];
  48. $model = $model->getModelTime($time, $model, 'd.add_time');
  49. }
  50. if (isset($where['title']) && $where['title']) {
  51. $model = $model->where('d.title|d.id|d.abstract', 'like', "%$where[title]%");
  52. }
  53. if (isset($where['cate_id']) && $where['cate_id']) {
  54. $model = $model->where('d.cate_id', $where['cate_id']);
  55. }
  56. if (isset($where['is_show']) && $where['is_show'] != '') {
  57. $model = $model->where('d.is_show', $where['is_show']);
  58. }
  59. if (isset($where['mer_id']) && $where['mer_id'] != '') {
  60. $model = $model->where('d.mer_id', $where['mer_id']);
  61. }
  62. if (isset($where['status']) && $where['status'] != '') {
  63. $model = $model->where('d.status', $where['status']);
  64. } else {
  65. $model = $model->where('d.status', 'in', [1, -1, 0]);
  66. }
  67. $model = $model->join('DataDownloadCategpry c', 'd.cate_id=c.id','left');
  68. return $model->where(['d.is_del' => 0]);
  69. }
  70. /**获取列表
  71. * @param $where
  72. * @return array
  73. * @throws \think\Exception
  74. */
  75. public static function get_download_list($where)
  76. {
  77. $data = self::setWhere($where)->order('d.sort DESC,d.id DESC')->field('d.*,c.title as cate_name')
  78. ->page((int)$where['page'], (int)$where['limit'])
  79. ->select();
  80. foreach ($data as $key => &$item) {
  81. $item['add_time'] = ($item['add_time'] != 0 || $item['add_time']) ? date('Y-m-d H:i:s', $item['add_time']) : '';
  82. }
  83. $data = count((array)$data) ? $data->toArray() : [];
  84. $count = self::setWhere($where)->count();
  85. return compact('data', 'count');
  86. }
  87. /**获取列表
  88. * @param $where
  89. * @return array
  90. * @throws \think\Exception
  91. */
  92. public static function get_download_examine_list($where)
  93. {
  94. $data = self::setWhere($where)->order('sort DESC,id DESC')
  95. ->page((int)$where['page'], (int)$where['limit'])
  96. ->select()
  97. ->each(function ($item) {
  98. $item['fail_time'] = date('Y-m-d H:i:s', $item['fail_time']);
  99. $item['add_time'] = ($item['add_time'] != 0 || $item['add_time']) ? date('Y-m-d H:i:s', $item['add_time']) : '';
  100. $item['cate_name'] = DataDownloadCategpry::where('id', $item['cate_id'])->value('title');
  101. });
  102. $data = count((array)$data) ? $data->toArray() : [];
  103. $count = self::setWhere($where)->count();
  104. return compact('data', 'count');
  105. }
  106. /**获取资料
  107. * @param $where
  108. */
  109. public static function dataDownloadLists($where, $source)
  110. {
  111. $data = self::setWhere($where)->where('d.id', 'not in', $source)->field('d.*,c.title as cate_name')->page($where['page'], $where['limit'])->select();
  112. $count = self::setWhere($where)->where('d.id', 'not in', $source)->count();
  113. return compact('data', 'count');
  114. }
  115. }