Appadv.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 数据层模型
  14. */
  15. class Appadv extends BaseModel
  16. {
  17. /**
  18. * 获取APP广告位列表
  19. * @author csdeshang
  20. * @param array $condition 查询条件
  21. * @param int $pagesize 分页页数
  22. * @param str $orderby 排序
  23. * @return array 二维数组
  24. */
  25. public function getAppadvpositionList($condition = array(), $pagesize = '', $orderby = 'ap_id desc') {
  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. if ($pagesize) {
  45. $result = Db::name('appadv')->where($condition)->order($orderby)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  46. $this->page_info = $result;
  47. return $result->items();
  48. } else {
  49. return Db::name('appadv')->where($condition)->order($orderby)->select()->toArray();
  50. }
  51. }
  52. /**
  53. * 新增广告位
  54. * @author csdeshang
  55. * @param array $data 参数内容
  56. * @return bool 布尔类型的返回结果
  57. */
  58. public function addAppadvposition($data) {
  59. return Db::name('appadvposition')->insertGetId($data);
  60. }
  61. /**
  62. * 新增广告
  63. * @author csdeshang
  64. * @param array $data 参数内容
  65. * @return bool 布尔类型的返回结果
  66. */
  67. public function addAppadv($data) {
  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. dkcache("appadv/{$ap_id}");
  81. return Db::name('appadvposition')->where('ap_id', $ap_id)->update($data);
  82. }
  83. /**
  84. * 获取一个app广告位
  85. * @author csdeshang
  86. * @param array $condition 查询条件
  87. * @return array
  88. */
  89. public function getOneAppadvposition($condition = array()) {
  90. return Db::name('appadvposition')->where($condition)->find();
  91. }
  92. /**
  93. * 删除一个广告位
  94. * @author csdeshang
  95. * @param array $ap_id 参数内容
  96. * @return bool 布尔类型的返回结果
  97. */
  98. public function delAppadvposition($ap_id) {
  99. $apId = (int) $ap_id;
  100. dkcache("appadv/{$apId}");
  101. return Db::name('appadvposition')->where('ap_id', $apId)->delete();
  102. }
  103. /**
  104. * 获取一个广告位
  105. * @author csdeshang
  106. * @param array $condition 条件
  107. * @return type
  108. */
  109. public function getOneAppadv($condition = array()) {
  110. return Db::name('appadv')->where($condition)->find();
  111. }
  112. /**
  113. * 更新记录
  114. * @author csdeshang
  115. * @param array $data 更新内容
  116. * @return bool
  117. */
  118. public function editAppadv($adv_id,$data) {
  119. $adv_array = Db::name('appadv')->where('adv_id', $adv_id)->find();
  120. if ($adv_array) {
  121. // drop cache
  122. $apId = (int) $adv_array['ap_id'];
  123. dkcache("appadv/{$apId}");
  124. }
  125. return Db::name('appadv')->where('adv_id', $adv_id)->update($data);
  126. }
  127. /**
  128. * 删除一条广告
  129. * @author csdeshang
  130. * @param array $adv_id 广告位id
  131. * @return bool 布尔类型的返回结果
  132. */
  133. public function delAppadv($adv_id) {
  134. $adv = Db::name('appadv')->where('adv_id',$adv_id)->find();
  135. if ($adv) {
  136. // drop cache
  137. $apId = (int) $adv['ap_id'];
  138. dkcache("appadv/{$apId}");
  139. }
  140. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_APPADV. DIRECTORY_SEPARATOR .$adv['adv_code']);
  141. return Db::name('appadv')->where('adv_id',$adv_id)->delete();
  142. }
  143. }