Commit 3977d8ae by 朱继来

添加自营样片导出

parent f77c6faf
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\UserSampleApplyModel;
use DB;
use Excel;
Class ExportController extends Controller
{
// 统一入口
public function entrance(Request $request, $id)
{
return $this->$id($request);
}
// 导出会员
public function selfSampleExport($request)
{
$UserSampleApplyModel = new UserSampleApplyModel();
$data = $UserSampleApplyModel->lists($request, 1);
foreach ($data as $k=>$v) {
$cellData[$k]['user_id'] = $v['user_id'];
$cellData[$k]['account'] = $v['account'];
$cellData[$k]['invite_count'] = $v['invite_count'];
$cellData[$k]['apply_num_total'] = $v['apply_num_total'];
$cellData[$k]['apply_count'] = $v['apply_count'];
$cellData[$k]['order_id'] = $v['order_id'];
$cellData[$k]['order_sn'] = $v['order_sn'];
$cellData[$k]['goods_id'] = $v['goods_id'];
$cellData[$k]['goods_name'] = $v['goods_name'];
$cellData[$k]['create_time'] = $v['create_time'];
}
$headerCell = ['用户ID', '用户账户', '邀请人数', '已申请样片数', '剩余领取次数', '订单ID', '订单编号', '样片ID', '样片名称', '最近一次领取时间'];
$fileName ='自营样片领取记录导出'.date('_YmdHis');
$sheetName = '自营样片';
$this->commonFunc($cellData, $headerCell, $fileName, $sheetName);
}
/**
* 导出
* @param [type] $cellData [导出数据]
* @param [type] $headerCell [菜单项]
* @param [type] $fileName [文件名]
* @param string $sheetName [sheet名]
* @return [type] [description]
*/
public function commonFunc($cellData, $headerCell, $fileName, $sheetName='')
{
$sheetName = $sheetName ? $sheetName : '导出';
array_unshift($cellData, $headerCell);
Excel::create($fileName, function($excel) use ($cellData, $sheetName){
$excel->sheet($sheetName, function($sheet) use ($cellData){
$sheet->rows($cellData);
});
})->export('xls');
}
}
\ No newline at end of file
......@@ -108,6 +108,7 @@ Route::group(['middleware' => 'web'], function () {
Route::match(['get', 'post'],'/web/{key}', 'WebController@info');
Route::match(['get', 'post'],'/api/{key}', 'ApiController@Entrance');
Route::match(['get', 'post'], '/export/{key}', 'ExportController@entrance');
Route::match(['get', 'post'], '/refund/{id}', 'OrderController@refund');
......
......@@ -72,6 +72,8 @@ class UserSampleApplyModel extends Model
if ($export) {
$list = $list->get()->toArray();
$list = $this->handle($list);
if (empty($list)) {
echo '<script>alert("导出数据为空");history.go(-1);</script>';die;
}
......
......@@ -23,13 +23,14 @@ layui.use(['form', 'table', 'laydate'], function(){
,{field: 'user_id', title: '用户ID', width: 100}
,{field: 'account', title: '用户账户', width: 150}
,{field: 'invite_count', title: '邀请人数', width: 100}
,{field: 'apply_num_total', title: '已申请样片数', width: 150}
,{field: 'apply_count', title: '剩余领取次数', width: 150}
,{field: 'apply_num_total', title: '已申请样片数', width: 120}
,{field: 'apply_count', title: '剩余领取次数', width: 120}
,{field: 'order_id', title: '订单ID', width: 100}
,{field: 'order_sn', title: '订单编号', width: 150}
,{field: 'goods_id', title: '样片ID', width: 100}
,{field: 'goods_name', title: '样片名称', width: 215}
,{field: 'create_time', title: '最近一次领取时间', width: 200}
,{title: '操作', align:'center', fixed: 'right', toolbar: '#list_action', width: 200}
,{field: 'goods_name', title: '样片名称', width: 200}
,{field: 'create_time', title: '最近一次领取时间', width: 180}
,{title: '操作', align:'center', fixed: 'right', toolbar: '#list_action', width: 195}
]]
,limit: 10
,limits: [10, 20, 50,]
......@@ -47,6 +48,29 @@ layui.use(['form', 'table', 'laydate'], function(){
return false;
});
// 导出
$('.export').click(function() {
var account = $('input[name=account]').val(),
goods_name = $('input[name=goods_name]').val(),
order_sn = $('input[name=order_sn]').val(),
begin_time = $('input[name=begin_time]').val(),
end_time = $('input[name=end_time]').val(),
url = '/export/selfSampleExport';
if (!account && !goods_name && !order_sn && !begin_time && !end_time) {
layer.msg('请选择筛选条件');
return false;
}
layer.confirm('确定导出数据吗?', {
title: '导出数据'
,btn: ['确定', '取消']
}, function(){
layer.closeAll('dialog'); // 确定时关闭弹框
window.location.href = url+'?account='+account+'&goods_name='+goods_name+'&order_sn='+order_sn+'&begin_time='+begin_time+'&end_time='+end_time;
});
})
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment