心理咨询网
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SingleModel.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /**
  3. * @copyright (C)2016-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2017年12月15日
  7. * 单页文章模型类
  8. */
  9. namespace app\admin\model\content;
  10. use core\basic\Model;
  11. class SingleModel extends Model
  12. {
  13. // 获取文章列表
  14. public function getList($mcode)
  15. {
  16. $field = array(
  17. 'a.id',
  18. 'a.scode',
  19. 'b.name as sortname',
  20. 'a.title',
  21. 'a.date',
  22. 'a.status',
  23. 'a.visits',
  24. 'b.mcode',
  25. 'a.ico',
  26. 'a.pics',
  27. 'a.outlink',
  28. 'b.filename',
  29. 'c.urlname'
  30. );
  31. $join = array(
  32. array(
  33. 'ay_content_sort b',
  34. 'a.scode=b.scode',
  35. 'LEFT'
  36. ),
  37. array(
  38. 'ay_model c',
  39. 'b.mcode=c.mcode',
  40. 'LEFT'
  41. )
  42. );
  43. return parent::table('ay_content a')->distinct()
  44. ->field($field)
  45. ->where("b.mcode='$mcode'")
  46. ->where("a.acode='" . session('acode') . "'")
  47. ->where('c.type=1')
  48. ->join($join)
  49. ->where('a.id IN(SELECT MAX(d.id) FROM ay_content d WHERE d.scode=a.scode)')
  50. ->order('a.id DESC')
  51. ->select();
  52. }
  53. // 查找文章
  54. public function findSingle($mcode, $field, $keyword)
  55. {
  56. $fields = array(
  57. 'a.id',
  58. 'a.scode',
  59. 'b.name as sortname',
  60. 'a.title',
  61. 'a.date',
  62. 'a.status',
  63. 'a.visits',
  64. 'b.mcode',
  65. 'a.ico',
  66. 'a.pics',
  67. 'a.outlink',
  68. 'b.filename',
  69. 'c.urlname'
  70. );
  71. $join = array(
  72. array(
  73. 'ay_content_sort b',
  74. 'a.scode=b.scode',
  75. 'LEFT'
  76. ),
  77. array(
  78. 'ay_model c',
  79. 'b.mcode=c.mcode',
  80. 'LEFT'
  81. )
  82. );
  83. return parent::table('ay_content a')->distinct()
  84. ->field($fields)
  85. ->where("b.mcode='$mcode'")
  86. ->where("a.acode='" . session('acode') . "'")
  87. ->where('c.type=1')
  88. ->like($field, $keyword)
  89. ->join($join)
  90. ->group('b.name')
  91. ->order('a.id DESC')
  92. ->select();
  93. }
  94. // 检查文章
  95. public function checkSingle($where)
  96. {
  97. return parent::table('ay_content')->field('id')
  98. ->where($where)
  99. ->find();
  100. }
  101. // 获取文章详情
  102. public function getSingle($id)
  103. {
  104. $field = array(
  105. 'a.*',
  106. 'b.name as sortname',
  107. 'c.*',
  108. 'b.filename',
  109. 'd.urlname'
  110. );
  111. $join = array(
  112. array(
  113. 'ay_content_sort b',
  114. 'a.scode=b.scode',
  115. 'LEFT'
  116. ),
  117. array(
  118. 'ay_content_ext c',
  119. 'a.id=c.contentid',
  120. 'LEFT'
  121. ),
  122. array(
  123. 'ay_model d',
  124. 'b.mcode=d.mcode',
  125. 'LEFT'
  126. )
  127. );
  128. return parent::table('ay_content a')->field($field)
  129. ->where("a.id=$id")
  130. ->where("a.acode='" . session('acode') . "'")
  131. ->join($join)
  132. ->find();
  133. }
  134. // 添加文章
  135. public function addSingle(array $data)
  136. {
  137. return parent::table('ay_content')->autoTime()->insert($data);
  138. }
  139. // 删除文章
  140. public function delSingle($id)
  141. {
  142. return parent::table('ay_content')->where("id=$id")
  143. ->where("acode='" . session('acode') . "'")
  144. ->delete();
  145. }
  146. // 修改文章
  147. public function modSingle($id, $data)
  148. {
  149. return parent::table('ay_content')->autoTime()
  150. ->where("id=$id")
  151. ->where("acode='" . session('acode') . "'")
  152. ->update($data);
  153. }
  154. // 查找文章扩展内容
  155. public function findContentExt($id)
  156. {
  157. return parent::table('ay_content_ext')->where("contentid=$id")->find();
  158. }
  159. // 添加文章扩展内容
  160. public function addContentExt(array $data)
  161. {
  162. return parent::table('ay_content_ext')->insert($data);
  163. }
  164. // 修改文章扩展内容
  165. public function modContentExt($id, $data)
  166. {
  167. return parent::table('ay_content_ext')->where("contentid=$id")->update($data);
  168. }
  169. // 删除文章扩展内容
  170. public function delContentExt($id)
  171. {
  172. return parent::table('ay_content_ext')->where("contentid=$id")->delete();
  173. }
  174. // 检查自定义URL名称
  175. public function checkFilename($where)
  176. {
  177. return parent::table('ay_content')->field('id')
  178. ->where($where)
  179. ->find();
  180. }
  181. }