代为充值调整+流水查看

master
wangxinglong 2021-11-29 13:56:26 +08:00
parent a8e09eff85
commit 417d813f30
12 changed files with 296 additions and 69 deletions

View File

@ -50,11 +50,15 @@ class Recharge extends Base
//这里确定支付成功
$total_fee = $res['total_fee'] / 100;
//加余额
$business->save(["balance" => ($business["balance"] + $total_fee)]);
$business->save([
"balance" => ($business["balance"] + $total_fee),
"total_recharge" => ($business["total_recharge"] + $total_fee)
]);
//修改支付状态
$recharge->save([
"money" => $total_fee,
"state" => RechargeModel::state_on,
"open_id" => $res['openid'],
"update_time" => date("Y-m-d H:i:s"),
"balance" => $business->balance
]);
@ -109,11 +113,15 @@ class Recharge extends Base
//这里确定支付成功
$total_fee = $message['total_fee'] / 100;
//加余额
$business->save(["balance" => ($business["balance"] + $total_fee)]);
$business->inc()->save([
"balance" => ($business["balance"] + $total_fee),
"total_recharge" => ($business["total_recharge"] + $total_fee)]
);
//修改支付状态
$recharge->save([
"money" => $total_fee,
"state" => RechargeModel::state_on,
"open_id" => $message['openid'],
"update_time" => date("Y-m-d H:i:s"),
"balance" => $business->balance
]);

View File

@ -5,6 +5,7 @@ namespace app\controller\manager;
/*流水查看*/
use app\model\CouponBill;
use app\repository\BillRepository;
class Bill extends Base
@ -17,20 +18,28 @@ class Bill extends Base
*/
public function index()
{
$startTime = input("start_time/s", date("Y-m-d H:i:s", strtotime(date("Y-m-d") . " -1 month")));
$endTime = input("end_time/s", date("Y-m-d 00:00:00"));
if ($this->request->isPost()) {
$repo = BillRepository::getInstance();
$keyword = $this->request->param('keyword/s', '');
$page = $this->request->param('page/d', 1);
$size = $this->request->param('size/d', 30);
$orders = ['sort'=>'asc'];
$list = $repo->billList($keyword, $page, $size, $orders);
$keyword = $this->request->param('keyword/s', '');
$page = $this->request->param('page/d', 1);
$size = $this->request->param('size/d', 30);
$orders = ['id' => 'desc'];
$list = $repo->billList($page, $size, $keyword, $startTime, $endTime, $orders);
$list['agency_money_sum'] = BillRepository::getInstance()->getAgencyMoneySum(CouponBill::agency_money, $startTime, $endTime);
$list['admin_money_sum'] = BillRepository::getInstance()->getAgencyMoneySum(CouponBill::admin_money, $startTime, $endTime);
$list['consumer_money_sum'] = BillRepository::getInstance()->getAgencyMoneySum(CouponBill::consumer_money, $startTime, $endTime);
return $this->json(0, 'success', $list);
}
$this->data["agency_money_sum"] = BillRepository::getInstance()->getAgencyMoneySum(CouponBill::agency_money);
$this->data["admin_money_sum"] = BillRepository::getInstance()->getAgencyMoneySum(CouponBill::admin_money);
$this->data["consumer_money_sum"] = BillRepository::getInstance()->getAgencyMoneySum(CouponBill::consumer_money);
$this->data["startTime"] = $startTime;
$this->data["endTime"] = $endTime;
return $this->view();
}

View File

@ -37,10 +37,10 @@ class Business extends Base
$page = $this->request->param('page/d', 1);
$size = $this->request->param('size/d', 30);
$whereMap = [["business.state", "=", BusinessModel::state_on]];
$orders = ['business.id' => 'desc'];
$whereMap = [["c.state", "=", BusinessModel::state_on]];
$orders = ['a.id' => 'desc'];
if (!empty($keyword)) {
$whereMap[] = ['account.nick_name|business.business_name', 'like', "%$keyword%"];
$whereMap[] = ['b.nick_name|c.business_name', 'like', "%$keyword%"];
}
$list = $repo->businessList($whereMap, $page, $size, $orders);
@ -48,10 +48,10 @@ class Business extends Base
//得到当前商家的所有优惠券
$date = date("Y-m-d H:i:s");
//优惠券总数
$item->coupon_total_count = CouponMain::where(["business_code" => $item->business->code])->sum("count");
$item->coupon_total_count = CouponMain::where(["business_code" => $item->business_code])->sum("count");
//进行中优惠券总数
$item->coupon_doing_count = CouponMain::where(["business_code" => $item->business->code])
$item->coupon_doing_count = CouponMain::where(["business_code" => $item->business_code])
->whereTime("start_time", "<", $date)
->whereTime("end_time", ">", $date)
->where("status", CouponMain::status_on)
@ -59,21 +59,21 @@ class Business extends Base
->sum("count");
//进行中优惠券总数
$item->coupon_receive_count = CouponMain::where(["business_code" => $item->business->code])->sum("received_count");
$item->coupon_receive_count = CouponMain::where(["business_code" => $item->business_code])->sum("received_count");
//过期未使用优惠券总数
$item->coupon_be_overdue_count = Coupon::where(["business_code" => $item->business->code])
$item->coupon_be_overdue_count = Coupon::where(["business_code" => $item->business_code])
->where("is_verificated", "=", Coupon::is_verificated_off)
->whereTime("end_time", "<", $date)
->count();
//已使用优惠券总数
$item->coupon_used_count = Coupon::where(["business_code" => $item->business->code])
$item->coupon_used_count = Coupon::where(["business_code" => $item->business_code])
->where("is_verificated", "=", Coupon::is_verificated_on)
->count();
//商家充值总额
$item->recharge_total_money = $item->business->total_recharge;
$item->recharge_total_money = $item->total_recharge;
});
return $this->json(0, 'success', $list);
@ -320,7 +320,7 @@ class Business extends Base
Db::startTrans();
try {
//创建充值订单
if (!$order = RechargeRepository::getInstance()->createOrder($businessCode, $money)) {
if (!$order = RechargeRepository::getInstance()->adminCreateOrder($businessCode, $money)) {
throw new RepositoryException('订单创建失败,请稍后重试');
}
//生成支付
@ -344,7 +344,7 @@ class Business extends Base
return $this->json("5001", $e->getMessage());
} catch (Exception $e) {
Db::rollback();
return $this->json("5001", $e->getMessage());
return $this->json("5002", $e->getMessage());
}
}

View File

@ -43,9 +43,10 @@ class Login extends BaseController
}
$userInfo = [
'user_id' => $member['id'],
'username' => $member['username'],
'nickname' => $member['nickname'],
'user_id' => $member['id'],
'username' => $member['username'],
'nickname' => $member['nickname'],
'business_code' => $member['business_code'],
];
$jwtToken = Jwt::generate($userInfo, env('app.expire', 7200));

View File

@ -14,5 +14,20 @@ use think\db\exception\ModelNotFoundException;
*/
class CouponBill extends Base
{
public const agency_money = "agency_money";
public const admin_money = "admin_money";
public const consumer_money = "consumer_money";
public function couponMain()
{
return $this->hasOne(CouponMain::class, 'id',"coupon_main_id");
}
public function business()
{
return $this->hasOne(Business::class, 'code',"business_code");
}
public function account()
{
return $this->hasOne(Account::class, 'user_code',"user_code");
}
}

View File

@ -25,12 +25,18 @@ class BillRepository extends Repository
{
/**
* 流水列表
* @param $keyword
* @param $page
* @param $size
* @param $orders
* @param $keyword
* @param null $startTime
* @param null $endTime
* @param array $orders
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function billList($keyword, $page, $size, $orders = ["a.id" => "desc"])
public function billList($page, $size, $keyword = null, $startTime = null, $endTime = null, $orders = ["id" => "desc"])
{
$failData = [
'total' => 0,
@ -38,14 +44,28 @@ class BillRepository extends Repository
'size' => $size,
'list' => new Collection(),
];
$rep = CouponBill::alias("a")
->join("business b", "a.business_code = b.code")
->wher(!empty($keyword), function ($q) use ($keyword) {
$q->where("b.business_name", "like", "%$keyword%");
$rep = CouponBill::with([
"business" => function ($query) use ($keyword) {
$query->field(["code", "business_name"])->when(empty($keyword), function ($q) use ($keyword) {
$q->where("business_name", "like", "%$keyword%");
});
},
"account" => function ($q) {
$q->field(["user_code", "nick_name"]);
},
"couponMain" => function ($q) {
$q->field(["id", "name"]);
},
])
->when(!empty($startTime), function ($q) use ($startTime) {
$q->whereTime("create_time", ">=", $startTime);
})
->when(!empty($endTime), function ($q) use ($endTime) {
$q->whereTime("create_time", "<=", $endTime);
});
$failData ['total'] = $rep->count();
$failData ['list'] = $rep->field("a.*,b.business_name")
$failData ['list'] = $rep
->page($page, $size)
->order($orders)
->select();
@ -53,4 +73,21 @@ class BillRepository extends Repository
}
/**
* 总收益
* @param $field
* @param null $start_time
* @param null $end_time
* @return float
*/
public function getAgencyMoneySum($field, $start_time = null, $end_time = null)
{
return CouponBill::when(!empty($start_time), function ($q) use ($start_time) {
$q->whereTime("create_time", ">=", $start_time);
})->when(!empty($end_time), function ($q) use ($end_time) {
$q->whereTime("create_time", "<=", $end_time);
})
->sum($field);
}
}

View File

@ -33,7 +33,10 @@ class BusinessRepository extends Repository
*/
public function businessList(array $where = [], int $page = 1, int $limit = 0, array $order = [])
{
$q = $this->model->alias("a")->field("id")->withJoin(["account" => ["avatar_url", "nick_name"], "business"]);
$q = $this->model->alias("a")
->join("account b","a.user_code = b.user_code")
->join("business c","a.business_code = c.code")
->field(["c.code as business_code","b.avatar_url", "b.nick_name as account_nick_name","c.business_name","c.total_recharge","c.id as basiness_id","c.balance"]);
$data = [
'total' => 0,
'current' => $page,
@ -113,7 +116,12 @@ class BusinessRepository extends Repository
/* 获取所有的商家*/
public function getBusinessAll()
{
return Business:: where("state", Business::state_on)->select();
return BusinessFlow::alias("a")
->join("account b","a.user_code = b.user_code")
->join("business c","a.business_code = c.code")
->field("c.code , c.business_name ")
->order("a.id desc")
->select();
}
/**

View File

@ -19,9 +19,32 @@ use think\Model;
*/
class RechargeRepository extends Repository
{
/**
* 后台创建一个支付订单
* @param $businessCode
* @param $money
* @return Recharge|Model
*/
public function adminCreateOrder($businessCode, $money)
{
$data = [
"order_num" => createUuid(),
"agency_code" => session('auth')['business_code']??'',
"business_code" => $businessCode,
"money" => $money,
"state" => Recharge::state_off,
"create_time" => date("Y-m-d H:i:s"),
"balance" => 0,
];
return Recharge::create($data);
}
/**
* 创建一个支付订单
* */
* @param $businessCode
* @param $money
* @return Recharge|Model
*/
public function createOrder($businessCode, $money)
{
$data = [
@ -34,5 +57,4 @@ class RechargeRepository extends Repository
];
return Recharge::create($data);
}
}

View File

@ -1,10 +1,11 @@
layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function () {
layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect',"laydate"], function () {
let $ = layui.jquery,
form = layui.form,
table = layui.table,
layer = layui.layer,
xmSelect = layui.xmSelect,
miniTab = layui.miniTab;
miniTab = layui.miniTab,
laydate = layui.laydate ;
/**** index begin ***/
//index页面
@ -30,6 +31,10 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function
limitName: 'size',
},
parseData: function (res) {
//console.log(res)
$("#new_agency_money_sum").text(res.data.agency_money_sum?res.data.agency_money_sum:0)
$("#new_admin_money_sum").text(res.data.admin_money_sum?res.data.admin_money_sum:0)
$("#new_consumer_money_sum").text(res.data.consumer_money_sum?res.data.consumer_money_sum:0)
return {
"code": res.code, //解析接口状态
"msg": res.msg, //解析提示文本
@ -40,11 +45,30 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function
page: true,
cols: [[
{type: 'checkbox'},
{field: 'id', width: 80, title: 'ID'},
{field: 'title', minWidth: 200, title: '标题'},
{templet:function(d){
if( d.account != undefined &&d.account){
return d.account.nick_name
}
return '';
}, title: '用户昵称'},
{templet:function(d){
if( d.business != undefined &&d.business){
return d.business.business_name
}
return '';
}, title: '商家名称'},
{templet:function(d){
if( d.couponMain != undefined &&d.couponMain){
return d.couponMain.name
}
return '';
}, title: '优惠券名称'},
{templet:"#row-commission", title: '持有比例(渠道商:平台:消费者)'},
{field: 'money', minWidth: 200, title: '金额'},
{field: 'create_time', minWidth: 200, title: '时间'},
]],
done: function () {
done: function (res, curr, count) {
Tools.setInsTb(insTb);
}
});
@ -60,6 +84,18 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function
return false;
});
//日期时间选择器
laydate.render({
elem: '#start_time'
,type: 'datetime'
});
//日期时间选择器
laydate.render({
elem: '#end_time'
,type: 'datetime'
});

View File

@ -40,25 +40,17 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function
page: true,
cols: [[
// {type: 'checkbox'},
{templet:function(d){
return d.business.id
}, width: 80, title: 'ID'},
{field:"basiness_id", width: 80, title: 'ID'},
{templet: '#row-cover', title: '头像', style: 'height: 90px;'},
{templet:function(d){
return d.account.nick_name
}, title: '昵称'},
{templet:function(d){
return d.business.business_name
} ,title: '商家名称'},
{field:"account_nick_name", title: '昵称'},
{field: "business_name" ,title: '商家名称'},
{field: 'coupon_total_count', title: '优惠券总数量'},
{field: 'coupon_doing_count', title: '进行中优惠券数量'},
{field: 'coupon_receive_count', title: '已领取优惠券数量'},
{field: 'coupon_be_overdue_count', title: '过期未使用优惠券数量'},
{field: 'coupon_used_count', title: '已使用优惠数量'},
{templet:function(d){
return d.business.balance
},field: 'balance',title: '商家余额'},
{field: 'balance',title: '商家余额'},
{field: 'recharge_total_money', title: '充值总额'},
{templet: '#row-operate', minWidth: 350, field: 'right', align: 'center', title: '操作', fixed: 'right'}
]],

View File

@ -15,14 +15,99 @@
vertical-align: middle;
border: 0;
}
.l_font{
font-size: 26px;height: 25px
}
</style>
<div class="layui-row layui-col-space12">
<div class="layui-row layui-col-space15">
</div>
<div class="layui-col-md10">
<div class="layui-col-md12">
<div class="layui-col-md3">
<div class="layui-panel" style="border-radius: 8px;">
<div class="layui-row" style="padding: 5% 0;text-align: center">
<h3><strong>总流水:</strong></h3>
<span class="l_font" > &nbsp;</span>
</div>
</div>
</div>
<div class="layui-col-md3">
<div class="layui-panel" style="border-radius: 8px;">
<div class="layui-row" style="padding: 5% 0;text-align: center">
<h3><strong>渠道商提成总额</strong></h3>
<span class="l_font">{$agency_money_sum ?? 0}</span>
</div>
</div>
</div>
<div class="layui-col-md3">
<div class="layui-panel" style="border-radius: 8px;">
<div class="layui-row" style="padding: 5% 0;text-align: center">
<h3><strong>太古平台提成总额</strong></h3>
<span class="l_font">{$admin_money_sum ?? 0}</span>
</div>
</div>
</div>
<div class="layui-col-md3">
<div class="layui-panel" style="border-radius: 8px;">
<div class="layui-row" style="padding: 5% 0;text-align: center">
<h3><strong>消费者提成总额</strong></h3>
<span class="l_font">{$consumer_money_sum?? 0}</span>
</div>
</div>
</div>
</div>
<div class="layui-col-md12">
<div class="layui-col-md3">
<div class="layui-panel" style="border-radius: 8px;">
<div class="layui-row" style="padding: 5% 0;text-align: center">
<h3><strong>当前流水:</strong></h3>
<span class="l_font" > &nbsp;</span>
</div>
</div>
</div>
<div class="layui-col-md3">
<div class="layui-panel" style="border-radius: 8px;">
<div class="layui-row" style="padding: 5% 0;text-align: center">
<h3><strong>渠道商提成总额</strong></h3>
<span class="l_font" id="new_agency_money_sum"> &nbsp;</span>
</div>
</div>
</div>
<div class="layui-col-md3">
<div class="layui-panel" style="border-radius: 8px;">
<div class="layui-row" style="padding: 5% 0;text-align: center">
<h3><strong>太古平台提成总额</strong></h3>
<span class="l_font" id="new_admin_money_sum"> &nbsp;</span>
</div>
</div>
</div>
<div class="layui-col-md3">
<div class="layui-panel" style="border-radius: 8px;">
<div class="layui-row" style="padding: 5% 0;text-align: center">
<h3><strong>消费者提成总额</strong></h3>
<span class="l_font" id="new_consumer_money_sum"> &nbsp;</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="layui-col-xs12 layui-col-md12">
<div id="echarts-records" style="background-color:#ffffff;min-height:600px;">
<div class="layuimini-container location-index-page">
<div class="layuimini-main">
<fieldset class="table-search-fieldset" style="display: none">
<fieldset class="table-search-fieldset" >
<legend>搜索信息</legend>
<div style="margin: 10px 10px 10px 10px">
<form class="layui-form layui-form-pane" action="">
@ -33,7 +118,18 @@
<input type="text" name="keyword" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">开始时间</label>
<div class="layui-inline">
<input type="text" name="start_time" id="start_time" value="{$startTime}" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">结束时间</label>
<div class="layui-inline">
<input type="text" name="end_time" id="end_time" value="{$endTime}" class="layui-input">
</div>
</div>
<div class="layui-inline">
<button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
@ -53,14 +149,17 @@
<!-- toolbar -->
<script type="text/html" id="toolbar-tpl">
<a class="layui-btn layui-btn-primary layui-btn-sm" data-table-refresh lay-event="refresh"><i class="fa fa-refresh"></i></a>
</script>
<!-- 列 轮播图 -->
<script type="text/html" id="row-cover">
<div class="layui-layer-photos">
<img src="{{ getFileRequestUrl(d.src) }}" layer-src="{{ getFileRequestUrl(d.src) }}" alt="">
</div>
<script type="text/html" id="row-commission">
比例: <span style="font-weight: bold">{{ d.commission_agency}} : {{ d.commission_admin}} : {{ d.commission_consumer}}</span> <br>
金额: <span style="font-weight: bold">{{ d.agency_money}} : {{ d.admin_money}} : {{ d.consumer_money}}</span>
</script>
<script src="__MANAGER__/js/bill.js?v={:mt_rand()}"></script>

View File

@ -51,12 +51,12 @@
<!-- 操作列 -->
<script type="text/html" id="row-operate">
<a class="layui-btn layui-btn-primary layui-btn-xs" data-href="/manager/business/business-coupon-list.html?business_code={{d.business.code}}" data-title="【{{ d.business.business_name }}】优惠券浏览" lay-event="">优惠券浏览</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" data-href="/manager/business/business-deduction-list.html?business_code={{d.business.code}}" data-title="【{{ d.business.business_name }}】扣费记录" lay-event="">扣费记录</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" data-href="/manager/business/business-recharge-list.html?business_code={{d.business.code}}" data-title="【{{ d.business.business_name }}】充值记录" lay-event="">充值记录</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" data-href="/manager/business/business-detail.html?business_code={{d.business.code}}" data-title="【{{ d.business.business_name }}】基本资料" lay-event="">基本资料</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" data-href="/manager/business/assign.html?business_code={{d.business.code}}" data-title="给【{{ d.business.business_name }}】指派代理商" lay-event="">指派代理商</a>
<a class="layui-btn layui-btn-xs" href="javascript:;" layuimini-content-href="/manager/business/recharge-behalf.html?business_code={{d.business.code}}" data-title="给【{{ d.business.business_name }}】充值" >代为充值</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" data-href="/manager/business/business-coupon-list.html?business_code={{d.business_code}}" data-title="【{{ d.business_name }}】优惠券浏览" lay-event="">优惠券浏览</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" data-href="/manager/business/business-deduction-list.html?business_code={{d.business_code}}" data-title="【{{ d.business_name }}】扣费记录" lay-event="">扣费记录</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" data-href="/manager/business/business-recharge-list.html?business_code={{d.business_code}}" data-title="【{{ d.business_name }}】充值记录" lay-event="">充值记录</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" data-href="/manager/business/business-detail.html?business_code={{d.business_code}}" data-title="【{{ d.business_name }}】基本资料" lay-event="">基本资料</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" data-href="/manager/business/assign.html?business_code={{d.business_code}}" data-title="给【{{ d.business_name }}】指派代理商" lay-event="">指派代理商</a>
<a class="layui-btn layui-btn-xs" href="javascript:;" layuimini-content-href="/manager/business/recharge-behalf.html?business_code={{d.business_code}}" data-title="给【{{ d.business_name }}】充值" >代为充值</a>
</script>
<!-- toolbar -->
@ -67,7 +67,7 @@
<!-- 列 轮播图 -->
<script type="text/html" id="row-cover">
<div class="layui-layer-photos">
<img src="{{ d.account.avatar_url }}" layer-src="{{ d.account.avatar_url }}" alt="">
<img src="{{ d.avatar_url }}" layer-src="{{ d.avatar_url }}" alt="">
</div>
</script>