model = new MoneyLogModel(); //$this->assign('typeList', site_config('addonsd.money_in_type')); $list = site_config('addonsd.money_out_type'); //dump( $list);die; $this->assign('bankList', site_config('addonsd.bank_account')); $this->relationField=['users']; } //查看 #[Route('GET,JSON','index')] public function index() { if (false === $this->request->isAjax()) { return $this->fetch(); } if($this->request->post('selectpage')){ return $this->selectpage(); } [$where, $order, $limit, $with] = $this->buildparams(); $list = $this->model ->withJoin($with,'left') //如果没有使用operate filter过滤的情况下,推荐使用with关联,可以提高查询效率 ->where('money_log.status', 1) ->where($where) ->order($order) ->paginate($limit); $result = ['total' => $list->total(), 'rows' => $list->items()]; return json($result); } //修改 #[Route("GET,POST","edit")] public function edit() { if(!$this->request->isPost()){ $catelist= site_config('addonsd.money_in_type'); $this->assign('parentList', $catelist); } return $this->_edit(); } //删除 #[Route("GET,POST","del")] public function del() { $ids = $this->request->param("ids"); if (empty($ids)) { $this->error(__('参数%s不能为空', ['s'=>'ids'])); } $pk = $this->model->getPk(); $list = $this->model->where($pk, 'in', $ids)->select(); $count = 0; Db::startTrans(); try { foreach ($list as $item) { if(count($this->volidateFields)>0){ foreach ($this->volidateFields as $field=>$value){ if($item[$field]!=$value){ $this->error(__('没有操作权限')); } } } $item->status=0; $count += $item->save(); } if($this->callback){ $callback=$this->callback; $callback($ids); } Db::commit(); } catch (\Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($count) { $this->success(); } $this->error(__('没有记录被删除')); } //更新 #[Route("GET,POST","multi")] public function multi() { //通过定义callback回调函数来执行更新后的操作 $this->callback=function ($ids,$field,$value){}; return $this->_multi(); } //导入 #[Route("GET,POST","import")] public function import() { //通过定义callback回调函数来处理导入的数据 $this->callback=function ($inserData){ return $inserData; }; return $this->_import(); } }