495 lines
21 KiB
PHP
495 lines
21 KiB
PHP
<?php
|
||
use app\models\Order;
|
||
/**
|
||
* @author Any
|
||
* @description KISS
|
||
* @date 2021年6月30日
|
||
* @version 1.0.0
|
||
*
|
||
* _____LOG_____
|
||
*
|
||
*/
|
||
$this->title = '订单列表';
|
||
$this->params['breadcrumbs'][] = $this->title;
|
||
|
||
$status_labels = Order::statusLabels();
|
||
$status = \Yii::$app->request->get('status');
|
||
$cat_id = \Yii::$app->request->get('cat_id');
|
||
?>
|
||
<style type="text/css">
|
||
.layui-table-cell {
|
||
height: auto;
|
||
}
|
||
</style>
|
||
<div class="layui-fluid">
|
||
<div class="layui-card">
|
||
<div class="layui-card-header">
|
||
<?= $this->title ?>
|
||
</div>
|
||
<div class="layui-card-header layuiadmin-card-header-auto">
|
||
<div class="layui-form-item">
|
||
<div class="layui-inline layui-float-right layui-form">
|
||
|
||
|
||
<div class="layui-inline layui-form-item">
|
||
<div class="layui-input-inline">
|
||
<select name="store_id">
|
||
<option value=""></option>
|
||
<?php foreach ($store as $index => $item):?>
|
||
<option value="<?= $item['id'] ?>" <?= Yii::$app->request->get("store_id") == $item['id'] ? "selected" : "" ?> ><?= $item['name'] ?></option>
|
||
<?php endforeach;?>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="layui-inline layui-form-item">
|
||
<div class="layui-input-inline">
|
||
<select class="layui-select" name="status">
|
||
<option value="" <?=$status === null ? 'selected' : ''?>>全部状态</option>
|
||
<?php foreach ($status_labels as $key => $val):?>
|
||
<option value="<?=$key?>" <?=$status == $key && $status != null ? 'selected' : ''?>><?=$val?></option>
|
||
<?php endforeach;?>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="layui-inline layui-form-item">
|
||
<label class="layui-form-label">时间选择</label>
|
||
<div class="layui-input-block">
|
||
<input type="text" name="times" id="times" placeholder="选择日期" autocomplete="off" class="layui-input" readonly>
|
||
</div>
|
||
</div>
|
||
<div class="layui-inline layui-form-item">
|
||
<label class="layui-form-label">关键词</label>
|
||
<div class="layui-input-block">
|
||
<input type="text" name="keywords" placeholder="搜索标题" autocomplete="off" class="layui-input" value="<?=\Yii::$app->request->get("keywords")?>">
|
||
</div>
|
||
</div>
|
||
<div class="layui-inline">
|
||
<button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="dtable-search">
|
||
<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
|
||
</button>
|
||
<button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="dtable-export">
|
||
<i class="layui-icon layui-icon-export layuiadmin-button-btn"></i>导出excel
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="layui-card-body">
|
||
<table id="dtable" lay-filter="dtable"></table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!--工具栏模板-->
|
||
<script type="text/html" id="toolBarTpl">
|
||
<div class="layui-btn-container">
|
||
</div>
|
||
</script>
|
||
|
||
<!--行操作列模板-->
|
||
<script type="text/html" id="rowBarTpl">
|
||
{{# if(d.state == '0'){ }}
|
||
<button class="layui-btn layui-btn-xs layui-bg-red layui-hide" lay-event="cancel">取消</button>
|
||
{{# } }}
|
||
{{# if(d.earnings >= '1'){ }}
|
||
<button class="layui-btn layui-btn-xs layui-bg-blue layui-hide" lay-event="search_multi">分账查询</button>
|
||
{{# } }}
|
||
{{# if(d.earnings == '0' || d.earnings == '2'){ }}
|
||
<button class="layui-btn layui-btn-xs layui-bg-blue layui-hide" lay-event="multi">手动分账</button>
|
||
{{# } }}
|
||
<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</button>
|
||
</script>
|
||
|
||
|
||
<script type="text/html" id="statusTpl">
|
||
{{# if(d.state == '0'){ }}
|
||
<span class="layui-badge layui-bg-orange">待支付</span>
|
||
{{# } else if(d.state == '1'){ }}
|
||
<span class="layui-badge layui-bg-green">已支付</span>
|
||
{{# } else if(d.state == '2'){ }}
|
||
<span class="layui-badge layui-bg-red">已取消</span>
|
||
{{# } else if(d.state == '3'){ }}
|
||
<span class="layui-badge layui-bg-blue">已完成</span>
|
||
{{# } }}
|
||
</script>
|
||
<script type="text/html" id="earningsTpl">
|
||
{{# if(d.earnings != '-1'){ }}
|
||
<span>金额:{{d.earnings_money}}</span><br>
|
||
{{# } }}
|
||
<span>分账进度:{{d.earnings_cn}}</span>
|
||
</script>
|
||
|
||
<script type="text/html" id="phoneTpl">
|
||
<span>用户名:{{d.nickname}}</span><br>
|
||
<span>手机号:{{d.mobile_phone}}</span>
|
||
</script>
|
||
<script type="text/html" id="dateTpl">
|
||
<span>开始日期:{{d.created_at_cn}}</span><br>
|
||
<span>结束日期:{{d.updated_at_cn}}</span>
|
||
</script>
|
||
<script type="text/html" id="ordernoTpl">
|
||
<span>{{d.order_no}}</span><br>
|
||
<!-- <span class="layui-badge layui-bg-blue">分账订单号:{{d.psOrderMulti_cn}}</span><br>-->
|
||
<!-- <span class="layui-badge layui-bg-blue">完结订单号:{{d.psOrderFinish_cn}}</span>-->
|
||
</script>
|
||
|
||
<script type="text/html" id="ball_number">
|
||
<a href="/admin/ball/qc-data?qr_number={{d.goods_id}}" title="跳转球车详情">{{d.goods_id}}</a>
|
||
</script>
|
||
<script>
|
||
<?php $this->beginBlock('js_script_wrap') ?>
|
||
function toExcel(FileName, ShowLabel, JSONData) {
|
||
//先转化json
|
||
var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
|
||
var excel = '<table>';
|
||
//设置表头
|
||
var row = "<tr align='left'>";//设置Excel的左居中
|
||
for (var i = 0, l = ShowLabel.length; i < l; i++) {
|
||
for (var key in ShowLabel[i]) {
|
||
if(ShowLabel[i][key] instanceof Object){
|
||
row += "<td>" + ShowLabel[i][key]['title'] + '</td>';
|
||
}else{
|
||
row += "<td>" + ShowLabel[i][key] + '</td>';
|
||
}
|
||
}
|
||
}
|
||
//换行
|
||
excel += row + "</tr>";
|
||
//设置数据
|
||
for (var i = 0; i < arrData.length; i++) {
|
||
var rowData = "<tr align='left'>";
|
||
|
||
for (var y = 0; y < ShowLabel.length; y++) {
|
||
for(var k in ShowLabel[y]){
|
||
if (ShowLabel[y].hasOwnProperty(k)) {
|
||
if(ShowLabel[y][k] instanceof Object){
|
||
rowData += "<td style='vnd.ms-excel.numberformat:@'>" + ShowLabel[y][k]['option'][(arrData[i][k]===null? "" : arrData[i][k])] + "</td>";
|
||
}else{
|
||
rowData += "<td style='vnd.ms-excel.numberformat:@'>" + (arrData[i][k]===null? "" : arrData[i][k]) + "</td>";
|
||
}
|
||
//vnd.ms-excel.numberformat:@ 输出为文本
|
||
}
|
||
}
|
||
}
|
||
excel += rowData + "</tr>";
|
||
}
|
||
excel += "</table>";
|
||
var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
|
||
excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
|
||
excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel';
|
||
excelFile += '; charset=UTF-8">';
|
||
excelFile += "<head>";
|
||
excelFile += "<!--[if gte mso 9]>";
|
||
excelFile += "<xml>";
|
||
excelFile += "<x:ExcelWorkbook>";
|
||
excelFile += "<x:ExcelWorksheets>";
|
||
excelFile += "<x:ExcelWorksheet>";
|
||
excelFile += "<x:Name>";
|
||
excelFile += "{worksheet}";
|
||
excelFile += "</x:Name>";
|
||
excelFile += "<x:WorksheetOptions>";
|
||
excelFile += "<x:DisplayGridlines/>";
|
||
excelFile += "</x:WorksheetOptions>";
|
||
excelFile += "</x:ExcelWorksheet>";
|
||
excelFile += "</x:ExcelWorksheets>";
|
||
excelFile += "</x:ExcelWorkbook>";
|
||
excelFile += "</xml>";
|
||
excelFile += "<![endif]-->";
|
||
excelFile += "</head>";
|
||
excelFile += "<body>";
|
||
excelFile += excel;
|
||
excelFile += "</body>";
|
||
excelFile += "</html>";
|
||
var uri = 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile);
|
||
var link = document.createElement("a");
|
||
link.href = uri;
|
||
link.style = "visibility:hidden";
|
||
link.download = FileName + ".xls";
|
||
document.body.appendChild(link);
|
||
link.click();
|
||
document.body.removeChild(link);
|
||
}
|
||
layui.config({
|
||
base: '/statics/layuiadmin/' //静态资源所在路径
|
||
}).extend({
|
||
index: 'lib/index' //主入口模块
|
||
}).use(['index', 'user', 'table','form','laydate'], function () {
|
||
var $ = layui.$
|
||
, form = layui.form
|
||
, table = layui.table
|
||
, admin = layui.admin,
|
||
laydate=layui.laydate;
|
||
|
||
|
||
form.render();
|
||
|
||
|
||
|
||
//日期时间范围
|
||
laydate.render({
|
||
elem: '#times'
|
||
,type: 'datetime'
|
||
,range: true
|
||
});
|
||
|
||
//search
|
||
form.on('submit(dtable-search)', function (obj) {
|
||
var field = obj.field;
|
||
reload_table_data(field);
|
||
});
|
||
|
||
//search
|
||
form.on('submit(dtable-export)', function (obj) {
|
||
var field = obj.field;
|
||
field.page = 1;
|
||
field.limit = 999999;
|
||
layer.msg('数据获取中...', {
|
||
icon: 16
|
||
,shade: 0.01
|
||
,time:0,
|
||
});
|
||
$.ajax('<?=\Yii::$app->urlManager->createUrl(['admin/mall/order/index'])?>',{
|
||
type:"GET",
|
||
dataType:"json",
|
||
data:field,
|
||
success:function(res){
|
||
layer.closeAll();
|
||
if(res.code == 0){
|
||
layer.msg('生成excel...', {
|
||
icon: 16
|
||
,shade: 0.01
|
||
,time:0,
|
||
});
|
||
var date_obj = new Date();
|
||
var FileName = "订单数据列表"+(date_obj.getFullYear()+"-"+(date_obj.getMonth()+1)+"-"+date_obj.getDate()+"_"+date_obj.getHours()+"_"+date_obj.getMinutes());
|
||
var ShowLabel= [{ id: 'id' }, { order_no: '订单号' }, { total_price: '租赁金额' }, { yh_price: '优惠金额' }
|
||
, { total_pay_price: '实付金额' }
|
||
, { nickname: '用户名' }
|
||
, { mobile_phone: '手机号' }
|
||
, { store_name: '门店' }
|
||
, { plugin_sign_cn: '购买服务' }
|
||
, { goods_id: '球车编号' }
|
||
, { state: {"title":'状态',"option":{0:'待支付',1:"已支付",2:"已取消",3:'已完成'}} }
|
||
, { created_at_cn: '开始日期' }
|
||
, { updated_at_cn: '结束日期' }
|
||
, { res_date: '租赁时长' }
|
||
, { res_second: '租赁时长(秒)' }
|
||
];
|
||
toExcel(FileName,ShowLabel,res.data);
|
||
layer.closeAll();
|
||
} else {
|
||
layer.msg(res.msg, {
|
||
offset: '15px'
|
||
,icon: 2
|
||
,time: 1000
|
||
}, function(){
|
||
});
|
||
}
|
||
},
|
||
error:function(xhr,type,err){
|
||
layer.closeAll();
|
||
layer.msg(xhr.responseText, {
|
||
offset: '15px'
|
||
,icon: 2
|
||
,time: 1000
|
||
}, function(){
|
||
});
|
||
}
|
||
})
|
||
// reload_table_data(field);
|
||
});
|
||
|
||
|
||
|
||
|
||
//重新加载表格数据
|
||
function reload_table_data(conf){
|
||
table.reload('dtable', {
|
||
url:'<?=\Yii::$app->urlManager->createUrl(['admin/mall/order/index'])?>'
|
||
,page: true
|
||
,where: conf
|
||
});
|
||
};
|
||
|
||
//执行渲染
|
||
table.render({
|
||
//指定原始表格元素选择器(推荐id选择器)
|
||
elem: '#dtable'
|
||
//容器高度
|
||
//,height: 315
|
||
//容器宽度
|
||
//,width: 720
|
||
//设置表头
|
||
,cols: [[
|
||
{checkbox: true}
|
||
, {field: 'id', title: 'ID', width: 80}
|
||
, {field: 'order_no', title: '订单号',templet:'#ordernoTpl', minWidth: 220}
|
||
, {field: 'total_price', title: '租赁金额', minWidth: 100}
|
||
, {field: 'yh_price', title: '优惠金额', minWidth: 100}
|
||
, {field: 'total_pay_price', title: '实付金额', minWidth: 100}
|
||
, {field: 'mobile_phone', title: '下单用户',templet:'#phoneTpl', minWidth: 200}
|
||
, {field: 'store_name', title: '门店', minWidth: 200}
|
||
, {field: 'plugin_sign_cn', title: '购买服务', minWidth: 80}
|
||
, {field: 'goods_id', title: '球车编号',templet:'#ball_number', minWidth: 120}
|
||
, {field: 'state', title: '状态', templet:'#statusTpl', minWidth: 100}
|
||
// , {field: 'earnings', title: '门店收益(元)',templet:'#earningsTpl'}
|
||
, {field: 'created_at_cn', title: '起始时间', minWidth: 230, templet:'#dateTpl'}
|
||
, {field: 'res_date', title: '租赁时长', minWidth: 120}
|
||
]
|
||
]
|
||
, url:'<?=\Yii::$app->urlManager->createUrl(['admin/mall/order/index'])?>'
|
||
, page:true
|
||
//指向自定义工具栏模板选择器
|
||
, toolbar:'#toolBarTpl'
|
||
//头部工具栏右侧的图标按钮
|
||
, defaultToolbar:['filter', 'print', 'exports']
|
||
, limit: 10
|
||
, limits:[10,20,30,40,50,60,70,80,90,100]
|
||
, title:'<?=$this->title?>'
|
||
, data:[]
|
||
, done: function(res, curr, count){
|
||
setTimeout(function(){
|
||
$(".layui-table-main tr").each(function (index ,val) {
|
||
$(".layui-table-fixed").each(function () {
|
||
$($(this).find(".layui-table-body tbody tr")[index]).height($(val).height());
|
||
});
|
||
});
|
||
$(".layui-table-header tr").each(function (index ,val) {
|
||
$(".layui-table-fixed").each(function () {
|
||
$($(this).find(".layui-table-header thead tr")[index]).height($(val).height());
|
||
});
|
||
});
|
||
},500);
|
||
}
|
||
});
|
||
|
||
|
||
//监听工具条
|
||
table.on('tool(dtable)', function(obj){
|
||
var row_data = obj.data;
|
||
var lay_event = obj.event;
|
||
var id = row_data.id;
|
||
var confirm_url = null;
|
||
var confirm_tip = null;
|
||
var ids = [];
|
||
ids.push(id);
|
||
|
||
if(lay_event == "cancel"){
|
||
confirm_url = "<?=\Yii::$app->urlManager->createUrl(['admin/mall/order/cancel'])?>";
|
||
confirm_tip = "确定取消此订单吗";
|
||
}
|
||
|
||
if(lay_event == "delete"){
|
||
confirm_url = "<?=\Yii::$app->urlManager->createUrl(['admin/mall/order/delete'])?>";
|
||
confirm_tip = "确定删除此订单吗";
|
||
}
|
||
if(lay_event == "finish"){
|
||
confirm_url = "<?=\Yii::$app->urlManager->createUrl(['admin/mall/order/finish'])?>";
|
||
confirm_tip = "确定将此订单变更为完成吗";
|
||
}
|
||
if(lay_event == "multi"){
|
||
confirm_url = "<?=\Yii::$app->urlManager->createUrl(['admin/mall/order/multi'])?>";
|
||
confirm_tip = "确定此订单发起分账吗";
|
||
}
|
||
if(lay_event == "search_multi"){
|
||
return search_multi(row_data)
|
||
}
|
||
|
||
if(confirm_url != null){
|
||
layer.confirm(confirm_tip, {
|
||
btn: ['确定','取消']
|
||
}, function(){
|
||
$.ajax(confirm_url,{
|
||
type:"POST",
|
||
dataType:"json",
|
||
data:{
|
||
ids:ids,
|
||
_csrf:_csrf
|
||
},
|
||
success:function(res){
|
||
if(res.code == 0){
|
||
layer.msg(res.msg, {
|
||
offset: '15px'
|
||
,icon: 1
|
||
,time: 1000
|
||
}, function(){
|
||
location.reload();
|
||
});
|
||
} else {
|
||
layer.msg(res.msg, {
|
||
offset: '15px'
|
||
,icon: 2
|
||
,time: 1000
|
||
}, function(){
|
||
});
|
||
}
|
||
},
|
||
error:function(xhr,type,err){
|
||
layer.msg(xhr.responseText, {
|
||
offset: '15px'
|
||
,icon: 2
|
||
,time: 1000
|
||
}, function(){
|
||
});
|
||
}
|
||
})
|
||
}, function(){
|
||
});
|
||
}
|
||
});
|
||
|
||
//查询分账进度
|
||
function search_multi(data){
|
||
var loadingMsg = layer.msg('数据请求中...', {icon: 16, shade: [0.5], scrollbar: false, time: 0});
|
||
var confirm_url = "<?=\Yii::$app->urlManager->createUrl(['admin/mall/order/search-multi2'])?>";
|
||
$.ajax(confirm_url, {
|
||
type: "POST",
|
||
dataType: "json",
|
||
data: {
|
||
id: data.id,
|
||
_csrf:_csrf
|
||
},
|
||
success: function (res) {
|
||
if (res.code == 0) {
|
||
layer.close(loadingMsg);
|
||
layer.open({
|
||
type: 1
|
||
,title: false //不显示标题栏
|
||
,closeBtn: false
|
||
,area: '400px;'
|
||
,shade: 0.8
|
||
,id: 'LAY_layuipro' //设定一个id,防止重复弹出
|
||
,btn: ['确认']
|
||
,btnAlign: 'c'
|
||
,moveType: 1 //拖拽模式,0或者1
|
||
,content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">'+res.msg+'</div>'
|
||
|
||
});
|
||
} else {
|
||
layer.msg(res.msg, {
|
||
offset: '15px'
|
||
, icon: 2
|
||
, time: 1000
|
||
}, function () {
|
||
});
|
||
}
|
||
},
|
||
error: function (xhr, type, err) {
|
||
layer.msg(xhr.responseText, {
|
||
offset: '15px'
|
||
, icon: 2
|
||
, time: 1000
|
||
}, function () {
|
||
});
|
||
}
|
||
})
|
||
}
|
||
|
||
});
|
||
|
||
<?php $this->endBlock(); ?>
|
||
</script>
|
||
<?php $this->registerJs($this->blocks['js_script_wrap'], \yii\web\View::POS_END); ?>
|
||
|