LotteryController.class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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\LotteryModel;
  16. class LotteryController extends CommonController{
  17. protected function _initialize(){
  18. parent::_initialize();
  19. $this->breadcrumb1='营销活动';
  20. $this->breadcrumb2='抽奖活动';
  21. }
  22. public function index(){
  23. $model=new LotteryModel();
  24. $state = I('get.state',0);
  25. $where = ' and sg.state='.$state;
  26. if($state == 1) {
  27. // $where .= ' and end_time > '.time();
  28. }
  29. $data=$model->show_lottery_page($where);
  30. $this->assign('empty',$data['empty']);// 赋值数据集
  31. $this->assign('list',$data['list']);// 赋值数据集
  32. $this->assign('page',$data['page']);// 赋值分页输出
  33. $this->state = $state;
  34. $this->display();
  35. }
  36. public function addGoods()
  37. {
  38. $voucher_list = M('voucher')->where( "store_id=0 and end_time>".time() )->select();
  39. $this->voucher_list = $voucher_list;
  40. $this->display('lottery');
  41. }
  42. /**
  43. 提交抽奖活动申请
  44. **/
  45. public function sub_lottery()
  46. {
  47. $voucher_id = I('post.voucher_id',0);
  48. $win_quantity = I('post.win_quantity',0);
  49. $is_auto_open = I('post.is_auto_open',0);
  50. $real_win_quantity = I('post.real_win_quantity',0);
  51. $result = array('code' => 0);
  52. $data = I('post.goods_ids_arr');
  53. if($voucher_id == 0){
  54. $result['msg'] = '请选择退款时赠送的优惠券';
  55. echo json_encode($result);
  56. die();
  57. }
  58. foreach($data as $goods_id)
  59. {
  60. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  61. //seller_id store_id
  62. $spike_data = array();
  63. $spike_data['goods_id'] = $goods_id;
  64. $spike_data['state'] = 0;
  65. $spike_data['is_open_lottery'] = 0;
  66. $spike_data['voucher_id'] = $voucher_id;
  67. $spike_data['win_quantity'] = $win_quantity;
  68. $spike_data['is_auto_open'] = $is_auto_open;
  69. $spike_data['real_win_quantity'] = $real_win_quantity;
  70. $spike_data['quantity'] = $goods_info['quantity'];
  71. $spike_data['begin_time'] = 0;
  72. $spike_data['end_time'] = 0;
  73. $spike_data['seller_id'] = $goods_info['store_id'];
  74. $spike_data['addtime'] = time();
  75. $rs = M('lottery_goods')->add($spike_data);
  76. if($rs) {
  77. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'lottery', 'status' => 0) );
  78. }
  79. }
  80. $result['code'] = 1;
  81. echo json_encode($result);
  82. die();
  83. }
  84. public function shenhe()
  85. {
  86. $result = array('code' => 0);
  87. $goods_id = I('get.goods_id',0);
  88. $id = I('get.id',0);
  89. $begin_time = I('post.begin_time');
  90. $end_time = I('post.end_time');
  91. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  92. if(empty($goods_info)) {
  93. $result['msg'] = '该商品已删除';
  94. echo json_encode($result);
  95. die();
  96. } else if($goods_info['quantity'] ==0){
  97. $result['msg'] = '该商品库存不足';
  98. echo json_encode($result);
  99. die();
  100. } else{
  101. $data = array();
  102. $data['state'] = 1;
  103. $data['begin_time'] = strtotime($begin_time);
  104. $data['end_time'] = strtotime($end_time);
  105. $rs = M('lottery_goods')->where( array('id' => $id) )->save($data);
  106. if($rs) {
  107. //begin_time end_time
  108. M('pin_goods')->where( array('goods_id' =>$goods_id) )
  109. ->save( array('begin_time' =>strtotime($begin_time),'end_time' => strtotime($end_time) ) );
  110. $goods_data = array();
  111. $goods_data['type'] = 'lottery';
  112. $goods_data['lock_type'] = 'lottery';
  113. $goods_data['status'] = 1;
  114. $grs = M('goods')->where( array('goods_id' => $goods_id) )->save($goods_data);
  115. if($grs) {
  116. $result['code'] = 1;
  117. echo json_encode($result);
  118. die();
  119. }
  120. }
  121. }
  122. }
  123. }
  124. ?>