Adv.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 数据层模型
  15. */
  16. class Adv extends BaseModel {
  17. public $page_info;
  18. /**
  19. * 新增广告位
  20. * @author csdeshang
  21. * @param array $data 参数内容
  22. * @return bool 布尔类型的返回结果
  23. */
  24. public function addAdvposition($data) {
  25. return Db::name('advposition')->insertGetId($data);
  26. }
  27. /**
  28. * 新增广告
  29. * @author csdeshang
  30. * @param array $data 参数内容
  31. * @return bool 布尔类型的返回结果
  32. */
  33. public function addAdv($data) {
  34. $result = Db::name('adv')->insertGetId($data);
  35. $apId = (int) $data['ap_id'];
  36. dkcache("adv/{$apId}");
  37. return $result;
  38. }
  39. /**
  40. * 删除一条广告
  41. * @author csdeshang
  42. * @param array $adv_id 广告id
  43. * @return bool 布尔类型的返回结果
  44. */
  45. public function delAdv($adv_id) {
  46. $adv = Db::name('adv')->where('adv_id',$adv_id)->find();
  47. if ($adv) {
  48. // drop cache
  49. $apId = (int) $adv['ap_id'];
  50. dkcache("adv/{$apId}");
  51. }
  52. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ADV. DIRECTORY_SEPARATOR .$adv['adv_code']);
  53. return Db::name('adv')->where('adv_id',$adv_id)->delete();
  54. }
  55. /**
  56. * 删除一个广告位
  57. * @author csdeshang
  58. * @param array $ap_id 广告位id
  59. * @return bool 布尔类型的返回结果
  60. */
  61. public function delAdvposition($ap_id) {
  62. $apId = (int) $ap_id;
  63. dkcache("adv/{$apId}");
  64. return Db::name('advposition')->where('ap_id', $apId)->delete();
  65. }
  66. /**
  67. * 获取广告位列表
  68. * @author csdeshang
  69. * @param array $condition 查询条件
  70. * @param obj $pagesize 分页页数
  71. * @param str $orderby 排序
  72. * @return array 二维数组
  73. */
  74. public function getAdvpositionList($condition = array(), $pagesize = '', $orderby = 'ap_id desc') {
  75. if ($pagesize) {
  76. $result = Db::name('advposition')->where($condition)->order($orderby)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  77. $this->page_info = $result;
  78. return $result->items();
  79. } else {
  80. return Db::name('advposition')->where($condition)->order($orderby)->select()->toArray();
  81. }
  82. }
  83. public function getOneAdvposition($condition = array()) {
  84. return Db::name('advposition')->where($condition)->find();
  85. }
  86. public function getOneAdv($condition = array()) {
  87. return Db::name('adv')->where($condition)->find();
  88. }
  89. /**
  90. * 根据条件查询多条记录
  91. * @author csdeshang
  92. * @param array $condition 查询条件
  93. * @param obj $pagesize 分页页数
  94. * @param int $limit 数量限制
  95. * @param str $orderby 排序
  96. * @return array 二维数组
  97. */
  98. public function getAdvList($condition = array(), $pagesize = '', $limit = 0, $orderby = 'adv_id desc') {
  99. if ($pagesize) {
  100. $result = Db::name('adv')->where($condition)->order($orderby)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  101. $this->page_info = $result;
  102. return $result->items();
  103. } else {
  104. return Db::name('adv')->where($condition)->order($orderby)->select()->toArray();
  105. }
  106. }
  107. /**
  108. * 手机端广告位获取
  109. * @author csdeshang
  110. * @param array $condition 条件
  111. * @param str $orderby 排序
  112. * @return array
  113. */
  114. public function mbadvlist($condition,$orderby='adv_sort desc'){
  115. return Db::name('adv')->alias('a')->join('advposition n','a.ap_id=n.ap_id')->where($condition)->order($orderby)->select()->toArray();
  116. }
  117. /**
  118. * 更新记录
  119. * @author csdeshang
  120. * @param array $data 更新内容
  121. * @return bool
  122. */
  123. public function editAdv($adv_id,$data) {
  124. $adv_array = Db::name('adv')->where('adv_id', $adv_id)->find();
  125. if ($adv_array) {
  126. // drop cache
  127. $apId = (int) $adv_array['ap_id'];
  128. dkcache("adv/{$apId}");
  129. }
  130. return Db::name('adv')->where('adv_id', $adv_id)->update($data);
  131. }
  132. /**
  133. * 更新广告位记录
  134. * @author csdeshang
  135. * @param array $data 更新内容
  136. * @return bool
  137. */
  138. public function editAdvposition($ap_id,$data) {
  139. dkcache("adv/{$ap_id}");
  140. return Db::name('advposition')->where('ap_id', $ap_id)->update($data);
  141. }
  142. }
  143. ?>