Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
e670afb3
Commit
e670afb3
authored
Sep 30, 2016
by
庄欣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试
parent
237dde85
Show whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
370 additions
and
56 deletions
+370
-56
app/Article/v1/Controller/Article.php
+9
-2
app/City/Model/City.php
+73
-1
app/Http/Response/Response.php
+2
-1
app/Http/Validation/ValidatorBase.php
+1
-0
app/Kw/Model/Keywords.php
+2
-1
app/Libraries/ElasticSearch/Search.php
+5
-2
app/Photo/Model/Details.php
+6
-4
app/Photo/v1/Controller/Details.php
+49
-2
app/Photo/v1/Controller/Photo.php
+17
-4
app/Providers/AppServiceProvider.php
+1
-0
app/Sets/Events/SetsClosePromotiondEvent.php
+19
-0
app/Sets/Model/Sets.php
+10
-5
app/Sets/Validation/SetsValidator.php
+18
-1
app/Sets/v1/Controller/Sets.php
+21
-5
app/Traits/Controller.php
+28
-9
app/Traits/Models.php
+7
-3
app/Works/Listeners/WorksSearcherListener.php
+1
-1
app/Works/Model/Keywords.php
+6
-1
app/Works/Model/Sets.php
+2
-1
app/Works/Model/Works.php
+22
-3
app/Works/Validation/WorksValidator.php
+37
-4
app/Works/v1/Controller/Works.php
+22
-4
routes/api.php
+12
-2
No files found.
app/Article/v1/Controller/Article.php
View file @
e670afb3
...
@@ -51,7 +51,7 @@ class Article extends \Illuminate\Routing\Controller
...
@@ -51,7 +51,7 @@ class Article extends \Illuminate\Routing\Controller
$model
=
ArtModel
::
newArt
(
$post
);
$model
=
ArtModel
::
newArt
(
$post
);
if
(
$model
!==
false
)
{
if
(
$model
!==
false
)
{
Event
::
fire
(
new
ArtAddEvent
(
$model
));
Event
::
fire
(
new
ArtAddEvent
(
$model
));
return
Response
::
ok
();
return
Response
::
ok
(
$model
->
id
);
}
else
{
}
else
{
return
Response
::
error
();
return
Response
::
error
();
}
}
...
@@ -69,10 +69,17 @@ class Article extends \Illuminate\Routing\Controller
...
@@ -69,10 +69,17 @@ class Article extends \Illuminate\Routing\Controller
$model
=
ArtModel
::
findOrFail
(
$id
);
$model
=
ArtModel
::
findOrFail
(
$id
);
$post
=
$request
->
all
();
$post
=
$request
->
all
();
isset
(
$post
[
'content'
])
&&
$post
[
'content'
]
=
$this
->
csrf
(
$post
,
'content'
);
isset
(
$post
[
'content'
])
&&
$post
[
'content'
]
=
$this
->
csrf
(
$post
,
'content'
);
$validate_Data
=
array_merge
(
$model
->
toArray
(),
$post
);
$validator
=
new
ArtValidator
();
$res
=
$validator
->
validate
(
$validate_Data
);
if
(
$res
==
false
)
{
$messages
=
$validator
->
getMessages
();
return
Response
::
error
(
$messages
,
HttpStatus
::
HttpValidationFailed
);
}
$res
=
$model
->
uptArt
(
$post
);
$res
=
$model
->
uptArt
(
$post
);
if
(
$res
!==
false
)
{
if
(
$res
!==
false
)
{
Event
::
fire
(
new
ArtEditedEvent
(
$model
));
Event
::
fire
(
new
ArtEditedEvent
(
$model
));
return
Response
::
ok
();
return
Response
::
ok
(
$model
->
id
);
}
else
{
}
else
{
return
Response
::
error
();
return
Response
::
error
();
}
}
...
...
app/City/Model/City.php
View file @
e670afb3
...
@@ -7,8 +7,79 @@
...
@@ -7,8 +7,79 @@
*/
*/
namespace
App\City\Model
;
namespace
App\City\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Support\Facades\Cache
;
class
City
extends
Model
class
City
extends
Model
{
{
protected
$table
=
"myp_city"
;
protected
$table
=
"myp_site"
;
//存储、更新地点缓存
public
static
function
getPlace
(
$id
,
$forceUpdate
=
false
)
{
$key
=
base64_encode
(
"place-"
.
$id
);
if
(
!
Cache
::
has
(
$key
)
||
$forceUpdate
==
true
)
{
Cache
::
put
(
$key
,
self
::
where
(
'id'
,
$id
)
->
get
());
}
return
Cache
::
get
(
$key
);
}
public
static
function
getPlaceName
(
$id
,
$field
=
"name"
)
{
if
(
empty
(
$id
))
{
return
""
;
}
$cache
=
self
::
getPlace
(
$id
);
if
(
empty
(
$cache
))
{
return
$id
;
}
return
$cache
->
$field
;
}
public
static
function
getPlaceParent
(
$id
)
{
if
(
empty
(
$id
))
{
return
""
;
}
return
self
::
getPlaceName
(
self
::
getPlaceName
(
$id
,
"previous"
));
}
public
static
function
getPlaceRoot
(
$id
)
{
if
(
empty
(
$id
))
{
return
""
;
}
while
(
self
::
getPlace
(
$id
)
->
level
!=
0
)
{
$id
=
self
::
getPlaceRoot
(
self
::
getPlace
(
$id
)
->
previous
);
}
return
$id
;
}
public
static
function
getChina
()
{
return
1
;
}
public
static
function
list_to_tree
(
$list
,
$pk
=
'id'
,
$pid
=
'pid'
,
$child
=
'child'
,
$root
=
0
)
{
// 创建Tree
$tree
=
array
();
if
(
is_array
(
$list
))
{
// 创建基于主键的数组引用
$refer
=
array
();
foreach
(
$list
as
$key
=>
$data
)
{
$refer
[
$data
[
$pk
]]
=&
$list
[
$key
];
}
foreach
(
$list
as
$key
=>
$data
)
{
// 判断是否存在parent
$parentId
=
$data
[
$pid
];
if
(
$root
==
$parentId
)
{
$tree
[]
=&
$list
[
$key
];
}
else
{
if
(
isset
(
$refer
[
$parentId
]))
{
$parent
=&
$refer
[
$parentId
];
$parent
[
$child
][]
=&
$list
[
$key
];
}
}
}
}
return
$tree
;
}
}
}
\ No newline at end of file
app/Http/Response/Response.php
View file @
e670afb3
...
@@ -22,10 +22,11 @@ class Response
...
@@ -22,10 +22,11 @@ class Response
}
}
//method put,post,head return
//method put,post,head return
public
static
function
ok
(
$code
=
HttpStatus
::
HttpOk
)
public
static
function
ok
(
$
data
=
""
,
$
code
=
HttpStatus
::
HttpOk
)
{
{
return
[
return
[
'code'
=>
$code
,
'code'
=>
$code
,
'data'
=>
$data
,
'api_ver'
=>
RouteServiceProvider
::
getVersion
()
'api_ver'
=>
RouteServiceProvider
::
getVersion
()
];
];
}
}
...
...
app/Http/Validation/ValidatorBase.php
View file @
e670afb3
...
@@ -15,6 +15,7 @@ class ValidatorBase extends Validator
...
@@ -15,6 +15,7 @@ class ValidatorBase extends Validator
public
function
validate
(
array
$post
)
public
function
validate
(
array
$post
)
{
{
self
::
$_validator
=
self
::
make
(
$post
,
$this
->
validator
,
$this
->
message
);
self
::
$_validator
=
self
::
make
(
$post
,
$this
->
validator
,
$this
->
message
);
file_put_contents
(
"/var/www/log1.txt"
,
json_encode
(
$post
));
if
(
self
::
$_validator
->
passes
())
{
if
(
self
::
$_validator
->
passes
())
{
if
(
method_exists
(
$this
,
"custom_validate"
))
{
if
(
method_exists
(
$this
,
"custom_validate"
))
{
$res
=
call_user_func_array
([
$this
,
"custom_validate"
],
[
$post
]);
$res
=
call_user_func_array
([
$this
,
"custom_validate"
],
[
$post
]);
...
...
app/Kw/Model/Keywords.php
View file @
e670afb3
...
@@ -9,6 +9,7 @@ class Keywords extends Model
...
@@ -9,6 +9,7 @@ class Keywords extends Model
{
{
use
Models
;
use
Models
;
protected
$table
=
"myp_kw"
;
protected
$table
=
"myp_kw"
;
public
$timestamps
=
false
;
public
function
__construct
(
array
$attributes
=
[])
public
function
__construct
(
array
$attributes
=
[])
{
{
...
@@ -20,7 +21,6 @@ class Keywords extends Model
...
@@ -20,7 +21,6 @@ class Keywords extends Model
{
{
$this
->
create_time
=
date
(
"Y-m-d H:i:s"
,
time
());
$this
->
create_time
=
date
(
"Y-m-d H:i:s"
,
time
());
$this
->
is_del
=
0
;
$this
->
is_del
=
0
;
$this
->
sort
=
0
;
}
}
public
static
function
getIdByWords
(
$words
,
$uid
=
0
,
$auto_add
=
false
)
public
static
function
getIdByWords
(
$words
,
$uid
=
0
,
$auto_add
=
false
)
...
@@ -40,6 +40,7 @@ class Keywords extends Model
...
@@ -40,6 +40,7 @@ class Keywords extends Model
$model
->
uid
=
$uid
;
$model
->
uid
=
$uid
;
$model
->
follow_count
=
0
;
$model
->
follow_count
=
0
;
$model
->
used_count
=
1
;
$model
->
used_count
=
1
;
$model
->
recommend
=
0
;
$model
->
save
();
$model
->
save
();
return
$model
;
return
$model
;
}
else
{
}
else
{
...
...
app/Libraries/ElasticSearch/Search.php
View file @
e670afb3
<?php
<?php
namespace
App\Libraries\ElasticSearch
;
namespace
App\Libraries\ElasticSearch
;
use
Illuminate\Support\Facades\Log
;
class
Search
{
class
Search
{
protected
static
$server
=
[];
protected
static
$server
=
[];
...
@@ -26,7 +27,7 @@ class Search {
...
@@ -26,7 +27,7 @@ class Search {
protected
function
__construct
(
$index_name
)
protected
function
__construct
(
$index_name
)
{
{
$this
->
server_ip
=
"http://"
.
config
(
"app.
ip"
)
.
":"
.
config
(
"app
.port"
);
$this
->
server_ip
=
"http://"
.
config
(
"app.
elastic_searcher.ip"
)
.
":"
.
config
(
"app.elastic_searcher
.port"
);
$this
->
index_name
=
$index_name
;
$this
->
index_name
=
$index_name
;
}
}
...
@@ -46,7 +47,8 @@ class Search {
...
@@ -46,7 +47,8 @@ class Search {
$this
->
type_name
=
$type
;
$this
->
type_name
=
$type
;
$this
->
data_id
=
$id
;
$this
->
data_id
=
$id
;
$this
->
data
=
$data
;
$this
->
data
=
$data
;
return
$this
->
go
();
$res
=
$this
->
go
();
return
$res
;
}
}
...
@@ -78,6 +80,7 @@ class Search {
...
@@ -78,6 +80,7 @@ class Search {
curl_setopt
(
$curl
,
CURLOPT_URL
,
$this
->
buildRequest
());
curl_setopt
(
$curl
,
CURLOPT_URL
,
$this
->
buildRequest
());
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
$res
=
curl_exec
(
$curl
);
$res
=
curl_exec
(
$curl
);
Log
::
info
(
$res
);
$decode
=
json_decode
(
$res
);
$decode
=
json_decode
(
$res
);
if
(
json_last_error
())
{
if
(
json_last_error
())
{
return
false
;
return
false
;
...
...
app/Photo/Model/Details.php
View file @
e670afb3
...
@@ -3,18 +3,21 @@
...
@@ -3,18 +3,21 @@
namespace
App\Photo\Model
;
namespace
App\Photo\Model
;
use
\Illuminate\Database\Eloquent\Model
;
use
App\Traits\Models
;
use
Illuminate\Support\Facades\DB
;
class
Details
extends
\Illuminate\Database\Eloquent\Model
class
Details
extends
\Illuminate\Database\Eloquent\Model
{
{
use
Models
;
const
fields
=
[
const
fields
=
[
"url"
,
"file_name"
,
"image_width"
,
"image_height"
,
"hit"
"url"
,
"file_name"
,
"image_width"
,
"image_height"
,
"hit"
];
];
public
$table
=
"myp_xp_set_details"
;
public
$table
=
"myp_xp_set_details"
;
public
$timestamps
=
false
;
public
$timestamps
=
false
;
public
$fillable
=
[
"url"
,
"file_name"
,
"image_width"
,
"image_height"
];
public
function
__construct
(
array
$attributes
=
[])
public
function
__construct
(
array
$attributes
=
[])
{
{
...
@@ -24,7 +27,6 @@ class Details extends \Illuminate\Database\Eloquent\Model
...
@@ -24,7 +27,6 @@ class Details extends \Illuminate\Database\Eloquent\Model
public
function
beforeValidationOnCreate
()
public
function
beforeValidationOnCreate
()
{
{
parent
::
beforeValidationOnCreate
();
$this
->
hit
=
0
;
$this
->
hit
=
0
;
$this
->
is_del
=
0
;
$this
->
is_del
=
0
;
$this
->
create_time
=
date
(
"Y-m-d H:i:s"
,
time
());
$this
->
create_time
=
date
(
"Y-m-d H:i:s"
,
time
());
...
...
app/Photo/v1/Controller/Details.php
View file @
e670afb3
...
@@ -4,11 +4,57 @@ namespace App\Photo\v1\Controller;
...
@@ -4,11 +4,57 @@ namespace App\Photo\v1\Controller;
use
App\Http\Response\HttpStatus
;
use
App\Http\Response\HttpStatus
;
use
App\Http\Response\Response
;
use
App\Http\Response\Response
;
use
App\Traits\Controller
;
use
App\Traits\Controller
;
use
Illuminate\Database\Eloquent\ModelNotFoundException
;
use
App\Photo\Model\Details
as
DetailModel
;
use
Symfony\Component\HttpFoundation\Request
;
use
App\Photo\Model\Photo
as
PhotoModel
;
use
App\Photo\Model\Photo
as
PhotoModel
;
use
Illuminate\Http\Request
;
class
Details
extends
\Illuminate\Routing\Controller
class
Details
extends
\Illuminate\Routing\Controller
{
{
use
Controller
;
protected
$query_fields
=
[
"xp_id"
,
"is_del"
];
public
function
index
(
$id
)
{
$query
=
request
()
->
query
();
$where
=
$this
->
filter
(
$query
);
$where
[
'xp_id'
]
=
$id
;
is_null
(
$where
)
&&
$where
=
[];
$row
=
isset
(
$query
[
"size"
])
?
$query
[
"size"
]
:
config
(
"app.default_perpage"
);
return
Response
::
success
(
DetailModel
::
where
(
$where
)
->
paginate
(
$row
)
->
toArray
());
}
public
function
store
(
$id
,
Request
$request
)
{
try
{
$model
=
PhotoModel
::
findOrFail
(
$id
);
$details
=
DetailModel
::
add
(
$request
->
all
(),
null
);
$res
=
$model
->
relation_details
()
->
saveMany
(
$details
);
if
(
$res
)
{
return
Response
::
ok
();
}
else
{
return
Response
::
error
();
}
}
catch
(
ModelNotFoundException
$e
){
return
Response
::
error
(
HttpStatus
::
HttpNotFound
,
"选片未找到"
);
}
}
public
function
destory
(
$id
,
$ids
)
{
try
{
$model
=
PhotoModel
::
findOrFail
(
$id
);
$res
=
$model
->
relation_details
()
->
whereIn
(
"id"
,
$ids
)
->
delete
();
if
(
$res
)
{
return
Response
::
ok
();
}
else
{
return
Response
::
error
();
}
}
catch
(
ModelNotFoundException
$e
){
return
Response
::
error
(
HttpStatus
::
HttpNotFound
,
"选片未找到"
);
}
}
}
}
\ No newline at end of file
app/Photo/v1/Controller/Photo.php
View file @
e670afb3
...
@@ -25,7 +25,8 @@ class Photo extends \Illuminate\Routing\Controller
...
@@ -25,7 +25,8 @@ class Photo extends \Illuminate\Routing\Controller
$where
=
$this
->
filter
(
$query
);
$where
=
$this
->
filter
(
$query
);
is_null
(
$where
)
&&
$where
=
[];
is_null
(
$where
)
&&
$where
=
[];
$row
=
isset
(
$query
[
"size"
])
?
$query
[
"size"
]
:
config
(
"app.default_perpage"
);
$row
=
isset
(
$query
[
"size"
])
?
$query
[
"size"
]
:
config
(
"app.default_perpage"
);
return
Response
::
success
(
PhotoModel
::
where
(
$where
)
->
paginate
(
$row
)
->
toArray
());
$model
=
$this
->
getOrder
(
PhotoModel
::
class
,
$where
);
return
Response
::
success
(
$model
->
paginate
(
$row
)
->
toArray
());
}
}
...
@@ -51,7 +52,7 @@ class Photo extends \Illuminate\Routing\Controller
...
@@ -51,7 +52,7 @@ class Photo extends \Illuminate\Routing\Controller
}
}
$model
=
PhotoModel
::
newPhoto
(
$post
);
$model
=
PhotoModel
::
newPhoto
(
$post
);
if
(
$model
!==
false
)
{
if
(
$model
!==
false
)
{
return
Response
::
ok
();
return
Response
::
ok
(
$model
->
id
);
}
else
{
}
else
{
return
Response
::
error
();
return
Response
::
error
();
}
}
...
@@ -63,12 +64,12 @@ class Photo extends \Illuminate\Routing\Controller
...
@@ -63,12 +64,12 @@ class Photo extends \Illuminate\Routing\Controller
$model
=
PhotoModel
::
findOrFail
(
$id
);
$model
=
PhotoModel
::
findOrFail
(
$id
);
$res
=
$model
->
update
(
$request
->
all
());
$res
=
$model
->
update
(
$request
->
all
());
if
(
$res
!==
false
)
{
if
(
$res
!==
false
)
{
return
Response
::
ok
();
return
Response
::
ok
(
$model
->
id
);
}
else
{
}
else
{
return
Response
::
error
();
return
Response
::
error
();
}
}
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
return
Response
::
error
(
HttpStatus
::
HttpNotFound
,
"选片未找到"
);
return
Response
::
error
(
"选片未找到"
,
HttpStatus
::
HttpNotFound
);
}
}
}
}
...
@@ -83,4 +84,15 @@ class Photo extends \Illuminate\Routing\Controller
...
@@ -83,4 +84,15 @@ class Photo extends \Illuminate\Routing\Controller
}
catch
(
ModelNotFoundException
$e
){}
}
catch
(
ModelNotFoundException
$e
){}
return
Response
::
ok
();
return
Response
::
ok
();
}
}
public
function
show
(
$id
)
{
try
{
$model
=
PhotoModel
::
findOrFail
(
$id
);
return
Response
::
success
(
$model
->
toArray
());
}
catch
(
ModelNotFoundException
$e
){
return
Response
::
error
(
"选片未找到"
,
HttpStatus
::
HttpNotFound
);
}
}
}
}
\ No newline at end of file
app/Providers/AppServiceProvider.php
View file @
e670afb3
...
@@ -4,6 +4,7 @@ namespace App\Providers;
...
@@ -4,6 +4,7 @@ namespace App\Providers;
use
Illuminate\Support\ServiceProvider
;
use
Illuminate\Support\ServiceProvider
;
use
Illuminate\Support\Facades\Validator
;
use
Illuminate\Support\Facades\Validator
;
use
Illuminate\Support\Facades\Log
;
class
AppServiceProvider
extends
ServiceProvider
class
AppServiceProvider
extends
ServiceProvider
{
{
...
...
app/Sets/Events/SetsClosePromotiondEvent.php
0 → 100755
View file @
e670afb3
<?php
namespace
App\Sets\Events
;
use
Illuminate\Queue\SerializesModels
;
use
Illuminate\Support\Facades\Event
;
use
App\Sets\Model\Sets
as
SetsModel
;
class
SetsEditedEvent
extends
Event
{
use
SerializesModels
;
public
$model
;
public
function
__construct
(
SetsModel
$model
)
{
$this
->
model
=
$model
;
}
}
app/Sets/Model/Sets.php
View file @
e670afb3
...
@@ -6,6 +6,7 @@ use App\Sets\Model\Category;
...
@@ -6,6 +6,7 @@ use App\Sets\Model\Category;
use
\Illuminate\Database\Eloquent\Model
;
use
\Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Relations\Relation
;
use
Illuminate\Database\Eloquent\Relations\Relation
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\DB
;
use
App\City\Model\City
as
CityModel
;
class
Sets
extends
Model
class
Sets
extends
Model
{
{
...
@@ -23,6 +24,10 @@ class Sets extends Model
...
@@ -23,6 +24,10 @@ class Sets extends Model
'abroad'
,
'modeling_count_from_user'
,
'is_promotion'
,
"temp_price"
,
"type"
'abroad'
,
'modeling_count_from_user'
,
'is_promotion'
,
"temp_price"
,
"type"
];
];
const
fields
=
[
'id'
,
'title'
,
'cover'
,
'price'
,
'type'
,
'is_promotion'
,
'is_shelf'
,
'create_time'
];
public
function
__construct
(
array
$attributes
=
[])
public
function
__construct
(
array
$attributes
=
[])
{
{
parent
::
__construct
(
$attributes
);
parent
::
__construct
(
$attributes
);
...
@@ -129,31 +134,31 @@ class Sets extends Model
...
@@ -129,31 +134,31 @@ class Sets extends Model
$data
[
'temp_price'
]
=
$data
[
'price'
];
$data
[
'temp_price'
]
=
$data
[
'price'
];
$this
->
update
(
$data
);
$this
->
update
(
$data
);
//促销
//促销
if
(
isset
(
$data
[
'promotion'
]))
{
if
(
isset
(
$data
[
'promotion'
])
&&
!
empty
(
$data
[
'promotion'
])
)
{
$models
=
Promotion
::
add
(
$data
[
'promotion'
]);
$models
=
Promotion
::
add
(
$data
[
'promotion'
]);
$this
->
relation_promotion
()
->
update
([
'is_del'
=>
1
]);
$this
->
relation_promotion
()
->
update
([
'is_del'
=>
1
]);
$this
->
relation_promotion
()
->
saveMany
(
$models
);
$this
->
relation_promotion
()
->
saveMany
(
$models
);
};
};
//绑定的样片
//绑定的样片
if
(
isset
(
$data
[
'works'
]))
{
if
(
isset
(
$data
[
'works'
])
&&
!
empty
(
$data
[
'works'
])
)
{
$models
=
Works
::
add
(
$data
[
'works'
]);
$models
=
Works
::
add
(
$data
[
'works'
]);
$this
->
relation_works
()
->
delete
();
$this
->
relation_works
()
->
delete
();
$this
->
relation_works
()
->
saveMany
(
$models
);
$this
->
relation_works
()
->
saveMany
(
$models
);
};
};
//输入的附件
//输入的附件
if
(
isset
(
$data
[
'attachment'
]))
{
if
(
isset
(
$data
[
'attachment'
])
&&
!
empty
(
$data
[
'attachment'
])
)
{
$models
=
Attachment
::
add
(
$data
[
'attachment'
]);
$models
=
Attachment
::
add
(
$data
[
'attachment'
]);
$this
->
relation_attatchment
()
->
delete
();
$this
->
relation_attatchment
()
->
delete
();
$this
->
relation_attatchment
()
->
saveMany
(
$models
);
$this
->
relation_attatchment
()
->
saveMany
(
$models
);
};
};
//分类
//分类
if
(
isset
(
$data
[
'category'
]))
{
if
(
isset
(
$data
[
'category'
])
&&
!
empty
(
$data
[
'category'
])
)
{
$models
=
Category
::
add
(
$data
[
'category'
]);
$models
=
Category
::
add
(
$data
[
'category'
]);
$this
->
relation_category
()
->
delete
();
$this
->
relation_category
()
->
delete
();
$this
->
relation_category
()
->
saveMany
(
$models
);
$this
->
relation_category
()
->
saveMany
(
$models
);
};
};
//关键词
//关键词
if
(
isset
(
$data
[
'keywords'
]))
{
if
(
isset
(
$data
[
'keywords'
])
&&
!
empty
(
$data
[
'keywords'
])
)
{
$models
=
Keywords
::
add
(
$data
[
'keywords'
],
$this
->
uid
);
$models
=
Keywords
::
add
(
$data
[
'keywords'
],
$this
->
uid
);
$this
->
relation_keywords
()
->
delete
();
$this
->
relation_keywords
()
->
delete
();
$this
->
relation_keywords
()
->
saveMany
(
$models
);
$this
->
relation_keywords
()
->
saveMany
(
$models
);
...
...
app/Sets/Validation/SetsValidator.php
View file @
e670afb3
...
@@ -89,6 +89,10 @@ class SetsValidator extends Validator
...
@@ -89,6 +89,10 @@ class SetsValidator extends Validator
'is_shelf.required'
=>
'上下架状态必填'
,
'is_shelf.required'
=>
'上下架状态必填'
,
'is_promotion.required'
=>
'促销状态必填'
,
'is_promotion.required'
=>
'促销状态必填'
,
'is_promotion.in'
=>
'促销状态必须为0或1'
,
'is_promotion.in'
=>
'促销状态必须为0或1'
,
'is_shelf.in'
=>
'上下架必须为0或1'
,
'duration_unit.in'
=>
'时间区间应为小时、天、周'
,
'start_time.date'
=>
'请输入正确的开始时间'
,
'end_time.date'
=>
'请输入正确的结束时间'
];
];
/**
/**
...
@@ -100,53 +104,66 @@ class SetsValidator extends Validator
...
@@ -100,53 +104,66 @@ class SetsValidator extends Validator
$messages
=
[];
$messages
=
[];
if
(
empty
(
$data
[
'works'
]))
{
if
(
empty
(
$data
[
'works'
]))
{
$messages
[]
=
"该套系至少应绑定一个样片集"
;
$messages
[]
=
"该套系至少应绑定一个样片集"
;
return
$messages
;
}
}
if
(
empty
(
$data
[
'category'
]))
{
if
(
empty
(
$data
[
'category'
]))
{
$messages
[]
=
"该套系必须至少选择一个分类"
;
$messages
[]
=
"该套系必须至少选择一个分类"
;
return
$messages
;
}
}
if
(
$data
[
'modeling_count'
]
<
$data
[
'modeling_count_from_user'
])
{
if
(
$data
[
'modeling_count'
]
<
$data
[
'modeling_count_from_user'
])
{
$messages
[]
=
"摄影师最多提供数不可大于造型总数量"
;
$messages
[]
=
"摄影师最多提供数不可大于造型总数量"
;
return
$messages
;
}
}
if
(
$data
[
'start_time'
]
>
$data
[
'end_time'
])
{
if
(
$data
[
'start_time'
]
>
$data
[
'end_time'
])
{
$messages
[]
=
"套系开始时间必须小于结束时间"
;
$messages
[]
=
"套系开始时间必须小于结束时间"
;
return
$messages
;
}
}
if
(
$data
[
"is_promotion"
]
==
1
&&
empty
(
$data
[
'promotion'
][
'id'
]))
{
if
(
$data
[
"is_promotion"
]
==
1
&&
empty
(
$data
[
'promotion'
][
'id'
]))
{
if
(
$data
[
'promotion'
][
'promotion_start_time'
]
>=
$data
[
'promotion'
][
'promotion_end_time'
])
{
if
(
$data
[
'promotion'
][
'promotion_start_time'
]
>=
$data
[
'promotion'
][
'promotion_end_time'
])
{
$messages
[]
=
"特惠开始时间应小于特惠停止时间"
;
$messages
[]
=
"特惠开始时间应小于特惠停止时间"
;
return
$messages
;
}
}
if
((
int
)
$data
[
'promotion'
][
'per_user_count'
]
>
$data
[
'promotion'
][
'p_order_count'
])
{
if
((
int
)
$data
[
'promotion'
][
'per_user_count'
]
>
$data
[
'promotion'
][
'p_order_count'
])
{
$messages
[]
=
"特惠的限购额度应小于特惠数量"
;
$messages
[]
=
"特惠的限购额度应小于特惠数量"
;
return
$messages
;
}
}
if
(
$data
[
'promotion'
][
'p_order_count'
]
<=
0
)
{
if
(
$data
[
'promotion'
][
'p_order_count'
]
<=
0
)
{
$messages
[]
=
"特惠数量应大于0"
;
$messages
[]
=
"特惠数量应大于0"
;
return
$messages
;
}
}
if
(
$data
[
'promotion'
][
'promotion_start_time'
]
<
$data
[
'start_time'
])
{
if
(
$data
[
'promotion'
][
'promotion_start_time'
]
<
$data
[
'start_time'
])
{
$messages
[]
=
"特惠的开始时间应大于套系的起始有效时间"
;
$messages
[]
=
"特惠的开始时间应大于套系的起始有效时间"
;
return
$messages
;
}
}
if
(
$data
[
'promotion'
][
'promotion_end_time'
]
>
$data
[
'end_time'
])
{
if
(
$data
[
'promotion'
][
'promotion_end_time'
]
>
$data
[
'end_time'
])
{
$messages
[]
=
"特惠的结束时间应小于在套系终止有效时间"
;
$messages
[]
=
"特惠的结束时间应小于在套系终止有效时间"
;
return
$messages
;
}
}
$startdate
=
strtotime
(
$data
[
'promotion'
][
'promotion_start_time'
]);
$startdate
=
strtotime
(
$data
[
'promotion'
][
'promotion_start_time'
]);
$enddate
=
strtotime
(
$data
[
'promotion'
][
'promotion_end_time'
]);
$enddate
=
strtotime
(
$data
[
'promotion'
][
'promotion_end_time'
]);
$days
=
round
((
$enddate
-
$startdate
)
/
3600
/
24
)
;
$days
=
round
((
$enddate
-
$startdate
)
/
3600
/
24
)
;
if
(
$days
>
100
)
{
if
(
$days
>
100
)
{
$messages
[]
=
"特惠时间长度不应大于100天"
;
$messages
[]
=
"特惠时间长度不应大于100天"
;
return
$messages
;
}
}
if
(
$data
[
'promotion'
][
'promotion_price'
]
>=
$data
[
'price'
])
{
if
(
$data
[
'promotion'
][
'promotion_price'
]
>=
$data
[
'price'
])
{
$messages
[]
=
"特惠价格应小于套系价格"
;
$messages
[]
=
"特惠价格应小于套系价格"
;
return
$messages
;
}
}
if
(
$data
[
'promotion'
][
'promotion_price'
]
<
5
)
{
if
(
$data
[
'promotion'
][
'promotion_price'
]
<
5
)
{
$messages
[]
=
"特惠价格应大于5元"
;
$messages
[]
=
"特惠价格应大于5元"
;
return
$messages
;
}
}
$validator
=
new
PromotionValidator
();
$validator
=
new
PromotionValidator
();
$res
=
$validator
->
validate
(
$data
[
'promotion'
]);
$res
=
$validator
->
validate
(
$data
[
'promotion'
]);
if
(
$res
->
fails
())
{
if
(
$res
->
fails
())
{
$messages
[]
=
$validator
->
getMessages
();
$messages
[]
=
$validator
->
getMessages
();
return
$messages
;
}
}
unset
(
$validator
);
unset
(
$validator
);
}
}
...
@@ -155,7 +172,7 @@ class SetsValidator extends Validator
...
@@ -155,7 +172,7 @@ class SetsValidator extends Validator
foreach
(
$data
[
"attachment"
]
as
$item
)
{
foreach
(
$data
[
"attachment"
]
as
$item
)
{
if
(
!
empty
(
$item
[
'title'
]))
{
if
(
!
empty
(
$item
[
'title'
]))
{
$res
=
$validator
->
validate
(
$item
);
$res
=
$validator
->
validate
(
$item
);
if
(
$res
->
fails
()
)
{
if
(
$res
==
false
)
{
$messages
[]
=
$validator
->
getMessages
();
$messages
[]
=
$validator
->
getMessages
();
break
;
break
;
}
}
...
...
app/Sets/v1/Controller/Sets.php
View file @
e670afb3
...
@@ -89,7 +89,7 @@ class Sets extends \Illuminate\Routing\Controller
...
@@ -89,7 +89,7 @@ class Sets extends \Illuminate\Routing\Controller
$model
=
SetsModel
::
newSets
(
$post
);
$model
=
SetsModel
::
newSets
(
$post
);
if
(
$model
!==
false
)
{
if
(
$model
!==
false
)
{
Event
::
fire
(
new
SetsEditedEvent
(
$model
));
Event
::
fire
(
new
SetsEditedEvent
(
$model
));
return
Response
::
ok
();
return
Response
::
ok
(
$model
->
id
);
}
else
{
}
else
{
return
Response
::
error
(
SetsModel
::
getError
());
return
Response
::
error
(
SetsModel
::
getError
());
}
}
...
@@ -104,10 +104,18 @@ class Sets extends \Illuminate\Routing\Controller
...
@@ -104,10 +104,18 @@ class Sets extends \Illuminate\Routing\Controller
{
{
try
{
try
{
$model
=
SetsModel
::
findOrFail
(
$id
);
$model
=
SetsModel
::
findOrFail
(
$id
);
$res
=
$model
->
fill
(
$request
->
all
())
->
save
();
$data
=
$request
->
all
();
$validate_Data
=
array_merge
(
$model
->
toArray
(),
$data
);
$validator
=
new
SetsValidator
();
$res
=
$validator
->
validate
(
$validate_Data
);
if
(
$res
==
false
)
{
$messages
=
$validator
->
getMessages
();
return
Response
::
error
(
$messages
,
HttpStatus
::
HttpValidationFailed
);
}
$res
=
$model
->
uptSets
(
$data
);
if
(
$res
)
{
if
(
$res
)
{
Event
::
fire
(
new
SetsEditedEvent
(
$model
));
Event
::
fire
(
new
SetsEditedEvent
(
$model
));
return
Response
::
ok
();
return
Response
::
ok
(
$model
->
id
);
}
else
{
}
else
{
return
Response
::
error
();
return
Response
::
error
();
}
}
...
@@ -116,7 +124,6 @@ class Sets extends \Illuminate\Routing\Controller
...
@@ -116,7 +124,6 @@ class Sets extends \Illuminate\Routing\Controller
}
}
}
}
public
function
destory
(
$id
)
public
function
destory
(
$id
)
{
{
try
{
try
{
...
@@ -124,7 +131,7 @@ class Sets extends \Illuminate\Routing\Controller
...
@@ -124,7 +131,7 @@ class Sets extends \Illuminate\Routing\Controller
$res
=
$model
->
delete
();
$res
=
$model
->
delete
();
if
(
$res
)
{
if
(
$res
)
{
Event
::
fire
(
new
SetsEditedEvent
(
$model
));
Event
::
fire
(
new
SetsEditedEvent
(
$model
));
return
Response
::
ok
();
return
Response
::
ok
(
$model
->
id
);
}
else
{
}
else
{
return
Response
::
error
();
return
Response
::
error
();
}
}
...
@@ -132,4 +139,12 @@ class Sets extends \Illuminate\Routing\Controller
...
@@ -132,4 +139,12 @@ class Sets extends \Illuminate\Routing\Controller
return
Response
::
error
(
HttpStatus
::
HttpNotFound
,
"样片未找到"
);
return
Response
::
error
(
HttpStatus
::
HttpNotFound
,
"样片未找到"
);
}
}
}
}
public
function
all
(
$ids
)
{
$where
[
'id'
]
=
explode
(
","
,
$ids
);
$model
=
$this
->
setBlurSearch
(
SetsModel
::
class
,
$where
,
"id"
,
"in"
);
return
Response
::
success
(
$model
->
select
(
SetsModel
::
fields
)
->
get
());
}
}
}
\ No newline at end of file
app/Traits/Controller.php
View file @
e670afb3
...
@@ -14,8 +14,6 @@ trait Controller
...
@@ -14,8 +14,6 @@ trait Controller
*/
*/
public
function
filter
(
$where
)
public
function
filter
(
$where
)
{
{
$order
=
isset
(
$where
[
"order"
])
?
$where
[
"order"
]
:
"id-desc"
;
$where
[
'order'
]
=
$order
;
if
(
is_null
(
$where
)
||
empty
(
$where
))
{
if
(
is_null
(
$where
)
||
empty
(
$where
))
{
return
[];
return
[];
}
}
...
@@ -34,22 +32,39 @@ trait Controller
...
@@ -34,22 +32,39 @@ trait Controller
return
$where
;
return
$where
;
}
}
public
function
set
BlurSearch
(
$model
,
$where
,
$key
,
$condition
=
"like"
)
public
function
set
DefaultOrder
(
$where
)
{
{
$result_model
=
null
;
$order
=
isset
(
$where
[
"order"
])
?
$where
[
"order"
]
:
"id-desc"
;
$where
[
'order'
]
=
$order
;
return
$where
;
}
public
function
getOrder
(
$model
,
&
$where
)
{
if
(
!
empty
(
$model
->
unionOrders
))
{
return
$model
;
}
if
(
!
isset
(
$where
[
'order'
]))
{
$where
=
$this
->
setDefaultOrder
(
$where
);
}
list
(
$field
,
$sort
)
=
explode
(
"-"
,
$where
[
"order"
]);
list
(
$field
,
$sort
)
=
explode
(
"-"
,
$where
[
"order"
]);
$result_model
=
$model
::
orderBy
(
$field
,
$sort
);
try
{
try
{
unset
(
$where
[
'order'
]);
unset
(
$where
[
'order'
]);
unset
(
$where
[
'page'
]);
unset
(
$where
[
'page'
]);
unset
(
$where
[
'size'
]);
unset
(
$where
[
'size'
]);
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
}
return
$model
::
orderBy
(
$field
,
$sort
);
}
}
public
function
setBlurSearch
(
$model
,
$where
,
$key
,
$condition
=
"like"
)
{
$result_model
=
null
;
$result_model
=
$this
->
getOrder
(
$model
,
$where
);
if
(
!
in_array
(
$key
,
array_keys
(
$where
)))
{
if
(
!
in_array
(
$key
,
array_keys
(
$where
)))
{
return
$result_model
->
where
(
$where
);
return
$result_model
->
where
(
$where
);
}
}
$where
[
$key
]
=
trim
(
$where
[
$key
]);
is_string
(
$where
[
$key
])
&&
$where
[
$key
]
=
trim
(
$where
[
$key
]);
switch
(
$condition
)
{
switch
(
$condition
)
{
case
"like"
:
case
"like"
:
$result_model
=
$result_model
->
where
(
$key
,
"like"
,
"%"
.
$where
[
$key
]
.
"%"
);
$result_model
=
$result_model
->
where
(
$key
,
"like"
,
"%"
.
$where
[
$key
]
.
"%"
);
...
@@ -70,7 +85,7 @@ trait Controller
...
@@ -70,7 +85,7 @@ trait Controller
$result_model
=
$result_model
->
where
(
$where
);
$result_model
=
$result_model
->
where
(
$where
);
break
;
break
;
case
"in"
:
case
"in"
:
$result_model
=
$result_model
->
whereIn
(
$key
,
"in"
,
$where
[
$key
]);
$result_model
=
$result_model
->
whereIn
(
$key
,
$where
[
$key
]);
break
;
break
;
}
}
unset
(
$where
[
$key
]);
unset
(
$where
[
$key
]);
...
@@ -87,4 +102,7 @@ trait Controller
...
@@ -87,4 +102,7 @@ trait Controller
public
function
csrf
(
$data
,
$key
)
{
public
function
csrf
(
$data
,
$key
)
{
return
preg_replace
(
"/<script[^>]*>.*<\/script>/i"
,
""
,
$data
[
$key
]);
return
preg_replace
(
"/<script[^>]*>.*<\/script>/i"
,
""
,
$data
[
$key
]);
}
}
}
}
\ No newline at end of file
app/Traits/Models.php
View file @
e670afb3
...
@@ -27,12 +27,16 @@ Trait Models
...
@@ -27,12 +27,16 @@ Trait Models
return
static
::
get
([
"id"
])
->
count
();
return
static
::
get
([
"id"
])
->
count
();
}
}
public
static
function
add
(
array
$data
,
$uid
)
public
static
function
add
(
array
$data
,
$uid
=
null
)
{
{
$items
=
[];
$items
=
[];
foreach
(
$data
as
$item
)
{
foreach
(
$data
as
$item
)
{
$item
=
new
static
(
$item
,
$uid
);
if
(
$uid
!=
null
)
{
array_push
(
$items
,
$item
);
$model
=
new
static
(
$item
,
$uid
);
}
else
{
$model
=
new
static
(
$item
);
}
array_push
(
$items
,
$model
);
}
}
return
$items
;
return
$items
;
}
}
...
...
app/Works/Listeners/WorksSearcherListener.php
View file @
e670afb3
...
@@ -26,7 +26,7 @@ class WorksSearcherListener
...
@@ -26,7 +26,7 @@ class WorksSearcherListener
'works_id'
=>
$works
->
id
,
'works_id'
=>
$works
->
id
,
'name'
=>
$works
->
name
,
'name'
=>
$works
->
name
,
'kw'
=>
implode
(
" "
,
$keyworks
),
'kw'
=>
implode
(
" "
,
$keyworks
),
'photographer_name'
=>
UserModel
::
getUserInfo
(
$works
->
uid
,[
'nickname'
]),
'photographer_name'
=>
UserModel
::
getUserInfo
(
$works
->
uid
,[
'nickname'
])
->
nickname
,
'lasttime'
=>
date
(
"Y-m-d H:i:s"
,
time
())
'lasttime'
=>
date
(
"Y-m-d H:i:s"
,
time
())
]);
]);
}
}
...
...
app/Works/Model/Keywords.php
View file @
e670afb3
...
@@ -14,16 +14,20 @@ class Keywords extends Model
...
@@ -14,16 +14,20 @@ class Keywords extends Model
protected
$fillable
=
[
protected
$fillable
=
[
"kw_id"
,
"kw_name"
"kw_id"
,
"kw_name"
];
];
public
$timestamps
=
false
;
public
function
__construct
(
array
$attributes
=
[],
$uid
=
null
)
public
function
__construct
(
array
$attributes
=
[],
$uid
=
null
)
{
{
parent
::
__construct
(
$attributes
);
parent
::
__construct
(
$attributes
);
$model
=
\App\Kw\Model\Keywords
::
getIdByWords
(
$attributes
[
'kw_name'
]
,
$uid
,
true
);
if
(
!
empty
(
$attributes
))
{
$model
=
\App\Kw\Model\Keywords
::
getIdByWords
(
$attributes
[
'kw_name'
],
$uid
,
true
);
$this
->
kw_id
=
$model
->
id
;
$this
->
kw_id
=
$model
->
id
;
$this
->
kw_name
=
$model
->
kw_name
;
$this
->
kw_name
=
$model
->
kw_name
;
}
$this
->
beforeValidationOnCreate
();
$this
->
beforeValidationOnCreate
();
}
}
public
function
beforeValidationOnCreate
()
public
function
beforeValidationOnCreate
()
{
{
$this
->
is_del
=
0
;
$this
->
is_del
=
0
;
$this
->
create_time
=
date
(
"Y-m-d H:i:s"
,
time
());
}
}
}
}
\ No newline at end of file
app/Works/Model/Sets.php
View file @
e670afb3
...
@@ -6,5 +6,5 @@ use \Illuminate\Database\Eloquent\Model;
...
@@ -6,5 +6,5 @@ use \Illuminate\Database\Eloquent\Model;
class
Sets
extends
Model
class
Sets
extends
Model
{
{
protected
$table
=
"myp_
works_category
"
;
protected
$table
=
"myp_
sets_works
"
;
}
}
\ No newline at end of file
app/Works/Model/Works.php
View file @
e670afb3
...
@@ -11,6 +11,7 @@ namespace App\Works\Model;
...
@@ -11,6 +11,7 @@ namespace App\Works\Model;
use
App\Photo\v1\Controller\Details
;
use
App\Photo\v1\Controller\Details
;
use
App\Works\Events\DetailDeleteEvent
;
use
App\Works\Events\DetailDeleteEvent
;
use
App\Works\Model\Details
as
DetailModel
;
use
App\Works\Model\Details
as
DetailModel
;
use
App\Sets\Model\Works
as
SetsModel
;
use
App\Traits\Models
;
use
App\Traits\Models
;
use
\Illuminate\Database\Eloquent\Model
;
use
\Illuminate\Database\Eloquent\Model
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\DB
;
...
@@ -41,6 +42,7 @@ class Works extends Model
...
@@ -41,6 +42,7 @@ class Works extends Model
$this
->
count
=
0
;
$this
->
count
=
0
;
$this
->
create_time
=
date
(
"Y-m-d H:i:s"
,
time
());
$this
->
create_time
=
date
(
"Y-m-d H:i:s"
,
time
());
$this
->
is_del
=
0
;
$this
->
is_del
=
0
;
$this
->
introduction
=
" "
;
}
}
public
function
skipAttributesOnUpdate
()
public
function
skipAttributesOnUpdate
()
...
@@ -49,7 +51,11 @@ class Works extends Model
...
@@ -49,7 +51,11 @@ class Works extends Model
}
}
protected
$fillable
=
[
protected
$fillable
=
[
'uid'
,
'name'
,
'cover'
,
"is_hidden"
'uid'
,
'name'
,
'cover'
,
"is_hidden"
,
"introduction"
];
const
fields
=
[
'id'
,
'name'
,
'cover'
,
"is_hidden"
,
'create_time'
];
];
public
function
relation_sets
()
public
function
relation_sets
()
...
@@ -98,9 +104,13 @@ class Works extends Model
...
@@ -98,9 +104,13 @@ class Works extends Model
}
}
}
}
if
(
isset
(
$data
[
'keywords'
])
&&
!
empty
(
$data
[
'keywords'
]))
{
if
(
isset
(
$data
[
'keywords'
])
&&
!
empty
(
$data
[
'keywords'
]))
{
$models
=
Keywords
::
add
(
$data
[
'keywords'
]);
$models
=
Keywords
::
add
(
$data
[
'keywords'
]
,
$data
[
'uid'
]
);
$model
->
relation_keywords
()
->
saveMany
(
$models
);
$model
->
relation_keywords
()
->
saveMany
(
$models
);
}
}
if
(
isset
(
$data
[
'sets'
])
&&
!
empty
(
$data
[
'sets'
]))
{
$models
=
SetsModel
::
add
(
$data
[
'sets'
]);
$model
->
relation_sets
()
->
saveMany
(
$models
);
}
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
self
::
throwError
(
$e
);
self
::
throwError
(
$e
);
DB
::
rollBack
();
DB
::
rollBack
();
...
@@ -129,10 +139,19 @@ class Works extends Model
...
@@ -129,10 +139,19 @@ class Works extends Model
$this
->
relation_detail
()
->
delete
();
$this
->
relation_detail
()
->
delete
();
$this
->
relation_detail
()
->
saveMany
(
$details
);
$this
->
relation_detail
()
->
saveMany
(
$details
);
}
}
if
(
isset
(
$data
[
'keywords'
])
&&
!
empty
(
$data
[
'keywords'
]))
{
if
(
isset
(
$data
[
'keywords'
])
&&
!
empty
(
$data
[
'keywords'
]))
{
$models
=
Keywords
::
add
(
$data
[
'keywords'
],
$data
[
'uid'
]);
$models
=
Keywords
::
add
(
$data
[
'keywords'
],
$this
->
uid
);
$this
->
relation_keywords
()
->
delete
();
$this
->
relation_keywords
()
->
saveMany
(
$models
);
$this
->
relation_keywords
()
->
saveMany
(
$models
);
}
}
if
(
isset
(
$data
[
'sets'
])
&&
!
empty
(
$data
[
'sets'
]))
{
$models
=
SetsModel
::
add
(
$data
[
'sets'
]);
$this
->
relation_sets
()
->
delete
();
$this
->
relation_sets
()
->
saveMany
(
$models
);
}
$this
->
update
(
$data
);
$this
->
update
(
$data
);
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
self
::
throwError
(
$e
);
self
::
throwError
(
$e
);
...
...
app/Works/Validation/WorksValidator.php
View file @
e670afb3
<?php
<?php
namespace
App\Works\Validation
;
namespace
App\Works\Validation
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Log
;
use
App\Http\Validation\ValidatorBase
as
Validator
;
use
App\Http\Validation\ValidatorBase
as
Validator
;
class
WorksValidator
extends
Validator
class
WorksValidator
extends
Validator
{
{
protected
$validator
=
[
protected
$validator
=
[
'name'
=>
'required|chinese_length:2,15'
,
'name'
=>
'required|chinese_length:2,15'
,
'details'
=>
'array_length_min:5,array_length_max:15'
,
'uid'
=>
'required'
,
'uid'
=>
'required'
,
'cover'
=>
'required'
];
];
protected
$message
=
[
protected
$message
=
[
'name.required'
=>
'请填写样片名称'
,
'name.required'
=>
'请填写样片名称'
,
'name.chinese_length'
=>
'样片名称应为2到15字之间'
,
'name.chinese_length'
=>
'样片名称应为2到15字之间'
,
'details.array_length_min'
=>
'您必须上传5-15张照片'
,
'details.array_length_max'
=>
'您必须上传5-15张照片'
,
'uid.required'
=>
'uid必需'
,
'uid.required'
=>
'uid必需'
,
'cover.required'
=>
'必须设置封面图片'
];
];
public
function
custom_validate
(
$post
)
{
$message
=
[];
if
(
strtoupper
(
request
()
->
getMethod
())
==
"POST"
||
(
strtoupper
(
request
()
->
getMethod
())
==
"PUT"
&&
isset
(
$post
[
'details'
]))
)
{
if
(
!
isset
(
$post
[
'details'
])
||
empty
(
$post
[
'details'
]))
{
$message
[]
=
"您必须上传5-15张照片"
;
return
$message
;
};
$count
=
count
(
$post
[
'details'
]);
if
(
$count
<
5
||
$count
>
15
)
{
$message
[]
=
"您必须上传5-15张照片"
;
return
$message
;
}
}
if
(
strtoupper
(
request
()
->
getMethod
())
==
"POST"
||
(
strtoupper
(
request
()
->
getMethod
())
==
"PUT"
&&
isset
(
$post
[
'sets'
]))
)
{
if
(
!
isset
(
$post
[
'sets'
])
||
empty
(
$post
[
'sets'
]))
{
if
(
!
isset
(
$post
[
'FROM_SETS'
])
||
$post
[
'FROM_SETS'
]
!=
1
)
{
$message
[]
=
"您必须绑定至少一个套系"
;
return
$message
;
}
}
}
return
$message
;
}
}
}
\ No newline at end of file
app/Works/v1/Controller/Works.php
View file @
e670afb3
...
@@ -83,16 +83,16 @@ class Works extends \Illuminate\Routing\Controller
...
@@ -83,16 +83,16 @@ class Works extends \Illuminate\Routing\Controller
$validator
=
new
WorksValidator
();
$validator
=
new
WorksValidator
();
$post
=
$request
->
all
();
$post
=
$request
->
all
();
$res
=
$validator
->
validate
(
$post
);
$res
=
$validator
->
validate
(
$post
);
if
(
$res
->
fails
()
)
{
if
(
$res
==
false
)
{
$messages
=
$validator
->
getMessages
();
$messages
=
$validator
->
getMessages
();
return
Response
::
error
(
$messages
,
HttpStatus
::
HttpValidationFailed
);
return
Response
::
error
(
$messages
,
HttpStatus
::
HttpValidationFailed
);
}
}
$model
=
WorksModel
::
newWorks
(
$post
);
$model
=
WorksModel
::
newWorks
(
$post
);
if
(
$model
!==
false
)
{
if
(
$model
!==
false
)
{
Event
::
fire
(
new
WorksEditedEvent
(
$model
));
Event
::
fire
(
new
WorksEditedEvent
(
$model
));
return
Response
::
ok
(
);
return
Response
::
success
(
$model
->
id
);
}
else
{
}
else
{
return
Response
::
error
();
return
Response
::
error
(
WorksModel
::
getError
()
);
}
}
}
}
...
@@ -105,10 +105,18 @@ class Works extends \Illuminate\Routing\Controller
...
@@ -105,10 +105,18 @@ class Works extends \Illuminate\Routing\Controller
{
{
try
{
try
{
$model
=
WorksModel
::
findOrFail
(
$id
);
$model
=
WorksModel
::
findOrFail
(
$id
);
$data
=
$request
->
all
();
$validate_Data
=
array_merge
(
$model
->
toArray
(),
$data
);
$validator
=
new
WorksValidator
();
$res
=
$validator
->
validate
(
$validate_Data
);
if
(
$res
==
false
)
{
$messages
=
$validator
->
getMessages
();
return
Response
::
error
(
$messages
,
HttpStatus
::
HttpValidationFailed
);
}
$res
=
$model
->
uptWorks
(
$request
->
all
());
$res
=
$model
->
uptWorks
(
$request
->
all
());
if
(
$res
)
{
if
(
$res
)
{
Event
::
fire
(
new
WorksEditedEvent
(
$model
));
Event
::
fire
(
new
WorksEditedEvent
(
$model
));
return
Response
::
ok
(
);
return
Response
::
success
(
$model
->
id
);
}
else
{
}
else
{
return
Response
::
error
();
return
Response
::
error
();
}
}
...
@@ -137,4 +145,13 @@ class Works extends \Illuminate\Routing\Controller
...
@@ -137,4 +145,13 @@ class Works extends \Illuminate\Routing\Controller
return
Response
::
error
(
HttpStatus
::
HttpNotFound
,
"样片未找到"
);
return
Response
::
error
(
HttpStatus
::
HttpNotFound
,
"样片未找到"
);
}
}
}
}
public
function
all
(
$ids
)
{
$where
[
'id'
]
=
explode
(
","
,
$ids
);
$model
=
$this
->
setBlurSearch
(
WorksModel
::
class
,
$where
,
"id"
,
"in"
);
return
Response
::
success
(
$model
->
select
(
WorksModel
::
fields
)
->
get
());
}
}
}
\ No newline at end of file
routes/api.php
View file @
e670afb3
...
@@ -5,7 +5,6 @@ Route::resource ("test" , \App\Test\Controller\TestController::class);
...
@@ -5,7 +5,6 @@ Route::resource ("test" , \App\Test\Controller\TestController::class);
//套系
//套系
Route
::
group
([
"prefix"
=>
"sets"
,
'namespace'
=>
Provider
::
getNamespace
(
"sets"
)],
function
(){
Route
::
group
([
"prefix"
=>
"sets"
,
'namespace'
=>
Provider
::
getNamespace
(
"sets"
)],
function
(){
//套系列表
//套系列表
Route
::
get
(
"/"
,
"Sets@index"
);
Route
::
get
(
"/"
,
"Sets@index"
);
//套系详情
//套系详情
...
@@ -15,10 +14,14 @@ Route::group(["prefix" => "sets", 'namespace' => Provider::getNamespace("sets")]
...
@@ -15,10 +14,14 @@ Route::group(["prefix" => "sets", 'namespace' => Provider::getNamespace("sets")]
//新增套系
//新增套系
Route
::
post
(
"/"
,
"Sets@store"
);
Route
::
post
(
"/"
,
"Sets@store"
);
//编辑套系
//编辑套系
/*
Route::put ("/{id}" , "Sets@update");
Route
::
put
(
"/
{
id
}
"
,
"Sets@update"
);
//删除套系
//删除套系
Route
::
delete
(
"/
{
id
}
"
,
"Sets@destory"
);
/*
Route::delete("/{id}/hard", "Sets@delete");
Route::delete("/{id}/hard", "Sets@delete");
*/
*/
//获取IDS所含ID的所有套系,使用,隔开
Route
::
get
(
"/all/
{
ids
}
"
,
"Sets@all"
);
});
});
//分类
//分类
...
@@ -52,6 +55,8 @@ Route::group(["prefix" => "works", 'namespace' => Provider::getNamespace("works"
...
@@ -52,6 +55,8 @@ Route::group(["prefix" => "works", 'namespace' => Provider::getNamespace("works"
Route
::
delete
(
"/
{
ids
}
/image"
,
"Details@destory"
)
->
where
([
'ids'
=>
'\S+'
]);
Route
::
delete
(
"/
{
ids
}
/image"
,
"Details@destory"
)
->
where
([
'ids'
=>
'\S+'
]);
//新增样片里的照片
//新增样片里的照片
Route
::
post
(
"/
{
id
}
/image"
,
"Details@store"
);
Route
::
post
(
"/
{
id
}
/image"
,
"Details@store"
);
//获取IDS所含ID的所有样片,使用,隔开
Route
::
get
(
"/all/
{
ids
}
"
,
"Works@all"
);
});
});
...
@@ -86,12 +91,17 @@ Route::group(["prefix" => "photo", 'namespace' => Provider::getNamespace("photo"
...
@@ -86,12 +91,17 @@ Route::group(["prefix" => "photo", 'namespace' => Provider::getNamespace("photo"
Route
::
post
(
"/"
,
"Photo@store"
);
Route
::
post
(
"/"
,
"Photo@store"
);
Route
::
delete
(
"/
{
id
}
"
,
"Photo@destory"
)
->
where
([
'id'
=>
'\d+'
]);
Route
::
delete
(
"/
{
id
}
"
,
"Photo@destory"
)
->
where
([
'id'
=>
'\d+'
]);
Route
::
put
(
"/
{
id
}
"
,
"Photo@update"
)
->
where
([
'id'
=>
'\d+'
]);
Route
::
put
(
"/
{
id
}
"
,
"Photo@update"
)
->
where
([
'id'
=>
'\d+'
]);
Route
::
post
(
"/
{
id
}
"
,
"Details@store"
)
->
where
([
'id'
=>
'\d+'
]);
Route
::
delete
(
"/
{
id}/{ids
}
"
,
"Details@destory"
);
Route
::
get
(
"/
{
id
}
"
,
"Photo@show"
)
->
where
([
'id'
=>
'\d+'
]);
Route
::
get
(
"/
{
id
}
/list"
,
"Details@index"
)
->
where
([
'id'
=>
'\d+'
]);
});
});
//城市
//城市
Route
::
group
([
"prefix"
=>
"city"
,
'namespace'
=>
Provider
::
getNamespace
(
"city"
)],
function
(){
Route
::
group
([
"prefix"
=>
"city"
,
'namespace'
=>
Provider
::
getNamespace
(
"city"
)],
function
(){
Route
::
get
(
"/"
,
"City@index"
);
Route
::
get
(
"/"
,
"City@index"
);
});
});
//关键词
//关键词
...
...
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