Commit 6f5921c5 by 杨树贤

ä¿修复用户可以兑换自己的红包码的bug

parent a1c9a05a
Showing with 8 additions and 3 deletions
...@@ -25,15 +25,16 @@ class CodesController extends Controller ...@@ -25,15 +25,16 @@ class CodesController extends Controller
*/ */
public function store(Request $request, CodeService $service) public function store(Request $request, CodeService $service)
{ {
$userId = $request->user->user_id;
$code = $request->get('code'); $code = $request->get('code');
if (empty($code)) { if (empty($code)) {
return $this->Export(self::INVALID_PARAMETER); return $this->Export(self::INVALID_PARAMETER);
} elseif (!$this->checkCode($code)) { } elseif (!$this->checkCode($code, $userId)) {
return $this->Export(self::INVALID_CODE); return $this->Export(self::INVALID_CODE);
} }
$data = [ $data = [
'user_id' => $request->user->user_id, 'user_id' => $userId,
'code' => $request->get('code'), 'code' => $request->get('code'),
]; ];
$result = $service->addCode($data); $result = $service->addCode($data);
...@@ -56,8 +57,12 @@ class CodesController extends Controller ...@@ -56,8 +57,12 @@ class CodesController extends Controller
} }
//检查红包码是否正确 //检查红包码是否正确
private function checkCode($code) private function checkCode($code, $userId = 0)
{ {
//检查是不是自己,自己不能兑换自己的红包码
if ($userId == substr($code, 3)) {
return false;
}
//先检查是否是RDD开头 //先检查是否是RDD开头
if (substr($code, 0, 3) !== 'RDD') { if (substr($code, 0, 3) !== 'RDD') {
return false; return false;
......
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