Fieldproprietor.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. namespace app\admin\controller\field;
  3. use app\admin\BaseController;
  4. use think\facade\Db;
  5. use think\facade\View;
  6. use app\admin\model\Fieldrules as FieldrulesModel;
  7. use app\admin\model\CostProject as CostprojectModel;
  8. use app\admin\model\Admin as AdminModel;
  9. class Fieldproprietor extends BaseController{
  10. protected $FeildrulesModel;
  11. protected $CostprojectModel;
  12. public function initialize(){
  13. parent::initialize();
  14. $this->AdminModel = new AdminModel;
  15. $this->FieldrulesModel = new FieldrulesModel;
  16. $this->CostprojectModel = new CostprojectModel;
  17. }
  18. public function add(){
  19. if(request()->isAjax()){
  20. $param = get_params();
  21. if (!empty($param['id']) && $param['id'] > 0) { //编辑
  22. $id = $param['id'];
  23. unset($param['id']);
  24. $param_1 = array();
  25. $param_2 = array();
  26. foreach($param as $key => $value){
  27. if(strripos($key, '_edit')){
  28. $param_2[$key] = $value;
  29. }else{
  30. $param_1[$key] = $value;
  31. }
  32. }
  33. $data[] = array();
  34. $field_data = json_encode($param_1);
  35. $field_data_edit = json_encode($param_2);
  36. $operator_nickname = get_login_admin('nickname');
  37. $data = [
  38. 'field_rules' => $field_data,
  39. 'field_edit_rules' => $field_data_edit,
  40. 'operator' => $operator_nickname,
  41. ];
  42. Db::startTrans();
  43. try{
  44. $result = $this->FieldrulesModel->where('id', $id)->save($data);
  45. Db::commit();
  46. }catch(\Exception $e){
  47. // 回滚事务
  48. Db::rollback();
  49. return to_assign(1, '保存失败:' . $e->getMessage());
  50. }
  51. if(!$result){
  52. return to_assign(1, '保存失败:' . '网络异常');
  53. }
  54. return to_assign(0,"操作成功",$id);
  55. }else{ //新增
  56. // halt($param);
  57. $param_1 = array();
  58. $param_2 = array();
  59. foreach($param as $key => $value){
  60. if(strripos($key, '_edit')){
  61. $param_2[$key] = $value;
  62. }else{
  63. $param_1[$key] = $value;
  64. }
  65. }
  66. $field_data = json_encode($param_1);
  67. $field_data_edit = json_encode($param_2);
  68. $operator_nickname = get_login_admin('nickname');
  69. $data = array();
  70. $data = [
  71. 'field_rules' => $field_data,
  72. 'field_edit_rules' => $field_data_edit,
  73. 'operator' => $operator_nickname,
  74. ];
  75. Db::startTrans();
  76. try{
  77. //自增id
  78. $result = $this->FieldrulesModel->insertGetId($data);
  79. Db::commit();
  80. }catch(\Exception $e){
  81. // 回滚事务
  82. Db::rollback();
  83. return to_assign(1, '保存失败:' . $e->getMessage());
  84. }
  85. if(!$result){
  86. return to_assign(1, '保存失败:' . '网络异常');
  87. }
  88. }
  89. return to_assign(0,"操作成功",$result);
  90. }else{
  91. $id = empty(get_params('id')) ? 0 : get_params('id');
  92. $login_admin = get_login_admin();
  93. // dump($login_admin);
  94. $where_unit = array();
  95. if($login_admin['permission'] != 1){
  96. $where_unit[] = [
  97. ['unit_name', '=', $login_admin['unit_name']],
  98. ];
  99. }
  100. if ($id > 0) { // 编辑
  101. $field = self::field_rules($id);
  102. $field_edit = self::field_edit_rules($id);
  103. $field = array_merge($field, $field_edit);
  104. }else{ // 新增
  105. $field = self::field_project();
  106. }
  107. // halt($field);
  108. View::assign('field', $field);
  109. View::assign('id', $id);
  110. return view();
  111. }
  112. }
  113. public function delete(){
  114. $id = get_params('id');
  115. $result = $this->FieldrulesModel->where('id', $id)->delete();
  116. if($result){
  117. add_log('delete', $id);
  118. return to_assign(0, "删除成功");
  119. }else{
  120. return to_assign(1, "删除失败");
  121. }
  122. }
  123. // 获取可读字段
  124. public function field_rules($id){
  125. //可读字段
  126. $field_rules = $this->FieldrulesModel->where('id', $id)->order('id', 'desc')->value('field_rules');
  127. $field_rules = json_decode($field_rules,true);
  128. return $field_rules;
  129. }
  130. // 获取可编辑字段
  131. public function field_edit_rules($id){
  132. //可读字段
  133. $field_edit_rules = $this->FieldrulesModel->where('id', $id)->order('id', 'desc')->value('field_edit_rules');
  134. $field_edit_rules = json_decode($field_edit_rules,true);
  135. return $field_edit_rules;
  136. }
  137. // zjl获取可读字段
  138. public function get_field_rules($admin_id){
  139. //可读字段
  140. $field_rules = $this->FieldrulesModel->where('admin_id', $admin_id)->order('id', 'desc')->value('field_rules');
  141. $field_rules = json_decode($field_rules,true);
  142. if(empty($field_rules)){
  143. $field_rules = 0;
  144. }
  145. return $field_rules;
  146. }
  147. // zjl获取可读字段
  148. // public function get_field_rules_New($admin_id){
  149. // $group_id = Db::name('admin_group_access')->where('uid', $admin_id)->value('group_id');
  150. // //可读字段
  151. // $field_rules = $this->FieldrulesModel->where('group_id', $group_id)->order('id', 'desc')->value('field_rules');
  152. // $field_rules = json_decode($field_rules,true);
  153. // if(empty($field_rules)){
  154. // $field_rules = 0;
  155. // }
  156. // return $field_rules;
  157. // }
  158. // 获取可读字段
  159. public function get_field_rules_New($admin_id){
  160. // $admin_id = 67;
  161. $group_id = Db::name('admin_group_access')->where('uid', $admin_id)->value('group_id');
  162. //可读字段
  163. $field_rules = $this->FieldrulesModel->where('group_id', $group_id)->order('id', 'desc')->value('field_rules');
  164. // dump($field_rules);
  165. $field_rules = json_decode($field_rules,true);
  166. if(empty($field_rules)){
  167. $field_rules = [
  168. "project_status" => "1",
  169. "project_status_edit" => "1",
  170. "project_num" => "1",
  171. "project_num_edit" => "1",
  172. "project_name" => "1",
  173. "project_name_edit" => "1",
  174. "project_time" => "1",
  175. "project_time_edit" => "1",
  176. "entrust_unit" => "1",
  177. "entrust_unit_edit" => "1",
  178. "entrust_head" => "1",
  179. "entrust_head_edit" => "1",
  180. "entrust_phone" => "1",
  181. "entrust_phone_edit" => "1",
  182. "review_unit" => "1",
  183. "review_unit_edit" => "1",
  184. "review_head" => "1",
  185. "review_head_edit" => "1",
  186. "review_head_phone" => "1",
  187. "review_head_phone_edit" => "1",
  188. "sent_review_unit" => "1",
  189. "sent_review_unit_edit" => "1",
  190. "sent_review_head" => "1",
  191. "sent_review_head_edit" => "1",
  192. "sent_review_phone" => "1",
  193. "sent_review_phone_edit" => "1",
  194. "construction_unit" => "1",
  195. "construction_unit_edit" => "1",
  196. "construction_head" => "1",
  197. "construction_head_edit" => "1",
  198. "construction_phone" => "1",
  199. "construction_phone_edit" => "1",
  200. "project_scale" => "1",
  201. "project_scale_edit" => "1",
  202. "project_region" => "1",
  203. "project_region_edit" => "1",
  204. "engineering_category" => "1",
  205. "engineering_category_edit" => "1",
  206. "engineering_type" => "1",
  207. "engineering_type_edit" => "1",
  208. "fiscal_nature" => "1",
  209. "fiscal_nature_edit" => "1",
  210. "sent_review_cost" => "1",
  211. "sent_review_cost_edit" => "1",
  212. "preparation_amount" => "1",
  213. "preparation_amount_edit" => "1",
  214. "sent_review_amount" => "1",
  215. "sent_review_amount_edit" => "1",
  216. "sent_review_approver_amount" => "1",
  217. "sent_review_approver_amount_edit" => "1",
  218. "construction_approver_amount" => "1",
  219. "construction_approver_amount_edit" => "1",
  220. "authorize_amount" => "1",
  221. "authorize_amount_edit" => "1",
  222. "review_add_reduce_amount" => "1",
  223. "review_add_reduce_amount_edit" => "1",
  224. "review_add_reduce_rate" => "1",
  225. "review_add_reduce_rate_edit" => "1",
  226. "report_time" => "1",
  227. "report_time_edit" => "1",
  228. "charge_standard" => "1",
  229. "charge_standard_edit" => "1",
  230. "invoicing__amount" => "1",
  231. "invoicing__amount_edit" => "1",
  232. "invoicing__num" => "1",
  233. "invoicing__num_edit" => "1",
  234. "operate_name" => "1",
  235. "operate_name_edit" => "1",
  236. "operate_team_names" => "1",
  237. "operate_team_names_edit" => "1",
  238. "project_dead_time" => "1",
  239. "project_dead_time_edit" => "1",
  240. "create_time" => "1",
  241. "create_time_edit" => "1",
  242. ];
  243. }
  244. // dump($field_rules);
  245. return $field_rules;
  246. }
  247. public function field_project(){
  248. $c_field = Db::query("show full columns from cp_cost_project");
  249. $field[] = array();
  250. foreach($c_field as $key => $value){
  251. $field[$key] = $value['Field'];
  252. }
  253. $field = array_flip($field);
  254. unset($field['id']);
  255. foreach($field as $key => $value){
  256. $field[$key] = 0;
  257. }
  258. return $field;
  259. }
  260. }