AdvimgController.class.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author J_da
  7. *
  8. */
  9. namespace Seller\Controller;
  10. class AdvimgController extends CommonController{
  11. protected function _initialize(){
  12. parent::_initialize();
  13. $this->breadcrumb1='广告图片';
  14. $this->breadcrumb2='广告列表';
  15. $this->sellerid = SELLERUID;
  16. }
  17. /**
  18. * 广告列表
  19. */
  20. public function index()
  21. {
  22. $_GPC = I('request.');
  23. $this->gpc = $_GPC;
  24. $condition = ' 1 ';
  25. $pindex = max(1, intval($_GPC['page']));
  26. $psize = 20;
  27. $time = $_GPC['time'];
  28. if (!empty($_GPC['keyword'])) {
  29. $_GPC['keyword'] = trim($_GPC['keyword']);
  30. $condition .= ' and adv_name like "%'.$_GPC['keyword'].'%" ';
  31. }
  32. if (isset($_GPC['enabled']) && trim($_GPC['enabled']) != '') {
  33. $_GPC['enabled'] = trim($_GPC['enabled']);
  34. $condition .= ' and enabled = ' . $_GPC['enabled'];
  35. }
  36. $label = M('lionfish_comshop_advimg')->where( $condition )->order(' displayorder desc ')->limit( (($pindex - 1) * $psize) . ',' . $psize )->select();
  37. $total = M('lionfish_comshop_advimg')->where( $condition )->count();
  38. $pager = pagination2($total, $pindex, $psize);
  39. $this->label = $label;
  40. $this->pager = $pager;
  41. $this->display();
  42. }
  43. /**
  44. * 添加广告
  45. */
  46. public function add(){
  47. $_GPC = I('request.');
  48. if (IS_POST) {
  49. $data = $_GPC['data'];
  50. if(empty($data['thumb'])){
  51. show_json(0, array('message' => '广告图片不能为空'));
  52. }
  53. if(empty($data['link']) && $data['linktype']<3){
  54. show_json(0, array('message' => '广告链接不能为空'));
  55. }
  56. D('Seller/Advimg')->update($_GPC);
  57. show_json(1, array('url' => U('advimg/add')));
  58. }
  59. // $id = intval($_GPC['id']);
  60. $id = M('lionfish_comshop_advimg')->field('id')->order('id desc')->find();
  61. $item = '';
  62. if (!empty($id)) {
  63. $item = M('lionfish_comshop_advimg')->where( $id )->find();
  64. $item['pos'] = explode(',', $item['pos']);
  65. }
  66. $category = D('Seller/GoodsCategory')->getFullCategory(false, true);
  67. $this->category = $category;
  68. $this->item = $item;
  69. $this->display();
  70. }
  71. /**
  72. * 更新弹窗广告状态
  73. */
  74. public function change_status(){
  75. $_GPC = I('request.');
  76. $id = intval($_GPC['id']);
  77. if (empty($id)) {
  78. $id = $_GPC['ids'];
  79. }
  80. if( is_array($id) )
  81. {
  82. M('lionfish_comshop_advimg')->where( array('id' => array('in', $id)) )->save( array('enabled' => intval($_GPC['enabled'])) );
  83. }else{
  84. M('lionfish_comshop_advimg')->where( array('id' =>$id ) )->save( array('enabled' => intval($_GPC['enabled'])) );
  85. }
  86. show_json(1, array('url' => U('advimg/index')));
  87. }
  88. /**
  89. * 删除弹窗广告
  90. */
  91. public function delete(){
  92. $_GPC = I('request.');
  93. $id = intval($_GPC['id']);
  94. if (empty($id)) {
  95. $id = $_GPC['ids'];
  96. }
  97. if( is_array($id) )
  98. {
  99. M('lionfish_comshop_advimg')->where( array('id' => array('in', $id)) )->delete();
  100. }else{
  101. M('lionfish_comshop_advimg')->where( array('id' =>$id ) )->delete();
  102. }
  103. show_json(1, array('url' => U('advimg/index')));
  104. }
  105. }
  106. ?>