Commit 39c4c89a by 杨树贤

完成用户兑换的相关服务

parent a33b0058
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\UserExchangeService;
use App\Http\Services\UserIntegralService;
use App\Http\Transformers\UserExchangeTransformer;
use App\Http\Transformers\UserIntegralTransformer;
use Illuminate\Http\Request;
class UserExchangesApiController extends Controller
{
private $service;
private $transformer;
public function __construct(UserExchangeService $service, UserExchangeTransformer $transformer)
{
$this->service = $service;
$this->transformer = $transformer;
}
public function userExchangeListApi(Request $request)
{
$params = $this->getListParams($request);
$data = $this->service->getUserExchangeList($params);
$data = $this->transformer->transform($data);
return $this->apiReturn(0, 'ok', [
'data' => $data['data'],
'count' => $data['count'],
]);
}
public function userExchangeBillListApi(Request $request)
{
$data = $this->service->getUserExchangeList($request->all());
$data = $this->transformer->billTransform($data);
return $this->apiReturn(0, 'ok', [
'data' => $data['data'],
'count' => $data['count'],
]);
}
private function getListParams(Request $request)
{
//因为数据库没有存mobile,所以要根据mobile去获取userId
$userId = $this->service->getUserIdByMobile($request->mobile);
$params = array_merge($request->toArray(), ['user_id' => $userId]);
if ($request->has('mobile') && $request->mobile) {
$params['user_id'] = $params['user_id'] ?: 0;
}
unset($params['mobile']);
return $params;
}
public function changeUserExchangeStatusApi(Request $request)
{
$id = $request->id;
$status = $request->status;
$path = 'user_exchanges/' . $id;
$result = $this->service->changeUserExchangeStatus($path, ['status' => $status]);
return $result;
}
public function batchUpdateStatusApi(Request $request)
{
$path = '/user_exchanges/batchUpdateStatus';
$result = $this->service->batchUpdateStatus($path, $request->all());
return $result;
}
}
\ No newline at end of file
<?php
namespace App\Http\Controllers;
use App\Http\Services\UserExchangeService;
use App\Http\Services\UserIntegralService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class UserExchangesController extends Controller
{
public $service;
public function __construct(UserExchangeService $service)
{
$this->service = $service;
}
public function Entrance(Request $request, $id = 'index')
{
if ($request->path() == '/') {
$path = 'web/index';
} else {
$path = $request->path();
}
$this->data = [
'menus' => $request->menus,
'header' => $request->user->header,
'username' => $request->user->email,
'useremail' => $request->user->email,
'uri' => '/' . $path,
'id' => $id,
];
return $this->$id($request);
}
public function __call($method, $parameters)
{
return $this->errhtml('NotFind', '没有这个页面');
}
public function userExchangeList()
{
$this->data['title'] = '用户兑换管理';
return $this->view();
}
public function userExchangeBillList(Request $request)
{
$this->data['title'] = '用户兑换详细';
//获取该用户的红包信息
$userIntegralService = new UserIntegralService();
$userIntegral = $userIntegralService->getUserIntegral($request->user_id);
$this->data['user_integral'] = array_get($userIntegral, 'data');
//获取红包列表做tab项
$this->data['types'] = [1 => '话费充值', 2 => '微信转账'];
return $this->view();
}
public function auditUserExchange(Request $request)
{
$this->data['title'] = '审核用户兑换';
//获得该次申请的详情
$userExchange = $this->service->getUserExchange($request->user_id);
$user = $this->service->getUser($request->user_id);
$userExchange['data']['mobile'] = $user['mobile'];
$this->data['audit_id'] = $request->user->userId;
$this->data['audit_name'] = $request->user->name;
$this->data['user_exchange'] = $userExchange['data'];
return $this->view();
}
}
......@@ -4,6 +4,7 @@
namespace App\Http\Services;
use App\Model\RedisModel;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;
......@@ -69,4 +70,31 @@ class BaseService
return $data;
}
public function getUsersFromRedis($userIds = [])
{
$redis = new RedisModel();
$users = $redis->hmget('ic_user', $userIds);
foreach ($users as $key => $user) {
$users[$key] = json_decode($user, true);
}
return $users;
}
public function getUserIdByMobile($mobile)
{
$redis = new RedisModel();
$userId = json_decode($redis->hget('ic_user_mobile', $mobile), true);
return $userId;
}
public function getUser($userId)
{
$redis = new RedisModel();
$user = json_decode($redis->hget('ic_user', $userId), true);
return $user;
}
}
\ No newline at end of file
<?php
namespace App\Http\Services;
use App\Model\RedisModel;
class UserExchangeService extends BaseService
{
public function getUserExchange($userId)
{
$path = '/user_exchanges/' . $userId;
return $this->apiGet($path);
}
public function getUserExchangeList($params)
{
$path = '/user_exchanges?' . http_build_query($params);
return $this->apiGet($path);
}
public function changeUserExchangeStatus($path, $data = [])
{
return $this->apiPatch($path, $data);
}
public function batchUpdateStatus($path, $data = [])
{
return $this->apiPost($path, $data);
}
}
\ No newline at end of file
<?php
namespace App\Http\Transformers;
use App\Http\Services\UserExchangeService;
class UserExchangeTransformer
{
protected $service;
public function __construct(UserExchangeService $service)
{
$this->service = $service;
}
public function transform($data)
{
$userIds = array_column($data['data'], 'user_id');
$userMobiles = [];
$certifications = [];
if ($userIds) {
if ($userIds) {
$users = $this->service->getUsersFromRedis($userIds);
foreach ($users as $user) {
$userMobiles[$user['user_id']] = $user['mobile'];
$certifications[$user['user_id']] = array_get($user, 'company_type', 0);
}
}
}
foreach ($data['data'] as &$item) {
$mobile = array_get($userMobiles, $item['user_id'], '无');
$item['mobile'] = $mobile;
$item['certification_status'] = array_get($certifications, $item['user_id'], 0);
if ($item['certification_status'] === 1) {
$item['certification_status'] = '企业认证';
} elseif ($item['certification_status'] === 2) {
$item['certification_status'] = '个人认证';
} else {
$item['certification_status'] = '暂无认证';
}
$item['status'] = transform($item['status'], function ($value) {
switch ($value) {
case 1:
return '已兑换';
break;
case -1:
return '拒绝兑换';
break;
default:
return '待审核';
break;
}
});
}
return $data;
}
public function billTransform($data)
{
foreach ($data['data'] as &$item) {
$userId = \request()->user_id;
$users = $this->service->getUsersFromRedis($userId);
foreach ($users as $user) {
$mobile[$user['user_id']] = $user['mobile'];
}
$item['mobile'] = array_get($mobile, $userId);
$item['type'] = transform($item['type'], function ($value) {
switch ($value) {
case 1:
return '话费充值';
break;
case 2:
return '微信转账';
break;
default:
return '其他';
break;
}
});
$item['status'] = transform($item['status'], function ($value) {
switch ($value) {
case 1:
return '已兑换';
break;
case -1:
return '拒绝兑换';
break;
default:
return '待审核';
break;
}
});
$item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
$item['audit_time'] = $item['audit_time'] ? date('Y-m-d H:i:s', $item['audit_time']) : '暂无';
}
unset($item);
return $data;
}
}
\ No newline at end of file
......@@ -8124,7 +8124,7 @@ body.md-skin {
#page-wrapper {
position: inherit;
margin: 0 0 0 220px;
min-height: 1200px;
min-height: 968px;
padding: 0;
}
#page-wrapper iframe {
......
layui.use('form', function () {
var form = layui.form;
form.on('submit(AuditUserExchange)', function (data) {
let url = '/user_exchanges/api/changeUserExchangeStatusApi';
$.ajax({
type: 'POST',
url: url,
data: data.field,
timeout: 10000,
success: function (result) {
if (result.errcode === 0) {
layer.msg('审核完成');
window.location = '/user_exchanges/userExchangeList';
}
},
error: function () {
return layer.msg('网络错误,请重试', {icon: 5});
}
});
});
});
function getRequestParams() {
var url = window.location.href;
var theRequest = {};
if (url.indexOf("?") !== -1) {
var str = url.split("?")[1];//获取url中"?"符后的字串
strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
layui.use(['table', 'form', 'laydate', 'layer', 'element'], function () {
var form = layui.form;
var table = layui.table;
table.render({
elem: '#list'
, skin: 'line'
, url: '/user_exchanges/api/userExchangeBillListApi'
, method: 'get'
, request: {
pageName: 'page'
, limitName: 'page_size'
}
, where: getRequestParams()
, toolbar: '#toolbarLeft'
, defaultToolbar: ['filter']
, loading: true
, cols: [[
{field: 'mobile', title: '账号'}
, {field: 'exchanged_amount', title: '兑换金额'}
, {field: 'type', title: '事件'}
, {field: 'status', title: '执行结果'}
, {field: 'add_time', title: '添加时间'}
, {field: 'audit_time', title: '审核时间'}
]]
, id: 'UserExchangeBill'
, page: {}
});
var element = layui.element;
//一些事件监听
element.on('tab(UserExchangeBillTab)', function (data) {
table.reload('UserExchangeBill', {
where: {
type: this.id,
}
});
});
});
\ No newline at end of file
function getRequestParams() {
var url = window.location.href;
var theRequest = {};
if (url.indexOf("?") !== -1) {
var str = url.split("?")[1];//获取url中"?"符后的字串
strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
function changeStatus(checkStatus, status, table) {
var data = checkStatus.data;
var ids = [];
for (var key in data) {
ids.push(data[key].id);
}
var operateText = status ? '恢复' : '禁用';
layer.confirm('确定批量拒绝兑换选中行?', function (index) {
$.ajax({
url: '/user_exchanges/api/batchUpdateStatusApi',
type: 'post',
data: {ids: ids, status: status},
dataType: 'json',
timeout: 10000,
success: function (res) {
if (!res) return layer.msg('网络错误,请重试', {icon: 5});
if (res.errcode === 0) {
var msg = '批量拒绝成功';
layer.msg(msg);
table.reload('UserExchange');
}
},
error: function () {
return layer.msg('网络错误,请重试', {icon: 5});
}
})
})
}
layui.use(['table', 'form', 'laydate', 'layer'], function () {
var table = layui.table;
var form = layui.form;
table.render({
elem: '#UserExchange'
, skin: 'line'
, url: '/user_exchanges/api/userExchangeListApi'
, method: 'get'
, request: {
pageName: 'page'
, limitName: 'page_size'
}
, where: getRequestParams()
, toolbar: '#toolbarLeft'
, defaultToolbar: ['filter']
, loading: true
, cols: [[
{type: 'checkbox'}
, {field: 'id', title: '序号'}
, {field: 'mobile', title: '注册手机号'}
, {field: 'exchanged_amount', title: '兑换金额'}
, {field: 'exchanged_amount', title: '已兑换'}
, {field: 'type', title: '兑换类型',templet: '#type'}
, {field: 'certification_status', title: '认证状态'}
, {field: 'status', title: '兑换状态', templet: '#status'}
, {field: 'experience', title: '操作', templet: '#operate', fixed: 'right'}
]]
, id: 'UserExchange'
, page: {}
});
//头工具栏事件
table.on('toolbar(UserExchange)', function (obj) {
var checkStatus = table.checkStatus(obj.config.id);
switch (obj.event) {
case 'batchDisableStatus':
changeStatus(checkStatus, -1, table);
break;
}
});
//监听行工具事件
table.on('tool(UserExchange)', function (obj) {
var data = obj.data
, layEvent = obj.event;
switch (layEvent) {
case 'audit':
window.location = '/user_exchanges/auditUserExchange?user_id=' + obj.data.user_id;
break;
case 'bills':
window.location = '/user_exchanges/userExchangeBillList?user_id=' + obj.data.user_id;
break;
}
});
});
\ No newline at end of file
<div class="layui-card">
<div class="layui-card-body" style="padding-top: 20px">
<div class="layui-form">
<input type="hidden" name="id" value="{{$user_exchange['id']}}">
<input type="hidden" name="audit_id" value="{{$audit_id}}">
<div class="layui-form-item">
<label class="layui-form-label">注册手机号</label>
<div class="layui-input-block">
<input type="text" value="{{$user_exchange['mobile']}}" disabled
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">兑换金额</label>
<div class="layui-input-block">
<input type="text" value="{{$user_exchange['exchanged_amount']}}" disabled
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">当前审核人</label>
<div class="layui-input-block">
<input type="text" value="{{$audit_name}}" disabled="disabled"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('status','审批选择',1,[1=>'通过',-1=>'拒绝']) !!}
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit="" lay-filter="AuditUserExchange">确定审核</button>
<button type="reset" class="layui-btn layui-btn-primary" onclick="history.back()">返回列表</button>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
......@@ -12,13 +12,13 @@
</div>
<div class="layui-form-item">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('type','商品类型',0,[0=>'无',1=>'类型1',2=>'类型2']) !!}
{!! $statusPresenter->render('type','商品类型',0,[0=>'无',1=>'话费充值',2=>'微信提现']) !!}
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">兑换所需金额</label>
<div class="layui-input-inline">
<input type="text" name="amount""
<input type="text" name="amount"
lay-verify="required|number"
autocomplete="off" class="layui-input">
</div>
......@@ -41,7 +41,7 @@
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit="" lay-filter="CreateExchangeSetting">立即提交</button>
{{-- <button type="reset" class="layui-btn layui-btn-primary">重置</button>--}}
<button type="reset" class="layui-btn layui-btn-primary" onclick="history.back()">返回列表</button>
</div>
</div>
</div>
......
......@@ -32,6 +32,7 @@
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit="" lay-filter="creat_integral">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary" onclick="history.back()">返回列表</button>
</div>
</div>
</div>
......
......@@ -12,7 +12,7 @@
<div class="layui-inline">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('type','商品类型',request()->get('type'),[0=>'无',1=>'类型1',2=>'类型2']) !!}
{!! $statusPresenter->render('type','商品类型',request()->get('type'),[0=>'无',1=>'话费充值',2=>'微信提现']) !!}
</div>
<div class="layui-inline">
......@@ -33,7 +33,7 @@
</div>
<div class="layui-card-body" style="padding-top: 20px">
<div style="padding-bottom: 10px;">
{{-- <button class="layui-btn layui-btn-danger layuiadmin-btn-list" data-type="batchdel">禁用</button>--}}
{{-- <button class="layui-btn layui-btn-danger layuiadmin-btn-list" data-type="batchdel">禁用</button>--}}
<a href="/exchange/settings/createExchangeSetting" class="layui-btn layuiadmin-btn-list"
data-type="add">添加</a>
</div>
......
......@@ -12,7 +12,7 @@
</div>
<div class="layui-form-item">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('type','商品类型',$exchangeSetting['type'],[0=>'无',1=>'类型1',2=>'类型2']) !!}
{!! $statusPresenter->render('type','商品类型',$exchangeSetting['type'],[0=>'无',1=>'话费充值',2=>'微信提现']) !!}
</div>
<div class="layui-form-item">
<div class="layui-inline">
......@@ -41,7 +41,7 @@
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit="" lay-filter="UpdateExchangeSetting">立即提交</button>
{{-- <button type="reset" class="layui-btn layui-btn-primary">重置</button>--}}
<button type="reset" class="layui-btn layui-btn-primary" onclick="history.back()">返回列表</button>
</div>
</div>
</div>
......
......@@ -23,7 +23,8 @@
<div class="layui-inline">
<label class="layui-form-label">每个用户日限</label>
<div class="layui-input-inline">
<input type="text" name="daily_limit" value="{{$integral['daily_limit']}}" lay-verify="required|number"
<input type="text" name="daily_limit" value="{{$integral['daily_limit']}}"
lay-verify="required|number"
autocomplete="off" class="layui-input">
</div>
</div>
......@@ -35,7 +36,7 @@
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit="" lay-filter="update_integral">立即提交</button>
{{-- <button type="reset" class="layui-btn layui-btn-primary">重置</button>--}}
<button type="reset" class="layui-btn layui-btn-primary" onclick="history.back()">返回列表</button>
</div>
</div>
</div>
......
<div class="layui-card">
<div class="layui-card-body" style="padding-top: 20px">
<div class="layui-row">
<div class="layui-col-sm6 layui-col-md4">
<div class="layui-card">
<div class="layui-card-header">
用户已得红包
</div>
<div class="layui-card-body layuiadmin-card-list">
<p class="layuiadmin-big-font">{{$user_integral['integral']}}</p>
</div>
</div>
</div>
<div class="layui-col-sm6 layui-col-md4">
<div class="layui-card">
<div class="layui-card-header">
已提现红包
</div>
<div class="layui-card-body layuiadmin-card-list">
<p class="layuiadmin-big-font">{{$user_integral['exchanged_integral']}}</p>
</div>
</div>
</div>
<div class="layui-col-sm6 layui-col-md4">
<div class="layui-card">
<div class="layui-card-header">
账户剩余红包
</div>
<div class="layui-card-body layuiadmin-card-list">
<p class="layuiadmin-big-font">{{$user_integral['integral']-$user_integral['exchanged_integral']}}</p>
</div>
</div>
</div>
</div>
<div class="layui-tab layui-tab-brief" lay-filter="UserExchangeBillTab">
<ul class="layui-tab-title">
<li class="layui-this">全部类型</li>
@foreach($types as $key=> $type)
<li id="{{$key}}">{{$type}}</li>
@endforeach
</ul>
</div>
<table class="layui-table" id="list" lay-filter="UserExchangeBill"></table>
</div>
</div>
<div class="layui-card">
<div class="layui-form layui-card-header layuiadmin-card-header-auto">
<form class="layui-form" action="">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">注册手机号</label>
<div class="layui-input-inline">
<input type="text" name="mobile" value="{{request()->get('mobile')}}"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('status','兑换状态',request()->get('status')) !!}
</div>
<div class="layui-inline">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('type','商品类型',request()->get('type'),[0=>'无',1=>'话费充值',2=>'微信提现']) !!}
</div>
<div class="layui-inline">
<button type="submit" class="layui-btn">
<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
</button>
<a type="button" class="layui-btn" href="/user_exchanges/userExchangeList">
<i class="layui-icon layui-icon-refresh-3 layuiadmin-button-btn" title="重置搜索"></i>
</a>
</div>
</div>
</form>
</div>
<div class="layui-card-body" style="padding-top: 20px">
<table class="layui-table" id="UserExchange" lay-filter="UserExchange"></table>
</div>
</div>
<script type="text/html" id="operate">
@{{# if(d.status == '已兑换' || d.status == '拒绝兑换'){ }}
<a class="layui-btn layui-btn-primary layui-btn-xs">已审</a>
@{{# } else { }}
<a class="layui-btn layui-btn-green layui-btn-xs" lay-event="audit">审核</a>
@{{# } }}
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="bills">明细</a>
</script>
<script type="text/html" id="status">
@{{# if(d.status == '已兑换'){ }}
<span class="layui-badge-dot layui-bg-blue"></span>
@{{# } else { }}
<span class="layui-badge-dot layui-bg-gray"></span>
@{{# } }}
@{{d.status}}
</script>
<script type="text/html" id="type">
@{{# if(d.type == 1){ }}
话费充值
@{{# } }}
@{{# if(d.type == 2){ }}
微信兑换
@{{# } }}
@{{# if(d.type == 0){ }}
@{{# } }}
</script>
<script type="text/html" id="toolbarLeft">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="batchDisableStatus">批量拒绝兑换选中行</button>
{{-- <button class="layui-btn layui-btn-green layui-btn-sm" lay-event="batchRecoverStatus">恢复所选中行</button>--}}
</div>
</script>
\ No newline at end of file
......@@ -27,6 +27,7 @@ Route::group(['middleware' => 'web'], function () {
Route::match(['get', 'post'], '/user_integrals/{key}', 'UserIntegralsController@Entrance');
Route::match(['get', 'post'], '/integral_bills/{key}', 'IntegralBillsController@Entrance');
Route::match(['get', 'post'], '/exchange/settings/{key}', 'ExchangeSettingsController@Entrance');
Route::match(['get', 'post'], '/user_exchanges/{key}', 'UserExchangesController@Entrance');
});
Route::get('/time', function () {
......@@ -40,7 +41,8 @@ Route::namespace('Api')->group(function () {
Route::match(['get', 'post'], '/integrals/api/deleteIntegral', 'IntegralsApiController@deleteIntegralApi');
Route::match(['get', 'post'], '/integrals/api/storeIntegralApi', 'IntegralsApiController@storeIntegralApi');
Route::match(['get', 'post'], '/integrals/api/updateIntegralApi', 'IntegralsApiController@updateIntegralApi');
Route::match(['get', 'post'], '/integrals/api/changeIntegralStatusApi', 'IntegralsApiController@changeIntegralStatusApi');
Route::match(['get', 'post'], '/integrals/api/changeIntegralStatusApi',
'IntegralsApiController@changeIntegralStatusApi');
Route::match(['get', 'post'], '/integrals/api/batchUpdateStatusApi', 'IntegralsApiController@batchUpdateStatusApi');
//用户积分
......@@ -64,5 +66,15 @@ Route::namespace('Api')->group(function () {
'ExchangeSettingsApiController@changeExchangeSettingStatusApi');
Route::match(['get', 'post'], '/exchange/settings/api/batchUpdateStatusApi',
'ExchangeSettingsApiController@batchUpdateStatusApi');
//用户兑换管理
Route::match(['get', 'post'], '/user_exchanges/api/userExchangeBillListApi',
'UserExchangesApiController@userExchangeBillListApi');
Route::match(['get', 'post'], '/user_exchanges/api/userExchangeListApi',
'UserExchangesApiController@userExchangeListApi');
Route::match(['get', 'post'], '/user_exchanges/api/batchUpdateStatusApi',
'UserExchangesApiController@batchUpdateStatusApi');
Route::match(['get', 'post'], '/user_exchanges/api/changeUserExchangeStatusApi',
'UserExchangesApiController@changeUserExchangeStatusApi');
});
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