lqmac 8 months ago
parent e1e4edef95
commit 1a18218bd8
  1. 233
      application/admin/controller/order/MarkingPaperOrder.php
  2. 71
      application/admin/view/order/marking_paper_order/order_info.php
  3. 372
      application/admin/view/order/marking_paper_order/test_paper_order.php

@ -0,0 +1,233 @@
<?php
// 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\admin\controller\order;
use Api\Express;
use app\admin\controller\AuthController;
use service\AlipayTradeWapService;
use service\FormBuilder as Form;
use app\admin\model\user\User;
use app\admin\model\user\UserBill;
use basic\ModelBasic;
use behavior\wap\StoreProductBehavior;
use behavior\wechat\PaymentBehavior;
use EasyWeChat\Core\Exception;
use service\CacheService;
use service\HookService;
use service\JsonService as Json;
use think\Db;
use think\Request;
use think\Url;
use app\admin\model\order\TestPaperOrder as TestPaperOrderModel;
use app\admin\model\questions\TestPaperObtain;
use service\KuaiMiniProgramService;
use service\TouMiniProgramService;
/**
* 订单管理控制器 同一个订单表放在一个控制器
* Class TestPaperOrder
*/
class MarkingPaperOrder extends AuthController
{
/**试卷订单
* @return mixed
*/
public function index()
{
$this->assign([
'year' => getMonth('y'),
'real_name' => $this->request->get('real_name', ''),
'orderCount' => TestPaperOrderModel::orderCount(),
]);
return $this->fetch('test_paper_order');
}
/**
* 获取头部订单金额等信息
* return json
*
*/
public function getBadge()
{
$where = parent::postMore([
['status', ''],
['real_name', ''],
['is_del', 0],
['data', ''],
['type', ''],
['order', '']
]);
return Json::successful(TestPaperOrderModel::getBadge($where));
}
/**
* 获取订单列表
* return json
*/
public function test_paper_order_list()
{
$where = parent::getMore([
['status', ''],
['real_name', $this->request->param('real_name', '')],
['is_del', 0],
['data', ''],
['type', ''],
['order', ''],
['page', 1],
['limit', 20],
['excel', 0]
]);
return Json::successlayui(TestPaperOrderModel::OrderList($where));
}
/**
* 修改退款状态
* @param $id
* @return \think\response\Json|void
*/
public function refund_y($id)
{
if (!$id) return $this->failed('数据不存在');
$product = TestPaperOrderModel::get($id);
if (!$product) return Json::fail('数据不存在!');
if ($product['paid'] == 1) {
$f = array();
$f[] = Form::input('order_id', '退款单号', $product->getData('order_id'))->disabled(1);
$f[] = Form::number('refund_price', '退款金额', $product->getData('pay_price'))->precision(2)->min(0.01);
$f[] = Form::radio('type', '状态', 1)->options([['label' => '直接退款', 'value' => 1]]);
$form = Form::make_post_form('退款处理', $f, Url::build('updateRefundY', array('id' => $id)), 4);
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
} else return Json::fail('数据不存在!');
}
/**退款处理
* @param Request $request
* @param $id
*/
public function updateRefundY(Request $request, $id)
{
$data = parent::postMore([
'refund_price',
['type', 1],
], $request);
if (!$id) return $this->failed('数据不存在');
$product = TestPaperOrderModel::get($id);
if (!$product) return Json::fail('数据不存在!');
if ($product['pay_price'] == $product['refund_price']) return Json::fail('已退完支付金额!不能再退款了');
if (!$data['refund_price']) return Json::fail('请输入退款金额');
$refund_price = $data['refund_price'];
$data['refund_price'] = bcadd($data['refund_price'], $product['refund_price'], 2);
$bj = bccomp((float)$product['pay_price'], (float)$data['refund_price'], 2);
if ($bj < 0) return Json::fail('退款金额大于支付金额请修改退款金额');
if ($data['type'] == 1) {
$data['refund_status'] = 2;
} else if ($data['type'] == 2) {
$data['refund_status'] = 0;
}
$type = $data['type'];
unset($data['type']);
$refund_data['pay_price'] = $product['pay_price'];
$refund_data['refund_price'] = $refund_price;
switch ($product['pay_type']) {
case 'weixin':
try {
HookService::listen('wechat_pay_order_refund', $product['order_id'], $refund_data, true, PaymentBehavior::class);
} catch (\Exception $e) {
return Json::fail($e->getMessage());
}
break;
case 'yue':
ModelBasic::beginTrans();
$res = User::bcInc($product['uid'], 'now_money', $refund_price, 'uid');
ModelBasic::checkTrans($res);
if (!$res) return Json::fail('余额退款失败!');
break;
case 'zhifubao':
$res = AlipayTradeWapService::init()->AliPayRefund($product['order_id'], $product['trade_no'], $refund_price, '试卷退款', 'refund');
if (empty($res) || $res != 10000) {
return Json::fail('支付宝退款失败!');
}
break;
case 'toutiao':
try {
$refund_data['order_id'] = $product['order_id'];
$refund_data['refund_reason_wap_explain'] = $product['refund_reason_wap_explain'] ?? '协商商户主动退款';
$res = (new TouMiniProgramService())->createRefund($refund_data);
if (empty($res) || $res['err_no'] != 0) {
return Json::fail('抖音退款失败!');
}
} catch (\Exception $e) {
return Json::fail($e->getMessage());
}
break;
case 'kuaishou':
try {
$refund_data['order_id'] = $product['order_id'];
$refund_data['refund_reason_wap_explain'] = '协商商户主动退款';
$res = (new KuaiMiniProgramService())->createRefund($refund_data);
if (empty($res) || $res['result'] != 1) {
return Json::fail('快手退款失败!');
}
} catch (\Exception $e) {
return Json::fail($e->getMessage());
}
break;
default:
return Json::fail('退款失败!');
break;
}
$data['refund_reason_time'] = time();
$resEdit = TestPaperOrderModel::edit($data, $id);
if ($resEdit) {
$data['type'] = $type;
TestPaperObtain::where('order_id', $product['order_id'])->delete();
$pay_type = $product['pay_type'] == 'yue' ? 'now_money' : $product['pay_type'];
if ($product['pay_type'] == 'yue') {
$balance = User::where(['uid' => $product['uid']])->value('now_money');
} else {
$balance = 0;
}
UserBill::income('试卷退款', $product['uid'], $pay_type, 'pay_test_paper_refund', $refund_price, $product['id'], $balance, '订单退款' . floatval($refund_price) . '元');
return Json::successful('修改成功!');
} else {
return Json::successful('修改失败!');
}
}
/**订单详情
* @param string $oid
* @return mixed|void
* @throws \think\exception\DbException
*/
public function order_info($oid = '')
{
if (!$oid || !($orderInfo = TestPaperOrderModel::get($oid)))
return $this->failed('订单不存在!');
$userInfo = User::getAllUserinfo($orderInfo['uid']);
$this->assign(compact('orderInfo', 'userInfo'));
return $this->fetch();
}
/**订单删除
* @param int $id
*/
public function delete($id = 0)
{
if (!$id) return Json::fail('参数错误!');
$data['is_del'] = 1;
$data['is_system_del'] = 1;
TestPaperOrderModel::edit($data, $id);
return Json::successful('删除成功!');
}
}

@ -0,0 +1,71 @@
{extend name="public/container"}
{block name="content"}
<div class="ibox-content order-info">
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
用户信息
</div>
<div class="panel-body">
<div class="row show-grid">
<div class="col-xs-6" >用户昵称: {$userInfo.nickname}</div>
<div class="col-xs-6">联系电话: {$userInfo.phone}</div>
</div>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
订单信息
</div>
<div class="panel-body">
<div class="row show-grid">
<div class="col-xs-6" >订单编号: {$orderInfo.order_id}</div>
<div class="col-xs-6" style="color: #8BC34A;">订单状态:
{if condition="$orderInfo['paid'] eq 0 && $orderInfo['status'] eq 0"}
未支付
{elseif condition="$orderInfo['paid'] eq 1 && $orderInfo['status'] eq 0 && $orderInfo['refund_status'] eq 0"/}
已支付
{elseif condition="$orderInfo['paid'] eq 1 && $orderInfo['refund_status'] eq 2"/}
已退款
{/if}
</div>
<div class="col-xs-6">试卷总数: {$orderInfo.total_num}</div>
<div class="col-xs-6">订单总价: ¥{$orderInfo.total_price}</div>
<div class="col-xs-6">实际支付: ¥{$orderInfo.pay_price}</div>
{if condition="$orderInfo['refund_price'] GT 0"}
<div class="col-xs-6" style="color: #f1a417">退款金额: ¥{$orderInfo.refund_price}</div>
{/if}
<div class="col-xs-6">创建时间: {$orderInfo.add_time|date="Y/m/d H:i",###}</div>
<div class="col-xs-6">支付方式:
{if condition="$orderInfo['paid'] eq 1"}
{if condition="$orderInfo['pay_type'] eq 'weixin'"}
微信支付
{elseif condition="$orderInfo['pay_type'] eq 'yue'"}
余额支付
{elseif condition="$orderInfo['pay_type'] eq 'zhifubao'"}
支付宝支付
{else/}
其他支付
{/if}
{else/}
未支付
{/if}
</div>
{notempty name="orderInfo.pay_time"}
<div class="col-xs-6">支付时间: {$orderInfo.pay_time|date="Y/m/d H:i",###}</div>
{/notempty}
</div>
</div>
</div>
</div>
</div>
</div>
<script src="{__FRAME_PATH}js/content.min.js?v=1.0.0"></script>
{/block}
{block name="script"}
{/block}

@ -0,0 +1,372 @@
{extend name="public/container"}
{block name="head"}
<style>
.layui-form-label {
width: 100px;
padding: 5px 15px;
}
.layui-input-block {
margin-left: 100px;
}
.layui-btn-group .layui-btn-normal {
border: 1px solid #0092DC;
border-left: none;
}
.layui-btn-group .layui-btn-normal:first-child {
border-left: 1px solid #0092DC;
}
</style>
{/block}
{block name="content"}
<div v-cloak id="app" class="layui-fluid">
<div class="layui-row layui-col-space15">
<!--搜索条件-->
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-header">考试订单</div>
<div class="layui-card-body">
<form class="layui-form" lay-filter="form" action="" @submit.prevent>
<div class="layui-form-item">
<label class="layui-form-label">订单状态:</label>
<div class="layui-input-block">
<div class="layui-btn-group">
<button :class="[where.status === item.value ? 'layui-btn-normal' : 'layui-btn-primary', 'layui-btn layui-btn-sm']" @click="where.status = item.value" type="button" v-for="item in orderStatus">
{{item.name}}
<span v-if="item.count !== undefined" :class="{ 'layui-bg-gray': item.class === undefined }" class="layui-badge">{{item.count}}</span>
</button>
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">创建时间:</label>
<div class="layui-input-inline" data-type="data" style="width: auto;">
<div class="layui-btn-group">
<button :class="[where.data === item.value ? 'layui-btn-normal' : 'layui-btn-primary', 'layui-btn layui-btn-sm']" type="button" v-for="item in dataList" @click="setData(item)">{{item.name}}</button>
</div>
</div>
<div class="layui-input-inline">
<input type="text" name="date" placeholder="自定义" autocomplete="off" id="date" class="layui-input" style="height: 30px;">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">搜索内容:</label>
<div class="layui-input-inline">
<input type="text" name="real_name" v-model="where.real_name" placeholder="请输入订单号、昵称、UID" autocomplete="off" class="layui-input" style="height: 30px;">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" @click="search">
<i class="layui-icon">&#xe615;</i>搜索
</button>
<button class="layui-btn layui-btn-primary layui-btn-sm export" @click="excel">
<i class="layui-icon">&#xe67d;</i>导出
</button>
<button class="layui-btn layui-btn-primary layui-btn-sm export" @click="refresh">
<i class="layui-icon">&#xe669;</i>刷新
</button>
</div>
</div>
</form>
</div>
</div>
</div>
<!--end-->
<!-- 中间详细信息-->
<div :class="item.col!=undefined ? 'layui-col-sm'+item.col+' '+'layui-col-md'+item.col:'layui-col-sm6 layui-col-md3'" v-for="item in badge" v-if="item.count > 0">
<div class="layui-card">
<div class="layui-card-header">
{{item.name}}
<span class="layui-badge layuiadmin-badge" :class="item.background_color">{{item.field}}</span>
</div>
<div class="layui-card-body">
<p class="layuiadmin-big-font">{{item.count}}</p>
<p v-show="item.content!=undefined">
{{item.content}}
<span class="layuiadmin-span-color">{{item.sum}}<i :class="item.class"></i></span>
</p>
</div>
</div>
</div>
<!--enb-->
<!--列表-->
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-body">
<table class="layui-hide" id="List" lay-filter="List"></table>
</div>
</div>
</div>
<!--end-->
</div>
</div>
<!--订单-->
<script type="text/html" id="order_id">
<h4>{{d.order_id}}</h4>
<span style="color: {{d.color}};">{{d.order_name}}</span>  
</script>
<!--用户信息-->
<script type="text/html" id="userinfo">
{{d.nickname==null ? '暂无昵称':d.nickname}}/{{d.uid}}
</script>
<!--支付状态-->
<script type="text/html" id="paid">
{{# if(d.pay_type==1){ }}
<p>{{d.pay_type_name}}</p>
{{# }else{ }}
{{# if(d.pay_type_info!=undefined){ }}
<p><span>线下支付</span></p>
<p><button type="button" lay-event='offline_btn' class="offline_btn btn btn-w-m btn-white">立即支付</button></p>
{{# }else{ }}
<p>{{d.pay_type_name}}</p>
{{# } }}
{{# }; }}
</script>
<!--订单状态-->
<script type="text/html" id="status">
{{d.status_name}}
{{# if(d.paid==1 && d.refund_status==1){ }}
<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" onclick="$eb.createModalFrame('退款原因','{:Url('reason_refund')}?oid={{d.id}}',{w:800,h:600})">退款原因</button>
{{# }; }}
</script>
<!--商品信息-->
<script type="text/html" id="info">
{{# if(d._info.image){ }}
<img style="height:25px;cursor: pointer;" src="{{d._info.image}}">
{{# };}}
<span>{{d._info.title}}</span>
</script>
<script type="text/html" id="act">
{{# if(d._status==1 && d.nickname!=null){ }}
<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" onclick="dropdown(this)">
<i class="layui-icon">&#xe625;</i>操作
</button>
<ul class="layui-nav-child layui-anim layui-anim-upbit">
<li>
<a href="javascript:void(0);" onclick="$eb.createModalFrame('订单详情','{:Url('order_info')}?oid={{d.id}}')">
<i class="fa fa-file-text"></i> 订单详情
</a>
</li>
<li>
<a lay-event='delete' href="javascript:void(0);" >
<i class="fa fa-trash"></i> 删除
</a>
</li>
</ul>
{{# }else if(d._status==2 && d.nickname!=null){ }}
<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" onclick="dropdown(this)">
<i class="layui-icon">&#xe625;</i>操作
</button>
<ul class="layui-nav-child layui-anim layui-anim-upbit">
<li>
<a href="javascript:void(0);" onclick="$eb.createModalFrame('订单详情','{:Url('order_info')}?oid={{d.id}}')">
<i class="fa fa-file-text"></i> 订单详情
</a>
</li>
{{# if(d.pay_price!=d.refund_price){ }}
<li>
<a href="javascript:void(0);" onclick="$eb.createModalFrame('退款','{:Url('refund_y')}?id={{d.id}}',{w:400,h:300})">
<i class="fa fa-history"></i> 立即退款
</a>
</li>
{{# } ;}}
<li>
<a lay-event='delete' href="javascript:void(0);" >
<i class="fa fa-trash"></i> 删除
</a>
</li>
</ul>
{{# }else if(d._status==3 && d.nickname!=null){ }}
<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" onclick="dropdown(this)">
<i class="layui-icon">&#xe625;</i>操作
</button>
<ul class="layui-nav-child layui-anim layui-anim-upbit">
<li>
<a href="javascript:void(0);" onclick="$eb.createModalFrame('订单详情','{:Url('order_info')}?oid={{d.id}}')">
<i class="fa fa-file-text"></i> 订单详情
</a>
</li>
{{# if(d.pay_price != d.refund_price){ }}
<li>
<a href="javascript:void(0);" onclick="$eb.createModalFrame('退款','{:Url('refund_y')}?id={{d.id}}',{w:400,h:300})">
<i class="fa fa-history"></i>立即退款
</a>
</li>
{{# } ;}}
<li>
<a lay-event='delete' href="javascript:void(0);" >
<i class="fa fa-trash"></i> 删除
</a>
</li>
</ul>
{{# }else if(d._status==7 && d.nickname!=null){ }}
<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" onclick="dropdown(this)">
<i class="layui-icon">&#xe625;</i>操作
</button>
<ul class="layui-nav-child layui-anim layui-anim-upbit">
<li>
<a href="javascript:void(0);" onclick="$eb.createModalFrame('订单详情','{:Url('order_info')}?oid={{d.id}}')">
<i class="fa fa-file-text"></i> 订单详情
</a>
</li>
{{# if(d.pay_price != d.refund_price){ }}
<li>
<a href="javascript:void(0);" onclick="$eb.createModalFrame('退款','{:Url('refund_y')}?id={{d.id}}',{w:400,h:300})">
<i class="fa fa-history"></i>立即退款
</a>
</li>
{{# } ;}}
<li>
<a lay-event='delete' href="javascript:void(0);" >
<i class="fa fa-trash"></i> 删除
</a>
</li>
</ul>
{{# }else if(d.nickname==null){ }}
<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" onclick="dropdown(this)">
<i class="layui-icon">&#xe625;</i>操作
</button>
<ul class="layui-nav-child layui-anim layui-anim-upbit">
<li>
<a lay-event='delete' href="javascript:void(0);" >
<i class="fa fa-trash"></i> 删除
</a>
</li>
</ul>
{{# }; }}
</script>
<script src="{__ADMIN_PATH}js/layuiList.js"></script>
{/block}
{block name="script"}
<script>
//下拉框
$(document).click(function (e) {
$('.layui-nav-child').hide();
})
function dropdown(that){
var oEvent = arguments.callee.caller.arguments[0] || event;
oEvent.stopPropagation();
var offset = $(that).offset();
var top=offset.top-$(window).scrollTop();
var index = $(that).parents('tr').data('index');
$('.layui-nav-child').each(function (key) {
if (key != index) {
$(this).hide();
}
});
if($(document).height() < top+$(that).next('ul').height()){
$(that).next('ul').css({
'padding': 10,
'top': - ($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height()/2),
'min-width': 'inherit',
'position': 'absolute'
}).toggle();
}else{
$(that).next('ul').css({
'padding': 10,
'top':$(that).parent('td').height() / 2 + $(that).height(),
'min-width': 'inherit',
'position': 'absolute'
}).toggle();
}
}
var real_name='<?=$real_name?>';
var orderCount=<?=json_encode($orderCount)?>;
require(['vue'],function(Vue) {
new Vue({
el: "#app",
data: {
badge: [],
orderStatus: [
{name: '全部', value: ''},
{name: '未支付', value: 0,count:orderCount.wz},
{name: '已支付', value: 1,count:orderCount.wf,class:true},
{name: '已退款', value: -2,count:orderCount.yt},
],
dataList: [
{name: '全部', value: ''},
{name: '今天', value: 'today'},
{name: '昨天', value: 'yesterday'},
{name: '本周', value: 'week'},
{name: '本月', value: 'month'},
{name: '本季度', value: 'quarter'},
{name: '本年', value: 'year'},
],
where:{
data:'',
status:'',
real_name:real_name || '',
excel:0,
},
showtime: false,
},
methods: {
setData:function(item){
this.where.data = item.value;
layui.form.val('form', {
'date': ''
});
},
getBadge:function() {
var that=this;
layList.basePost(layList.Url({c:'order.test_paper_order',a:'getBadge'}),this.where,function (rem) {
that.badge=rem.data;
});
},
search:function () {
this.getBadge();
this.where.excel=0;
layList.reload(this.where,true);
},
refresh:function () {
window.location.reload();
},
excel:function () {
this.where.excel=1;
location.href=layList.U({c:'order.test_paper_order',a:'test_paper_order_list',q:this.where});
}
},
mounted:function () {
var that=this;
that.getBadge();
layui.laydate.render({
elem: '#date',
range: true,
done: function (value){
that.where.data = value;
}
});
layList.tableList('List',"{:Url('test_paper_order_list',['real_name'=>$real_name])}",function (){
return [
{field: 'order_id', title: '订单号', width:'13%',templet:'#order_id'},
{field: 'nickname', title: '用户信息',templet:'#userinfo',align: 'center', width:'10%'},
{field: 'info', title: '试卷信息',templet:"#info"},
{field: 'pay_price', title: '实际支付',align: 'center', width:'10%'},
{field: 'paid', title: '支付状态',templet:'#paid',align: 'center', width:'10%'},
{field: 'status', title: '订单状态',templet:'#status',align: 'center', width:'10%'},
{field: 'right', title: '操作',align:'center',toolbar:'#act', width:'10%'},
];
});
layList.tool(function (event,data,obj) {
switch (event) {
case 'delete':
var url=layList.U({c:'order.test_paper_order',a:'delete',q:{id:data.id}});
$eb.$swal('delete',function(){
$eb.axios.get(url).then(function(res){
if(res.status == 200 && res.data.code == 200) {
$eb.$swal('success',res.data.msg);
obj.del();
}else
return Promise.reject(res.data.msg || '删除失败')
}).catch(function(err){
$eb.$swal('error',err);
});
});
break;
}
});
}
})
});
</script>
{/block}
Loading…
Cancel
Save