Adv.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Adv extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 新增广告位
  16. * @author csdeshang
  17. * @param array $data 参数内容
  18. * @return bool 布尔类型的返回结果
  19. */
  20. public function addAdvposition($data)
  21. {
  22. return Db::name('advposition')->insertGetId($data);
  23. }
  24. /**
  25. * 新增广告
  26. * @author csdeshang
  27. * @param array $data 参数内容
  28. * @return bool 布尔类型的返回结果
  29. */
  30. public function addAdv($data)
  31. {
  32. $result = Db::name('adv')->insertGetId($data);
  33. $apId = (int) $data['ap_id'];
  34. dkcache("adv/{$apId}");
  35. return $result;
  36. }
  37. /**
  38. * 删除一条广告
  39. * @author csdeshang
  40. * @param array $adv_id 广告id
  41. * @return bool 布尔类型的返回结果
  42. */
  43. public function delAdv($adv_id)
  44. {
  45. $adv = Db::name('adv')->where('adv_id', $adv_id)->find();
  46. if ($adv) {
  47. // drop cache
  48. $apId = (int) $adv['ap_id'];
  49. dkcache("adv/{$apId}");
  50. }
  51. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ADV . DIRECTORY_SEPARATOR . $adv['adv_code']);
  52. return Db::name('adv')->where('adv_id', $adv_id)->delete();
  53. }
  54. /**
  55. * 删除一个广告位
  56. * @author csdeshang
  57. * @param array $ap_id 广告位id
  58. * @return bool 布尔类型的返回结果
  59. */
  60. public function delAdvposition($ap_id)
  61. {
  62. $apId = (int) $ap_id;
  63. dkcache("adv/{$apId}");
  64. return Db::name('advposition')->where('ap_id', $apId)->delete();
  65. }
  66. /**
  67. * 获取广告位列表
  68. * @author csdeshang
  69. * @param array $condition 查询条件
  70. * @param obj $pagesize 分页页数
  71. * @param str $orderby 排序
  72. * @return array 二维数组
  73. */
  74. public function getAdvpositionList($condition = array(), $pagesize = '', $orderby = 'ap_id desc')
  75. {
  76. if ($pagesize) {
  77. $result = Db::name('advposition')->where($condition)->order($orderby)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  78. $this->page_info = $result;
  79. return $result->items();
  80. } else {
  81. return Db::name('advposition')->where($condition)->order($orderby)->select()->toArray();
  82. }
  83. }
  84. public function getOneAdvposition($condition = array())
  85. {
  86. return Db::name('advposition')->where($condition)->find();
  87. }
  88. public function getOneAdv($condition = array())
  89. {
  90. return Db::name('adv')->where($condition)->find();
  91. }
  92. /**
  93. * 根据条件查询多条记录
  94. * @author csdeshang
  95. * @param array $condition 查询条件
  96. * @param obj $pagesize 分页页数
  97. * @param int $limit 数量限制
  98. * @param str $orderby 排序
  99. * @return array 二维数组
  100. */
  101. public function getAdvList($condition = array(), $pagesize = '', $limit = 0, $orderby = 'adv_id desc')
  102. {
  103. if ($pagesize) {
  104. $result = Db::name('adv')->where($condition)->order($orderby)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  105. $this->page_info = $result;
  106. return $result->items();
  107. } else {
  108. return Db::name('adv')->where($condition)->order($orderby)->select()->toArray();
  109. }
  110. }
  111. /**
  112. * 手机端广告位获取
  113. * @author csdeshang
  114. * @param array $condition 条件
  115. * @param str $orderby 排序
  116. * @return array
  117. */
  118. public function mbadvlist($condition, $orderby = 'adv_sort desc')
  119. {
  120. return Db::name('adv')->alias('a')->join('advposition n', 'a.ap_id=n.ap_id')->where($condition)->order($orderby)->select()->toArray();
  121. }
  122. /**
  123. * 更新记录
  124. * @author csdeshang
  125. * @param array $data 更新内容
  126. * @return bool
  127. */
  128. public function editAdv($adv_id, $data)
  129. {
  130. $adv_array = Db::name('adv')->where('adv_id', $adv_id)->find();
  131. if ($adv_array) {
  132. // drop cache
  133. $apId = (int) $adv_array['ap_id'];
  134. dkcache("adv/{$apId}");
  135. }
  136. return Db::name('adv')->where('adv_id', $adv_id)->update($data);
  137. }
  138. /**
  139. * 更新广告位记录
  140. * @author csdeshang
  141. * @param array $data 更新内容
  142. * @return bool
  143. */
  144. public function editAdvposition($ap_id, $data)
  145. {
  146. dkcache("adv/{$ap_id}");
  147. return Db::name('advposition')->where('ap_id', $ap_id)->update($data);
  148. }
  149. }