Commit 9281a9ba by 杨树贤

完成兑换配置项的获取接口

parent 1c06503e
......@@ -3,6 +3,10 @@
namespace App\Http\Controllers;
use App\Http\Transformers\ExchangeSettingTransformer;
use App\Services\ExchangeSettingService;
use Common\Model\RedisModel;
use Illuminate\Http\Request;
/**
* 商品兑换配置
......@@ -11,8 +15,36 @@ namespace App\Http\Controllers;
*/
class ExchangeSettingsController extends Controller
{
public function index()
/**
* @var ExchangeSettingService
*/
private $service;
public function __construct(ExchangeSettingService $service)
{
$this->service = $service;
}
/**
* 获取配置列表
* @param Request $request
* @param ExchangeSettingTransformer $transformer
* @return array|false|string
*/
public function index(Request $request, ExchangeSettingTransformer $transformer)
{
$type = $request->get('type');
//is_api是为了告诉服务器是接口去请求
$map = $type ? ['type' => $type, 'is_api' => 1] : [];
$exchangeSettings = $this->service->getExchangeSettingList($map);
$exchangeSettings = $transformer->transform($exchangeSettings);
$userId = $request->user->user_id;
//从redis里面取出用户的剩余红包
$redis = new RedisModel();
$user = json_decode($redis->hget('ic_user', $userId), true);
$integral = array_get($user, 'integral');
$exchangeSettings['integral'] = $integral;
return $this->Export(0, 'ok', $exchangeSettings);
}
}
\ No newline at end of file
<?php
namespace App\Http\Transformers;
class ExchangeSettingTransformer
{
public function transform($data = [])
{
if (isset($data['data']) && is_array($data['data'])) {
foreach ($data['data'] as $key => &$value) {
unset($value['add_time']);
unset($value['update_time']);
unset($value['status']);
}
unset($value);
}
return $data;
}
}
\ No newline at end of file
......@@ -6,5 +6,12 @@ namespace App\Services;
class ExchangeSettingService
{
public function getExchangeSettingList($map = [])
{
$url = config('website.BaseUrl') . '/exchange_settings/list';
$result = reportCurl($url, $map, true);
$result = json_decode($result, true);
return $result;
}
}
\ No newline at end of file
......@@ -34,6 +34,9 @@ $router->group(['middleware' => ['web', 'login']], function () use ($router) {
$router->get('integral_bills/list', 'IntegralBillsController@index');
//红包兑换流水
$router->get('user_exchanges/list', 'UserExchangesController@index');
//商品配置列表
$router->get('exchange_settings/list', 'ExchangeSettingsController@index');
});
$router->group(['middleware' => 'web'], function () use ($router) {
$router->post('/oss/upload', 'OssController@upload');
......
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