SpikeController.class.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. * ==========================================================================
  6. * @link https://www.nanodreamtech.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.nanodreamtech.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Controller;
  15. use Admin\Model\SpikeModel;
  16. class SpikeController extends CommonController{
  17. protected function _initialize(){
  18. parent::_initialize();
  19. $this->breadcrumb1='营销活动';
  20. $this->breadcrumb2='限时秒杀活动商品';
  21. }
  22. public function index(){
  23. $model=new SpikeModel();
  24. $data=$model->show_spike_page();
  25. foreach($data['list'] as $key => $val)
  26. {
  27. $wait_goods = M('spike_goods')->where( array('spike_id' => $val['id'], 'state' => 0) )->count();
  28. $on_goods = M('spike_goods')->where( array('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->display();
  37. }
  38. /**
  39. 限时秒杀
  40. **/
  41. public function take_spike()
  42. {
  43. $id = I('get.id','0');
  44. $subject = M('spike')->where( array('id' => $id) )->find();
  45. $this->subject = $subject;
  46. $this->display();
  47. }
  48. /**
  49. * 切换审核状态
  50. */
  51. function toggle_statues_show()
  52. {
  53. $id = I('post.gid',0);
  54. $spike_info =M('Spike')->where( array('id' => $id) )->find();
  55. $status = $spike_info['is_best'] == 1 ? 0: 1;
  56. $res = M('Spike')->where( array('id' => $id) )->save( array('is_best' => $status) );
  57. echo json_encode( array('code' => 1) );
  58. die();
  59. }
  60. /**
  61. 提交限时秒杀
  62. **/
  63. public function sub_spike()
  64. {
  65. $subject_id = I('get.id');
  66. $data = I('post.goods_ids_arr');
  67. $result = array('code' => 0);
  68. if( empty($data))
  69. {
  70. $result['msg'] = '未选中商品';
  71. echo json_encode($result);
  72. die();
  73. }
  74. $subject = M('spike')->where( array('id' => $subject_id) )->find();
  75. foreach($data as $goods_id)
  76. {
  77. $goods_info = M('goods')->field('store_id')->where( array('goods_id' => $goods_id) )->find();
  78. $super_data = array();
  79. $super_data['spike_id'] = $subject_id;
  80. $super_data['goods_id'] = $goods_id;
  81. $super_data['state'] = 1;
  82. $super_data['begin_time'] = $subject['begin_time'];
  83. $super_data['end_time'] = $subject['end_time'];
  84. $super_data['seller_id'] = $goods_info['store_id'];
  85. $super_data['addtime'] = time();
  86. $rs = M('spike_goods')->add($super_data);
  87. if($rs) {
  88. $up_data = array('type' =>'spike','status' => 1);
  89. M('goods')->where( array('goods_id' => $goods_id) )->save( $up_data );
  90. }
  91. }
  92. $result['code'] = 1;
  93. echo json_encode($result);
  94. die();
  95. }
  96. public function add()
  97. {
  98. if(IS_POST){
  99. $data = array();
  100. $data['name'] = trim(I('post.name'));
  101. $data['begin_time'] = strtotime( I('post.begin_time') );
  102. $data['end_time'] = strtotime( I('post.end_time') );
  103. $data['add_time'] = time();
  104. $rs = M('spike')->add($data);
  105. if (!$rs) {
  106. $status = array('status'=>'back','message'=>'添加失败');
  107. $this->osc_alert($status);
  108. }
  109. $status = array('status'=>'success','message'=>'添加活动成功!','jump'=>U('Spike/index'));
  110. $this->osc_alert($status);
  111. }
  112. $this->display();
  113. }
  114. public function shenhe()
  115. {
  116. $result = array('code' => 0);
  117. $id = I('get.id',0);
  118. $spike_goods = M('spike_goods')->where( array('id' => $id) )->find();
  119. if($spike_goods){
  120. $rs = M('spike_goods')->where(array('id' => $id) )->save( array('state' => 1) );
  121. if($rs) {
  122. M('goods')->where( array('goods_id' => $spike_goods['goods_id']) )->save( array('type' => 'spike','status' =>1 ) );
  123. $result['code'] = 1;
  124. echo json_encode($result);
  125. die();
  126. }
  127. }else {
  128. $result['msg'] = '非法操作';
  129. echo json_encode($result);
  130. die();
  131. }
  132. }
  133. public function activity_goods()
  134. {
  135. $id = I('get.id');
  136. $model=new SpikeModel();
  137. $data=$model->show_spikegoods_page($id);
  138. $this->assign('empty',$data['empty']);// 赋值数据集
  139. $this->assign('list',$data['list']);// 赋值数据集
  140. $this->assign('page',$data['page']);// 赋值分页输出
  141. $this->display();
  142. }
  143. public function update()
  144. {
  145. $id = I('post.id');
  146. $data['name'] = trim(I('post.name'));
  147. $data['begin_time'] = strtotime( I('post.begin_time') );
  148. $data['end_time'] = strtotime( I('post.end_time') );
  149. $rs = M('spike')->where( array('id' => $id) )->save($data);
  150. M('spike_goods')->where( array('spike_id' => $id) )->save( array('begin_time' => $data['begin_time'], 'end_time' => $data['end_time']) );
  151. if (!$rs) {
  152. $status = array('status'=>'back','message'=>'编辑失败');
  153. $this->osc_alert($status);
  154. }
  155. $status = array('status'=>'success','message'=>'编辑限时秒杀成功!','jump'=>U('Spike/index'));
  156. $this->osc_alert($status);
  157. }
  158. public function edit()
  159. {
  160. $id = I('get.id');
  161. $spike = M('spike')->where( array('id' => $id) )->find();
  162. $this->spike = $spike;
  163. $this->display();
  164. }
  165. }
  166. ?>