AdminModel = new AdminModel; $this->FieldrulesModel = new FieldrulesModel; $this->CostprojectModel = new CostprojectModel; } public function add(){ if(request()->isAjax()){ $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { //编辑 $id = $param['id']; unset($param['id']); $param_1 = array(); $param_2 = array(); foreach($param as $key => $value){ if(strripos($key, '_edit')){ $param_2[$key] = $value; }else{ $param_1[$key] = $value; } } $data[] = array(); $field_data = json_encode($param_1); $field_data_edit = json_encode($param_2); $operator_nickname = get_login_admin('nickname'); $data = [ 'field_rules' => $field_data, 'field_edit_rules' => $field_data_edit, 'operator' => $operator_nickname, ]; Db::startTrans(); try{ $result = $this->FieldrulesModel->where('id', $id)->save($data); Db::commit(); }catch(\Exception $e){ // 回滚事务 Db::rollback(); return to_assign(1, '保存失败:' . $e->getMessage()); } if(!$result){ return to_assign(1, '保存失败:' . '网络异常',$id); } }else{ //新增 // halt($param); $param_1 = array(); $param_2 = array(); foreach($param as $key => $value){ if(strripos($key, '_edit')){ $param_2[$key] = $value; }else{ $param_1[$key] = $value; } } $field_data = json_encode($param_1); $field_data_edit = json_encode($param_2); $operator_nickname = get_login_admin('nickname'); $data = array(); $data = [ 'field_rules' => $field_data, 'field_edit_rules' => $field_data_edit, 'operator' => $operator_nickname, ]; Db::startTrans(); try{ //自增id $result = $this->FieldrulesModel->insertGetId($data); Db::commit(); }catch(\Exception $e){ // 回滚事务 Db::rollback(); return to_assign(1, '保存失败:' . $e->getMessage()); } if(!$result){ return to_assign(1, '保存失败:' . '网络异常'); } } return to_assign(0,"操作成功",$result); }else{ $id = empty(get_params('id')) ? 0 : get_params('id'); $login_admin = get_login_admin(); // dump($login_admin); $where_unit = array(); if($login_admin['permission'] != 1){ $where_unit[] = [ ['unit_name', '=', $login_admin['unit_name']], ]; } if ($id > 0) { // 编辑 $field = self::field_rules($id); $field_edit = self::field_edit_rules($id); $field = array_merge($field, $field_edit); }else{ // 新增 $field = self::field_project(); } // halt($field); View::assign('field', $field); View::assign('id', $id); return view(); } } public function delete(){ $id = get_params('id'); $result = $this->FieldrulesModel->where('id', $id)->delete(); if($result){ add_log('delete', $id); return to_assign(0, "删除成功"); }else{ return to_assign(1, "删除失败"); } } // 获取可读字段 public function field_rules($id){ //可读字段 $field_rules = $this->FieldrulesModel->where('id', $id)->order('id', 'desc')->value('field_rules'); $field_rules = json_decode($field_rules,true); return $field_rules; } // 获取可编辑字段 public function field_edit_rules($id){ //可读字段 $field_edit_rules = $this->FieldrulesModel->where('id', $id)->order('id', 'desc')->value('field_edit_rules'); $field_edit_rules = json_decode($field_edit_rules,true); return $field_edit_rules; } // zjl获取可读字段 public function get_field_rules($admin_id){ $group_id = Db::name('AdminGroupAccess')->where('uid', $admin_id)->value('group_id'); //可读字段 $field_rules = $this->FieldrulesModel->where('group_id', $group_id)->order('id', 'desc')->value('field_rules'); $field_rules = json_decode($field_rules,true); if(empty($field_rules)){ $field_rules = 0; } return $field_rules; } // 获取可读字段 public function get_field_rules_New($admin_id){ // $admin_id = 67; $group_id = Db::name('admin_group_access')->where('uid', $admin_id)->value('group_id'); //可读字段 $field_rules = $this->FieldrulesModel->where('group_id', $group_id)->order('id', 'desc')->value('field_rules'); // dump($field_rules); $field_rules = json_decode($field_rules,true); if(empty($field_rules)){ $field_rules = [ "project_status" => "1", "project_status_edit" => "1", "project_num" => "1", "project_num_edit" => "1", "project_name" => "1", "project_name_edit" => "1", "project_time" => "1", "project_time_edit" => "1", "entrust_unit" => "1", "entrust_unit_edit" => "1", "entrust_head" => "1", "entrust_head_edit" => "1", "entrust_phone" => "1", "entrust_phone_edit" => "1", "review_unit" => "1", "review_unit_edit" => "1", "review_head" => "1", "review_head_edit" => "1", "review_head_phone" => "1", "review_head_phone_edit" => "1", "sent_review_unit" => "1", "sent_review_unit_edit" => "1", "sent_review_head" => "1", "sent_review_head_edit" => "1", "sent_review_phone" => "1", "sent_review_phone_edit" => "1", "construction_unit" => "1", "construction_unit_edit" => "1", "construction_head" => "1", "construction_head_edit" => "1", "construction_phone" => "1", "construction_phone_edit" => "1", "project_scale" => "1", "project_scale_edit" => "1", "project_region" => "1", "project_region_edit" => "1", "engineering_category" => "1", "engineering_category_edit" => "1", "engineering_type" => "1", "engineering_type_edit" => "1", "fiscal_nature" => "1", "fiscal_nature_edit" => "1", "sent_review_cost" => "1", "sent_review_cost_edit" => "1", "preparation_amount" => "1", "preparation_amount_edit" => "1", "sent_review_amount" => "1", "sent_review_amount_edit" => "1", "sent_review_approver_amount" => "1", "sent_review_approver_amount_edit" => "1", "construction_approver_amount" => "1", "construction_approver_amount_edit" => "1", "authorize_amount" => "1", "authorize_amount_edit" => "1", "review_add_reduce_amount" => "1", "review_add_reduce_amount_edit" => "1", "review_add_reduce_rate" => "1", "review_add_reduce_rate_edit" => "1", "report_time" => "1", "report_time_edit" => "1", "charge_standard" => "1", "charge_standard_edit" => "1", "invoicing__amount" => "1", "invoicing__amount_edit" => "1", "invoicing__num" => "1", "invoicing__num_edit" => "1", "operate_name" => "1", "operate_name_edit" => "1", "operate_team_names" => "1", "operate_team_names_edit" => "1", "project_dead_time" => "1", "project_dead_time_edit" => "1", "create_time" => "1", "create_time_edit" => "1", ]; } // dump($field_rules); return $field_rules; } // 获取可编辑字段 public function get_field_rules_edit_New($admin_id){ // $admin_id = 67; $group_id = Db::name('admin_group_access')->where('uid', $admin_id)->value('group_id'); //可读字段 $field_rules = $this->FieldrulesModel->where('group_id', $group_id)->order('id', 'desc')->value('field_edit_rules'); // dump($field_rules); $field_rules = json_decode($field_rules,true); if(empty($field_rules)){ $field_rules = [ "project_status" => "1", "project_status_edit" => "1", "project_num" => "1", "project_num_edit" => "1", "project_name" => "1", "project_name_edit" => "1", "project_time" => "1", "project_time_edit" => "1", "entrust_unit" => "1", "entrust_unit_edit" => "1", "entrust_head" => "1", "entrust_head_edit" => "1", "entrust_phone" => "1", "entrust_phone_edit" => "1", "review_unit" => "1", "review_unit_edit" => "1", "review_head" => "1", "review_head_edit" => "1", "review_head_phone" => "1", "review_head_phone_edit" => "1", "sent_review_unit" => "1", "sent_review_unit_edit" => "1", "sent_review_head" => "1", "sent_review_head_edit" => "1", "sent_review_phone" => "1", "sent_review_phone_edit" => "1", "construction_unit" => "1", "construction_unit_edit" => "1", "construction_head" => "1", "construction_head_edit" => "1", "construction_phone" => "1", "construction_phone_edit" => "1", "project_scale" => "1", "project_scale_edit" => "1", "project_region" => "1", "project_region_edit" => "1", "engineering_category" => "1", "engineering_category_edit" => "1", "engineering_type" => "1", "engineering_type_edit" => "1", "fiscal_nature" => "1", "fiscal_nature_edit" => "1", "sent_review_cost" => "1", "sent_review_cost_edit" => "1", "preparation_amount" => "1", "preparation_amount_edit" => "1", "sent_review_amount" => "1", "sent_review_amount_edit" => "1", "sent_review_approver_amount" => "1", "sent_review_approver_amount_edit" => "1", "construction_approver_amount" => "1", "construction_approver_amount_edit" => "1", "authorize_amount" => "1", "authorize_amount_edit" => "1", "review_add_reduce_amount" => "1", "review_add_reduce_amount_edit" => "1", "review_add_reduce_rate" => "1", "review_add_reduce_rate_edit" => "1", "report_time" => "1", "report_time_edit" => "1", "charge_standard" => "1", "charge_standard_edit" => "1", "invoicing__amount" => "1", "invoicing__amount_edit" => "1", "invoicing__num" => "1", "invoicing__num_edit" => "1", "operate_name" => "1", "operate_name_edit" => "1", "operate_team_names" => "1", "operate_team_names_edit" => "1", "project_dead_time" => "1", "project_dead_time_edit" => "1", "create_time" => "1", "create_time_edit" => "1", ]; } // dump($field_rules); return $field_rules; } public function field_project(){ $c_field = Db::query("show full columns from cp_cost_project"); $field[] = array(); foreach($c_field as $key => $value){ $field[$key] = $value['Field']; } $field = array_flip($field); unset($field['id']); foreach($field as $key => $value){ $field[$key] = 0; } return $field; } }