Appadv.php 4.7 KB

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