Commit ec67c539 by 杨树贤

完成用户积分列表

parent 19589fc5
......@@ -44,7 +44,7 @@ PERM_URL=http://perm.icsales.cc/api/check
PERM_ID=7
PERM_GOURL=http://perm.icsales.cc
ADMIN_GROUP=10000,20000
NOT_AUTH=ApiGoodsList,ApiInquiryIndex,ApiVisitTrend,ApiIndexOne,ApiIndextwo,ApiViolationGoodsList,ApiInquiryList
NOT_AUTH=ApiGoodsList,ApiInquiryIndex,ApiVisitTrend,ApiIndexOne,ApiIndextwo,ApiViolationGoodsList,ApiInquiryList,userIntegralListApi
MENU_ID=7
MENU_URL=http://data.icsales.cc/api/config/
......
......@@ -15,7 +15,7 @@ class IntegralsApiController extends Controller
{
$data = $service->getIntegralList('/integrals?' . http_build_query($request->all()));
$data = $this->integralListTransformer($data);
$data = $this->transformer($data);
return $this->apiReturn(0, 'ok', [
'data' => $data['data'],
......@@ -23,7 +23,7 @@ class IntegralsApiController extends Controller
]);
}
private function integralListTransformer($data)
private function transformer($data)
{
foreach ($data['data'] as &$item) {
$item['status'] = $item['status'] ? '使用中' : '已停用';
......
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\UserIntegralService;
use App\Http\Transformers\UserIntegralTransformer;
use Illuminate\Http\Request;
class UserIntegralsApiController extends Controller
{
private $service;
private $transformer;
public function __construct(UserIntegralService $service,UserIntegralTransformer $transformer)
{
$this->service = $service;
$this->transformer = $transformer;
}
public function userIntegralListApi(Request $request)
{
$params = $this->getListParams($request);
$data = $this->service->getUserIntegralList($params);
$data = $this->transformer->transform($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 (isset($params['user_id'])) {
$params['user_id'] = $params['user_id'] ?: 0;
}
unset($params['mobile']);
return $params;
}
public function changeUserIntegralStatusApi(Request $request)
{
$id = $request->id;
$status = $request->exchange_status;
$path = 'user_integrals/' . $id;
$result = $this->service->changeUserIntegralStatus($path, ['exchange_status' => $status]);
return $result;
}
}
\ No newline at end of file
<?php
namespace App\Http\Controllers;
use App\Http\Services\UserIntegralService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class UserIntegralsController extends Controller
{
public $service;
public function __construct(UserIntegralService $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 userIntegralList()
{
$this->data['title'] = '用户积分管理';
return $this->view();
}
}
......@@ -11,14 +11,14 @@ class BaseService
private $client;
public function __construct() {
$this->client = new Client([
'base_uri' => '192.168.10.10:61009',
// 'base_uri' => '192.168.10.10:61009',
'base_uri' => 'http://ic_server_welfare.test',
'timeout' => 20,
]);
}
public function apiGet($requestPath)
{
// dd($requestPath);
$response = $this->client->request('GET', $requestPath);
$data = json_decode($response->getBody()->getContents(), true);
if ($data['errcode'] !== 0) {
......@@ -63,7 +63,6 @@ class BaseService
if ($data['errcode'] !== 0) {
ErrorLog($requestPath, $data['errcode'], $data['errmsg']);
}
return $data;
}
}
\ No newline at end of file
<?php
namespace App\Http\Services;
use App\Model\RedisModel;
class UserIntegralService extends BaseService
{
public function getUserIntegralList($params)
{
$path = '/user_integrals?' . http_build_query($params);
return $this->apiGet($path);
}
public function getUserMobilesFromRedis($userIds = [])
{
$redis = new RedisModel();
$users = $redis->hmget('ic_user', $userIds);
$userMobiles = [];
foreach ($users as $user) {
$user = json_decode($user, true);
$userMobiles[$user['user_id']] = $user['mobile'];
}
return $userMobiles;
}
public function getUserIdByMobile($mobile)
{
$redis = new RedisModel();
$userId = json_decode($redis->hget('ic_user_mobile', $mobile), true);
return $userId;
}
public function changeUserIntegralStatus($path, $data = [])
{
return $this->apiPatch($path, $data);
}
}
\ No newline at end of file
<?php
namespace App\Http\Transformers;
use App\Http\Services\UserIntegralService;
class UserIntegralTransformer
{
protected $service;
public function __construct(UserIntegralService $service) {
$this->service = $service;
}
public function transform($data)
{
$userIds = array_column($data['data'], 'user_id');
if ($userIds) {
$userMobiles = $this->service->getUserMobilesFromRedis($userIds);
}
foreach ($data['data'] as &$item) {
$item['exchange_status'] = $item['exchange_status'] ? '正常' : '禁用';
$mobile = array_get($userMobiles, $item['user_id'], '无');
$item['mobile'] = $mobile;
}
unset($item);
return $data;
}
}
\ No newline at end of file
<?php
namespace App\Presenters;
class StatusPresenter
{
public function render($name, $text, $status = null, $data = [0 => '禁用', 1 => '启用'])
{
$html = <<<EOF
<label class="layui-form-label">$text</label>
<div class="layui-input-inline">
<select name="$name">
{$this->optionsRender($data, $status)}
</select>
</div>
EOF;
return $html;
}
public function optionsRender($data, $status)
{
$optionsHtml = ' <option value="">全部</option>';
$checked = '';
foreach ($data as $key => $value) {
if ($status !== null) {
$checked = ($key == $status) ? "selected='selected'" : '';
}
$optionsHtml = $optionsHtml . "<option value='$key' $checked>$value</option>";
}
return $optionsHtml;
}
}
\ 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;
}
layui.use(['table', 'form', 'laydate', 'layer'], function () {
var table = layui.table;
table.render({
elem: '#UserIntegral'
, skin: 'line'
, url: '/user_integrals/api/userIntegralList'
, 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: 'integral', title: '账户红包'}
, {field: 'exchanged_integral', title: '累计兑换'}
, {field: 'certification_status', title: '认证状态'}
, {field: 'exchange_status', title: '兑换状态', templet: '#exchange_status'}
, {field: 'experience', title: '操作', templet: '#operate', fixed: 'right'}
]]
, id: 'Reload'
, page: {}
});
//头工具栏事件
table.on('toolbar(UserIntegral)', function (obj) {
var checkStatus = table.checkStatus(obj.config.id);
switch (obj.event) {
case 'batchDisableStatus':
var data = checkStatus.data;
var ids = [];
for (var key in data) {
ids.push(data[key].id);
}
break;
case 'getCheckLength':
var data = checkStatus.data;
layer.msg('选中了:' + data.length + ' 个');
break;
case 'isAll':
layer.msg(checkStatus.isAll ? '全选' : '未全选');
break;
}
});
//监听行工具事件
table.on('tool(UserIntegral)', function (obj) {
var data = obj.data
, layEvent = obj.event;
switch (layEvent) {
case 'disable':
layer.confirm('确定要禁用用户兑换红包?', function (index) {
//向服务端发送禁用指令
$.get('/user_integrals/api/changeUserIntegralStatus', {
id: obj.data.id,
exchange_status: 0
}, function (result) {
if (result.errcode === 0) {
layer.msg('禁用成功!');
layer.close(index);
table.reload('Reload');
}
});
});
break;
case 'recover':
layer.confirm('确定要恢复用户兑换红包?', function (index) {
$.get('/user_integrals/api/changeUserIntegralStatus', {
id: obj.data.id,
exchange_status: 1
}, function (result) {
if (result.errcode === 0) {
layer.msg('恢复成功!');
layer.close(index);
table.reload('Reload');
}
});
});
break;
case 'flow':
window.location = '/integrals/updateIntegral?id=' + obj.data.id;
break;
}
});
});
\ No newline at end of file
......@@ -62,7 +62,7 @@
</form>
<table class="layui-table" id="list" lay-filter="Reload"></table>
<div class="layui-form">
<div class="layui-form" style="margin-top: 10px">
<input type="checkbox" lay-filter="qx" title="全选" lay-skin="primary" name="qx">
<button class="layui-btn" id="down">批量禁用</button>
</div>
......
<div class="layui-card">
<div class="layui-card-body" style="padding-top: 20px">
<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="name" value="{{request()->get('name')}}"
class="layui-input">
</div>
</div>
<div class="layui-inline">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('status','配置状态',request()->get('status'),[0=>'已禁用',1=>'使用中']) !!}
</div>
<div class="layui-inline">
<button type="submit" class="layui-btn layui-btn-sm">
<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
</button>
<a type="button" href="/user_integrals/userIntegralList"
class="layui-btn layui-btn-primary layui-btn-sm">
<i class="layui-icon layui-icon-refresh-3" title="重置搜索"></i>
</a>
</div>
</div>
</form>
<table class="layui-table" id="list" lay-filter="Integral"></table>
</div>
</div>
......
<div class="layui-card">
<div class="layui-card-body" style="padding-top: 20px">
<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('exchange_status','兑换状态',request()->get('exchange_status')) !!}
</div>
<div class="layui-inline">
<button type="submit" class="layui-btn layui-btn-sm">
<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
</button>
<a type="button" href="/user_integrals/userIntegralList"
class="layui-btn layui-btn-primary layui-btn-sm">
<i class="layui-icon layui-icon-refresh-3" title="重置搜索"></i>
</a>
</div>
</div>
</form>
<table class="layui-table" id="UserIntegral" lay-filter="UserIntegral"></table>
</div>
</div>
<script type="text/html" id="operate">
@{{# if(d.exchange_status == '正常'){ }}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="disable">禁用</a>
@{{# } else { }}
<a class="layui-btn layui-btn-green layui-btn-xs" lay-event="recover">恢复</a>
@{{# } }}
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="setting">明细</a>
</script>
<script type="text/html" id="exchange_status">
@{{# if(d.exchange_status == '正常'){ }}
<span class="layui-badge-dot layui-bg-blue"></span>
@{{# } else { }}
<span class="layui-badge-dot layui-bg-gray"></span>
@{{# } }}
@{{d.exchange_status}}
</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
......@@ -24,6 +24,7 @@ Route::group(['middleware' => 'web'], function () {
Route::match(['get', 'post'], '/offer/api/{key}', 'OfferApiController@Entrance');
Route::match(['get', 'post'], '/integrals/{key}', 'IntegralsController@Entrance');
Route::match(['get', 'post'], '/user_integrals/{key}', 'UserIntegralsController@Entrance');
});
Route::get('/time', function () {
......@@ -35,5 +36,9 @@ Route::namespace('Api')->group(function () {
Route::get('/integrals/api/deleteIntegral', 'IntegralsApiController@deleteIntegralApi');
Route::post('/integrals/api/storeIntegralApi', 'IntegralsApiController@storeIntegralApi');
Route::post('/integrals/api/updateIntegralApi', 'IntegralsApiController@updateIntegralApi');
//用户积分
Route::get('/user_integrals/api/userIntegralList', 'UserIntegralsApiController@userIntegralListApi');
Route::get('/user_integrals/api/changeUserIntegralStatus', 'UserIntegralsApiController@changeUserIntegralStatusApi');
});
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