Commit 1a39378c by 杨树贤

完成积分信息的增删改查

parent 9e65b5d7
......@@ -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=
NOT_AUTH=ApiGoodsList,ApiInquiryIndex,ApiVisitTrend,ApiIndexOne,ApiIndextwo,ApiViolationGoodsList,ApiInquiryList
MENU_ID=7
MENU_URL=http://data.icsales.cc/api/config/
......
......@@ -8,4 +8,5 @@ Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.env
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\IntegralService;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
class IntegralsApiController extends Controller
{
public function integralListApi(Request $request, IntegralService $service)
{
$data = $service->getIntegralList('/integrals?' . http_build_query($request->all()));
$data = $this->integralListTransformer($data);
return $this->apiReturn(0, 'ok', [
'data' => $data['data'],
'count' => $data['count'],
]);
}
private function integralListTransformer($data)
{
foreach ($data['data'] as &$item) {
$item['status'] = $item['status'] ? '使用中' : '已停用';
$item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
$item['update_time'] = $item['update_time'] ? date('Y-m-d H:i:s', $item['update_time']) : '暂无更新';
$item['daily_limit'] = "每日{$item['daily_limit']}次";
}
unset($item);
return $data;
}
public function storeIntegralApi(Request $request, IntegralService $service)
{
$result = $service->storeIntegral('/integrals', $request->all());
return $result;
}
public function updateIntegralApi(Request $request, IntegralService $service)
{
$result = $service->updateIntegral('/integrals/' . $request->id, $request->all());
return $result;
}
public function deleteIntegralApi(Request $request, IntegralService $service)
{
$result = $service->deleteIntegral('/integrals/' . $request->id);
return $result;
}
}
\ No newline at end of file
<?php
namespace App\Http\Controllers;
use App\Http\Services\IntegralService;
use Illuminate\Http\Request;
class IntegralsController extends Controller
{
public $service;
public function __construct(IntegralService $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 integralList()
{
$this->data['title'] = '红包列表';
return $this->view();
}
public function createIntegral()
{
$this->data['title'] = '新增红包';
return $this->view();
}
public function updateIntegral(Request $request)
{
$this->data['title'] = '修改红包';
$integral = $this->service->getIntegral('/integrals/' . $request->id);
$this->data['integral'] = $integral['data'];
return $this->view();
}
public function storeIntegral(Request $request)
{
$result = $this->service->storeIntegral('/integrals', $request->all());
if ($result['errno'] === 0) {
return redirect('/integrals/integralList');
}
}
}
\ No newline at end of file
<?php
namespace App\Http\Services;
use GuzzleHttp\Client;
class BaseService
{
private $client;
public function __construct() {
$this->client = new Client([
'base_uri' => '192.168.10.10:61009',
'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) {
ErrorLog($requestPath, $data['errcode'], $data['errmsg']);
}
return $data;
}
public function apiDelete($requestPath)
{
$response = $this->client->request('DELETE', $requestPath);
$data = json_decode($response->getBody()->getContents(), true);
if ($data['errcode'] !== 0) {
ErrorLog($requestPath, $data['errcode'], $data['errmsg']);
}
return $data;
}
public function apiPost($requestPath, $data = [])
{
$response = $this->client->request('POST', $requestPath,
['form_params' => $data]
);
$data = json_decode($response->getBody()->getContents(), true);
if ($data['errcode'] !== 0) {
ErrorLog($requestPath, $data['errcode'], $data['errmsg']);
}
return $data;
}
public function apiPatch($requestPath, $data = [])
{
$response = $this->client->request('PATCH', $requestPath,
['form_params' => $data]
);
$data = json_decode($response->getBody()->getContents(), true);
if ($data['errcode'] !== 0) {
ErrorLog($requestPath, $data['errcode'], $data['errmsg']);
}
return $data;
}
}
\ No newline at end of file
<?php
namespace App\Http\Services;
class IntegralService extends BaseService
{
public function getIntegral($path)
{
return $this->apiGet($path);
}
public function getIntegralList($path)
{
return $this->apiGet($path);
}
public function deleteIntegral($path)
{
return $this->apiDelete($path);
}
public function storeIntegral($path, $data)
{
return $this->apiPost($path, $data);
}
public function updateIntegral($path, $data)
{
return $this->apiPatch($path, $data);
}
}
\ No newline at end of file
......@@ -27,10 +27,7 @@
],
"psr-4": {
"App\\": "app/"
},
"files": [
"app/helpers.php"
]
}
},
"autoload-dev": {
"psr-4": {
......
layui.use('form', function () {
var form = layui.form;
form.on('switch(switchStatus)', function (data) {
this.value = this.checked ? 1 : 0;
});
form.on('submit(creat_integral)', function (data) {
// console.log(data.field); //当前容器的全部表单字段,名值对形式:{name: value}
let url = '/integrals/api/storeIntegralApi';
$.ajax({
type: 'POST',
url: url,
data: data.field,
success: function (result) {
if (result.errcode === 0) {
layer.msg('新增成功');
window.location = '/integrals/integralList';
}
}
});
return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
});
});
layui.use(['table', 'form', 'laydate', 'layer'], function () {
var table = layui.table;
var form = layui.form;
table.render({
elem: '#list'
, skin: 'line'
, url: '/integrals/api/integralList'
, method: 'get'
, request: {
pageName: 'page'
, limitName: 'page_size'
}
, toolbar: '#toolbarLeft'
, defaultToolbar: ['filter']
, loading: true
, cols: [[
{field: 'id', title: '序号'}
, {field: 'name', title: '红包名称'}
, {field: 'integral_amount', title: '奖励金额'}
, {field: 'daily_limit', title: '每个用户日限', templet: '#title'}
, {field: 'status', title: '配置状态', templet: '#status'}
, {field: 'update_time', title: '配置更新时间', templet: '#update_time'}
, {field: 'experience', title: '操作', templet: '#operate', fixed: 'right'}
]]
, id: 'Reload'
, page: {
// layout: ['prev', 'page', 'next', 'count', 'skip'] //自定义分页布局
}
});
//监听行工具事件
table.on('tool(Integral)', function (obj) { //注:tool 是工具条事件名,test 是 table 原始容器的属性 lay-filter="对应的值"
var data = obj.data //获得当前行数据
, layEvent = obj.event; //获得 lay-event 对应的值
if (layEvent === 'detail') {
layer.msg('查看操作');
} else if (layEvent === 'del') {
layer.confirm('真的删除积分项吗', function (index) {
//向服务端发送删除指令
console.log(obj.data.id);
$.get('/integrals/api/deleteIntegral', {id: obj.data.id}, function (result) {
if (result.errcode === 0) {
layer.msg('删除成功!');
layer.close(index);
table.reload('Reload');
}
});
});
} else if (layEvent === 'edit') {
window.location = '/integrals/updateIntegral?id=' + obj.data.id;
} else if (layEvent === 'setting') {
//iframe层-父子操作
layer.open({
type: 2,
area: ['500px', '350px'],
fixed: false, //不固定
maxmin: true,
content: '/integrals/settingIntegral'
});
}
});
form.on('submit(load)', function (data) {
//执行重载
table.reload('Reload', {
page: {
curr: 1 //重新从第 1 页开始
}
, where: data.field
});
return false;
});
//实现额外的全选 --start
form.on('checkbox(qx)', function (data) {
var checkStatus = table.checkStatus('Reload');
if (data.elem.checked) {//选中
if (checkStatus.isAll == true) {//已经全选
return false;
}
} else {
if (checkStatus.isAll == false) {//已经全选
return false;
}
}
$('.layui-table-header thead tr th .laytable-cell-checkbox .layui-form-checkbox').trigger('click');
});
table.on('checkbox(Reload)', function (obj) {
var checkStatus = table.checkStatus('Reload');
if (checkStatus.isAll == true) {
$('input[name=qx]').prop("checked", true);
} else {
$('input[name=qx]').removeAttr("checked");
}
form.render(); //更新渲染
});
// 实现额外的全选 --end
$('#down').click(function () {
var checkStatus = table.checkStatus('Reload')
, data = checkStatus.data;
ids = [];
for (var i in data) {
if (data[i].audit_status == 1 && data[i].goods_id > 0) {
ids[i] = data[i].goods_id;
}
}
if (!ids || ids.length < 1) return layer.msg('没有可以操作的数据', {offset: 200, icon: 6});
layer.prompt(function (val, index) {
if (!val) return layer.msg('请输入禁用原因', {icon: 6});
layer.msg('处理中', {icon: 16, time: 10000});
var data = {
goods_id: ids,
prohibit_remark: val
};
$.ajax({
url: '/goods/api/ApiProhibitGoods',
type: 'post',
data: data,
dataType: 'json',
timeout: 10000,
success: function (res) {
if (!res) return layer.msg('网络错误,请重试', {icon: 5});
layer.msg(res.errmsg, {icon: 6});
if (res.errcode == 0) {
window.location.reload();
}
},
error: function () {
return layer.msg('网络错误,请重试', {icon: 5});
}
})
});
})
});
\ No newline at end of file
layui.use('form', function () {
var form = layui.form;
form.on('switch(switchStatus)', function (data) {
this.value = this.checked ? 1 : 0;
});
form.on('submit(update_integral)', function (data) {
let url = '/integrals/api/updateIntegralApi';
$.ajax({
type: 'POST',
url: url,
data: data.field,
success: function (result) {
if (result.errcode === 0) {
layer.msg('新增成功');
window.location = '/integrals/integralList';
}
}
});
});
});
<div class="layui-card">
<div class="layui-card-body" style="padding-top: 20px">
<div class="layui-form">
<div class="layui-form-item">
<label class="layui-form-label">红包名称</label>
<div class="layui-input-block">
<input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入红包名称"
class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">奖励金额</label>
<div class="layui-input-block">
<input type="text" name="integral_amount" lay-verify="required" autocomplete="off"
placeholder="请输入奖励金额"
class="layui-input">
</div>
</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="daily_limit" lay-verify="required" autocomplete="off" class="layui-input">
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">配置状态</label>
<div class="layui-input-block">
<input type="checkbox" checked="" value="1" name="status" lay-skin="switch" lay-filter="switchStatus"
lay-text="使用中|已停用">
<div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch">
<em>使用中</em><i></i>
</div>
</div>
</div>
<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">重置</button>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
<div class="layui-card">
<div class="layui-card-body" style="padding-top: 20px">
<table class="layui-table" id="list" lay-filter="Integral"></table>
</div>
</div>
<script type="text/html" id="operate">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="setting">设置</a>
</script>
<script type="text/html" id="toolbarLeft">
<div class="layui-btn-container">
<a href="/integrals/createIntegral" class="layui-btn layui-btn-sm" lay-event="getCheckData">新增红包</a>
</div>
</script>
<script>
</script>
\ 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="{{$integral['id']}}">
<div class="layui-form-item">
<label class="layui-form-label">红包名称</label>
<div class="layui-input-block">
<input type="text" name="name" value="{{$integral['name']}}" lay-verify="title" autocomplete="off" placeholder="请输入红包名称"
class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">奖励金额</label>
<div class="layui-input-block">
<input type="text" name="integral_amount" value="{{$integral['integral_amount']}}" lay-verify="title" autocomplete="off"
placeholder="请输入奖励金额"
class="layui-input">
</div>
</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="daily_limit" value="{{$integral['daily_limit']}}" autocomplete="off" class="layui-input">
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">配置状态</label>
<div class="layui-input-block">
@php
$check = $integral['status']?'checked':'';
@endphp
<input type="checkbox" {{$check}} value="{{$integral['status']}}" name="status" lay-skin="switch" lay-filter="switchStatus"
lay-text="使用中|已停用">
<div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch">
<em>使用中</em><i></i>
</div>
</div>
</div>
<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>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
......@@ -12,19 +12,28 @@
*/
Route::group(['middleware' => 'web'], function () {
Route::get('/', 'WebController@Entrance');
Route::get('/xxx', 'WebController@Entrance');
Route::get('/web/index', 'WebController@Entrance');
Route::get('/integrals', 'WebController@Entrance');
Route::match(['get', 'post'],'/goods/{key}', 'GoodsWebController@Entrance');
Route::match(['get', 'post'],'/goods/api/{key}', 'GoodsApiController@Entrance');
Route::match(['get', 'post'],'/api/{key}', 'ApiController@Entrance');
Route::match(['get', 'post'],'/inquiry/{key}', 'InquiryWebController@Entrance');
Route::match(['get', 'post'],'/inquiry/api/{key}', 'InquiryApiController@Entrance');
Route::match(['get', 'post'],'/offer/{key}', 'OfferWebController@Entrance');
Route::match(['get', 'post'],'/offer/api/{key}', 'OfferApiController@Entrance');
Route::get('/', 'WebController@Entrance');
Route::get('/xxx', 'WebController@Entrance');
Route::get('/web/index', 'WebController@Entrance');
Route::match(['get', 'post'], '/goods/{key}', 'GoodsWebController@Entrance');
Route::match(['get', 'post'], '/goods/api/{key}', 'GoodsApiController@Entrance');
Route::match(['get', 'post'], '/api/{key}', 'ApiController@Entrance');
Route::match(['get', 'post'], '/inquiry/{key}', 'InquiryWebController@Entrance');
Route::match(['get', 'post'], '/inquiry/api/{key}', 'InquiryApiController@Entrance');
Route::match(['get', 'post'], '/offer/{key}', 'OfferWebController@Entrance');
Route::match(['get', 'post'], '/offer/api/{key}', 'OfferApiController@Entrance');
Route::match(['get', 'post'], '/integrals/{key}', 'IntegralsController@Entrance');
});
Route::get('/time', function () {
return time();
});
\ No newline at end of file
});
Route::namespace('Api')->group(function () {
Route::get('/integrals/api/integralList', 'IntegralsApiController@integralListApi');
Route::get('/integrals/api/deleteIntegral', 'IntegralsApiController@deleteIntegralApi');
Route::post('/integrals/api/storeIntegralApi', 'IntegralsApiController@storeIntegralApi');
Route::post('/integrals/api/updateIntegralApi', 'IntegralsApiController@updateIntegralApi');
});
......@@ -9,6 +9,7 @@ return array(
'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.php',
'App\\Exceptions\\Handler' => $baseDir . '/app/Exceptions/Handler.php',
'App\\Http\\Controllers\\ApiController' => $baseDir . '/app/Http/Controllers/ApiController.php',
'App\\Http\\Controllers\\Api\\IntegralsController' => $baseDir . '/app/Http/Controllers/Api/IntegralsController.php',
'App\\Http\\Controllers\\Auth\\ForgotPasswordController' => $baseDir . '/app/Http/Controllers/Auth/ForgotPasswordController.php',
'App\\Http\\Controllers\\Auth\\LoginController' => $baseDir . '/app/Http/Controllers/Auth/LoginController.php',
'App\\Http\\Controllers\\Auth\\RegisterController' => $baseDir . '/app/Http/Controllers/Auth/RegisterController.php',
......@@ -18,6 +19,7 @@ return array(
'App\\Http\\Controllers\\GoodsWebController' => $baseDir . '/app/Http/Controllers/GoodsWebController.php',
'App\\Http\\Controllers\\InquiryApiController' => $baseDir . '/app/Http/Controllers/InquiryApiController.php',
'App\\Http\\Controllers\\InquiryWebController' => $baseDir . '/app/Http/Controllers/InquiryWebController.php',
'App\\Http\\Controllers\\IntegralsController' => $baseDir . '/app/Http/Controllers/IntegralsController.php',
'App\\Http\\Controllers\\OfferApiController' => $baseDir . '/app/Http/Controllers/OfferApiController.php',
'App\\Http\\Controllers\\OfferWebController' => $baseDir . '/app/Http/Controllers/OfferWebController.php',
'App\\Http\\Controllers\\WebController' => $baseDir . '/app/Http/Controllers/WebController.php',
......@@ -28,6 +30,7 @@ return array(
'App\\Http\\Middleware\\TrimStrings' => $baseDir . '/app/Http/Middleware/TrimStrings.php',
'App\\Http\\Middleware\\TrustProxies' => $baseDir . '/app/Http/Middleware/TrustProxies.php',
'App\\Http\\Middleware\\VerifyCsrfToken' => $baseDir . '/app/Http/Middleware/VerifyCsrfToken.php',
'App\\Http\\Services\\Integral' => $baseDir . '/app/Http/Services/Integral.php',
'App\\Model\\GoodsModel' => $baseDir . '/app/Model/GoodsModel.php',
'App\\Model\\RedisModel' => $baseDir . '/app/Model/RedisModel.php',
'App\\Model\\SkuViolation' => $baseDir . '/app/Model/SkuViolation.php',
......
......@@ -22,5 +22,4 @@ return array(
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
'f0906e6318348a765ffb6eb24e0d0938' => $vendorDir . '/laravel/framework/src/Illuminate/Foundation/helpers.php',
'58571171fd5812e6e447dce228f52f4d' => $vendorDir . '/laravel/framework/src/Illuminate/Support/helpers.php',
'b4e3f29b106af37a2bb239f73cdf68c7' => $baseDir . '/app/helpers.php',
);
......@@ -23,7 +23,6 @@ class ComposerStaticInit0f2e3b599ee0093c705be10a8ac95745
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
'f0906e6318348a765ffb6eb24e0d0938' => __DIR__ . '/..' . '/laravel/framework/src/Illuminate/Foundation/helpers.php',
'58571171fd5812e6e447dce228f52f4d' => __DIR__ . '/..' . '/laravel/framework/src/Illuminate/Support/helpers.php',
'b4e3f29b106af37a2bb239f73cdf68c7' => __DIR__ . '/../..' . '/app/helpers.php',
);
public static $prefixLengthsPsr4 = array (
......@@ -378,6 +377,7 @@ class ComposerStaticInit0f2e3b599ee0093c705be10a8ac95745
'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php',
'App\\Exceptions\\Handler' => __DIR__ . '/../..' . '/app/Exceptions/Handler.php',
'App\\Http\\Controllers\\ApiController' => __DIR__ . '/../..' . '/app/Http/Controllers/ApiController.php',
'App\\Http\\Controllers\\Api\\IntegralsController' => __DIR__ . '/../..' . '/app/Http/Controllers/Api/IntegralsController.php',
'App\\Http\\Controllers\\Auth\\ForgotPasswordController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/ForgotPasswordController.php',
'App\\Http\\Controllers\\Auth\\LoginController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/LoginController.php',
'App\\Http\\Controllers\\Auth\\RegisterController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/RegisterController.php',
......@@ -387,6 +387,7 @@ class ComposerStaticInit0f2e3b599ee0093c705be10a8ac95745
'App\\Http\\Controllers\\GoodsWebController' => __DIR__ . '/../..' . '/app/Http/Controllers/GoodsWebController.php',
'App\\Http\\Controllers\\InquiryApiController' => __DIR__ . '/../..' . '/app/Http/Controllers/InquiryApiController.php',
'App\\Http\\Controllers\\InquiryWebController' => __DIR__ . '/../..' . '/app/Http/Controllers/InquiryWebController.php',
'App\\Http\\Controllers\\IntegralsController' => __DIR__ . '/../..' . '/app/Http/Controllers/IntegralsController.php',
'App\\Http\\Controllers\\OfferApiController' => __DIR__ . '/../..' . '/app/Http/Controllers/OfferApiController.php',
'App\\Http\\Controllers\\OfferWebController' => __DIR__ . '/../..' . '/app/Http/Controllers/OfferWebController.php',
'App\\Http\\Controllers\\WebController' => __DIR__ . '/../..' . '/app/Http/Controllers/WebController.php',
......@@ -397,6 +398,7 @@ class ComposerStaticInit0f2e3b599ee0093c705be10a8ac95745
'App\\Http\\Middleware\\TrimStrings' => __DIR__ . '/../..' . '/app/Http/Middleware/TrimStrings.php',
'App\\Http\\Middleware\\TrustProxies' => __DIR__ . '/../..' . '/app/Http/Middleware/TrustProxies.php',
'App\\Http\\Middleware\\VerifyCsrfToken' => __DIR__ . '/../..' . '/app/Http/Middleware/VerifyCsrfToken.php',
'App\\Http\\Services\\Integral' => __DIR__ . '/../..' . '/app/Http/Services/Integral.php',
'App\\Model\\GoodsModel' => __DIR__ . '/../..' . '/app/Model/GoodsModel.php',
'App\\Model\\RedisModel' => __DIR__ . '/../..' . '/app/Model/RedisModel.php',
'App\\Model\\SkuViolation' => __DIR__ . '/../..' . '/app/Model/SkuViolation.php',
......
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