Award.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. namespace app\admin\controller;
  3. use think\admin\Controller;
  4. use think\admin\extend\DataExtend;
  5. use think\admin\helper\QueryHelper;
  6. use think\admin\service\AdminService;
  7. use think\admin\service\MenuService;
  8. use think\admin\service\NodeService;
  9. /**
  10. * 奖品订单管理
  11. * Class Menu
  12. * @package app\admin\controller
  13. */
  14. class Award extends Controller
  15. {
  16. /**
  17. * 当前操作数据库
  18. * @var string
  19. */
  20. private $table = 'Order';
  21. /**
  22. * 排行榜前50名
  23. * @auth true
  24. * @menu true
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\DbException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. */
  29. public function index()
  30. {
  31. $this->_query('UserTaskLog')->layTable(function (){
  32. $this->title = '排行榜前50名';
  33. $this->type = input('type', 'award');
  34. },function (QueryHelper $query){
  35. $query->alias('l')
  36. ->leftJoin('awards_order o', 'o.uid = l.uid')
  37. ->leftJoin('awards_user_info u', 'l.uid = u.uid')
  38. ->leftJoin('awards_gift g', 'o.gift_id = g.id')
  39. ->field(['l.id', 'l.uid', 'u.nickname', 'o.name', 'o.mobile', 'o.address', 'g.name as giftName', 'FROM_UNIXTIME(o.create_at) as createAt'])
  40. ->distinct('l.uid')
  41. ->order('l.number', 'desc')
  42. ->order('l.duration', 'asc')->limit(50);
  43. $query->equal('o.uid')->like('u.nickname');
  44. });
  45. }
  46. /**
  47. * 导出排行榜前50名
  48. * @auth true
  49. * @menu true
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\DbException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. */
  54. public function award()
  55. {
  56. $data = $this->app->db->name('UserTaskLog')->alias('l')
  57. ->leftJoin('awards_order o', 'o.uid = l.uid')
  58. ->leftJoin('awards_user_info u', 'o.uid = u.uid')
  59. ->leftJoin('awards_gift g', 'o.gift_id = g.id')
  60. ->field(['o.id', 'l.uid', 'u.nickname', 'o.name', 'o.mobile', 'o.address', 'g.name as giftName', 'FROM_UNIXTIME(o.create_at) as createAt'])
  61. ->order('l.number', 'desc')
  62. ->order('l.duration', 'asc')->select();
  63. //实例化
  64. $objExcel = new \PHPExcel();
  65. //设置文档属性
  66. $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
  67. //设置内容
  68. $objActSheet = $objExcel->getActiveSheet();
  69. $letter = explode(',', "A,B,C,D,E,F,G");
  70. $arrHeader = ['微博UID', '微博昵称', '收件人姓名', '联系人电话', '收件地址', '奖品名称','中奖时间'];
  71. //填充表头信息
  72. $lenth = count($arrHeader);
  73. for ($i = 0; $i < $lenth; $i++) {
  74. $objActSheet->setCellValue("$letter[$i]1", "$arrHeader[$i]");
  75. };
  76. //填充表格信息
  77. foreach ($data as $k => $v) {
  78. $k += 2;
  79. //表格内容
  80. $objActSheet->setCellValue('A' . $k, $v['uid']." ");
  81. $objActSheet->setCellValue('B' . $k, $v['nickname']);
  82. $objActSheet->setCellValue('C' . $k, $v['name']);
  83. $objActSheet->setCellValue('D' . $k, $v['mobile']." ");
  84. $objActSheet->setCellValue('E' . $k, $v['address']);
  85. $objActSheet->setCellValue('F' . $k, $v['giftName']);
  86. $objActSheet->setCellValue('G' . $k, $v['createAt']);
  87. }
  88. $outfile = "中奖信息" . date('Ymd') . ".xlsx";
  89. ob_end_clean();
  90. header("Content-Type: application/force-download");
  91. header("Content-Type: application/octet-stream");
  92. header("Content-Type: application/download");
  93. header('Content-Disposition:inline;filename="' . $outfile . '"');
  94. header("Content-Transfer-Encoding: binary");
  95. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  96. header("Pragma: no-cache");
  97. $objWriter->save('php://output');
  98. }
  99. /**
  100. * 中奖信息
  101. * @auth true
  102. * @menu true
  103. * @throws \think\db\exception\DataNotFoundException
  104. * @throws \think\db\exception\DbException
  105. * @throws \think\db\exception\ModelNotFoundException
  106. */
  107. public function luckDraw()
  108. {
  109. $this->_query($this->table)->layTable(function (){
  110. $this->title = '中奖信息';
  111. $this->type = input('type', 'luckDraw');
  112. },function (QueryHelper $query){
  113. $query->alias('o')
  114. ->leftJoin('awards_user_info u', 'o.uid = u.uid')
  115. ->leftJoin('awards_gift g', 'o.gift_id = g.id')
  116. ->field(['o.id', 'u.uid', 'u.nickname', 'o.name', 'o.mobile', 'o.address', 'g.name as giftName', 'FROM_UNIXTIME(o.create_at) as createAt'])
  117. ->where('o.type', 1)
  118. ->order('o.id desc');
  119. $query->equal('o.uid')->like('u.nickname');
  120. });
  121. }
  122. /**
  123. * 导出中奖信息
  124. * @auth true
  125. * @menu true
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\DbException
  128. * @throws \think\db\exception\ModelNotFoundException
  129. */
  130. public function drawAward()
  131. {
  132. $data = $this->app->db->name('Order')->alias('o')
  133. ->leftJoin('awards_user_info u', 'o.uid = u.uid')
  134. ->leftJoin('awards_gift g', 'o.gift_id = g.id')
  135. ->field(['o.id', 'o.uid', 'u.nickname', 'o.name', 'o.mobile', 'o.address', 'g.name as giftName', 'FROM_UNIXTIME(o.create_at) as createAt'])
  136. ->where('o.type', 1)
  137. ->order('o.id desc')->select();
  138. //实例化
  139. $objExcel = new \PHPExcel();
  140. //设置文档属性
  141. $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
  142. //设置内容
  143. $objActSheet = $objExcel->getActiveSheet();
  144. $letter = explode(',', "A,B,C,D,E,F,G");
  145. $arrHeader = ['微博UID', '微博昵称', '收件人姓名', '联系人电话', '收件地址', '奖品名称','中奖时间'];
  146. //填充表头信息
  147. $lenth = count($arrHeader);
  148. for ($i = 0; $i < $lenth; $i++) {
  149. $objActSheet->setCellValue("$letter[$i]1", "$arrHeader[$i]");
  150. };
  151. //填充表格信息
  152. foreach ($data as $k => $v) {
  153. $k += 2;
  154. //表格内容
  155. $objActSheet->setCellValue('A' . $k, $v['uid']." ");
  156. $objActSheet->setCellValue('B' . $k, $v['nickname']);
  157. $objActSheet->setCellValue('C' . $k, $v['name']);
  158. $objActSheet->setCellValue('D' . $k, $v['mobile']." ");
  159. $objActSheet->setCellValue('E' . $k, $v['address']);
  160. $objActSheet->setCellValue('F' . $k, $v['giftName']);
  161. $objActSheet->setCellValue('G' . $k, $v['createAt']);
  162. }
  163. $outfile = "中奖信息" . date('Ymd') . ".xlsx";
  164. ob_end_clean();
  165. header("Content-Type: application/force-download");
  166. header("Content-Type: application/octet-stream");
  167. header("Content-Type: application/download");
  168. header('Content-Disposition:inline;filename="' . $outfile . '"');
  169. header("Content-Transfer-Encoding: binary");
  170. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  171. header("Pragma: no-cache");
  172. $objWriter->save('php://output');
  173. }
  174. }