Award.php 8.4 KB

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