Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
adf067c6
Commit
adf067c6
authored
Dec 08, 2017
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
banner 增删改查
parent
0cd944eb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
114 additions
and
18 deletions
+114
-18
Banner.php
application/api/controller/Banner.php
+60
-0
Basic.php
application/api/extend/Basic.php
+9
-0
constant.php
application/constant.php
+10
-0
BannerModel.php
application/model/BannerModel.php
+35
-18
No files found.
application/api/controller/Banner.php
View file @
adf067c6
<?php
namespace
app\api\controller
;
/**
* Created by PhpStorm.
* User : zw
...
...
@@ -9,8 +11,65 @@ namespace app\api\controller;
*/
use
app\api\extend\Basic
;
use
app\model\BannerModel
;
use
think\Request
;
class
Banner
extends
Basic
{
protected
$bannerModel
;
public
function
__construct
(
$request
=
null
)
{
parent
::
__construct
(
$request
);
$this
->
bannerModel
=
new
BannerModel
();
}
/**
* 查询banner列表
* @return \think\Response
*/
public
function
getBannerList
()
{
$field
=
"id,title,pic_path,url,sort,is_show,create_time,update_time"
;
$params
[
'is_show'
]
=
array
(
"eq"
,
0
);
$result
=
$this
->
bannerModel
->
getBannerList
(
1
,
15
,
"sort desc"
,
$field
,
$params
);
return
$this
->
response
(
"200"
,
"request success"
,
$result
);
}
/**
* 新增or修改数据
* @return \think\Response
*/
public
function
addOrSave
()
{
$params
=
array
(
"id"
=>
2
,
"is_show"
=>
0
);
$msg
=
isset
(
$params
[
'id'
])
?
"修改"
:
"新增"
;
$result
=
$this
->
bannerModel
->
addOrUpdate
(
$params
);
if
(
$result
[
'code'
]
==
200
)
{
return
$this
->
response
(
"200"
,
$msg
.
"成功"
,
$result
[
"msg"
]);
}
else
{
return
$this
->
response
(
"101"
,
$msg
.
$result
[
"msg"
]);
}
}
public
function
upIsShow
()
{
$params
=
array
(
"id"
=>
1
,
"is_show"
=>
1
);
$result
=
$this
->
bannerModel
->
upIsShow
(
$params
);
if
(
$result
[
'code'
]
==
200
)
{
return
$this
->
response
(
"200"
,
"update success"
,
$result
[
"msg"
]);
}
else
{
return
$this
->
response
(
"101"
,
"update error"
);
}
}
}
\ No newline at end of file
application/api/extend/Basic.php
View file @
adf067c6
...
...
@@ -27,6 +27,15 @@ class Basic extends Controller
*/
public
$token
;
/**
* @var int userId
*/
protected
$userId
;
protected
$access_token
;
protected
$phone
;
/**
* 基础接口SDK
* @param Request|null $request
...
...
application/constant.php
0 → 100644
View file @
adf067c6
<?php
/**
* Created by PhpStorm.
* User : zw
* Date : 2017/12/7
* Time : 14:45
* Intro:
*/
define
(
"AAA"
,
123123
);
\ No newline at end of file
application/model/Banner.php
→
application/model/Banner
Model
.php
View file @
adf067c6
...
...
@@ -11,17 +11,19 @@ namespace app\model;
*/
use
think\Db
;
use
think\Model
;
use
think\Log
;
class
Banner
extends
Model
class
Banner
Model
extends
Model
{
// 设置当前模型对应的完整数据表名称
protected
$table
=
'u_banner'
;
protected
$db
;
protected
$logger
;
function
__construct
()
{
$this
->
db
=
Db
(
$this
->
table
);
$this
->
logger
=
new
Log
();
}
/**
...
...
@@ -32,14 +34,25 @@ class Banner extends Model
function
addOrUpdate
(
$param
)
{
$banner
=
$this
->
db
;
$arr
=
array
(
"title"
=>
$param
[
'title'
],
"pic_path"
=>
$param
[
'pic_path'
],
"url"
=>
$param
[
'url'
],
"sort"
=>
$param
[
'sort'
],
"is_show"
=>
$param
[
'is_show'
],
"update_time"
=>
time
()
);
$arr
=
array
();
if
(
isset
(
$param
[
'title'
]))
{
$arr
[
"title"
]
=
$param
[
'title'
];
}
if
(
isset
(
$param
[
'pic_path'
]))
{
$arr
[
"pic_path"
]
=
$param
[
'pic_path'
];
}
if
(
isset
(
$param
[
'url'
]))
{
$arr
[
"url"
]
=
$param
[
'url'
];
}
if
(
isset
(
$param
[
'sort'
]))
{
$arr
[
"sort"
]
=
$param
[
'sort'
];
}
if
(
isset
(
$param
[
'title'
]))
{
$arr
[
"is_show"
]
=
$param
[
'is_show'
];
}
if
(
isset
(
$param
[
'id'
]))
{
$result
=
$this
->
db
->
where
(
"id="
.
$param
[
'id'
])
...
...
@@ -47,7 +60,7 @@ class Banner extends Model
if
(
count
(
$result
)
>
0
)
{
$arr
[
"id"
]
=
$param
[
"id"
];
}
else
{
return
[
"
101"
,
"要修改
数据不存在"
];
return
[
"
code"
=>
"101"
,
"msg"
=>
"
数据不存在"
];
}
}
else
{
$arr
[
"create_time"
]
=
time
();
...
...
@@ -56,10 +69,10 @@ class Banner extends Model
try
{
$id
=
$banner
->
save
(
$arr
);
Db
::
commit
();
return
$id
;
return
[
"code"
=>
"200"
,
"msg"
=>
$id
]
;
}
catch
(
\Exception
$e
)
{
Db
::
rollback
();
return
[
"
101"
,
"保存
失败,数据异常"
];
return
[
"
code"
=>
"101"
,
"msg"
=>
"
失败,数据异常"
];
}
}
...
...
@@ -69,21 +82,24 @@ class Banner extends Model
* @param $param
* @return array
*/
function
upIsShow
(
$param
){
function
upIsShow
(
$param
)
{
$this
->
logger
->
info
(
'日志信息'
);
$banner
=
$this
->
db
;
$arr
=
array
(
"id"
=>
$param
[
'id'
],
"is_show"
=>
$param
[
'is_show'
],
"update_time"
=>
time
()
);
var_dump
(
$arr
);
exit
;
Db
::
startTrans
();
try
{
$id
=
$banner
->
save
(
$arr
);
Db
::
commit
();
return
$id
;
return
[
"code"
=>
"200"
,
"msg"
=>
$id
]
;
}
catch
(
\Exception
$e
)
{
Db
::
rollback
();
return
[
"
101"
,
"删除失败,数据异常"
];
return
[
"
code"
=>
"101"
,
"msg"
=>
"删除失败,数据异常"
];
}
}
...
...
@@ -96,8 +112,9 @@ class Banner extends Model
* @param $params
* @return mixed
*/
function
getBannerList
(
$pageNo
=
1
,
$pageSize
=
15
,
$order_
=
'id desc'
,
$field
,
$params
){
return
$data
=
$this
->
db
function
getBannerList
(
$pageNo
=
1
,
$pageSize
=
15
,
$order_
=
'id desc'
,
$field
,
$params
)
{
return
$this
->
db
->
field
(
$field
)
->
where
(
$params
)
->
order
(
$order_
)
...
...
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