SubjectController.class.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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\SubjectModel;
  16. class SubjectController extends CommonController{
  17. protected function _initialize(){
  18. parent::_initialize();
  19. $this->breadcrumb1='营销活动';
  20. $this->breadcrumb2='主题活动';
  21. $this->subjecttype = array('normal' => '正常活动',
  22. //'zeyuan' => '0元试用','niyuan' => '9.9元','oneyuan' => '1元购','haitao' => '海淘'
  23. );
  24. }
  25. public function index(){
  26. $model=new SubjectModel();
  27. $type = I('get.type','normal');
  28. $search = " where type = '{$type}'";
  29. $data=$model->show_subject_page($search);
  30. foreach($data['list'] as $key => $val)
  31. {
  32. $wait_goods = M('subject_goods')->where( array('subject_id' => $val['id'], 'state' => 0) )->count();
  33. $on_goods = M('subject_goods')->where( array('subject_id' => $val['id'], 'state' => 1) )->count();
  34. $val['wait_goods'] = $wait_goods;
  35. $val['on_goods'] = $on_goods;
  36. $data['list'][$key] = $val;
  37. }
  38. $this->assign('empty',$data['empty']);// 赋值数据集
  39. $this->assign('list',$data['list']);// 赋值数据集
  40. $this->assign('page',$data['page']);// 赋值分页输出
  41. $this->state = $state;
  42. $this->type = $type;
  43. $this->display();
  44. }
  45. function toggle_statues_show()
  46. {
  47. $id = I('post.gid',0);
  48. $goods_info =M('subject')->where( array('id' => $id) )->find();
  49. $is_hot = $goods_info['is_hot'] == 1 ? 0: 1;
  50. $res = M('subject')->where( array('id' => $id) )->save( array('is_hot' => $is_hot) );
  51. echo json_encode( array('code' => 1) );
  52. die();
  53. }
  54. public function add()
  55. {
  56. if(IS_POST){
  57. $data = array();
  58. $data['name'] = trim(I('post.name'));
  59. $data['type'] = I('post.type');
  60. $data['logo'] = trim(I('post.logo'));
  61. $data['banner'] = trim(I('post.banner'));
  62. $data['price'] =floatval(I('post.price'));
  63. $data['begin_time'] = strtotime( I('post.begin_time') );
  64. $data['end_time'] = strtotime( I('post.end_time') );
  65. $data['add_time'] = time();
  66. $rs = M('subject')->add($data);
  67. if (!$rs) {
  68. $status = array('status'=>'back','message'=>'添加失败');
  69. $this->osc_alert($status);
  70. }
  71. $status = array('status'=>'success','message'=>'添加活动成功!','jump'=>U('Subject/index'));
  72. $this->osc_alert($status);
  73. }
  74. $this->display();
  75. }
  76. /**
  77. 报名主题活动
  78. **/
  79. public function take_subject()
  80. {
  81. $id = I('get.id','0');
  82. $subject = M('subject')->where( array('id' => $id) )->find();
  83. $this->subject = $subject;
  84. $this->display();
  85. }
  86. /**
  87. 提交主题活动申请
  88. **/
  89. public function sub_subject()
  90. {
  91. $subject_id = I('get.id');
  92. $data = I('post.goods_ids_arr');
  93. $result = array('code' => 0);
  94. if( empty($data))
  95. {
  96. $result['msg'] = '未选中商品';
  97. echo json_encode($result);
  98. die();
  99. }
  100. $subject = M('subject')->where( array('id' => $subject_id) )->find();
  101. //type begin_time end_time price
  102. foreach($data as $goods_id)
  103. {
  104. $super_data = array();
  105. $goods_info = M('goods')->field('store_id')->where( array('goods_id' => $goods_id) )->find();
  106. $super_data['subject_id'] = $subject_id;
  107. $super_data['goods_id'] = $goods_id;
  108. $super_data['state'] = 1;
  109. $super_data['begin_time'] = $subject['begin_time'];
  110. $super_data['end_time'] = $subject['end_time'];
  111. $super_data['seller_id'] = $goods_info['store_id'];
  112. $super_data['addtime'] = time();
  113. $rs = M('subject_goods')->add($super_data);
  114. if($rs) {
  115. if($subject['type'] =='normal')
  116. {
  117. $subject['type'] = 'subject';
  118. }
  119. $up_data = array('type' =>$subject['type'],'status' => 1);
  120. M('goods')->where( array('goods_id' => $goods_id) )->save( $up_data );
  121. }
  122. }
  123. $result['code'] = 1;
  124. echo json_encode($result);
  125. die();
  126. }
  127. public function shenhe()
  128. {
  129. $result = array('code' => 0);
  130. $id = I('get.id',0);
  131. $subject_goods = M('subject_goods')->where( array('id' => $id) )->find();
  132. if($subject_goods){
  133. $subject = M('subject')->where( array('id' => $subject_goods['subject_id']) )->find();
  134. //`type` enum('normal','zeyuan','niyuan','oneyuan') DEFAULT NULL COMMENT
  135. //'活动类型,normal正常活动,zeyuan0元试用,niyuan9.9元,oneyuan1元购',
  136. if($subject['type'] =='normal'){
  137. $subject['type'] = 'subject';
  138. }
  139. $rs = M('subject_goods')->where(array('id' => $id) )->save( array('state' => 1) );
  140. if($rs) {
  141. $goods_arr = array('type' => $subject['type']);
  142. $goods_arr['status'] = 1;
  143. if($subject['price'] != -1){
  144. $goods_arr['lock_price'] = 1;
  145. $goods_arr['pinprice'] = $subject['price'];
  146. }
  147. M('goods')->where( array('goods_id' => $subject_goods['goods_id']) )->save( $goods_arr );
  148. $result['code'] = 1;
  149. echo json_encode($result);
  150. die();
  151. }
  152. }else {
  153. $result['msg'] = '非法操作';
  154. echo json_encode($result);
  155. die();
  156. }
  157. }
  158. public function activity_goods()
  159. {
  160. $id = I('get.id');
  161. $model=new SubjectModel();
  162. $data=$model->show_subjectgoods_page($id);
  163. $this->assign('empty',$data['empty']);// 赋值数据集
  164. $this->assign('list',$data['list']);// 赋值数据集
  165. $this->assign('page',$data['page']);// 赋值分页输出
  166. $this->display();
  167. }
  168. public function update()
  169. {
  170. $id = I('post.id');
  171. $data = array();
  172. $data['name'] = trim(I('post.name'));
  173. $data['logo'] = trim(I('post.logo'));
  174. $data['banner'] = trim(I('post.banner'));
  175. $data['type'] = I('post.type');
  176. $data['price'] =floatval(I('post.price'));
  177. $data['begin_time'] = strtotime( I('post.begin_time') );
  178. $data['end_time'] = strtotime( I('post.end_time') );
  179. $rs = M('subject')->where( array('id' => $id) )->save($data);
  180. if (!$rs) {
  181. $status = array('status'=>'back','message'=>'编辑失败');
  182. $this->osc_alert($status);
  183. }
  184. //subject_goods
  185. $up_data = array();
  186. $up_data['begin_time'] = strtotime( I('post.begin_time') );
  187. $up_data['end_time'] = strtotime( I('post.end_time') );
  188. //state
  189. $now_time = time();
  190. $state = 0;
  191. if( $now_time> $up_data['begin_time'] && $now_time < $up_data['end_time'])
  192. {
  193. $state = 1;
  194. }
  195. $up_data['state'] = $state;
  196. M('subject_goods')->where( array('subject_id' => $id) )->save($up_data);
  197. if($state == 0)
  198. {
  199. //下架
  200. $subject_goods = M('subject_goods')->where( array('subject_id' => $id) )->select();
  201. foreach($subject_goods as $sub_goods)
  202. {
  203. M('goods')->where( array('goods_id' => $sub_goods['goods_id']) )->save( array('status' => 0) );
  204. }
  205. }
  206. if($data['price'] != -1){
  207. $goods_arr = array();
  208. $goods_arr['lock_price'] = 1;
  209. $goods_arr['pinprice'] = $subject['price'];
  210. $subject_goods = M('subject_goods')->where( array('subject_id' => $id) )->select();
  211. foreach($subject_goods as $sub_goods)
  212. {
  213. M('goods')->where( array('goods_id' => $sub_goods['goods_id']) )->save( $goods_arr );
  214. }
  215. }
  216. $status = array('status'=>'success','message'=>'编辑活动成功!','jump'=>U('Subject/index', array('type' =>$data['type'])));
  217. $this->osc_alert($status);
  218. }
  219. public function edit()
  220. {
  221. $id = I('get.id');
  222. $subject = M('subject')->where( array('id' => $id) )->find();
  223. $this->subject = $subject;
  224. $this->display();
  225. }
  226. }
  227. ?>