租房掌柜微信小程序Api以及小程序前端模板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

105 lines
3.2 KiB

<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\index\controller;
use think\App;
use think\Db;
/**
* 合同管理
* Class Index
* @package app\index\controller
*/
class Contract extends Base
{
private $table = 'CloudHouseContract';
public function __construct(App $app = null)
{
parent::__construct($app);
parent::auth();
}
/**
* 获取合同列表
*/
public function index()
{
$_where = 'user_id = ' . USER_ID . ' AND is_del = 0';
$count = Db::name($this->table)->where($_where)->count();
$page = $this->request->param('page', 1);
$pagesize = $this->request->param('pagesize', 10);
$pages = ceil($count / $pagesize); //总页数
$_result = Db::name($this->table)->where($_where)->page($page, $pagesize)->order('id', "DESC")->select();
$_data['list'] = $_result;
$_data['pages'] = $pages;
self::formatData($_data['list']);
return send_http_status(200, $_data);
}
/**
* 合同详情
*/
public function view($id = '')
{
if (!$id) {
return;
}
//获取房源详情
$_data = Db::name($this->table)->where('user_id', USER_ID)->find($id);
if ($_data) {
$_data['create_time'] = date('Y-m-d', $_data['create_time']);
$_data['contract_starttime'] = date('Y-m-d', $_data['contract_starttime']);
$_data['contract_endtime'] = date('Y-m-d', $_data['contract_endtime']);
return send_http_status(200, $_data);
}
}
/**
* 删除合同信息
* @param string $id 合同id
* @return \type
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function del($id = '')
{
if ((!$id || !is_numeric($id))) {
return send_http_status(51003);
}
$affected = Db::name($this->table)->where('id', $id)->where('user_id', USER_ID)->update(['is_del' => 1]);
if ($affected) {
return send_http_status(200);
}
return send_http_status(413);
}
static private function formatData(&$data)
{
if (!$data) {
return;
}
array_walk($data, function (&$v, &$k) {
!empty($v['create_time']) ? $v['create_time'] = date('Y-m-d', $v['create_time']) : $v['create_time'] = '';
!empty($v['update_time']) ? $v['update_time'] = date('Y-m-d', $v['update_time']) : $v['update_time'] = '';
});
}
}