Field.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 Field 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, '保存失败:' . '网络异常',$id);
  53. }
  54. }else{ //新增
  55. // halt($param);
  56. $param_1 = array();
  57. $param_2 = array();
  58. foreach($param as $key => $value){
  59. if(strripos($key, '_edit')){
  60. $param_2[$key] = $value;
  61. }else{
  62. $param_1[$key] = $value;
  63. }
  64. }
  65. $field_data = json_encode($param_1);
  66. $field_data_edit = json_encode($param_2);
  67. $operator_nickname = get_login_admin('nickname');
  68. $data = array();
  69. $data = [
  70. 'field_rules' => $field_data,
  71. 'field_edit_rules' => $field_data_edit,
  72. 'operator' => $operator_nickname,
  73. ];
  74. Db::startTrans();
  75. try{
  76. //自增id
  77. $result = $this->FieldrulesModel->insertGetId($data);
  78. Db::commit();
  79. }catch(\Exception $e){
  80. // 回滚事务
  81. Db::rollback();
  82. return to_assign(1, '保存失败:' . $e->getMessage());
  83. }
  84. if(!$result){
  85. return to_assign(1, '保存失败:' . '网络异常');
  86. }
  87. }
  88. return to_assign(0,"操作成功",$result);
  89. }else{
  90. $id = empty(get_params('id')) ? 0 : get_params('id');
  91. $login_admin = get_login_admin();
  92. // dump($login_admin);
  93. $where_unit = array();
  94. if($login_admin['permission'] != 1){
  95. $where_unit[] = [
  96. ['unit_name', '=', $login_admin['unit_name']],
  97. ];
  98. }
  99. if ($id > 0) { // 编辑
  100. $field = self::field_rules($id);
  101. $field_edit = self::field_edit_rules($id);
  102. $field = array_merge($field, $field_edit);
  103. }else{ // 新增
  104. $field = self::field_project();
  105. }
  106. // halt($field);
  107. View::assign('field', $field);
  108. View::assign('id', $id);
  109. return view();
  110. }
  111. }
  112. public function delete(){
  113. $id = get_params('id');
  114. $result = $this->FieldrulesModel->where('id', $id)->delete();
  115. if($result){
  116. add_log('delete', $id);
  117. return to_assign(0, "删除成功");
  118. }else{
  119. return to_assign(1, "删除失败");
  120. }
  121. }
  122. // 获取可读字段
  123. public function field_rules($id){
  124. //可读字段
  125. $field_rules = $this->FieldrulesModel->where('id', $id)->order('id', 'desc')->value('field_rules');
  126. $field_rules = json_decode($field_rules,true);
  127. return $field_rules;
  128. }
  129. // 获取可编辑字段
  130. public function field_edit_rules($id){
  131. //可读字段
  132. $field_edit_rules = $this->FieldrulesModel->where('id', $id)->order('id', 'desc')->value('field_edit_rules');
  133. $field_edit_rules = json_decode($field_edit_rules,true);
  134. return $field_edit_rules;
  135. }
  136. // zjl获取可读字段
  137. public function get_field_rules($admin_id){
  138. $group_id = Db::name('AdminGroupAccess')->where('uid', $admin_id)->value('group_id');
  139. //可读字段
  140. $field_rules = $this->FieldrulesModel->where('group_id', $group_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. // 获取可读字段
  148. public function get_field_rules_New($admin_id){
  149. // $admin_id = 67;
  150. $group_id = Db::name('admin_group_access')->where('uid', $admin_id)->value('group_id');
  151. //可读字段
  152. $field_rules = $this->FieldrulesModel->where('group_id', $group_id)->order('id', 'desc')->value('field_rules');
  153. // dump($field_rules);
  154. $field_rules = json_decode($field_rules,true);
  155. if(empty($field_rules)){
  156. $field_rules = [
  157. "project_status" => "1",
  158. "project_status_edit" => "1",
  159. "project_num" => "1",
  160. "project_num_edit" => "1",
  161. "project_name" => "1",
  162. "project_name_edit" => "1",
  163. "project_time" => "1",
  164. "project_time_edit" => "1",
  165. "entrust_unit" => "1",
  166. "entrust_unit_edit" => "1",
  167. "entrust_head" => "1",
  168. "entrust_head_edit" => "1",
  169. "entrust_phone" => "1",
  170. "entrust_phone_edit" => "1",
  171. "review_unit" => "1",
  172. "review_unit_edit" => "1",
  173. "review_head" => "1",
  174. "review_head_edit" => "1",
  175. "review_head_phone" => "1",
  176. "review_head_phone_edit" => "1",
  177. "sent_review_unit" => "1",
  178. "sent_review_unit_edit" => "1",
  179. "sent_review_head" => "1",
  180. "sent_review_head_edit" => "1",
  181. "sent_review_phone" => "1",
  182. "sent_review_phone_edit" => "1",
  183. "construction_unit" => "1",
  184. "construction_unit_edit" => "1",
  185. "construction_head" => "1",
  186. "construction_head_edit" => "1",
  187. "construction_phone" => "1",
  188. "construction_phone_edit" => "1",
  189. "project_scale" => "1",
  190. "project_scale_edit" => "1",
  191. "project_region" => "1",
  192. "project_region_edit" => "1",
  193. "engineering_category" => "1",
  194. "engineering_category_edit" => "1",
  195. "engineering_type" => "1",
  196. "engineering_type_edit" => "1",
  197. "fiscal_nature" => "1",
  198. "fiscal_nature_edit" => "1",
  199. "sent_review_cost" => "1",
  200. "sent_review_cost_edit" => "1",
  201. "preparation_amount" => "1",
  202. "preparation_amount_edit" => "1",
  203. "sent_review_amount" => "1",
  204. "sent_review_amount_edit" => "1",
  205. "sent_review_approver_amount" => "1",
  206. "sent_review_approver_amount_edit" => "1",
  207. "construction_approver_amount" => "1",
  208. "construction_approver_amount_edit" => "1",
  209. "authorize_amount" => "1",
  210. "authorize_amount_edit" => "1",
  211. "review_add_reduce_amount" => "1",
  212. "review_add_reduce_amount_edit" => "1",
  213. "review_add_reduce_rate" => "1",
  214. "review_add_reduce_rate_edit" => "1",
  215. "report_time" => "1",
  216. "report_time_edit" => "1",
  217. "charge_standard" => "1",
  218. "charge_standard_edit" => "1",
  219. "invoicing__amount" => "1",
  220. "invoicing__amount_edit" => "1",
  221. "invoicing__num" => "1",
  222. "invoicing__num_edit" => "1",
  223. "operate_name" => "1",
  224. "operate_name_edit" => "1",
  225. "operate_team_names" => "1",
  226. "operate_team_names_edit" => "1",
  227. "project_dead_time" => "1",
  228. "project_dead_time_edit" => "1",
  229. "create_time" => "1",
  230. "create_time_edit" => "1",
  231. ];
  232. }
  233. // dump($field_rules);
  234. return $field_rules;
  235. }
  236. // 获取可编辑字段
  237. public function get_field_rules_edit_New($admin_id){
  238. // $admin_id = 67;
  239. $group_id = Db::name('admin_group_access')->where('uid', $admin_id)->value('group_id');
  240. //可读字段
  241. $field_rules = $this->FieldrulesModel->where('group_id', $group_id)->order('id', 'desc')->value('field_edit_rules');
  242. // dump($field_rules);
  243. $field_rules = json_decode($field_rules,true);
  244. if(empty($field_rules)){
  245. $field_rules = [
  246. "project_status" => "1",
  247. "project_status_edit" => "1",
  248. "project_num" => "1",
  249. "project_num_edit" => "1",
  250. "project_name" => "1",
  251. "project_name_edit" => "1",
  252. "project_time" => "1",
  253. "project_time_edit" => "1",
  254. "entrust_unit" => "1",
  255. "entrust_unit_edit" => "1",
  256. "entrust_head" => "1",
  257. "entrust_head_edit" => "1",
  258. "entrust_phone" => "1",
  259. "entrust_phone_edit" => "1",
  260. "review_unit" => "1",
  261. "review_unit_edit" => "1",
  262. "review_head" => "1",
  263. "review_head_edit" => "1",
  264. "review_head_phone" => "1",
  265. "review_head_phone_edit" => "1",
  266. "sent_review_unit" => "1",
  267. "sent_review_unit_edit" => "1",
  268. "sent_review_head" => "1",
  269. "sent_review_head_edit" => "1",
  270. "sent_review_phone" => "1",
  271. "sent_review_phone_edit" => "1",
  272. "construction_unit" => "1",
  273. "construction_unit_edit" => "1",
  274. "construction_head" => "1",
  275. "construction_head_edit" => "1",
  276. "construction_phone" => "1",
  277. "construction_phone_edit" => "1",
  278. "project_scale" => "1",
  279. "project_scale_edit" => "1",
  280. "project_region" => "1",
  281. "project_region_edit" => "1",
  282. "engineering_category" => "1",
  283. "engineering_category_edit" => "1",
  284. "engineering_type" => "1",
  285. "engineering_type_edit" => "1",
  286. "fiscal_nature" => "1",
  287. "fiscal_nature_edit" => "1",
  288. "sent_review_cost" => "1",
  289. "sent_review_cost_edit" => "1",
  290. "preparation_amount" => "1",
  291. "preparation_amount_edit" => "1",
  292. "sent_review_amount" => "1",
  293. "sent_review_amount_edit" => "1",
  294. "sent_review_approver_amount" => "1",
  295. "sent_review_approver_amount_edit" => "1",
  296. "construction_approver_amount" => "1",
  297. "construction_approver_amount_edit" => "1",
  298. "authorize_amount" => "1",
  299. "authorize_amount_edit" => "1",
  300. "review_add_reduce_amount" => "1",
  301. "review_add_reduce_amount_edit" => "1",
  302. "review_add_reduce_rate" => "1",
  303. "review_add_reduce_rate_edit" => "1",
  304. "report_time" => "1",
  305. "report_time_edit" => "1",
  306. "charge_standard" => "1",
  307. "charge_standard_edit" => "1",
  308. "invoicing__amount" => "1",
  309. "invoicing__amount_edit" => "1",
  310. "invoicing__num" => "1",
  311. "invoicing__num_edit" => "1",
  312. "operate_name" => "1",
  313. "operate_name_edit" => "1",
  314. "operate_team_names" => "1",
  315. "operate_team_names_edit" => "1",
  316. "project_dead_time" => "1",
  317. "project_dead_time_edit" => "1",
  318. "create_time" => "1",
  319. "create_time_edit" => "1",
  320. ];
  321. }
  322. // dump($field_rules);
  323. return $field_rules;
  324. }
  325. public function field_project(){
  326. $c_field = Db::query("show full columns from cp_cost_project");
  327. $field[] = array();
  328. foreach($c_field as $key => $value){
  329. $field[$key] = $value['Field'];
  330. }
  331. $field = array_flip($field);
  332. unset($field['id']);
  333. foreach($field as $key => $value){
  334. $field[$key] = 0;
  335. }
  336. return $field;
  337. }
  338. }