Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cdz_pay_v2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨苏杭
cdz_pay_v2
Commits
4fec2fb8
Commit
4fec2fb8
authored
Nov 20, 2018
by
banice
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://git.senthink.com/yangsh/cdz_pay_v2
parents
817c9b82
efaf590b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
108 additions
and
2 deletions
+108
-2
app/Http/Controllers/V1/Wx/UnrealCardsController.php
+73
-0
app/Http/Middleware/CorsMiddleware.php
+1
-1
app/Model/UnrealCardModel.php
+17
-0
app/Services/GeoHashServices.php
+12
-1
routes/web.php
+5
-0
No files found.
app/Http/Controllers/V1/Wx/UnrealCardsController.php
0 → 100644
View file @
4fec2fb8
<?php
namespace
App\Http\Controllers\V1\Wx
;
use
App\Http\Controllers\Controller
;
use
App\Model\UnrealCardModel
;
use
Illuminate\Http\Request
;
use
Validator
;
class
UnrealCardsController
extends
Controller
{
public
function
index
()
{
$userId
=
\Auth
::
id
();
$unrealCards
=
UnrealCardModel
::
where
(
'user_id'
,
$userId
)
->
paginate
(
15
);
return
$this
->
response
->
array
(
$this
->
getResponseCode
()
+
[
'data'
=>
$unrealCards
]);
}
public
function
store
(
Request
$request
)
{
$validator
=
Validator
::
make
(
$request
->
all
(),
[
'mac'
=>
'required'
,
]);
if
(
$validator
->
fails
())
{
abort
(
400
,
$validator
->
errors
()
->
first
());
}
// 验证卡号有效性
$mac
=
strtoupper
(
$request
->
get
(
'mac'
));
if
(
strlen
(
$mac
)
!=
10
)
{
$this
->
resultCode
=
'FAIL'
;
return
$this
->
response
->
array
(
$this
->
getResponseCode
()
+
[
'data'
=>
[
'message'
=>
'卡号不能低于10位'
]]);
}
$temp
=
substr
(
$mac
,
0
,
2
);
for
(
$i
=
2
;
$i
<
8
;
$i
+=
2
)
{
$temp
=
dechex
(
hexdec
(
$temp
)
^
hexdec
(
substr
(
$mac
,
$i
,
2
)));
}
if
(
strtoupper
(
$temp
)
!=
substr
(
$mac
,
-
2
))
{
$this
->
resultCode
=
'FAIL'
;
return
$this
->
response
->
array
(
$this
->
getResponseCode
()
+
[
'data'
=>
[
'message'
=>
'卡号错误'
]]);
}
$unrealCard
=
UnrealCardModel
::
where
(
'mac'
,
$mac
)
->
first
();
if
(
$unrealCard
)
{
$this
->
resultCode
=
'FAIL'
;
return
$this
->
response
->
array
(
$this
->
getResponseCode
()
+
[
'data'
=>
[
'message'
=>
'虚拟卡已经被使用'
]]);
}
// 保存
$unrealCard
=
new
UnrealCardModel
();
$unrealCard
->
user_id
=
\Auth
::
id
();
$unrealCard
->
mac
=
$mac
;
$unrealCard
->
save
();
return
$this
->
response
->
array
(
$this
->
getResponseCode
()
+
[
'data'
=>
[
'message'
=>
'绑定成功'
]]);
}
public
function
destroy
(
$id
)
{
$unrealCard
=
UnrealCardModel
::
find
(
$id
);
if
(
!
$unrealCard
)
{
$this
->
resultCode
=
'FAIL'
;
return
$this
->
response
->
array
(
$this
->
getResponseCode
()
+
[
'data'
=>
[
'message'
=>
'Not Found'
]]);
}
// 判断用户是否有权限删除
if
(
!
$unrealCard
->
user_id
||
$unrealCard
->
user_id
!=
\Auth
::
id
())
{
$this
->
resultCode
=
'FAIL'
;
return
$this
->
response
->
array
(
$this
->
getResponseCode
()
+
[
'data'
=>
[
'message'
=>
'无效数据'
]]);
}
$unrealCard
->
delete
();
return
$this
->
response
->
array
(
$this
->
getResponseCode
()
+
[
'data'
=>
[
'message'
=>
'删除成功'
]]);
}
}
app/Http/Middleware/CorsMiddleware.php
View file @
4fec2fb8
...
@@ -25,7 +25,7 @@ class CorsMiddleware
...
@@ -25,7 +25,7 @@ class CorsMiddleware
$headers
=
[
$headers
=
[
'Access-Control-Allow-Origin'
=>
'*'
,
'Access-Control-Allow-Origin'
=>
'*'
,
'Access-Control-Allow-Methods'
=>
'POST, GET, OPTIONS'
,
'Access-Control-Allow-Methods'
=>
'POST, GET, OPTIONS
, DELETE
'
,
'Access-Control-Allow-Credentials'
=>
'true'
,
'Access-Control-Allow-Credentials'
=>
'true'
,
'Access-Control-Max-Age'
=>
'86400'
,
'Access-Control-Max-Age'
=>
'86400'
,
'Access-Control-Allow-Headers'
=>
'Content-Type, Authorization, X-Requested-With'
'Access-Control-Allow-Headers'
=>
'Content-Type, Authorization, X-Requested-With'
...
...
app/Model/UnrealCardModel.php
0 → 100644
View file @
4fec2fb8
<?php
namespace
App\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
class
UnrealCardModel
extends
Model
{
use
SoftDeletes
;
protected
$table
=
'unreal_cards'
;
protected
$dates
=
[
'deleted_at'
];
}
\ No newline at end of file
app/Services/GeoHashServices.php
View file @
4fec2fb8
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
App\Services
;
namespace
App\Services
;
use
App\Model\StationModel
;
use
App\Model\StationModel
;
use
Lib\redis\RedisSingle
;
/**
/**
* geohash lenght | km error
* geohash lenght | km error
...
@@ -134,7 +135,7 @@ class GeoHashServices
...
@@ -134,7 +135,7 @@ class GeoHashServices
{
{
// 搜索该点附近的站点
// 搜索该点附近的站点
$geoHashCode
=
$this
->
getGeoHash
(
$latitude
,
$longitude
);
$geoHashCode
=
$this
->
getGeoHash
(
$latitude
,
$longitude
);
$stations
=
StationModel
::
select
([
'id'
,
'name'
,
'longitude'
,
'latitude'
,
'geohash'
])
$stations
=
StationModel
::
select
([
'id'
,
'
address'
,
'
name'
,
'longitude'
,
'latitude'
,
'geohash'
])
->
where
(
'geohash'
,
'like'
,
substr
(
$geoHashCode
,
0
,
4
)
.
'%'
)
->
where
(
'geohash'
,
'like'
,
substr
(
$geoHashCode
,
0
,
4
)
.
'%'
)
->
get
();
->
get
();
if
(
!
$stations
)
if
(
!
$stations
)
...
@@ -144,6 +145,15 @@ class GeoHashServices
...
@@ -144,6 +145,15 @@ class GeoHashServices
$stations
[
$key
][
'distance'
]
=
$this
->
getDistance
(
$latitude
,
$longitude
,
$station
[
'latitude'
],
$station
[
'longitude'
]);
$stations
[
$key
][
'distance'
]
=
$this
->
getDistance
(
$latitude
,
$longitude
,
$station
[
'latitude'
],
$station
[
'longitude'
]);
}
}
array_multisort
(
$stations
,
SORT_ASC
,
SORT_NUMERIC
,
array_column
(
$stations
,
'distance'
),
SORT_ASC
,
SORT_NUMERIC
);
array_multisort
(
$stations
,
SORT_ASC
,
SORT_NUMERIC
,
array_column
(
$stations
,
'distance'
),
SORT_ASC
,
SORT_NUMERIC
);
$redis
=
RedisSingle
::
getRedis
();
foreach
(
$stations
as
$key
=>
$station
)
{
if
(
$station
[
'distance'
]
>
$scale
)
{
unset
(
$stations
[
$key
]);
continue
;
}
$stations
[
$key
][
'freeCount'
]
=
count
(
$redis
->
zRangeByScore
(
"cdz:station:port:state:"
.
$station
[
'id'
]
.
':zset'
,
11
,
11
,
[
'withscores'
=>
TRUE
]));
}
return
$stations
;
return
$stations
;
}
}
}
}
\ No newline at end of file
routes/web.php
View file @
4fec2fb8
...
@@ -115,6 +115,11 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1', 'prefix' => 'api/
...
@@ -115,6 +115,11 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1', 'prefix' => 'api/
// 查找附近的站点
// 查找附近的站点
$api
->
post
(
'station/nearby'
,
'Station\StationController@nearby'
);
$api
->
post
(
'station/nearby'
,
'Station\StationController@nearby'
);
// 虚拟卡
$api
->
get
(
'unreal/cards'
,
'Wx\UnrealCardsController@index'
);
$api
->
post
(
'unreal/cards'
,
'Wx\UnrealCardsController@store'
);
$api
->
delete
(
'unreal/cards/{id}'
,
'Wx\UnrealCardsController@destroy'
);
});
});
$api
->
post
(
'refresh/token'
,
[
'as'
=>
'wx.refresh.token'
,
'uses'
=>
'Wx\AccessController@refreshToken'
]);
$api
->
post
(
'refresh/token'
,
[
'as'
=>
'wx.refresh.token'
,
'uses'
=>
'Wx\AccessController@refreshToken'
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment