Archives.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\home\model;
  14. use think\Model;
  15. use think\Page;
  16. use think\Db;
  17. use app\home\logic\FieldLogic;
  18. /**
  19. * 文档主表
  20. */
  21. class Archives extends Model
  22. {
  23. //初始化
  24. protected function initialize()
  25. {
  26. // 需要调用`Model`的`initialize`方法
  27. parent::initialize();
  28. $this->fieldLogic = new FieldLogic();
  29. }
  30. /**
  31. * 获取单条文档记录
  32. * @author wengxianhu by 2017-7-26
  33. */
  34. public function getViewInfo($aid, $litpic_remote = false, $where = [])
  35. {
  36. $result = array();
  37. $row = Db::name('archives')->field('*')->where($where)->find($aid);
  38. if (!empty($row)) {
  39. /*封面图*/
  40. if (empty($row['litpic'])) {
  41. $row['is_litpic'] = 0; // 无封面图
  42. } else {
  43. $row['is_litpic'] = 1; // 有封面图
  44. }
  45. $row['litpic'] = get_default_pic($row['litpic'], $litpic_remote); // 默认封面图
  46. /*文档基本信息*/
  47. if (1 == $row['channel']) { // 文章模型
  48. $articleModel = new \app\home\model\Article();
  49. $extFields = Db::name('article_content')->getTableFields();
  50. $extFields = array_flip($extFields);
  51. unset($extFields['id']);
  52. $rowExt = $articleModel->getInfo($aid);
  53. $rowExt = array_diff_key($extFields, $row);
  54. } else if (2 == $row['channel']) { // 产品模型
  55. /*产品参数*/
  56. $productAttrModel = new \app\home\model\ProductAttr();
  57. $attr_list = $productAttrModel->getProAttr($aid);
  58. $row['attr_list'] = !empty($attr_list[$aid]) ? $attr_list[$aid] : [];
  59. // 产品相册
  60. $image_list = [];
  61. $productImgModel = new \app\home\model\ProductImg();
  62. $image_list_tmp = $productImgModel->getProImg($aid);
  63. if (!empty($image_list_tmp[$aid])) {
  64. foreach ($image_list_tmp[$aid] as $key => $val) {
  65. $val['image_url'] = get_default_pic($val['image_url'], $litpic_remote);
  66. $image_list[$key] = $val;
  67. }
  68. }
  69. $row['image_list'] = $image_list;
  70. $productModel = new \app\home\model\Product();
  71. $extFields = Db::name('product_content')->getTableFields();
  72. $extFields = array_flip($extFields);
  73. unset($extFields['id']);
  74. $rowExt = $productModel->getInfo($aid);
  75. $rowExt = array_diff_key($extFields, $row);
  76. } else if (3 == $row['channel']) { // 图集模型
  77. // 图集相册
  78. $image_list = [];
  79. $imagesUploadModel = new \app\home\model\ImagesUpload();
  80. $image_list_tmp = $imagesUploadModel->getImgUpload($aid);
  81. if (!empty($image_list_tmp[$aid])) {
  82. foreach ($image_list_tmp[$aid] as $key => $val) {
  83. $val['image_url'] = get_default_pic($val['image_url'], $litpic_remote);
  84. $image_list[$key] = $val;
  85. }
  86. }
  87. $row['image_list'] = $image_list;
  88. $imagesModel = new \app\home\model\Images();
  89. $extFields = Db::name('images_content')->getTableFields();
  90. $extFields = array_flip($extFields);
  91. unset($extFields['id']);
  92. $rowExt = $imagesModel->getInfo($aid);
  93. $rowExt = array_diff_key($extFields, $row);
  94. } else if (4 == $row['channel']) { // 下载模型
  95. $downloadModel = new \app\home\model\Download();
  96. $extFields = Db::name('download_content')->getTableFields();
  97. $extFields = array_flip($extFields);
  98. unset($extFields['id']);
  99. $rowExt = $downloadModel->getInfo($aid);
  100. $rowExt = array_diff_key($extFields, $row);
  101. }
  102. $rowExt = $this->fieldLogic->getChannelFieldList($rowExt, $row['channel']); // 自定义字段的数据格式处理
  103. /*--end*/
  104. $result = array_merge($rowExt, $row);
  105. }
  106. return $result;
  107. }
  108. /**
  109. * 获取单页栏目记录
  110. * @author wengxianhu by 2017-7-26
  111. */
  112. public function getSingleInfo($typeid, $litpic_remote = false)
  113. {
  114. $result = array();
  115. /*文档基本信息*/
  116. $row = $this->readContentFirst($typeid);
  117. /*--end*/
  118. if (!empty($row)) {
  119. /*封面图*/
  120. if (empty($row['litpic'])) {
  121. $row['is_litpic'] = 0; // 无封面图
  122. } else {
  123. $row['is_litpic'] = 1; // 有封面图
  124. }
  125. $row['litpic'] = get_default_pic($row['litpic'], $litpic_remote); // 默认封面图
  126. /*--end*/
  127. $row = $this->fieldLogic->getTableFieldList($row, config('global.arctype_channel_id')); // 自定义字段的数据格式处理
  128. /*--end*/
  129. $row = $this->fieldLogic->getChannelFieldList($row, $row['channel']); // 自定义字段的数据格式处理
  130. $result = $row;
  131. }
  132. return $result;
  133. }
  134. /**
  135. * 读取指定栏目ID下有内容的栏目信息,只读取每一级的第一个栏目
  136. * @param intval $typeid 栏目ID
  137. * @return array
  138. */
  139. private function readContentFirst($typeid)
  140. {
  141. $result = false;
  142. while (true)
  143. {
  144. $singleModel = new \app\home\model\Single();
  145. $result = $singleModel->getInfoByTypeid($typeid);
  146. if (empty($result['content']) && preg_match('/^lists_single(_(.*))?\.htm$/i', $result['templist'])) {
  147. $map = array(
  148. 'parent_id' => $result['typeid'],
  149. 'current_channel' => 6,
  150. 'is_hidden' => 0,
  151. 'status' => 1,
  152. );
  153. $row = Db::name('arctype')->where($map)->field('*')->order('sort_order asc')->find(); // 查找下一级的单页模型栏目
  154. if (empty($row)) { // 不存在并返回当前栏目信息
  155. break;
  156. } elseif (6 == $row['current_channel']) { // 存在且是单页模型,则进行继续往下查找,直到有内容为止
  157. $typeid = $row['id'];
  158. }
  159. } else {
  160. break;
  161. }
  162. }
  163. return $result;
  164. }
  165. }