Award.php 8.0 KB

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