Commit f762bb2d authored by clone's avatar clone

banner增删改查

parent 86e177ed
<?php
namespace app\api\controller;
/**
* Created by PhpStorm.
* User : zw
* Date : 2017/12/8
* Time : 11:07
* Intro:
*/
use app\api\extend\Basic;
class Banner extends Basic
{
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ namespace app\api\controller;
* Time : 15:12
* Intro: 获取商铺list
*/
use app\common\Basic;
use app\api\extend\Basic;
use app\model\HouseInfos;
class Shop extends Basic
......@@ -20,7 +20,6 @@ class Shop extends Basic
*/
public function getShopList()
{
echo define(AAA);exit;
$params = array(
"site_area" => 2, //来源 1首页 2搜索
"title" => "尚美",
......
<?php
namespace app\api\extend;
/**
* Created by PhpStorm.
* User: zw
......@@ -11,7 +13,8 @@ use think\Controller;
use think\Request;
use think\Response;
class Basic extends Controller{
class Basic extends Controller
{
/**
* 访问请求对象
* @var Request
......@@ -44,9 +47,9 @@ class Basic extends Controller{
* @param string $type 返回类型 JSON XML
* @return Response
*/
public function response($msg, $code = 'SUCCESS', $data = [], $type = 'json')
public function response($code = 'SUCCESS', $msg, $data = [], $type = 'json')
{
$result = ['msg' => $msg, 'code' => $code, 'data' => $data, 'type' => strtolower($type)];
$result = [ 'code' => $code, 'msg' => $msg, 'data' => $data, 'type' => strtolower($type) ];
return Response::create($result, $type);
}
......@@ -60,7 +63,7 @@ class Basic extends Controller{
*/
public static function arr2tree($list, $id = 'id', $pid = 'pid', $son = 'sub')
{
list($tree, $map) = [[], []];
list($tree, $map) = [ [], [] ];
foreach ($list as $item) {
$map[$item[$id]] = $item;
}
......@@ -111,7 +114,7 @@ class Basic extends Controller{
*/
public static function getArrSubIds($list, $id = 0, $key = 'id', $pkey = 'pid')
{
$ids = [intval($id)];
$ids = [ intval($id) ];
foreach ($list as $vo) {
if (intval($vo[$pkey]) > 0 && intval($vo[$pkey]) === intval($id)) {
$ids = array_merge($ids, self::getArrSubIds($list, intval($vo[$key]), $key, $pkey));
......@@ -119,6 +122,7 @@ class Basic extends Controller{
}
return $ids;
}
/**
* Cors Options 授权处理
*/
......@@ -145,11 +149,11 @@ class Basic extends Controller{
public static function corsRequestHander()
{
return [
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Credentials' => true,
'Access-Control-Allow-Methods' => 'GET,POST,OPTIONS',
'Access-Defined-X-Support' => 'service@cuci.cc',
'Access-Defined-X-Servers' => 'Guangzhou Cuci Technology Co. Ltd',
'Access-Control-Allow-Methods' => 'GET,POST,OPTIONS',
'Access-Defined-X-Support' => 'service@cuci.cc',
'Access-Defined-X-Servers' => 'Guangzhou Cuci Technology Co. Ltd',
];
}
}
......
<?php
namespace app\model;
/**
* Created by PhpStorm.
* User : zw
......@@ -7,23 +9,100 @@ namespace app\model;
* Time : 17:50
* Intro:
*/
use think\Db;
use think\Model;
class Banner extends Model{
class Banner extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'u_banner';
protected $db;
function __construct()
{
$this->db = Db($this->table);
}
function add(){
$user = $this->db;
$user->data([
'name' => 'thinkphp',
'email' => 'thinkphp@qq.com'
]);
$user->save();
/**
* 新增banner修改banner
* @param $param
* @return array
*/
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()
);
if (isset($param['id'])) {
$result = $this->db
->where("id=" . $param['id'])
->select();
if (count($result) > 0) {
$arr["id"] = $param["id"];
} else {
return [ "101", "要修改数据不存在" ];
}
} else {
$arr["create_time"] = time();
}
Db::startTrans();
try {
$id = $banner->save($arr);
Db::commit();
return $id;
} catch (\Exception $e) {
Db::rollback();
return [ "101", "保存失败,数据异常" ];
}
}
/**
* 逻辑删除,不显示在前端
* @param $param
* @return array
*/
function upIsShow($param){
$banner = $this->db;
$arr = array(
"id" => $param['id'],
"is_show" => $param['is_show'],
"update_time" => time()
);
Db::startTrans();
try {
$id = $banner->save($arr);
Db::commit();
return $id;
} catch (\Exception $e) {
Db::rollback();
return [ "101", "删除失败,数据异常" ];
}
}
/**
* bannerList
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param $field
* @param $params
* @return mixed
*/
function getBannerList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field, $params){
return $data = $this->db
->field($field)
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment