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

修改订单状态

@@ -25,7 +25,7 @@ class Iphoneorder extends Backend @@ -25,7 +25,7 @@ class Iphoneorder extends Backend
25 $this->model = new \app\admin\model\Iphoneorder; 25 $this->model = new \app\admin\model\Iphoneorder;
26 26
27 } 27 }
28 - 28 +
29 /** 29 /**
30 * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 30 * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
31 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 31 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
@@ -33,6 +33,45 @@ class Iphoneorder extends Backend @@ -33,6 +33,45 @@ class Iphoneorder extends Backend
33 */ 33 */
34 34
35 /** 35 /**
  36 + * 查看
  37 + */
  38 + public function index()
  39 + {
  40 + //设置过滤方法
  41 + $this->request->filter(['strip_tags']);
  42 + if ($this->request->isAjax()) {
  43 + //如果发送的来源是Selectpage,则转发到Selectpage
  44 + if ($this->request->request('keyField')) {
  45 + return $this->selectpage();
  46 + }
  47 + list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  48 + $total = $this->model
  49 + ->where($where)
  50 + ->order($sort, $order)
  51 + ->count();
  52 +
  53 + $list = $this->model
  54 + ->where($where)
  55 + ->order($sort, $order)
  56 + ->limit($offset, $limit)
  57 + ->select();
  58 +
  59 + $list = collection($list)->toArray();
  60 + foreach ($list as &$v){
  61 + $user = Db::name('user')->where('id',$v['user_id'])->field('id,nickname,mobile')->find();
  62 + $v['user_id'] = $user['nickname'];
  63 + $v['user_phone'] = $user['mobile'];
  64 +
  65 + }
  66 + $result = array("total" => $total, "rows" => $list);
  67 +
  68 + return json($result);
  69 + }
  70 + return $this->view->fetch();
  71 + }
  72 +
  73 +
  74 + /**
36 * 添加 75 * 添加
37 */ 76 */
38 public function add() 77 public function add()
@@ -41,6 +80,8 @@ class Iphoneorder extends Backend @@ -41,6 +80,8 @@ class Iphoneorder extends Backend
41 $params = $this->request->post("row/a"); 80 $params = $this->request->post("row/a");
42 if ($params) { 81 if ($params) {
43 $params = $this->preExcludeFields($params); 82 $params = $this->preExcludeFields($params);
  83 + $params['status'] = 1;
  84 + $params['num'] = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
44 if ($this->dataLimit && $this->dataLimitFieldAutoFill) { 85 if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
45 $params[$this->dataLimitField] = $this->auth->id; 86 $params[$this->dataLimitField] = $this->auth->id;
46 } 87 }
@@ -75,6 +116,71 @@ class Iphoneorder extends Backend @@ -75,6 +116,71 @@ class Iphoneorder extends Backend
75 } 116 }
76 return $this->view->fetch(); 117 return $this->view->fetch();
77 } 118 }
  119 +
  120 +
  121 + /**
  122 + * 编辑
  123 + */
  124 + public function edit($ids = null)
  125 + {
  126 + $row = $this->model->get($ids);
  127 + if (!$row) {
  128 + $this->error(__('No Results were found'));
  129 + }
  130 + $adminIds = $this->getDataLimitAdminIds();
  131 + if (is_array($adminIds)) {
  132 + if (!in_array($row[$this->dataLimitField], $adminIds)) {
  133 + $this->error(__('You have no permission'));
  134 + }
  135 + }
  136 + if ($this->request->isPost()) {
  137 + $params = $this->request->post("row/a");
  138 + $user = Db::name('user')->where('id',$params['user_id'])->find();
  139 + //已经支付
  140 + if($params['status'] == 2){
  141 + //判断金额
  142 + if($params['money'] >= 8000){
  143 + $update['is_vip'] = 1;
  144 + $update['money'] = $user['money'] + $params['money'];
  145 + }else{
  146 + $update['money'] = $user['money'] + $params['money'];
  147 + }
  148 + Db::name('user')->where('id',$user['id'])->update($update);
  149 + }
  150 + if ($params) {
  151 + $params = $this->preExcludeFields($params);
  152 + $result = false;
  153 + Db::startTrans();
  154 + try {
  155 + //是否采用模型验证
  156 + if ($this->modelValidate) {
  157 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  158 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  159 + $row->validateFailException(true)->validate($validate);
  160 + }
  161 + $result = $row->allowField(true)->save($params);
  162 + Db::commit();
  163 + } catch (ValidateException $e) {
  164 + Db::rollback();
  165 + $this->error($e->getMessage());
  166 + } catch (PDOException $e) {
  167 + Db::rollback();
  168 + $this->error($e->getMessage());
  169 + } catch (Exception $e) {
  170 + Db::rollback();
  171 + $this->error($e->getMessage());
  172 + }
  173 + if ($result !== false) {
  174 + $this->success();
  175 + } else {
  176 + $this->error(__('No rows were updated'));
  177 + }
  178 + }
  179 + $this->error(__('Parameter %s can not be empty', ''));
  180 + }
  181 + $this->view->assign("row", $row);
  182 + return $this->view->fetch();
  183 + }
78 184
79 185
80 } 186 }
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 </div> 13 </div>
14 </div> 14 </div>
15 <div class="form-group"> 15 <div class="form-group">
16 - <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label> 16 + <label class="control-label col-xs-12 col-sm-2">{:__('支付状态')}:</label>
17 <div class="col-xs-12 col-sm-8"> 17 <div class="col-xs-12 col-sm-8">
18 {:build_radios('row[status]', ['1'=>'待支付', '2'=>'已支付'],$row.status)} 18 {:build_radios('row[status]', ['1'=>'待支付', '2'=>'已支付'],$row.status)}
19 </div> 19 </div>
@@ -26,11 +26,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -26,11 +26,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
26 {checkbox: true}, 26 {checkbox: true},
27 {field: 'id', title: __('Id')}, 27 {field: 'id', title: __('Id')},
28 {field: 'user_id', title: __('User_id')}, 28 {field: 'user_id', title: __('User_id')},
  29 + {field: 'user_phone', title: __('用户手机号')},
29 {field: 'money', title: __('Money'), operate:'BETWEEN'}, 30 {field: 'money', title: __('Money'), operate:'BETWEEN'},
30 - {field: 'status', title: __('支付状态'),searchList: {"1":"","2":'已支付'},formatter: Table.api.formatter.status}, 31 + {field: 'status', title: __('支付状态'),searchList: {"1":"待支付","2":'已支付'},formatter: Table.api.formatter.status},
31 {field: 'num', title: __('Num')}, 32 {field: 'num', title: __('Num')},
32 {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, 33 {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
33 - {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, 34 + // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
34 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} 35 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
35 ] 36 ]
36 ] 37 ]