Sponsor.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. namespace app\operate\controller;
  3. use app\common\model\User;
  4. use library\Controller;
  5. use think\Db;
  6. /**
  7. * 主办方
  8. * Class Sponsor
  9. * @package app\operate\controller
  10. */
  11. class Sponsor extends Controller
  12. {
  13. protected $table = 'ActivitySponsor';
  14. /**
  15. * 列表
  16. * @auth true
  17. * @menu true
  18. * @throws \think\Exception
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. * @throws \think\exception\DbException
  22. * @throws \think\exception\PDOException
  23. */
  24. public function index()
  25. {
  26. $this->title = '列表';
  27. $where = [];
  28. $where[] = ['f.is_deleted','=',0];
  29. if($title = input('title')) $where[] = ['f.title','like','%'.$title.'%'];
  30. $query = $this->_query($this->table)->alias('f')
  31. ->field('f.*')
  32. ->where($where)
  33. ->order('sort desc,f.id asc')->page();
  34. }
  35. /**
  36. * 添加
  37. * @auth true
  38. * @menu true
  39. * @throws \think\Exception
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. * @throws \think\exception\DbException
  43. * @throws \think\exception\PDOException
  44. */
  45. public function add()
  46. {
  47. $this->title = '添加';
  48. $this->_form($this->table, 'form');
  49. }
  50. /**
  51. * 编辑
  52. * @auth true
  53. * @menu true
  54. * @throws \think\Exception
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. * @throws \think\exception\DbException
  58. * @throws \think\exception\PDOException
  59. */
  60. public function edit()
  61. {
  62. $this->title = '编辑';
  63. $this->_form($this->table, 'form');
  64. }
  65. /**
  66. * 删除
  67. * @auth true
  68. * @throws \think\Exception
  69. * @throws \think\exception\PDOException
  70. */
  71. public function del()
  72. {
  73. $this->_save($this->table, ['is_deleted' => '1']);
  74. }
  75. /**
  76. * 批量删除
  77. * @auth true
  78. * @throws \think\Exception
  79. * @throws \think\exception\PDOException
  80. */
  81. public function remove()
  82. {
  83. $this->_save($this->table, ['is_deleted' => '1']);
  84. }
  85. /**
  86. * 表单数据处理
  87. * @param array $data
  88. */
  89. protected function _form_filter(&$data)
  90. {
  91. if ($this->request->isGet() && $this->request->action() == 'add') {
  92. $this->isAddMode = 1;
  93. $this->ladder = [];
  94. }
  95. if ($this->request->isGet() && $this->request->action() == 'edit') {
  96. $this->isAddMode = 0;
  97. $this->ladder = isset_full($data,'ladder') ? json_decode($data['ladder'],true):[];
  98. }
  99. }
  100. /**
  101. * 报名记录
  102. * @auth true
  103. * @menu true
  104. * @throws \think\Exception
  105. * @throws \think\db\exception\DataNotFoundException
  106. * @throws \think\db\exception\ModelNotFoundException
  107. * @throws \think\exception\DbException
  108. * @throws \think\exception\PDOException
  109. */
  110. public function apply()
  111. {
  112. $id = $this->request->get('act_id');
  113. $name = $this->request->get('name');
  114. $phone = $this->request->get('phone');
  115. $this->title = '报名记录';
  116. $where = [];
  117. $where[]= ['a.act_id','=' ,$id];
  118. $where[]= ['a.is_deleted','=' ,0];
  119. $where[]= ['a.status','=' ,1];
  120. $where[]= ['a.status','=' ,1];
  121. if($name) $where[]= ['a.name','like' ,'%'.$name.'%'];
  122. if($phone) $where[]= ['a.phone','like' ,'%'.$phone.'%'];
  123. $query = $this->_query('activity_apply')
  124. ->alias('a')
  125. ->field('a.*,u.name user_name,u.headimg')
  126. ->where($where)
  127. ->leftJoin('store_member u','u.id = a.user_id')
  128. ->order('a.id desc')->page();
  129. $this->fetch();
  130. }
  131. /**
  132. * 上架
  133. * @auth true
  134. * @menu true
  135. * @throws \think\Exception
  136. * @throws \think\db\exception\DataNotFoundException
  137. * @throws \think\db\exception\ModelNotFoundException
  138. * @throws \think\exception\DbException
  139. * @throws \think\exception\PDOException
  140. */
  141. public function up()
  142. {
  143. $this->_save($this->table, ['status' => '1']);
  144. }
  145. /**
  146. * 取消
  147. * @auth true
  148. * @menu true
  149. * @throws \think\Exception
  150. * @throws \think\db\exception\DataNotFoundException
  151. * @throws \think\db\exception\ModelNotFoundException
  152. * @throws \think\exception\DbException
  153. * @throws \think\exception\PDOException
  154. */
  155. public function down()
  156. {
  157. $this->_save($this->table, ['status' => '2']);
  158. }
  159. public function export(){
  160. $id = $this->request->get('act_id');
  161. $name = $this->request->get('name');
  162. $phone = $this->request->get('phone');
  163. $this->title = '报名记录';
  164. $where = [];
  165. $where[]= ['a.act_id','=' ,$id];
  166. $where[]= ['a.is_deleted','=' ,0];
  167. $where[]= ['a.status','=' ,1];
  168. $where[]= ['a.status','=' ,1];
  169. if($name) $where[]= ['a.name','like' ,'%'.$name.'%'];
  170. if($phone) $where[]= ['a.phone','like' ,'%'.$phone.'%'];
  171. $data =Db::name('activity_apply')
  172. ->alias('a')
  173. ->field('a.*,u.name user_name,u.headimg')
  174. ->where($where)
  175. ->leftJoin('store_member u','u.id = a.user_id')
  176. ->order('a.id desc')->select();
  177. if(empty($data)) $this->error('暂无可以导出的数据');
  178. foreach ($data as $k=>&$v) {
  179. }
  180. $field=array(
  181. 'A' => array('order_no', '订单号'),
  182. 'B' => array('name', '联系人'),
  183. 'C' => array('phone', '电话'),
  184. 'D' => array('money','订单金额'),
  185. 'E' => array('num','人数'),
  186. 'F' => array('email','邮箱'),
  187. 'G' => array('create_at', '时间'),
  188. );
  189. $this->phpExcelList($field,$data,'报名列表');
  190. }
  191. public function phpExcelList($field=[],$list=[],$title='文件'){
  192. $PHPExcel=new \PHPExcel();
  193. $PHPSheet=$PHPExcel->getActiveSheet();
  194. $PHPSheet->setTitle('demo'); //给当前主办方sheet设置名称
  195. foreach($list as $key=>$value)
  196. {
  197. foreach($field as $k=>$v){
  198. if($key == 0){
  199. $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
  200. }
  201. $i=$key+2;
  202. $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
  203. }
  204. }
  205. $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
  206. header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
  207. header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
  208. header('Cache-Control: max-age=0'); //禁止缓存
  209. $PHPWriter->save("php://output"); //输出到浏览器
  210. }
  211. protected function _form_result(&$data)
  212. {
  213. $this->success('操作成功', 'javascript:history.back()');
  214. }
  215. }