Adv.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\model\web;
  13. use think\facade\Cache;
  14. use app\model\BaseModel;
  15. use app\model\upload\Upload;
  16. /**
  17. * 广告管理
  18. * @author Administrator
  19. *
  20. */
  21. class Adv extends BaseModel
  22. {
  23. /**
  24. * 添加广告
  25. * @param array $data
  26. */
  27. public function addAdv($data)
  28. {
  29. $ap_id = model('adv')->add($data);
  30. Cache::tag("adv")->clear();
  31. return $this->success($ap_id);
  32. }
  33. /**
  34. * 修改广告
  35. * @param array $data
  36. */
  37. public function editAdv($data, $condition)
  38. {
  39. if (isset($data[ 'adv_image' ])) {
  40. $adv_info = model('adv')->getInfo($condition);
  41. if ($adv_info[ 'adv_image' ] && $data[ 'adv_image' ] && $adv_info[ 'adv_image' ] != $data[ 'adv_image' ]) {
  42. $upload_model = new Upload();
  43. $upload_model->deletePic($adv_info[ 'adv_image' ], $adv_info[ 'site_id' ]);
  44. }
  45. }
  46. $res = model('adv')->update($data, $condition);
  47. Cache::tag("adv")->clear();
  48. return $this->success($res);
  49. }
  50. /**
  51. * 删除广告
  52. * @param array $condition
  53. */
  54. public function deleteAdv($condition)
  55. {
  56. $list = model('adv')->getList($condition);
  57. if ($list) {
  58. foreach ($list as $k => $v) {
  59. if ($v[ 'adv_image' ]) {
  60. $upload_model = new Upload();
  61. $upload_model->deletePic($v[ 'adv_image' ], $v[ 'site_id' ]);
  62. }
  63. }
  64. }
  65. $res = model('adv')->delete($condition);
  66. Cache::tag("adv")->clear();
  67. return $this->success($res);
  68. }
  69. /**
  70. * 获取广告基础信息
  71. * @param int $ap_id
  72. * @return multitype:string mixed
  73. */
  74. public function getAdvInfo($ap_id)
  75. {
  76. $cache = Cache::get("adv_getAdvInfo_" . $ap_id);
  77. if (!empty($cache)) {
  78. return $this->success($cache);
  79. }
  80. $res = model('adv')->getInfo([ [ 'adv_id', '=', $ap_id ] ], 'adv_id, adv_title, ap_id, adv_url, adv_image, slide_sort, price, background,state');
  81. Cache::tag("adv")->set("adv_getAdvInfo_" . $ap_id, $res);
  82. return $this->success($res);
  83. }
  84. /**
  85. * 获取广告列表
  86. * @param array $condition
  87. * @param string $field
  88. * @param string $order
  89. * @param string $limit
  90. */
  91. public function getAdvList($condition = [], $field = 'adv_id, adv_title, ap_id, adv_url, adv_image, slide_sort, price, background', $order = 'slide_sort desc,adv_id desc', $limit = null)
  92. {
  93. $data = json_encode([ $condition, $field, $order, $limit ]);
  94. $cache = Cache::get("adv_getAdvList_" . $data);
  95. if (!empty($cache)) {
  96. return $this->success($cache);
  97. }
  98. $list = model('adv')->getList($condition, $field, $order, '', '', '', $limit);
  99. Cache::tag("adv")->set("adv_getAdvList_" . $data, $list);
  100. return $this->success($list);
  101. }
  102. /**
  103. * 获取广告分页列表
  104. * @param array $condition
  105. * @param number $page
  106. * @param string $page_size
  107. * @param string $order
  108. * @param string $field
  109. */
  110. public function getAdvPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'a.adv_id desc', $field = 'a.adv_id, a.ap_id, a.adv_title, a.adv_url, a.adv_image, a.slide_sort, a.price, a.background, a.state, ap.ap_name')
  111. {
  112. $data = json_encode([ $condition, $field, $order, $page, $page_size ]);
  113. $cache = Cache::get("adv_getAdvPageList_" . $data);
  114. if (!empty($cache)) {
  115. return $this->success($cache);
  116. }
  117. $join = [
  118. [
  119. 'adv_position ap',
  120. 'a.ap_id = ap.ap_id',
  121. 'left'
  122. ]
  123. ];
  124. $list = model('adv')->pageList($condition, $field, $order, $page, $page_size, 'a', $join);
  125. Cache::tag("adv")->set("adv_getAdvPageList_" . $data, $list);
  126. return $this->success($list);
  127. }
  128. }