Commit eeb76392 by 杨树贤

优化接口

parent d8e4e4b1
......@@ -20,7 +20,7 @@ class CaseController extends Controller
public function show(Request $request, CaseService $service)
{
$id = $request->get('id');
$id = $request->get('art_id');
$case = $service->getCase($id);
return $this->Export(0, 'ok', ['data' => $case]);
......
<?php
namespace App\Http\Controllers;
use App\Services\CodeService;
use Common\Model\RedisModel;
use Illuminate\Http\Request;
/**
* 红包码
* Class CodesController
* @package App\Http\Controllers
*/
class CodesController extends Controller
{
const INTEGRAL_TYPE_CODE = 3;
/**
* 兑换红包码
* @param Request $request
* @param CodeService $service
* @return array
*/
public function store(Request $request, CodeService $service)
{
$userId = $request->user->user_id;
$code = $request->get('code');
if (empty($code)) {
return $this->Export(self::INVALID_PARAMETER);
} elseif (!$this->checkCode($code, $userId)) {
return $this->Export(self::INVALID_CODE);
}
$data = [
'user_id' => $userId,
'code' => $request->get('code'),
];
$result = $service->addCode($data);
if ($result['errcode'] === self::SUCCESS) {
//成功之后还要返回红包码
$res['data']['code'] = $code;
//返回红包码能获取对应的金额
$redis = new RedisModel();
$integral = $redis->hget('ic_welfare_integrals', self::INTEGRAL_TYPE_CODE);
$integral = json_decode($integral, true);
$amount = array_get($integral, 'amount');
$res['data']['amount'] = $amount;
return $this->Export(0, 'ok', $res);
} elseif ($result['errcode'] === self::EXCHANGED_CODE) {
return $this->Export(self::EXCHANGED_CODE);
} else {
return $this->Export(self::EXCHANGE_CODE_FAIL);
}
}
//检查红包码是否正确
private function checkCode($code, $userId = 0)
{
//检查是不是自己,自己不能兑换自己的红包码
if ($userId == substr($code, 3)) {
return false;
}
//先检查是否是RDD开头
if (substr($code, 0, 3) !== 'RDD') {
return false;
}
//然后去redis里面取出user_id,判断是否有对应的用户
$userId = substr($code, 3);
$redis = new RedisModel();
$exists = $redis->hexists('ic_user', $userId);
if (!$exists) {
return false;
}
return true;
}
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ class FaqController extends Controller
public function show(Request $request,FaqService $service)
{
$faq = $service->getFaq($request->get('id'));
$faq = $service->getFaq($request->get('art_id'));
return $faq;
}
......
......@@ -22,7 +22,7 @@ class NoticeController extends Controller
public function show(Request $request,NoticeService $service)
{
$faq = $service->getNotice($request->get('id'));
$faq = $service->getNotice($request->get('art_id'));
return $faq;
}
......
......@@ -34,7 +34,6 @@ class ArticleModel extends BaseModel
//获取案例列表
public function getCaseList($map, $page, $pageSize)
{
$field = [
'art_id',
'title',
......@@ -97,8 +96,10 @@ class ArticleModel extends BaseModel
'article_addon',
])
->where('art_id', $id)
->first()
->toArray();
->first();
if (!empty($data)) {
$data = $data->toArray();
}
return $data;
}
......
......@@ -47,6 +47,7 @@ class CaseService extends BaseService
private function caseTransform($item)
{
if (!empty($item)) {
$item['type'] = array_get($item['type'], 'type_name', '');
$item['top_type'] = array_get($item['top_type'], 'type_name', '');
$item['publish_time'] = $item['publish_time'] ? date('Y-m-d H:i:s', $item['publish_time']) : 0;
......@@ -56,6 +57,8 @@ class CaseService extends BaseService
unset($item['article_tag']);
#todo 要从商品的服务那里根据goods_id去获取商品基础信息
}
return $item;
}
}
\ No newline at end of file
......@@ -25,13 +25,6 @@ class FaqService extends BaseService
private function transform($data)
{
foreach ($data as $key => &$item) {
foreach ($item['articles'] as $k => $v) {
$v['url'] = url() . '/faq/info?id=' . $v['art_id'];
}
}
unset($item);
return $data;
}
......
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