VoucherController.class.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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\VoucherModel;
  16. class VoucherController extends CommonController{
  17. protected function _initialize(){
  18. parent::_initialize();
  19. $this->breadcrumb1='平台优惠券';
  20. $this->breadcrumb2='平台券管理';
  21. }
  22. public function index(){
  23. $model=new VoucherModel();
  24. $data=$model->show_voucher_class_page(0);
  25. $this->assign('empty',$data['empty']);// 赋值数据集
  26. $this->assign('list',$data['list']);// 赋值数据集
  27. $this->assign('page',$data['page']);// 赋值分页输出
  28. $this->type = 0;
  29. $this->display();
  30. }
  31. function free_config()
  32. {
  33. $voucher_free_state_info = M('config')->where( array('name' => 'VOUCHER_FREE_STATE') )->find();
  34. $voucher_free_desc_info = M('config')->where( array('name' => 'VOUCHER_FREE_DESC') )->find();
  35. $voucher_free_image_info = M('config')->where( array('name' => 'VOUCHER_FREE_IMAGE') )->find();
  36. if(IS_POST){
  37. //value
  38. M('config')->where( array('name' => 'VOUCHER_FREE_STATE') )->save( array('value' => I('post.voucher_free_state')) );
  39. M('config')->where( array('name' => 'VOUCHER_FREE_DESC') )->save( array('value' => I('post.voucher_free_desc')) );
  40. M('config')->where( array('name' => 'VOUCHER_FREE_IMAGE') )->save( array('value' => I('post.voucher_free_image')) );
  41. $return = array(
  42. 'status'=>'success',
  43. 'message'=>'编辑成功',
  44. 'jump'=>U('Voucher/free_config')
  45. );
  46. $this->osc_alert($return);
  47. die();
  48. }
  49. $this->voucher_free_state_info = $voucher_free_state_info;
  50. $this->voucher_free_desc_info = $voucher_free_desc_info;
  51. $this->voucher_free_image_info = $voucher_free_image_info;
  52. $this->type = 1;
  53. $this->crumbs='免单券配置';
  54. $this->action=U('Voucher/free_config');
  55. $this->display('free_config');
  56. }
  57. function add(){
  58. if(IS_POST){
  59. $model=new VoucherModel();
  60. $data=I('post.');
  61. $data['store_id'] = 0;
  62. $data['type'] = 1;
  63. if( empty($data['voucher_title']) ) {
  64. $status = array('status'=>'back','message'=>'优惠券名称不能为空');
  65. $this->osc_alert($status);
  66. }
  67. if( empty($data['credit']) ) {
  68. $status = array('status'=>'back','message'=>'优惠券金额不能为空');
  69. $this->osc_alert($status);
  70. }
  71. if( empty($data['total_count']) ) {
  72. $status = array('status'=>'back','message'=>'可领取人数不能为空');
  73. $this->osc_alert($status);
  74. }
  75. $return=$model->add_voucher($data);
  76. $this->osc_alert($return);
  77. die();
  78. }
  79. $this->crumbs='新增';
  80. $this->action=U('Voucher/add');
  81. $this->display('edit');
  82. }
  83. public function membersend()
  84. {
  85. $id = I('get.id');
  86. $voucher_info = M('voucher')->where( array('id' => $id) )->find();
  87. $this->id = $id;
  88. $this->data = $voucher_info;
  89. $this->display();
  90. }
  91. /**
  92. * 上传会员Excel批量赠送优惠券
  93. */
  94. function sendvoucher_tomember_excel_done()
  95. {
  96. set_time_limit(0);
  97. $voucher_id = I('get.voucher_id');
  98. if(isset($_FILES["file"]) && ($_FILES["file"]["error"] == 0)){
  99. $excel_dir = ROOT_PATH.'Uploads/image/'.date('Y-m-d');
  100. $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
  101. RecursiveMkdir( $excel_dir );
  102. $path = $excel_dir.'/'.md5($_FILES['file']['name'].mt_rand(1, 999)).'.'.$extension;
  103. $rs = move_uploaded_file($_FILES["file"]["tmp_name"],$path);
  104. $voucher_model = D('Home/Voucher');
  105. $notify_model = D('Home/Weixinnotify');
  106. $result = importExecl($path);
  107. if(!empty($result)) {
  108. foreach($result as $member)
  109. {
  110. $member_id = $member[0];
  111. $res = $voucher_model->send_user_voucher_byId($voucher_id,$member_id,$check_count =false);
  112. if($res == 3)
  113. {
  114. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  115. $notify_model->send_quan_template_msg($member_info['openid'],$voucher_id);
  116. //$quan_msg_info = M('config')->where( array('name' => 'sendQuanNotice') )->find();
  117. //send_quan_template_msg($openid,$voucher_id)
  118. //发送成功,发送模板消息 Weixinnotify
  119. //send_template_msg($template_data,$url,$to_openid,$template_id)
  120. }
  121. }
  122. }
  123. }
  124. echo json_encode( array('code' => 1) );
  125. die();
  126. }
  127. public function voucherlist()
  128. {
  129. $id = I('get.id');
  130. $model=new VoucherModel();
  131. $data=$model->show_voucher_list_page($id);
  132. $voucher_info = M('voucher')->where( array('id' => $id) )->find();
  133. $this->voucher_info = $voucher_info;
  134. $this->assign('empty',$data['empty']);// 赋值数据集
  135. $this->assign('list',$data['list']);// 赋值数据集
  136. $this->assign('page',$data['page']);// 赋值分页输出
  137. $this->display();
  138. }
  139. public function del(){
  140. $id = I('get.id');
  141. $model=new VoucherModel();
  142. $return=$model->del_voucher($id);
  143. $this->osc_alert($return);
  144. }
  145. }
  146. ?>