|
|
@@ -23,9 +23,9 @@ class MoneyLog extends Backend
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
$this->model = new MoneyLogModel();
|
|
|
- //$this->assign('typeList', site_config('addonsd.money_in_type'));
|
|
|
- $list = site_config('addonsd.money_out_type');
|
|
|
- //dump( $list);die;
|
|
|
+ $this->assign('typeInList', site_config('addonsd.money_in_type')); //
|
|
|
+ $this->assign('typeOutList', site_config('addonsd.money_out_type'));
|
|
|
+
|
|
|
$this->assign('bankList', site_config('addonsd.bank_account'));
|
|
|
$this->relationField=['users'];
|
|
|
}
|
|
|
@@ -55,13 +55,63 @@ class MoneyLog extends Backend
|
|
|
|
|
|
//修改
|
|
|
#[Route("GET,POST","edit")]
|
|
|
- public function edit()
|
|
|
+ public function edit(mixed $row=null)
|
|
|
{
|
|
|
- if(!$this->request->isPost()){
|
|
|
- $catelist= site_config('addonsd.money_in_type');
|
|
|
- $this->assign('parentList', $catelist);
|
|
|
+ $ids = $this->request->get('ids');
|
|
|
+ if(!$row || is_array($row)){
|
|
|
+ $row = $this->model->find($ids);
|
|
|
+ }
|
|
|
+ if (!$row) {
|
|
|
+ $this->error(__('没有找到记录'));
|
|
|
+ }
|
|
|
+ if(count($this->volidateFields)>0){
|
|
|
+ foreach ($this->volidateFields as $field=>$value){
|
|
|
+ if($row[$field]!=$value){
|
|
|
+ $this->error(__('没有操作权限'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (false === $this->request->isPost()) {
|
|
|
+ $this->assign('parentList', self::getTypeAllByType($row->type));
|
|
|
+ $this->assign('row', $row);
|
|
|
+ return $this->fetch();
|
|
|
}
|
|
|
- return $this->_edit();
|
|
|
+ $params = array_merge($this->request->post("row/a"),$this->postParams);
|
|
|
+ if (empty($params)) {
|
|
|
+ $this->error(__('提交的参数不能为空'));
|
|
|
+ }
|
|
|
+ if(!$this->request->checkToken('__token__',['__token__'=>$this->request->post('__token__')])){
|
|
|
+ $this->error(__('token错误,请刷新页面重试'));
|
|
|
+ }
|
|
|
+ foreach ($params as &$value){
|
|
|
+ if(is_array($value)){
|
|
|
+ $value=implode(',',$value);
|
|
|
+ }
|
|
|
+ if($value===''){
|
|
|
+ $value=null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $result = false;
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ if(isEnglish($params['type_name'])){
|
|
|
+ $arr = self::getTypeAllByType((int)$params['type']);
|
|
|
+ $params['type_name'] = $arr[$params['type_name']];
|
|
|
+ }
|
|
|
+ $result = $row->save($params);
|
|
|
+ if($this->callback){
|
|
|
+ $callback=$this->callback;
|
|
|
+ $callback($row);
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ if (false === $result) {
|
|
|
+ $this->error(__('没有数据被更新'));
|
|
|
+ }
|
|
|
+ $this->success();
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -125,4 +175,10 @@ class MoneyLog extends Backend
|
|
|
return $this->_import();
|
|
|
}
|
|
|
|
|
|
+ //获取分类
|
|
|
+ private static function getTypeAllByType(int $type)
|
|
|
+ {
|
|
|
+ return ($type== 1)?site_config('addonsd.money_in_type'):site_config('addonsd.money_out_type');
|
|
|
+ }
|
|
|
+
|
|
|
}
|