Commit ffd5d364 by 杨树贤

添加红包码验证以及返回相关的信息到接口

parent 879343bf
......@@ -4,6 +4,7 @@
namespace App\Http\Controllers;
use App\Services\CodeService;
use Common\Model\RedisModel;
use Illuminate\Http\Request;
/**
......@@ -14,6 +15,8 @@ use Illuminate\Http\Request;
class CodesController extends Controller
{
const INTEGRAL_TYPE_CODE = 3;
/**
* 兑换红包码
* @param Request $request
......@@ -25,6 +28,8 @@ class CodesController extends Controller
$code = $request->get('code');
if (empty($code)) {
return $this->Export(self::INVALID_PARAMETER);
} elseif (!$this->checkCode($code)) {
return $this->Export(self::INVALID_CODE);
}
$data = [
......@@ -33,10 +38,37 @@ class CodesController extends Controller
];
$result = $service->addCode($data);
if ($result['errcode'] === self::SUCCESS) {
return $this->Export(0, 'ok');
//成功之后还要返回红包码
$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);
} else {
return $this->Export(self::EXCHANGE_CODE_FAIL);
}
}
//检查红包码是否正确
private function checkCode($code)
{
//先检查是否是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
......@@ -15,6 +15,8 @@ class Controller extends BaseController
//用户无法进行兑换,未认证
const CAN_NOT_EXCHANGE = 109005;
//红包码无效
const INVALID_CODE = 109006;
const EXCHANGED_TODAY = 109100;
//这个是服务那边返回的错误码,代表已经超出了每日每人可领取的对应项的数额(比如每人每天只能签到一次)
......
......@@ -25,6 +25,7 @@ class InviteService extends BaseService
$result['data'] = array_map(function ($value) use ($userNames,$mobiles) {
$value['invited_user_name'] = $userNames[$value['invited_user_id']];
$value['invited_user_mobile'] = $mobiles[$value['invited_user_id']];
$value['add_time'] = date('Y-m-d H:i');
return $value;
......
......@@ -13,6 +13,7 @@ return [
109003 => '登录失败',
109004 => '请求参数不正确',
109005 => '用户无法兑换,用户未认证',
109006 => '红包码无效',
109100 => '今天已经兑换过了,请明天再来吧',
109101 => '兑换名额被抢光了',
......
......@@ -48,7 +48,7 @@ $router->group(['middleware' => ['web', 'login']], function () use ($router) {
$router->get('invites/info', 'InvitesController@info');
//红包兑换
$router->addRoute(['GET', 'POST'], 'codes/exchange', 'CodesController@store');
$router->addRoute(['GET', 'POST'], 'codes/add', 'CodesController@store');
//好友助力
$router->get('assists/list', 'AssistsController@index');
......
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