Adv.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 Adv extends BaseModel {
  16. public $page_info;
  17. /**
  18. * 新增广告位
  19. * @author csdeshang
  20. * @param array $data 参数内容
  21. * @return bool 布尔类型的返回结果
  22. */
  23. public function addAdvposition($data) {
  24. return Db::name('advposition')->insertGetId($data);
  25. }
  26. /**
  27. * 新增广告
  28. * @author csdeshang
  29. * @param array $data 参数内容
  30. * @return bool 布尔类型的返回结果
  31. */
  32. public function addAdv($data) {
  33. $result = Db::name('adv')->insertGetId($data);
  34. $apId = (int) $data['ap_id'];
  35. dkcache("adv/{$apId}");
  36. return $result;
  37. }
  38. /**
  39. * 删除一条广告
  40. * @author csdeshang
  41. * @param array $adv_id 广告id
  42. * @return bool 布尔类型的返回结果
  43. */
  44. public function delAdv($adv_id) {
  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. $apId = (int) $ap_id;
  62. dkcache("adv/{$apId}");
  63. return Db::name('advposition')->where('ap_id', $apId)->delete();
  64. }
  65. /**
  66. * 获取广告位列表
  67. * @author csdeshang
  68. * @param array $condition 查询条件
  69. * @param obj $pagesize 分页页数
  70. * @param str $orderby 排序
  71. * @return array 二维数组
  72. */
  73. public function getAdvpositionList($condition = array(), $pagesize = '', $orderby = 'ap_id desc') {
  74. if ($pagesize) {
  75. $result = Db::name('advposition')->where($condition)->order($orderby)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  76. $this->page_info = $result;
  77. return $result->items();
  78. } else {
  79. return Db::name('advposition')->where($condition)->order($orderby)->select()->toArray();
  80. }
  81. }
  82. public function getOneAdvposition($condition = array()) {
  83. return Db::name('advposition')->where($condition)->find();
  84. }
  85. public function getOneAdv($condition = array()) {
  86. return Db::name('adv')->where($condition)->find();
  87. }
  88. /**
  89. * 根据条件查询多条记录
  90. * @author csdeshang
  91. * @param array $condition 查询条件
  92. * @param obj $pagesize 分页页数
  93. * @param int $limit 数量限制
  94. * @param str $orderby 排序
  95. * @return array 二维数组
  96. */
  97. public function getAdvList($condition = array(), $pagesize = '', $limit = 0, $orderby = 'adv_id desc') {
  98. if ($pagesize) {
  99. $result = Db::name('adv')->where($condition)->order($orderby)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  100. $this->page_info = $result;
  101. return $result->items();
  102. } else {
  103. return Db::name('adv')->where($condition)->order($orderby)->select()->toArray();
  104. }
  105. }
  106. /**
  107. * 手机端广告位获取
  108. * @author csdeshang
  109. * @param array $condition 条件
  110. * @param str $orderby 排序
  111. * @return array
  112. */
  113. public function mbadvlist($condition,$orderby='adv_sort desc'){
  114. return Db::name('adv')->alias('a')->join('advposition n','a.ap_id=n.ap_id')->where($condition)->order($orderby)->select()->toArray();
  115. }
  116. /**
  117. * 更新记录
  118. * @author csdeshang
  119. * @param array $data 更新内容
  120. * @return bool
  121. */
  122. public function editAdv($adv_id,$data) {
  123. $adv_array = Db::name('adv')->where('adv_id', $adv_id)->find();
  124. if ($adv_array) {
  125. // drop cache
  126. $apId = (int) $adv_array['ap_id'];
  127. dkcache("adv/{$apId}");
  128. }
  129. return Db::name('adv')->where('adv_id', $adv_id)->update($data);
  130. }
  131. /**
  132. * 更新广告位记录
  133. * @author csdeshang
  134. * @param array $data 更新内容
  135. * @return bool
  136. */
  137. public function editAdvposition($ap_id,$data) {
  138. dkcache("adv/{$ap_id}");
  139. return Db::name('advposition')->where('ap_id', $ap_id)->update($data);
  140. }
  141. }
  142. ?>