first commit
This commit is contained in:
79
app/Api/Controllers/UserController.php
Normal file
79
app/Api/Controllers/UserController.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Facades\PingAn\Log as LogFacade;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use PingAn;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->user = User::find(1);
|
||||
$data = [
|
||||
'user_id' => $this->user->id,
|
||||
'nickname' => $this->user->info->nickname,
|
||||
];
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
public function check(Request $request)
|
||||
{
|
||||
$res = $this->checkSign($request);
|
||||
if (!is_array($res)) {
|
||||
return $this->error($res);
|
||||
}
|
||||
$user_id = $res['user_id'];
|
||||
$user = User::find($user_id);
|
||||
return $this->success($user);
|
||||
}
|
||||
|
||||
//核销
|
||||
public function freezecoupon(Request $request)
|
||||
{
|
||||
$inputdata = $request->all();
|
||||
|
||||
$res = $this->checkSign($request);
|
||||
$inputdata['jiemi'] = $res;
|
||||
$log = LogFacade::insert($request->url(), 'POST', $inputdata, 'self'); //添加日志
|
||||
|
||||
if (!is_array($res)) {
|
||||
return $this->error($res, $log);
|
||||
}
|
||||
|
||||
$validator = \Validator::make($res, [
|
||||
'redemptionCode' => 'required',
|
||||
'total' => 'required',
|
||||
'outletId' => 'required',
|
||||
], [
|
||||
'redemptionCode.required' => '缺少卡券兑换码',
|
||||
'total.required' => '缺少订单总额',
|
||||
'outletId.required' => '缺少网点id',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first(), $log);
|
||||
}
|
||||
|
||||
$redemptionCode = $res['redemptionCode'] ?? ''; //'915400693355';
|
||||
$total = $res['total'] ?? ''; //订单总额;
|
||||
$outletId = $res['outletId'] ?? ''; //网点id;
|
||||
$redemptionCode = trim($redemptionCode);
|
||||
$outletId = trim($outletId);
|
||||
|
||||
$coupon = PingAn::coupondetail($redemptionCode, $total, $this->user, $outletId);
|
||||
if (is_string($coupon)) {
|
||||
return $this->error($coupon, $log);
|
||||
}
|
||||
|
||||
$freezecoupon = PingAn::freezecoupon($coupon, $this->user->id);
|
||||
if (!is_array($freezecoupon)) {
|
||||
return $this->error($freezecoupon, $log);
|
||||
}
|
||||
return $this->success($freezecoupon, $log);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user