|
|
|
|
@@ -382,7 +382,7 @@ class Playx extends Api
|
|
|
|
|
|
|
|
|
|
$token = strval($request->post('token', $request->post('session', $request->get('token', ''))));
|
|
|
|
|
if ($token === '') {
|
|
|
|
|
return $this->error(__('Invalid token'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config('playx.verify_token_local_only', false)) {
|
|
|
|
|
@@ -410,7 +410,7 @@ class Playx extends Api
|
|
|
|
|
$data = json_decode(strval($res->getBody()), true);
|
|
|
|
|
if ($code !== 200 || empty($data['user_id'])) {
|
|
|
|
|
$remoteMsg = $data['message'] ?? '';
|
|
|
|
|
$msg = is_string($remoteMsg) && $remoteMsg !== '' ? $remoteMsg : __('Invalid token');
|
|
|
|
|
$msg = is_string($remoteMsg) && $remoteMsg !== '' ? $remoteMsg : __('Token expiration');
|
|
|
|
|
|
|
|
|
|
return $this->error($msg, null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
@@ -454,20 +454,20 @@ class Playx extends Api
|
|
|
|
|
{
|
|
|
|
|
$tokenData = Token::get($token);
|
|
|
|
|
if (empty($tokenData) || (isset($tokenData['expire_time']) && intval($tokenData['expire_time']) <= time())) {
|
|
|
|
|
return $this->error(__('Invalid token'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
$tokenType = strval($tokenData['type'] ?? '');
|
|
|
|
|
if ($tokenType !== UserAuth::TOKEN_TYPE_MALL_USER) {
|
|
|
|
|
return $this->error(__('Invalid token'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
$assetId = intval($tokenData['user_id'] ?? 0);
|
|
|
|
|
if ($assetId <= 0) {
|
|
|
|
|
return $this->error(__('Invalid token'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$asset = MallUserAsset::where('id', $assetId)->find();
|
|
|
|
|
if (!$asset) {
|
|
|
|
|
return $this->error(__('Invalid token'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$playxUserId = strval($asset->playx_user_id ?? '');
|
|
|
|
|
@@ -507,7 +507,7 @@ class Playx extends Api
|
|
|
|
|
|
|
|
|
|
$assetId = $this->resolvePlayxAssetIdFromRequest($request);
|
|
|
|
|
if ($assetId === null) {
|
|
|
|
|
return $this->error(__('Invalid token'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$asset = $this->getAssetById($assetId);
|
|
|
|
|
@@ -546,7 +546,10 @@ class Playx extends Api
|
|
|
|
|
|
|
|
|
|
$claimRequestId = strval($request->post('claim_request_id', ''));
|
|
|
|
|
$assetId = $this->resolvePlayxAssetIdFromRequest($request);
|
|
|
|
|
if ($claimRequestId === '' || $assetId === null) {
|
|
|
|
|
if ($assetId === null) {
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
if ($claimRequestId === '') {
|
|
|
|
|
return $this->error(__('claim_request_id and user_id/session_id required'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -660,7 +663,7 @@ class Playx extends Api
|
|
|
|
|
|
|
|
|
|
$assetId = $this->resolvePlayxAssetIdFromRequest($request);
|
|
|
|
|
if ($assetId === null) {
|
|
|
|
|
return $this->error(__('Invalid token'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
$asset = $this->getAssetById($assetId);
|
|
|
|
|
if (!$asset || strval($asset->playx_user_id ?? '') === '') {
|
|
|
|
|
@@ -689,7 +692,7 @@ class Playx extends Api
|
|
|
|
|
|
|
|
|
|
$assetId = $this->resolvePlayxAssetIdFromRequest($request);
|
|
|
|
|
if ($assetId === null) {
|
|
|
|
|
return $this->error(__('Invalid token'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$list = MallAddress::where('playx_user_asset_id', $assetId)
|
|
|
|
|
@@ -713,16 +716,16 @@ class Playx extends Api
|
|
|
|
|
|
|
|
|
|
$assetId = $this->resolvePlayxAssetIdFromRequest($request);
|
|
|
|
|
if ($assetId === null) {
|
|
|
|
|
return $this->error(__('Invalid token'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$phone = trim(strval($request->post('phone', '')));
|
|
|
|
|
$receiverName = trim(strval($request->post('receiver_name', '')));
|
|
|
|
|
$region = $request->post('region', '');
|
|
|
|
|
$detailAddress = trim(strval($request->post('detail_address', '')));
|
|
|
|
|
$address = trim(strval($request->post('address', '')));
|
|
|
|
|
$defaultSetting = strval($request->post('default_setting', '0')) === '1' ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
if ($phone === '' || $detailAddress === '' || $address === '' || $region === '' || $region === null) {
|
|
|
|
|
if ($phone === '' || $receiverName === '' || $detailAddress === '' || $region === '' || $region === null) {
|
|
|
|
|
return $this->error(__('Missing required fields'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -734,10 +737,10 @@ class Playx extends Api
|
|
|
|
|
|
|
|
|
|
$created = MallAddress::create([
|
|
|
|
|
'playx_user_asset_id' => $assetId,
|
|
|
|
|
'receiver_name' => $receiverName,
|
|
|
|
|
'phone' => $phone,
|
|
|
|
|
'region' => $region,
|
|
|
|
|
'detail_address' => $detailAddress,
|
|
|
|
|
'address' => $address,
|
|
|
|
|
'default_setting' => $defaultSetting,
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
'update_time' => time(),
|
|
|
|
|
@@ -767,7 +770,7 @@ class Playx extends Api
|
|
|
|
|
|
|
|
|
|
$assetId = $this->resolvePlayxAssetIdFromRequest($request);
|
|
|
|
|
if ($assetId === null) {
|
|
|
|
|
return $this->error(__('Invalid token'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$id = intval($request->post('id', 0));
|
|
|
|
|
@@ -784,15 +787,15 @@ class Playx extends Api
|
|
|
|
|
if ($request->post('phone', null) !== null) {
|
|
|
|
|
$updates['phone'] = trim(strval($request->post('phone', '')));
|
|
|
|
|
}
|
|
|
|
|
if ($request->post('receiver_name', null) !== null) {
|
|
|
|
|
$updates['receiver_name'] = trim(strval($request->post('receiver_name', '')));
|
|
|
|
|
}
|
|
|
|
|
if ($request->post('region', null) !== null) {
|
|
|
|
|
$updates['region'] = $request->post('region', '');
|
|
|
|
|
}
|
|
|
|
|
if ($request->post('detail_address', null) !== null) {
|
|
|
|
|
$updates['detail_address'] = trim(strval($request->post('detail_address', '')));
|
|
|
|
|
}
|
|
|
|
|
if ($request->post('address', null) !== null) {
|
|
|
|
|
$updates['address'] = trim(strval($request->post('address', '')));
|
|
|
|
|
}
|
|
|
|
|
if ($request->post('default_setting', null) !== null) {
|
|
|
|
|
$updates['default_setting'] = strval($request->post('default_setting', '0')) === '1' ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
@@ -830,7 +833,7 @@ class Playx extends Api
|
|
|
|
|
|
|
|
|
|
$assetId = $this->resolvePlayxAssetIdFromRequest($request);
|
|
|
|
|
if ($assetId === null) {
|
|
|
|
|
return $this->error(__('Invalid token'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$id = intval($request->post('id', 0));
|
|
|
|
|
@@ -897,7 +900,10 @@ class Playx extends Api
|
|
|
|
|
|
|
|
|
|
$itemId = intval($request->post('item_id', 0));
|
|
|
|
|
$assetId = $this->resolvePlayxAssetIdFromRequest($request);
|
|
|
|
|
if ($itemId <= 0 || $assetId === null) {
|
|
|
|
|
if ($assetId === null) {
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
if ($itemId <= 0) {
|
|
|
|
|
return $this->error(__('item_id and user_id/session_id required'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -963,11 +969,21 @@ class Playx extends Api
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$itemId = intval($request->post('item_id', 0));
|
|
|
|
|
$addressId = intval($request->post('address_id', 0));
|
|
|
|
|
$assetId = $this->resolvePlayxAssetIdFromRequest($request);
|
|
|
|
|
$receiverName = $request->post('receiver_name', '');
|
|
|
|
|
$receiverPhone = $request->post('receiver_phone', '');
|
|
|
|
|
$receiverAddress = $request->post('receiver_address', '');
|
|
|
|
|
if ($itemId <= 0 || $assetId === null || $receiverName === '' || $receiverPhone === '' || $receiverAddress === '') {
|
|
|
|
|
if ($itemId <= 0 || $addressId <= 0) {
|
|
|
|
|
return $this->error(__('Missing required fields'));
|
|
|
|
|
}
|
|
|
|
|
if ($assetId === null) {
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$addrRow = MallAddress::where('id', $addressId)->where('playx_user_asset_id', $assetId)->find();
|
|
|
|
|
if (!$addrRow) {
|
|
|
|
|
return $this->error(__('Shipping address not found'));
|
|
|
|
|
}
|
|
|
|
|
$snapshot = MallAddress::snapshotForPhysicalOrder($addrRow);
|
|
|
|
|
if ($snapshot['receiver_phone'] === '' || $snapshot['receiver_address'] === '' || $snapshot['receiver_name'] === '') {
|
|
|
|
|
return $this->error(__('Missing required fields'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -996,9 +1012,10 @@ class Playx extends Api
|
|
|
|
|
'status' => MallOrder::STATUS_PENDING,
|
|
|
|
|
'mall_item_id' => $item->id,
|
|
|
|
|
'points_cost' => $item->score,
|
|
|
|
|
'receiver_name' => $receiverName,
|
|
|
|
|
'receiver_phone' => $receiverPhone,
|
|
|
|
|
'receiver_address' => $receiverAddress,
|
|
|
|
|
'mall_address_id' => $addressId,
|
|
|
|
|
'receiver_name' => $snapshot['receiver_name'],
|
|
|
|
|
'receiver_phone' => $snapshot['receiver_phone'],
|
|
|
|
|
'receiver_address' => $snapshot['receiver_address'],
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
'update_time' => time(),
|
|
|
|
|
]);
|
|
|
|
|
@@ -1026,7 +1043,10 @@ class Playx extends Api
|
|
|
|
|
|
|
|
|
|
$itemId = intval($request->post('item_id', 0));
|
|
|
|
|
$assetId = $this->resolvePlayxAssetIdFromRequest($request);
|
|
|
|
|
if ($itemId <= 0 || $assetId === null) {
|
|
|
|
|
if ($assetId === null) {
|
|
|
|
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
|
|
|
|
}
|
|
|
|
|
if ($itemId <= 0) {
|
|
|
|
|
return $this->error(__('item_id and user_id/session_id required'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|