Award.php 8.1 KB

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