作者 郭盛
1 个管道 的构建 通过 耗费 2 秒

修改订单状态

... ... @@ -25,7 +25,7 @@ class Iphoneorder extends Backend
$this->model = new \app\admin\model\Iphoneorder;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
... ... @@ -33,6 +33,45 @@ class Iphoneorder extends Backend
*/
/**
* 查看
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
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();
$list = collection($list)->toArray();
foreach ($list as &$v){
$user = Db::name('user')->where('id',$v['user_id'])->field('id,nickname,mobile')->find();
$v['user_id'] = $user['nickname'];
$v['user_phone'] = $user['mobile'];
}
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
/**
* 添加
*/
public function add()
... ... @@ -41,6 +80,8 @@ class Iphoneorder extends Backend
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$params['status'] = 1;
$params['num'] = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
... ... @@ -75,6 +116,71 @@ class Iphoneorder extends Backend
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
$user = Db::name('user')->where('id',$params['user_id'])->find();
//已经支付
if($params['status'] == 2){
//判断金额
if($params['money'] >= 8000){
$update['is_vip'] = 1;
$update['money'] = $user['money'] + $params['money'];
}else{
$update['money'] = $user['money'] + $params['money'];
}
Db::name('user')->where('id',$user['id'])->update($update);
}
if ($params) {
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$this->view->assign("row", $row);
return $this->view->fetch();
}
}
... ...
... ... @@ -13,7 +13,7 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<label class="control-label col-xs-12 col-sm-2">{:__('支付状态')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_radios('row[status]', ['1'=>'待支付', '2'=>'已支付'],$row.status)}
</div>
... ...
... ... @@ -26,11 +26,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'user_id', title: __('User_id')},
{field: 'user_phone', title: __('用户手机号')},
{field: 'money', title: __('Money'), operate:'BETWEEN'},
{field: 'status', title: __('支付状态'),searchList: {"1":"","2":'已支付'},formatter: Table.api.formatter.status},
{field: 'status', title: __('支付状态'),searchList: {"1":"待支付","2":'已支付'},formatter: Table.api.formatter.status},
{field: 'num', title: __('Num')},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
// {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
... ...