Appadv.php 4.9 KB

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