Fieldcompany.php 14 KB

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