mirror of https://gitee.com/karson/fastadmin.git
134 lines
3.6 KiB
PHP
134 lines
3.6 KiB
PHP
<?php
|
||
/**
|
||
* Created by PhpStorm.
|
||
* User: Windows 10
|
||
* Date: 2018-02-01
|
||
* Time: 11:58
|
||
*/
|
||
|
||
namespace app\api\controller;
|
||
use app\common\controller\Api;
|
||
|
||
/**
|
||
* 订单api接口
|
||
* Class Order
|
||
* @package app\api\controller
|
||
*/
|
||
class Order extends Api
|
||
{
|
||
public function _initialize()
|
||
{
|
||
parent::_initialize();
|
||
$this->model = model('Order');
|
||
}
|
||
/**
|
||
* 插入订单
|
||
* @return mixed
|
||
*/
|
||
public function add()
|
||
{
|
||
if (request()->isPost())
|
||
{
|
||
//$params = $this->request->post("row/a");
|
||
$params = input('post.');
|
||
if ($params)
|
||
{
|
||
if ($this->dataLimit && $this->dataLimitFieldAutoFill)
|
||
{
|
||
$params[$this->dataLimitField] = $this->auth->id;
|
||
}
|
||
try
|
||
{
|
||
//是否采用模型验证
|
||
if ($this->modelValidate)
|
||
{
|
||
$name = basename(str_replace('\\', '/', get_class($this->model)));
|
||
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
|
||
$this->model->validate($validate);
|
||
}
|
||
$result = $this->model->allowField(true)->save($params);
|
||
if ($result !== false)
|
||
{
|
||
$this->success('','',json(),[]);
|
||
}
|
||
else
|
||
{
|
||
$this->error($this->getError());
|
||
}
|
||
}
|
||
catch (\think\exception\PDOException $e)
|
||
{
|
||
$this->error($e->getMessage());
|
||
}
|
||
}
|
||
$this->error(__('Parameter %s can not be empty', ''));
|
||
}
|
||
//return $this->view->fetch();
|
||
return json('',200,[],'');
|
||
}
|
||
public function index()
|
||
{
|
||
//设置过滤方法
|
||
$this->request->filter(['strip_tags']);
|
||
// if ($this->request->isAjax())
|
||
// {
|
||
//如果发送的来源是Selectpage,则转发到Selectpage
|
||
if ($this->request->request('pkey_name'))
|
||
{
|
||
return $this->selectpage();
|
||
}
|
||
|
||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||
$total = $this->model
|
||
->where($where)
|
||
->order($sort, $order)
|
||
->count();
|
||
|
||
$list = $this->model
|
||
->where($where)
|
||
->order($sort, $order)
|
||
->limit($offset, $limit)
|
||
->select();
|
||
|
||
$result = array("total" => $total, "rows" => $list);
|
||
|
||
return json($result);
|
||
// $this->success('','',json(),$result);
|
||
// }
|
||
// return $this->view->fetch();
|
||
}
|
||
|
||
|
||
/**
|
||
* 倒计时删除订单
|
||
*/
|
||
public function del($ids = "")
|
||
{
|
||
if ($ids)
|
||
{
|
||
$pk = $this->model->getPk();
|
||
$adminIds = $this->getDataLimitAdminIds();
|
||
if (is_array($adminIds))
|
||
{
|
||
$count = $this->model->where($this->dataLimitField, 'in', $adminIds);
|
||
}
|
||
$list = $this->model->where($pk, 'in', $ids)->select();
|
||
$count = 0;
|
||
foreach ($list as $k => $v)
|
||
{
|
||
$count += $v->delete();
|
||
}
|
||
if ($count)
|
||
{
|
||
$this->success('操作成功','',json(),[]);
|
||
}
|
||
else
|
||
{
|
||
$this->error(__('No rows were deleted'));
|
||
}
|
||
}
|
||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||
}
|
||
|
||
|
||
} |