作者 郭文星

123

... ... @@ -3,6 +3,10 @@
namespace app\admin\controller\verification;
use app\common\controller\Backend;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 订单管理
... ... @@ -49,7 +53,7 @@ class Order extends Backend
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with(['store','coupon','activity','user'])
->where($where)
... ... @@ -74,5 +78,65 @@ class Order extends Backend
}
return $this->view->fetch();
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
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) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
//查询到用户信息
if($row){
$user=Db::name("user")->find($row['user_id']);
if($user['pid']>0){
$row['p_user']=Db::name("user")->find($user['pid']);
}
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$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()->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
public function findidbyid(){
$id=$this->request->param('id');
$thisuser=Db::name("user")->find($id);//查询到当前用户
return json($thisuser);
}
}
... ...
... ... @@ -31,6 +31,15 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">推广关系:</label>
<div class="col-xs-12 col-sm-8">
<p>
{$row.p_user.nickname|htmlentities}--{$row.p_user.pid|htmlentities}
<a onclick="findupuser({$row.p_user.pid})">++++</a>
</p>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Verification_coupon_ids')}:</label>
<div class="col-xs-12 col-sm-8">
<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 @@
</div>
</div>
</form>
<script>
function findupuser(id){
$.ajax({
type: 'get',
url: 'verification/order/findidbyid',
data: { id: id },
contentType: 'application/x-www-form-urlencoded',
// 会自动帮我们把返回的数据根据响应头设置的类型进行转换好(也就是会自动转成json对象)
success: function (response) {
console.log(response)
console.log(response)
console.log(response)
console.log(response)
console.log(response)
},
// xhr是ajax对象
error: function (xhr) {}
});
}
</script>
... ...