SuperSpikeController.class.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Controller;
  15. use Admin\Model\SuperSpikeModel;
  16. class SuperSpikeController extends CommonController{
  17. protected function _initialize(){
  18. parent::_initialize();
  19. $this->breadcrumb1='营销活动';
  20. $this->breadcrumb2='超值大牌活动';
  21. }
  22. public function index(){
  23. $model=new SuperSpikeModel();
  24. $data=$model->show_superspike_page();
  25. foreach($data['list'] as $key => $val)
  26. {
  27. $wait_goods = M('super_spike_goods')->where( array('super_spike_id' => $val['id'], 'state' => 0) )->count();
  28. $on_goods = M('super_spike_goods')->where( array('super_spike_id' => $val['id'], 'state' => 1) )->count();
  29. $val['wait_goods'] = $wait_goods;
  30. $val['on_goods'] = $on_goods;
  31. $data['list'][$key] = $val;
  32. }
  33. $this->assign('empty',$data['empty']);// 赋值数据集
  34. $this->assign('list',$data['list']);// 赋值数据集
  35. $this->assign('page',$data['page']);// 赋值分页输出
  36. $this->state = $state;
  37. $this->display();
  38. }
  39. public function add()
  40. {
  41. if(IS_POST){
  42. $data = array();
  43. $data['name'] = trim(I('post.name'));
  44. $data['begin_time'] = strtotime( I('post.begin_time') );
  45. $data['end_time'] = strtotime( I('post.end_time') );
  46. $data['add_time'] = time();
  47. $rs = M('super_spike')->add($data);
  48. if (!$rs) {
  49. $status = array('status'=>'back','message'=>'添加失败');
  50. $this->osc_alert($status);
  51. }
  52. $status = array('status'=>'success','message'=>'添加活动成功!','jump'=>U('SuperSpike/index'));
  53. $this->osc_alert($status);
  54. }
  55. $this->display();
  56. }
  57. public function shenhe()
  58. {
  59. $result = array('code' => 0);
  60. $id = I('get.id',0);
  61. $super_spike_goods = M('super_spike_goods')->where( array('id' => $id) )->find();
  62. if($super_spike_goods){
  63. $rs = M('super_spike_goods')->where(array('id' => $id) )->save( array('state' => 1) );
  64. if($rs) {
  65. M('goods')->where( array('goods_id' => $super_spike_goods['goods_id']) )->save( array('type' => 'super_spike','status' => 1) );
  66. $result['code'] = 1;
  67. echo json_encode($result);
  68. die();
  69. }
  70. }else {
  71. $result['msg'] = '非法操作';
  72. echo json_encode($result);
  73. die();
  74. }
  75. }
  76. public function activity_goods()
  77. {
  78. $id = I('get.id');
  79. $model=new SuperSpikeModel();
  80. $data=$model->show_superspikegoods_page($id);
  81. $this->assign('empty',$data['empty']);// 赋值数据集
  82. $this->assign('list',$data['list']);// 赋值数据集
  83. $this->assign('page',$data['page']);// 赋值分页输出
  84. $this->display();
  85. }
  86. /**
  87. 报名超值大牌活动
  88. **/
  89. public function take_superspike()
  90. {
  91. $id = I('get.id','0');
  92. $subject = M('super_spike')->where( array('id' => $id) )->find();
  93. $this->subject = $subject;
  94. $this->display();
  95. }
  96. /**
  97. 提交超值大牌
  98. **/
  99. public function sub_superspike()
  100. {
  101. $subject_id = I('get.id');
  102. $data = I('post.goods_ids_arr');
  103. $result = array('code' => 0);
  104. if( empty($data))
  105. {
  106. $result['msg'] = '未选中商品';
  107. echo json_encode($result);
  108. die();
  109. }
  110. $subject = M('super_spike')->where( array('id' => $subject_id) )->find();
  111. foreach($data as $goods_id)
  112. {
  113. $goods_info = M('goods')->field('store_id')->where( array('goods_id' => $goods_id) )->find();
  114. $super_data = array();
  115. $super_data['super_spike_id'] = $subject_id;
  116. $super_data['goods_id'] = $goods_id;
  117. $super_data['state'] = 1;
  118. $super_data['begin_time'] = $subject['begin_time'];
  119. $super_data['end_time'] = $subject['end_time'];
  120. $super_data['seller_id'] = $goods_info['store_id'];
  121. $super_data['addtime'] = time();
  122. $rs = M('super_spike_goods')->add($super_data);
  123. if($rs) {
  124. $up_data = array('type' =>'super_spike','status' => 1);
  125. M('goods')->where( array('goods_id' => $goods_id) )->save( $up_data );
  126. }
  127. }
  128. $result['code'] = 1;
  129. echo json_encode($result);
  130. die();
  131. }
  132. public function update()
  133. {
  134. $id = I('post.id');
  135. $data['name'] = trim(I('post.name'));
  136. $data['begin_time'] = strtotime( I('post.begin_time') );
  137. $data['end_time'] = strtotime( I('post.end_time') );
  138. $rs = M('super_spike')->where( array('id' => $id) )->save($data);
  139. M('super_spike_goods')->where( array('super_spike_id' => $id) )->save( array('begin_time' => $data['begin_time'], 'end_time' => $data['end_time']) );
  140. if (!$rs) {
  141. $status = array('status'=>'back','message'=>'编辑失败');
  142. $this->osc_alert($status);
  143. }
  144. $status = array('status'=>'success','message'=>'编辑活动成功!','jump'=>U('SuperSpike/index'));
  145. $this->osc_alert($status);
  146. }
  147. public function edit()
  148. {
  149. $id = I('get.id');
  150. $super_spike = M('super_spike')->where( array('id' => $id) )->find();
  151. $this->super_spike = $super_spike;
  152. $this->display();
  153. }
  154. }
  155. ?>