|
|
@@ -26,7 +26,7 @@ class Award extends Controller
|
|
|
private $table = 'Order';
|
|
|
|
|
|
/**
|
|
|
- * 奖品订单管理
|
|
|
+ * 排行榜前50名
|
|
|
* @auth true
|
|
|
* @menu true
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
@@ -35,24 +35,116 @@ class Award extends Controller
|
|
|
*/
|
|
|
public function index()
|
|
|
{
|
|
|
- $this->_query($this->table)->layTable(function (){
|
|
|
- $this->title = '奖品订单';
|
|
|
+ $this->_query('UserTaskLog')->layTable(function (){
|
|
|
+ $this->title = '排行榜前50名';
|
|
|
$this->type = input('type', 'award');
|
|
|
},function (QueryHelper $query){
|
|
|
- $query->alias('o')->leftJoin('awards_user_info u', 'o.uid = u.uid')
|
|
|
+ $query->alias('l')
|
|
|
+ ->leftJoin('awards_order o', 'o.uid = l.uid')
|
|
|
+ ->leftJoin('awards_user_info u', 'l.uid = u.uid')
|
|
|
+ ->field(['o.id', 'l.uid', 'u.nickname', 'o.name', 'o.mobile', 'o.address', 'g.name as giftName', 'FROM_UNIXTIME(o.create_at) as createAt'])
|
|
|
+ ->distinct('l.uid')
|
|
|
+ ->order('l.number', 'desc')
|
|
|
+ ->order('l.duration', 'asc')->limit(50);
|
|
|
+ $query->equal('o.uid')->like('u.nickname');
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出排行榜前50名
|
|
|
+ * @auth true
|
|
|
+ * @menu true
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function award()
|
|
|
+ {
|
|
|
+ $data = $this->app->db->name('UserTaskLog')->alias('l')
|
|
|
+ ->leftJoin('awards_order o', 'o.uid = l.uid')
|
|
|
+ ->leftJoin('awards_user_info u', 'o.uid = u.uid')
|
|
|
+ ->leftJoin('awards_gift g', 'o.gift_id = g.id')
|
|
|
+ ->field(['o.id', 'l.uid', 'u.nickname', 'o.name', 'o.mobile', 'o.address', 'g.name as giftName', 'FROM_UNIXTIME(o.create_at) as createAt'])
|
|
|
+ ->order('l.number', 'desc')
|
|
|
+ ->order('l.duration', 'asc')->select();
|
|
|
+
|
|
|
+ //实例化
|
|
|
+ $objExcel = new \PHPExcel();
|
|
|
+ //设置文档属性
|
|
|
+ $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
|
|
|
+ //设置内容
|
|
|
+ $objActSheet = $objExcel->getActiveSheet();
|
|
|
+ $letter = explode(',', "A,B,C,D,E,F,G");
|
|
|
+ $arrHeader = ['微博UID', '微博昵称', '收件人姓名', '联系人电话', '收件地址', '奖品名称','中奖时间'];
|
|
|
+ //填充表头信息
|
|
|
+ $lenth = count($arrHeader);
|
|
|
+ for ($i = 0; $i < $lenth; $i++) {
|
|
|
+ $objActSheet->setCellValue("$letter[$i]1", "$arrHeader[$i]");
|
|
|
+ };
|
|
|
+ //填充表格信息
|
|
|
+ foreach ($data as $k => $v) {
|
|
|
+ $k += 2;
|
|
|
+ //表格内容
|
|
|
+ $objActSheet->setCellValue('A' . $k, $v['uid']." ");
|
|
|
+ $objActSheet->setCellValue('B' . $k, $v['nickname']);
|
|
|
+ $objActSheet->setCellValue('C' . $k, $v['name']);
|
|
|
+ $objActSheet->setCellValue('D' . $k, $v['mobile']." ");
|
|
|
+ $objActSheet->setCellValue('E' . $k, $v['address']);
|
|
|
+ $objActSheet->setCellValue('F' . $k, $v['giftName']);
|
|
|
+ $objActSheet->setCellValue('G' . $k, $v['createAt']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $outfile = "中奖信息" . date('Ymd') . ".xlsx";
|
|
|
+ ob_end_clean();
|
|
|
+ header("Content-Type: application/force-download");
|
|
|
+ header("Content-Type: application/octet-stream");
|
|
|
+ header("Content-Type: application/download");
|
|
|
+ header('Content-Disposition:inline;filename="' . $outfile . '"');
|
|
|
+ header("Content-Transfer-Encoding: binary");
|
|
|
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
|
|
+ header("Pragma: no-cache");
|
|
|
+ $objWriter->save('php://output');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 中奖信息
|
|
|
+ * @auth true
|
|
|
+ * @menu true
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function luckDraw()
|
|
|
+ {
|
|
|
+ $this->_query($this->table)->layTable(function (){
|
|
|
+ $this->title = '中奖信息';
|
|
|
+ $this->type = input('type', 'luckDraw');
|
|
|
+ },function (QueryHelper $query){
|
|
|
+ $query->alias('o')
|
|
|
+ ->leftJoin('awards_user_info u', 'o.uid = u.uid')
|
|
|
->leftJoin('awards_gift g', 'o.gift_id = g.id')
|
|
|
- ->field(['o.id', 'u.uid', 'u.nickname', 'o.name', 'o.mobile', 'o.address', 'g.name as giftName'])
|
|
|
+ ->field(['o.id', 'u.uid', 'u.nickname', 'o.name', 'o.mobile', 'o.address', 'g.name as giftName', 'FROM_UNIXTIME(o.create_at) as createAt'])
|
|
|
+ ->where('o.type', 1)
|
|
|
->order('o.id desc');
|
|
|
$query->equal('o.uid')->like('u.nickname');
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- public function award()
|
|
|
+ /**
|
|
|
+ * 导出中奖信息
|
|
|
+ * @auth true
|
|
|
+ * @menu true
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function drawAward()
|
|
|
{
|
|
|
$data = $this->app->db->name('Order')->alias('o')
|
|
|
->leftJoin('awards_user_info u', 'o.uid = u.uid')
|
|
|
->leftJoin('awards_gift g', 'o.gift_id = g.id')
|
|
|
- ->field(['o.id', 'u.uid', 'u.nickname', 'o.name', 'o.mobile', 'o.address', 'g.name as giftName'])
|
|
|
+ ->field(['o.id', 'o.uid', 'u.nickname', 'o.name', 'o.mobile', 'o.address', 'g.name as giftName', 'FROM_UNIXTIME(o.create_at) as createAt'])
|
|
|
+ ->where('o.type', 1)
|
|
|
->order('o.id desc')->select();
|
|
|
|
|
|
//实例化
|
|
|
@@ -61,8 +153,8 @@ class Award extends Controller
|
|
|
$objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
|
|
|
//设置内容
|
|
|
$objActSheet = $objExcel->getActiveSheet();
|
|
|
- $letter = explode(',', "A,B,C,D,E,F");
|
|
|
- $arrHeader = ['微博UID', '微博昵称', '收件人姓名', '联系人电话', '收件地址', '奖品'];
|
|
|
+ $letter = explode(',', "A,B,C,D,E,F,G");
|
|
|
+ $arrHeader = ['微博UID', '微博昵称', '收件人姓名', '联系人电话', '收件地址', '奖品名称','中奖时间'];
|
|
|
//填充表头信息
|
|
|
$lenth = count($arrHeader);
|
|
|
for ($i = 0; $i < $lenth; $i++) {
|
|
|
@@ -78,6 +170,7 @@ class Award extends Controller
|
|
|
$objActSheet->setCellValue('D' . $k, $v['mobile']." ");
|
|
|
$objActSheet->setCellValue('E' . $k, $v['address']);
|
|
|
$objActSheet->setCellValue('F' . $k, $v['giftName']);
|
|
|
+ $objActSheet->setCellValue('G' . $k, $v['createAt']);
|
|
|
}
|
|
|
|
|
|
$outfile = "中奖信息" . date('Ymd') . ".xlsx";
|