Commit 08072c4c by 杨树贤

添加判断是否可兑换

parent ccd55a8b
......@@ -7,7 +7,7 @@ SYSTEM_CODE=09
SYSTEM_NAME=商品Api
ELK_NAME=ic_welfare_api
BaseUrl=http://192.168.10.20:61009
BaseUrl=http://192.168.10.10:61009
#BaseUrl=http://ic_server_welfare.test
ES_URL=http://soapi.icsales.com:8001
authapi=http://authapi.icsales.cc
......
......@@ -54,7 +54,7 @@ class AssistsController extends Controller
public function store(Request $request)
{
$map = [
'assist_user_id' => $request->user->user_id,
'assist_user_id' => $request->user->user_id,
'exchange_id' => $request->get('exchange_id'),
];
$result = $this->service->addAssist($map);
......
......@@ -11,7 +11,11 @@ class Controller extends BaseController
const SUCCESS = 0;
//请求参数错误
const INVALID_PARAMETER = 109000;
const INVALID_PARAMETER = 109004;
//用户无法进行兑换,未认证
const CAN_NOT_EXCHANGE = 109005;
const EXCHANGED_TODAY = 109100;
//这个是服务那边返回的错误码,代表已经超出了每日每人可领取的对应项的数额(比如每人每天只能签到一次)
const INTEGRAL_LIMIT = 509000;
......
......@@ -5,6 +5,8 @@ namespace App\Http\Controllers;
use App\Http\Transformers\ExchangeSettingTransformer;
use App\Services\ExchangeSettingService;
use App\Services\UserExchangeService;
use App\Services\UserIntegralService;
use Common\Model\RedisModel;
use Illuminate\Http\Request;
......@@ -44,6 +46,10 @@ class ExchangeSettingsController extends Controller
$user = json_decode($redis->hget('ic_user', $userId), true);
$integral = array_get($user, 'integral');
$exchangeSettings['integral'] = $integral;
$userExchangeService = new UserExchangeService();
$canExchangeStatus = $userExchangeService->checkCanExchange($userId);
$exchangeSettings['can_exchange'] = $canExchangeStatus;
return $this->Export(0, 'ok', $exchangeSettings);
}
......
......@@ -60,6 +60,14 @@ class UserExchangesController extends Controller
$exchangeId = 1;
$userId = $request->user->user_id;
//判断是否可以兑换
$exchangeStatus = $service->checkCanExchange($userId);
if ($exchangeStatus === -1) {
return $this->Export(self::CAN_NOT_EXCHANGE);
} elseif ($exchangeStatus === 0) {
return $this->Export(self::EXCHANGED_TODAY);
}
if (empty($exchangeId) || empty($type)) {
return $this->Export(self::INVALID_PARAMETER);
}
......
......@@ -28,4 +28,32 @@ class UserExchangeService
return $result;
}
//检查用户是否可以进行兑换
public function checkCanExchange($userId)
{
//判断用户是否可以进行兑换
$exchangeStatus = 1;
$redis = new RedisModel();
$user = json_decode($redis->hget('ic_user', $userId), true);
//第一个是未认证的用户不可兑换,
if (isset($user['auth_type'])) {
if ($user['auth_type'] == 0) {
$exchangeStatus = -1;
}
} else {
$exchangeStatus = -1;
}
//再判断今天是否已经兑换过
$time = date('Ymd');
$key = 'ic_exchanges_quota_' . $time;
$exchangeId = $redis->hget($key, $userId);
//第二个是今天已经兑换过的,不允许兑换
if ($exchangeId) {
$exchangeStatus = 0;
}
return $exchangeStatus;
}
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ return [
109002 => 'Hprose请求失败',
109003 => '登录失败',
109004 => '请求参数不正确',
109005 => '用户无法兑换,用户未认证',
109100 => '今天已经兑换过了,请明天再来吧',
109101 => '兑换名额被抢光了',
......
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