Adv.php 4.9 KB

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