作者 郭文星

123

@@ -3,6 +3,10 @@ @@ -3,6 +3,10 @@
3 namespace app\admin\controller\verification; 3 namespace app\admin\controller\verification;
4 4
5 use app\common\controller\Backend; 5 use app\common\controller\Backend;
  6 +use think\Db;
  7 +use think\exception\DbException;
  8 +use think\exception\PDOException;
  9 +use think\exception\ValidateException;
6 10
7 /** 11 /**
8 * 订单管理 12 * 订单管理
@@ -74,5 +78,65 @@ class Order extends Backend @@ -74,5 +78,65 @@ class Order extends Backend
74 } 78 }
75 return $this->view->fetch(); 79 return $this->view->fetch();
76 } 80 }
  81 + /**
  82 + * 编辑
  83 + *
  84 + * @param $ids
  85 + * @return string
  86 + * @throws DbException
  87 + * @throws \think\Exception
  88 + */
  89 + public function edit($ids = null)
  90 + {
  91 + $row = $this->model->get($ids);
  92 + if (!$row) {
  93 + $this->error(__('No Results were found'));
  94 + }
  95 + $adminIds = $this->getDataLimitAdminIds();
  96 + if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  97 + $this->error(__('You have no permission'));
  98 + }
  99 + //查询到用户信息
  100 + if($row){
  101 + $user=Db::name("user")->find($row['user_id']);
  102 + if($user['pid']>0){
  103 + $row['p_user']=Db::name("user")->find($user['pid']);
  104 + }
  105 + }
77 106
  107 + if (false === $this->request->isPost()) {
  108 + $this->view->assign('row', $row);
  109 + return $this->view->fetch();
  110 + }
  111 + $params = $this->request->post('row/a');
  112 + if (empty($params)) {
  113 + $this->error(__('Parameter %s can not be empty', ''));
  114 + }
  115 + $params = $this->preExcludeFields($params);
  116 + $result = false;
  117 + Db::startTrans();
  118 + try {
  119 + //是否采用模型验证
  120 + if ($this->modelValidate) {
  121 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  122 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  123 + $row->validateFailException()->validate($validate);
  124 + }
  125 + $result = $row->allowField(true)->save($params);
  126 + Db::commit();
  127 + } catch (ValidateException|PDOException|Exception $e) {
  128 + Db::rollback();
  129 + $this->error($e->getMessage());
  130 + }
  131 + if (false === $result) {
  132 + $this->error(__('No rows were updated'));
  133 + }
  134 + $this->success();
  135 + }
  136 +
  137 + public function findidbyid(){
  138 + $id=$this->request->param('id');
  139 + $thisuser=Db::name("user")->find($id);//查询到当前用户
  140 + return json($thisuser);
  141 + }
78 } 142 }
@@ -31,6 +31,15 @@ @@ -31,6 +31,15 @@
31 </div> 31 </div>
32 </div> 32 </div>
33 <div class="form-group"> 33 <div class="form-group">
  34 + <label class="control-label col-xs-12 col-sm-2">推广关系:</label>
  35 + <div class="col-xs-12 col-sm-8">
  36 + <p>
  37 + {$row.p_user.nickname|htmlentities}--{$row.p_user.pid|htmlentities}
  38 + <a onclick="findupuser({$row.p_user.pid})">++++</a>
  39 + </p>
  40 + </div>
  41 + </div>
  42 + <div class="form-group">
34 <label class="control-label col-xs-12 col-sm-2">{:__('Verification_coupon_ids')}:</label> 43 <label class="control-label col-xs-12 col-sm-2">{:__('Verification_coupon_ids')}:</label>
35 <div class="col-xs-12 col-sm-8"> 44 <div class="col-xs-12 col-sm-8">
36 <input id="c-verification_coupon_ids" data-rule="required" data-source="verification/coupon/index" data-multiple="true" class="form-control selectpage" name="row[verification_coupon_ids]" type="text" value="{$row.verification_coupon_ids|htmlentities}"> 45 <input id="c-verification_coupon_ids" data-rule="required" data-source="verification/coupon/index" data-multiple="true" class="form-control selectpage" name="row[verification_coupon_ids]" type="text" value="{$row.verification_coupon_ids|htmlentities}">
@@ -74,3 +83,24 @@ @@ -74,3 +83,24 @@
74 </div> 83 </div>
75 </div> 84 </div>
76 </form> 85 </form>
  86 +<script>
  87 + function findupuser(id){
  88 + $.ajax({
  89 + type: 'get',
  90 + url: 'verification/order/findidbyid',
  91 + data: { id: id },
  92 + contentType: 'application/x-www-form-urlencoded',
  93 +
  94 + // 会自动帮我们把返回的数据根据响应头设置的类型进行转换好(也就是会自动转成json对象)
  95 + success: function (response) {
  96 + console.log(response)
  97 + console.log(response)
  98 + console.log(response)
  99 + console.log(response)
  100 + console.log(response)
  101 + },
  102 + // xhr是ajax对象
  103 + error: function (xhr) {}
  104 + });
  105 + }
  106 +</script>