CostCompany.php 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\admin\controller\project;
  4. use app\admin\BaseController;
  5. use app\admin\model\CostProject as CostProjectModel;
  6. use app\admin\model\ProjectAudit;
  7. use app\admin\model\Admin;
  8. use app\admin\model\ProjectFile;
  9. use app\admin\validate\project\CostProjectValidate;
  10. use think\App;
  11. use think\exception\ValidateException;
  12. use think\facade\Db;
  13. use think\facade\Session;
  14. use think\facade\View;
  15. use app\admin\controller\field\Fieldcompany;
  16. use app\admin\controller\Pushmessage;
  17. class CostCompany extends BaseController
  18. {
  19. /**
  20. * 构造函数
  21. */
  22. public function __construct(App $app)
  23. {
  24. parent::__construct($app);
  25. $this->Field = new Fieldcompany($this->app);
  26. $this->model = new CostProjectModel();
  27. $this->Adminmodel = new Admin();
  28. $this->uid = get_login_admin('id');
  29. $this->filemodel = new ProjectFile();
  30. $this->Pushmessage = new Pushmessage();
  31. $this->isPay = Db::name("department")->where("id",get_login_admin("unit_name"))->value("is_pay");
  32. }
  33. private array $field_name=[
  34. "engineering_type" => "工程类型",
  35. "engineering_category" => "工程类别",
  36. "province" => "省",
  37. "city" => "市" ,
  38. "area" => "县" ,
  39. "project_scale" => "项目规模",
  40. "fiscal_nature" => "财政性质" ,
  41. "sent_review_cost" => "送审服务费" ,
  42. "sent_review_amount" => "送审金额",
  43. "authorize_amount" => "审定金额" ,
  44. "review_add_reduce_amount" => "审增减额",
  45. "review_add_reduce_rate" => "审增减率" ,
  46. "charge_standard" => "收费标准" ,
  47. ];
  48. /**
  49. * 数据列表
  50. */
  51. public function datalist()
  52. {
  53. if (request()->isAjax()) {
  54. $inarr = array();
  55. $review_unit = $this->model->where("review_unit", get_login_admin("unit_name"))->field('id,review_head,operate_head,operate_team')->select()->toArray();
  56. for ($i = 0; $i < count($review_unit); $i++) {
  57. $a = $review_unit[$i];
  58. $ids = $a["review_head"] . ',' . $a["operate_head"] . ',' . $a["operate_team"];
  59. $ids = explode(",", $ids);
  60. $c = in_array($this->uid, $ids);
  61. if ($c) {
  62. $inarr[] = $a["id"];
  63. }
  64. }
  65. //$inarr没去重,应该不要紧
  66. $param = get_params();
  67. if (isset($param["project_start_time"])) {
  68. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  69. }
  70. if (isset($param["project_end_time"])) {
  71. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  72. }
  73. $where3 = array();
  74. if (!empty($param['project_status'])) {
  75. $where3[] = ['project_status', '=', $param['project_status']];
  76. }
  77. if (!empty($param['province'])) {
  78. $where3[] = ['province', '=', $param['province']];
  79. }
  80. if (!empty($param['city'])) {
  81. $where3[] = ['city', '=', $param['city']];
  82. }
  83. if (!empty($param['area'])) {
  84. $where3[] = ['area', '=', $param['area']];
  85. }
  86. if (!empty($param['project_end_time'])) {
  87. $where3[] = ['project_end_time', '<', $param['project_end_time']];
  88. }
  89. if (!empty($param['project_start_time'])) {
  90. $where3[] = ['project_start_time', '>', $param['project_start_time']];
  91. }
  92. if (!empty($param['entrust_unit_name'])) {
  93. $where3[] = ['entrust_unit_name', 'like', '%' . $param['entrust_unit_name']. '%'];
  94. }
  95. if (!empty($param['sent_review_unit_name'])) {
  96. $where3[] = ['sent_review_unit_name', 'like', '%' . $param['sent_review_unit_name']. '%'];
  97. }
  98. if (!empty($param['keyword'])) {
  99. $keyword = $param['keyword'];
  100. $where3[] = ['project_num|project_name|entrust_maker_name', 'like', '%' . $keyword . '%'];
  101. }
  102. $where = [
  103. ["cp_cost_project.delete_time", "=", 0],
  104. ["project_status", ">", 3],
  105. ["review_unit","=",get_login_admin("unit_name")]
  106. ];
  107. if($this->isPay==0){
  108. $where[] = ["project_status","<",8];
  109. }
  110. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  111. $order = empty($param['order']) ? 'project_receive_time desc,id desc' : $param['order'];
  112. $field = $this->Field->get_field_rules_New($this->uid);
  113. $see_auth = isset($field["see_auth"])?$field["see_auth"]:3;
  114. $this->see_auth = $see_auth;
  115. if($see_auth==3){
  116. $list = $this->model
  117. ->where($where)->whereIn("id", $inarr)->where($where3)
  118. ->order($order)->paginate($rows, false, ['query' => $param])
  119. ->each(function ($item) {
  120. $item->creator = Db::name("admin")->where("id",$item->creator)->value("nickname");
  121. $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
  122. if ($red) {
  123. if ($red["detail"] || $red["comment"] || $red["report"] || $red["record"] || $red["user"] || $red["contact"]) {
  124. $item->red = 1;
  125. }
  126. } else {
  127. $item->red = 0;
  128. }
  129. $entrust_head_id = Db::name('department')->where(['id' => $item->entrust_unit])->value('leader_id');
  130. if (!($item->entrust_head_phone)) {
  131. $item->entrust_head_phone = Db::name('admin')->where("id", $entrust_head_id)->value("mobile");
  132. }
  133. if ( ($item->province&&$item->city&&$item->area)) {
  134. $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
  135. }
  136. $item->self_id = $this->see_auth;
  137. //作业人
  138. $item->operate_name = Db::name("admin")->where("id", $item->operate_head)->value("nickname");
  139. $operate_team_names = null;
  140. // halt($item->operate_team);
  141. //只有一个人会报错
  142. // dump($item->operate_team);
  143. $aaa = empty($item->operate_team) ? $item->operate_team : "0";
  144. // dump($aaa);
  145. // $aaa = isset($param['id']) ? $param['id'] : 0;
  146. $operate_team_names_ids = explode(",", $aaa);
  147. for ($i = 0; $i < count($operate_team_names_ids); $i++) {
  148. $name = Db::name("admin")->where("id", $operate_team_names_ids[$i])->value("nickname");
  149. if (!($i == 0)) {
  150. $name = "," . $name;
  151. }
  152. $operate_team_names = $operate_team_names . $name;
  153. }
  154. $item->operate_team_names = $operate_team_names;
  155. });
  156. }elseif ($see_auth==0){
  157. $list = $this->model
  158. ->where($where)->whereIn("id", $inarr)->where($where3)
  159. ->order($order)->paginate($rows, false, ['query' => $param])
  160. ->each(function ($item) {
  161. $item->creator = Db::name("admin")->where("id",$item->creator)->value("nickname");
  162. $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
  163. if ($red) {
  164. if ($red["detail"] || $red["comment"] || $red["report"] || $red["record"] || $red["user"] || $red["contact"]) {
  165. $item->red = 1;
  166. }
  167. } else {
  168. $item->red = 0;
  169. }
  170. $entrust_head_id = Db::name('department')->where(['id' => $item->entrust_unit])->value('leader_id');
  171. if (!($item->entrust_head_phone)) {
  172. $item->entrust_head_phone = Db::name('admin')->where("id", $entrust_head_id)->value("mobile");
  173. }
  174. if ( ($item->province&&$item->city&&$item->area)) {
  175. $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
  176. }
  177. //作业人
  178. $item->operate_name = Db::name("admin")->where("id", $item->operate_head)->value("nickname");
  179. $operate_team_names = null;
  180. // halt($item->operate_team);
  181. //只有一个人会报错
  182. // dump($item->operate_team);
  183. $aaa = isset($item->operate_team) ? $item->operate_team : "0";
  184. // dump($aaa);
  185. // $aaa = isset($param['id']) ? $param['id'] : 0;
  186. $operate_team_names_ids = explode(",", $aaa);
  187. for ($i = 0; $i < count($operate_team_names_ids); $i++) {
  188. $name = Db::name("admin")->where("id", $operate_team_names_ids[$i])->value("nickname");
  189. if (!($i == 0)) {
  190. $name = "," . $name;
  191. }
  192. $operate_team_names = $operate_team_names . $name;
  193. }
  194. $item->operate_team_names = $operate_team_names;
  195. });
  196. }else{
  197. $list = $this->model
  198. ->where($where)->where($where3)
  199. ->order($order)->paginate($rows, false, ['query' => $param])
  200. ->each(function ($item) {
  201. $item->creator = Db::name("admin")->where("id",$item->creator)->value("nickname");
  202. $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
  203. if ($red) {
  204. if ($red["detail"] || $red["comment"] || $red["report"] || $red["record"] || $red["user"] || $red["contact"]) {
  205. $item->red = 1;
  206. }
  207. } else {
  208. $item->red = 0;
  209. }
  210. $entrust_head_id = Db::name('department')->where(['id' => $item->entrust_unit])->value('leader_id');
  211. if (!($item->entrust_head_phone)) {
  212. $item->entrust_head_phone = Db::name('admin')->where("id", $entrust_head_id)->value("mobile");
  213. }
  214. if ( ($item->province&&$item->city&&$item->area)) {
  215. $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
  216. }
  217. $item->self_id = $this->see_auth;
  218. //作业人
  219. $item->operate_name = Db::name("admin")->where("id", $item->operate_head)->value("nickname");
  220. $operate_team_names = null;
  221. // halt($item->operate_team);
  222. //只有一个人会报错
  223. // dump($item->operate_team);
  224. $aaa = isset($item->operate_team) ? $item->operate_team : "0";
  225. // dump($aaa);
  226. // $aaa = isset($param['id']) ? $param['id'] : 0;
  227. $operate_team_names_ids = explode(",", $aaa);
  228. for ($i = 0; $i < count($operate_team_names_ids); $i++) {
  229. $name = Db::name("admin")->where("id", $operate_team_names_ids[$i])->value("nickname");
  230. if (!($i == 0)) {
  231. $name = "," . $name;
  232. }
  233. $operate_team_names = $operate_team_names . $name;
  234. }
  235. $item->operate_team_names = $operate_team_names;
  236. });
  237. }
  238. return table_assign(0, '', $list);
  239. } else {
  240. $field = $this->Field->get_field_rules_New($this->uid);
  241. $fields = [];
  242. foreach ($field as $k=>$v){
  243. if($v!=1){
  244. $fields[$k] = true;
  245. }else{
  246. $fields[$k] = false;
  247. }
  248. }
  249. // halt( json_encode($fields));
  250. View::assign('field', $fields);
  251. return view();
  252. }
  253. }
  254. /**
  255. * 首页临期数据列表
  256. */
  257. public function list1(){
  258. $param = get_params();
  259. $inarr = array();
  260. $review_unit = $this->model->where("review_unit", get_login_admin("unit_name"))->field('id,review_head,operate_head,operate_team')->select()->toArray();
  261. for ($i = 0; $i < count($review_unit); $i++) {
  262. $a = $review_unit[$i];
  263. $ids = $a["review_head"] . ',' . $a["operate_head"] . ',' . $a["operate_team"];
  264. $ids = explode(",", $ids);
  265. $c = in_array($this->uid, $ids);
  266. if ($c) {
  267. $inarr[] = $a["id"];
  268. }
  269. }
  270. $where = [
  271. ["cp_cost_project.delete_time", "=", 0],
  272. ["project_status", ">", 4],
  273. ["project_status", "<", 7],
  274. ['project_end_time', '<', strtotime('15 days')],
  275. ['project_end_time', '>', time()],
  276. ];
  277. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  278. $order = empty($param['order']) ? 'id desc' : $param['order'];
  279. $list = $this->model
  280. ->where($where)->whereIn("id", $inarr)->order($order)
  281. ->paginate(9999, false, ['query' => $param])
  282. ->each(function ($item) {
  283. });
  284. return table_assign(0, '', $list);
  285. }
  286. /**
  287. * 首页逾期数据列表
  288. */
  289. public function list2(){
  290. $param = get_params();
  291. $inarr = array();
  292. $review_unit = $this->model->where("review_unit", get_login_admin("unit_name"))->field('id,review_head,operate_head,operate_team')->select()->toArray();
  293. for ($i = 0; $i < count($review_unit); $i++) {
  294. $a = $review_unit[$i];
  295. $ids = $a["review_head"] . ',' . $a["operate_head"] . ',' . $a["operate_team"];
  296. $ids = explode(",", $ids);
  297. $c = in_array($this->uid, $ids);
  298. if ($c) {
  299. $inarr[] = $a["id"];
  300. }
  301. }
  302. $where = [
  303. ["cp_cost_project.delete_time", "=", 0],
  304. ["project_status", ">=", 4],
  305. ["project_status", "<=", 7],
  306. ['project_end_time', '<', time()],
  307. ];
  308. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  309. $order = empty($param['order']) ? 'id desc' : $param['order'];
  310. $list = $this->model
  311. ->where($where)->whereIn("id", $inarr)
  312. ->order($order)
  313. ->paginate(9999, false, ['query' => $param])
  314. ->each(function ($item) {
  315. });;
  316. return table_assign(0, '', $list);
  317. }
  318. /**
  319. * 公司建立项目
  320. */
  321. public function add(){
  322. if (request()->isAjax()) {
  323. $param = get_params();
  324. if (isset($param["project_start_time"])) {
  325. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  326. }
  327. if (isset($param["project_end_time"])) {
  328. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  329. }
  330. $param["review_unit"] = get_login_admin("unit_name");
  331. $param["review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
  332. $param["review_head"] = $this->uid;
  333. $param["review_head_name"] = get_login_admin("nickname");
  334. $param["review_head_phone"] = get_login_admin("mobile");
  335. $param["project_status"] = 4;
  336. $param["maker_type"] = 2;
  337. $param["creator"] = $this->uid;
  338. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  339. unset($param["file_ids"]);
  340. $file_id = [];
  341. $insertId = 0;
  342. try {
  343. $param['create_time'] = time();
  344. $insertId = $this->model->strict(false)->field(true)->insertGetId($param);
  345. if ($file_ids) {
  346. for ($a = 0; $a < count($file_ids); $a++) {
  347. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertId];
  348. }
  349. $this->filemodel->saveAll($file_id);
  350. }
  351. add_log('add', $insertId, $param);
  352. add_project_log("创建项目", $insertId, "创建项目");
  353. add_user($param["review_head"], $insertId);
  354. } catch (\Exception $e) {
  355. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  356. }
  357. return to_assign(0, '操作成功', ['aid' => $insertId]);
  358. }else{
  359. return view();
  360. }
  361. }
  362. public function save()
  363. {
  364. if (request()->isAjax()) {
  365. $param = get_params();
  366. // 检验完整性
  367. try {
  368. validate(CostProjectValidate::class)->check($param);
  369. } catch (ValidateException $e) {
  370. // 验证失败 输出错误信息
  371. return to_assign(1, $e->getError());
  372. }
  373. if (isset($param["plan_time"])) {
  374. $param["plan_time"] = $param["plan_time"] ? strtotime($param["plan_time"]) : 0;
  375. }
  376. if (isset($param["due_time"])) {
  377. $param["due_time"] = $param["due_time"] ? strtotime($param["due_time"]) : 0;
  378. }
  379. $param = array_merge($param, ["status" => 6]);
  380. // halt($param);
  381. $this->model->editCostProject($param);
  382. }
  383. }
  384. /**
  385. * 编辑
  386. */
  387. public function edit()
  388. {
  389. $param = get_params();
  390. $param["type"] = isset($param["type"]) ? $param["type"] : 0;
  391. if (request()->isAjax()) {
  392. // 检验完整性
  393. // try {
  394. // validate(CostProjectValidate::class)->check($param);
  395. // } catch (ValidateException $e) {
  396. // // 验证失败 输出错误信息
  397. // return to_assign(1, $e->getError());
  398. // }
  399. if (isset($param["project_start_time"])) {
  400. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  401. }
  402. if (isset($param["project_end_time"])) {
  403. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  404. }
  405. if ($param["type"] == 2) {
  406. $id = isset($param['id']) ? $param['id'] : 0;
  407. $project_status = $this->model->where("id", $id)->value("project_status");
  408. //判断当前状态是否是可编辑状态
  409. $detail = $this->model->getCostProjectById($id);
  410. $file_array = Db::name('ProjectFile')
  411. ->field('mf.id,mf.topic_id,mf.admin_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.nickname as admin_name')
  412. ->alias('mf')
  413. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  414. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  415. ->order('mf.create_time desc')
  416. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  417. ->select()->toArray();
  418. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  419. $comment = Db::name("project_comment")->where("type",$comment_type)
  420. ->where("project_id", $id)->order('create_time', 'asc')->select();
  421. $project_log = self::project_log($id);
  422. // halt($project_log);
  423. View::assign('project_log', $project_log);
  424. $field = $this->Field->get_field_rules_new($this->uid);
  425. $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
  426. //剩余时间
  427. $c = $detail['project_end_time']-time();
  428. if($c>0){
  429. $advent_time = floor($c / 86400)."天";
  430. }else{
  431. $c = -$c;
  432. $advent_time = floor($c / 86400)."天";
  433. }
  434. if (!empty($detail)) {
  435. View::assign('advent_time', $advent_time);
  436. View::assign('detail', $detail);
  437. View::assign('file_array', $file_array);
  438. View::assign('comment', $comment);
  439. View::assign('field', $field);
  440. View::assign('field_edit', $field_edit);
  441. View::assign('project_five', self::getProjectFive());
  442. return view();
  443. } else {
  444. throw new \think\exception\HttpException(404, '找不到页面');
  445. }
  446. }
  447. $field_name = array_keys($this->field_name);
  448. $ab= $this->model->where("id",$param["id"])->field($field_name)->find()->toArray();
  449. $c = array_intersect_key($param,$ab);
  450. $maker_name = get_login_admin("nickname");
  451. $content = '';
  452. // $a = [];
  453. foreach ($c as $key => $value) {
  454. if($c[$key]!==$ab[$key]){
  455. // $a[]=$c[$key];
  456. // $a[]=$ab[$key];
  457. $ab[$key] = !empty($ab[$key])?$ab[$key]:"无";
  458. $value = !empty($value)?$value:"无";
  459. $content = $content . $this->field_name[$key]."从".$ab[$key]."修改为".$value.",";
  460. }
  461. }
  462. // halt($a);
  463. $content =rtrim($content ,",");
  464. if(!empty($content)){
  465. $content = $maker_name."将".$content;
  466. }else{
  467. $content = "无修改";
  468. }
  469. add_project_log('编辑项目', $param['id'],$content,1);
  470. $this->model->editCostProject($param);
  471. } else {
  472. $id = isset($param['id']) ? $param['id'] : 0;
  473. $project_status = $this->model->where("id", $id)->value("project_status");
  474. //判断当前状态是否是可编辑状态
  475. // if ($project_status == 5) {
  476. $detail = $this->model->getCostProjectById($id);
  477. $file_array = Db::name('ProjectFile')
  478. ->field('mf.id,mf.topic_id,mf.admin_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.nickname as admin_name')
  479. ->alias('mf')
  480. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  481. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  482. ->order('mf.create_time desc')
  483. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  484. ->select()->toArray();
  485. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  486. $comment = Db::name("project_comment")->where("type",$comment_type)
  487. ->where("project_id", $id)->order('create_time', 'asc')->select();
  488. $project_log = self::project_log($id);
  489. // halt($file_array);
  490. View::assign('project_log', $project_log);
  491. $field = $this->Field->get_field_rules_new($this->uid);
  492. $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
  493. //剩余时间
  494. $c = $detail['project_end_time']-time();
  495. if($c>0){
  496. $advent_time = floor($c / 86400)."天";
  497. }else{
  498. $c = -$c;
  499. $advent_time = floor($c / 86400)."天";
  500. }
  501. $red = Db::name("new_msg")->where([["uid",'=',$this->uid],["project_id","=",$id]])->field('detail,comment,record,report,user,contact')->find();
  502. if(empty($red)){
  503. $red = ["detail"=>0,"comment"=>0,"record"=>0,"report"=>0,"user"=>0,"contact"=>0];
  504. }
  505. if (!empty($detail)) {
  506. View::assign('advent_time', $advent_time);
  507. View::assign('red', $red);
  508. View::assign('detail', $detail);
  509. View::assign('file_array', $file_array);
  510. View::assign('comment', $comment);
  511. View::assign('project_five', self::getProjectFive());
  512. View::assign('field', $field);
  513. View::assign('field_edit', $field_edit);
  514. return view();
  515. } else {
  516. throw new \think\exception\HttpException(404, '找不到页面');
  517. }
  518. }
  519. }
  520. /**
  521. * 归档
  522. */
  523. public function finish()
  524. {
  525. $param = get_params();
  526. $handle = $this->Pushmessage->handleParam($param);
  527. $param = $handle['param'];
  528. $id = isset($param['id']) ? $param['id'] : 0;
  529. $approver_name = $this->model->where("id", $id)->value("entrust_maker");
  530. $auditData = [
  531. "project_id" => $param["id"],
  532. "project_name" => $this->model->where("id", $id)->value('project_name'),
  533. "project_type" => "造价项目",
  534. "audit_name" => "申请归档审核",
  535. "audit_type" => 1,
  536. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  537. "sponsor_id" => $this->uid,
  538. "sponsor_unit" => Db::name("department")->where("id", get_login_admin("unit_name"))->value("title"),
  539. "approver" => $approver_name,
  540. "approver_name" => Db::name('admin')->where("id", $approver_name)->value("nickname"),
  541. "remark" => $param["finish_reason"],
  542. "create_time" => time()
  543. ];
  544. ProjectAudit::create($auditData);
  545. $this->model->where("id", $id)->update(["project_status" => 6]);
  546. if(empty($handle['financial'])){
  547. $handle['financial'] = (array)$approver_name;
  548. }else{
  549. $handle['financial'] = array_merge($handle['financial'],(array)$approver_name);
  550. }
  551. add_project_log("归档审批", $id,"归档审批");
  552. $this->Pushmessage->pushMessage($id, $handle['financial'], $handle['company']);
  553. return to_assign(0, "操作成功");
  554. }
  555. /**
  556. * 退审
  557. */
  558. public function dismissal()
  559. {
  560. $param = get_params();
  561. $handle = $this->Pushmessage->handleParam($param);
  562. $param = $handle['param'];
  563. $id = isset($param['id']) ? $param['id'] : 0;
  564. if (empty($param["dismissal_reason"])) {
  565. return to_assign(0, "退审原因不能为空");
  566. } else {
  567. $approver_name = $this->model->where("id", $id)->value("entrust_maker");
  568. $auditData = [
  569. "project_id" => $param["id"],
  570. "project_name" => $this->model->where("id", $id)->value('project_name'),
  571. "project_type" => "造价项目",
  572. "audit_name" => "申请退审审核",
  573. "audit_type" => 1,
  574. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  575. "sponsor_id" => $this->uid,
  576. "sponsor_unit" => Db::name("department")->where("id", get_login_admin("unit_name"))->value("title"),
  577. "approver" => $approver_name,
  578. "approver_name" => Db::name('admin')->where("id", $approver_name)->value("nickname"),
  579. "remark" => $param["dismissal_reason"],
  580. "create_time" => time()
  581. ];
  582. // halt($auditData);
  583. ProjectAudit::create($auditData);
  584. $this->model->where("id", $id)->update(["project_status" => 7]);
  585. add_project_log("退审审批", $id,"退审审批");
  586. if(empty($handle['financial'])){
  587. $handle['financial'] = (array)$approver_name;
  588. }else{
  589. $handle['financial'] = array_merge($handle['financial'],(array)$approver_name);
  590. }
  591. $this->Pushmessage->pushMessage($id, $handle['financial'], $handle['company']);
  592. return to_assign(0, "操作成功");
  593. }
  594. }
  595. /**
  596. * 查看信息
  597. */
  598. public function read()
  599. {
  600. $param = get_params();
  601. $id = isset($param['id']) ? $param['id'] : 0;
  602. $detail = $this->model->getCostProjectById($id);
  603. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  604. $comment = Db::name("project_comment")->where("type",$comment_type)
  605. ->where("project_id", $id)->order('create_time', 'asc')->select();
  606. $file_array = Db::name('ProjectFile')
  607. ->field('mf.id,mf.topic_id,mf.admin_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.nickname as admin_name')
  608. ->alias('mf')
  609. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  610. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  611. ->order('mf.create_time desc')
  612. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  613. ->select()->toArray();
  614. $report = Db::name("project_report")->where([["project_id", "=", $id], ["r.status", "=", 1]])->alias("r")->join("admin a", "r.maker_id = a.id")->field("r.*,a.nickname")->select();
  615. $uid = Db::name("relation")->where("uuid",$id)->column("uid");
  616. $contract = Db::name("contract")->whereIn("id",$uid)
  617. ->where("subject_id",get_login_admin("unit_name"))->column("id,name,type,sign_time,sign_name");
  618. $project_log = self::project_log($id);
  619. View::assign('project_log', $project_log);
  620. $field = $this->Field->get_field_rules_new($this->uid);
  621. $red = Db::name("new_msg")->where([["uid",'=',$this->uid],["project_id","=",$id]])->field('detail,comment,record,report,user,contact')->find();
  622. if(empty($red)){
  623. $red = ["detail"=>0,"comment"=>0,"record"=>0,"report"=>0,"user"=>0,"contact"=>0];
  624. }
  625. //剩余时间
  626. $c = $detail['project_end_time']-time();
  627. if($c>0){
  628. $advent_time = floor($c / 86400)."天";
  629. }else{
  630. $c = -$c;
  631. $advent_time = floor($c / 86400)."天";
  632. }
  633. // dump($field);
  634. if (!empty($detail)) {
  635. View::assign('advent_time', $advent_time);
  636. View::assign('detail', $detail);
  637. View::assign('project_id', $id);
  638. View::assign('comment', $comment);
  639. View::assign('contract', $contract);
  640. View::assign('file_array', $file_array);
  641. View::assign('report', $report);
  642. View::assign('field', $field);
  643. View::assign('red', $red);
  644. View::assign('project_five', self::getProjectFive());
  645. return view();
  646. } else {
  647. throw new \think\exception\HttpException(404, '找不到页面');
  648. }
  649. }
  650. //获取客户列表
  651. public function get_customer()
  652. {
  653. $param = get_params();
  654. $where = array();
  655. if (!empty($param['keywords'])) {
  656. $where[] = ['id|name', 'like', '%' . $param['keywords'] . '%'];
  657. }
  658. $where[] = ['delete_time', '=', 0];
  659. $where[] = ['status', '=', 1];
  660. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  661. $list = Db::name('institution')->where('institution_type', 1)->field('id,institution,address')->order('id asc')->where($where)->paginate($rows, false);
  662. table_assign(0, '', $list);
  663. }
  664. //添加附件
  665. public function add_file()
  666. {
  667. $param = get_params();
  668. $param['create_time'] = time();
  669. $param['admin_id'] = $this->uid;
  670. $fid = Db::name('project_file')->strict(false)->field(true)->insertGetId($param);
  671. }
  672. //删除
  673. public function delete_file()
  674. {
  675. if (request()->isDelete()) {
  676. $id = get_params("id");
  677. $detail = Db::name('ProjectFile')->where('id', $id)->find();
  678. if (Db::name('ProjectFile')->where('id', $id)->delete() !== false) {
  679. return to_assign(0, "删除成功");
  680. } else {
  681. return to_assign(0, "删除失败");
  682. }
  683. } else {
  684. return to_assign(1, "错误的请求");
  685. }
  686. }
  687. public function project_log($project_id)
  688. {
  689. // $project_id = 24;
  690. $login_admin = get_login_admin();
  691. $where = array();
  692. if ($login_admin['user_type'] == 2) {
  693. $where = [
  694. ['project_status', '>=', 3],
  695. ['unit_name', '=', $login_admin['unit_name']],
  696. ];
  697. } else {
  698. if ($login_admin['permission'] != 1) {
  699. $where = [
  700. ['unit_name', '=', $login_admin['unit_name']],
  701. ];
  702. }
  703. }
  704. // dump($where);
  705. $project_log = Db::name('ProjectLog')->where($where)
  706. ->where('project_id', $project_id)
  707. ->order('create_time', 'desc')
  708. ->select()->toArray();
  709. // foreach ($project_log as $key => $value) {
  710. // $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
  711. // if($login_admin['user_type'] != 0){
  712. // if(str($project_log[$key]['content'], '送审单位承担审核费')){
  713. // unset($project_log[$key]);
  714. // }
  715. // if(str($project_log[$key]['content'], '施工单位负责核减超5%评审费部分')){
  716. // unset($project_log[$key]);
  717. // }
  718. // }
  719. // }
  720. // dump($project_log);
  721. // View::assign('project_log', $project_log);
  722. // return View();
  723. return $project_log;
  724. }
  725. public function project_user()
  726. {
  727. $param = get_params();
  728. $ids = $this->model->where("id", $param["project_id"])->field("entrust_maker,review_head,operate_head,operate_team")->find()->toArray();
  729. $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"] . ',' . $ids["entrust_maker"];
  730. $idarr = explode(",", $idarr);
  731. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  732. $list = $this->Adminmodel->whereIn("id", $idarr)->field("id,nickname,unit_name,mobile")->paginate($rows, false, ['query' => $param])
  733. ->each(function ($item) {
  734. //获取单位的邮箱,单位信息页没做
  735. $item->email = Db::name('department')->where(['id' => $item->unit_name])->value('email');
  736. $type = Db::name('department')->where(['id' => $item->unit_name])->value('type');
  737. $item->unit_name = Db::name('department')->where(['id' => $item->unit_name])->value('title');
  738. // dump($type);
  739. if ($type == 0) {
  740. $item->unit_type = "委托单位";
  741. } elseif ($type == 1) {
  742. $item->unit_type = "送审单位";
  743. } elseif ($type == 2) {
  744. $item->unit_type = "评审机构";
  745. }
  746. })->toArray();
  747. $list = $list["data"];
  748. $shigong = $this->model->where('id', $param["project_id"])->find();
  749. $time_id_sent = time()-200;
  750. if ($shigong["sent_review_unit"] !== null ||
  751. $shigong["sent_review_head"] !== null ||
  752. $shigong["sent_review_phone"] !== null ||
  753. $shigong["sent_review_head_email"] !== null
  754. ) {
  755. $sent_review_data["id"] = $time_id_sent;
  756. $sent_review_data["nickname"] = $shigong["sent_review_head_name"];
  757. $sent_review_data["unit_name"] = $shigong["sent_review_unit_name"];
  758. $sent_review_data["email"] = $shigong["sent_review_head_email"];
  759. $sent_review_data["mobile"] = $shigong["sent_review_phone"];
  760. $sent_review_data["unit_type"] = "送审单位";
  761. array_push($list, $sent_review_data);
  762. }
  763. if(empty($ids['operate_team'])){
  764. $operate_team[] = '0';
  765. }else{
  766. $operate_team = explode(',', $ids['operate_team']);
  767. }
  768. for ($i = 0; $i < count($list); $i++) {
  769. if ($list[$i]['id'] == $ids['entrust_maker']) {
  770. // dump($list[$i]['id'],$ids['entrust_maker']);
  771. $list[$i]["type"] = 1;
  772. } elseif ($list[$i]['id'] == $ids['review_head']) {
  773. $list[$i]["type"] = 2;
  774. } elseif ($list[$i]['id'] == $ids['operate_head']) {
  775. $list[$i]["type"] = 3;
  776. } elseif (in_array($list[$i]['id'], $operate_team)) {
  777. $list[$i]["type"] = 4;
  778. } elseif ($list[$i]['id'] !== time() - 1000) {
  779. $list[$i]["type"] = 6;
  780. }
  781. }
  782. $type = array_column($list, 'type');
  783. array_multisort($type, SORT_ASC, $list);
  784. $lists["total"] = count($list);
  785. $lists["data"] = $list;
  786. return table_assign(0, '', $lists);
  787. }
  788. // 财政局接口
  789. public function remove_user()
  790. {
  791. $param = get_params();
  792. if ($param["type"] == 3) {
  793. $this->model->where("id", $param["project_id"])->update(["operate_head" => 0]);
  794. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  795. add_project_log("移除项目负责人",$param["project_id"],$name,5);
  796. remove_user($param["id"]);
  797. return to_assign(0, '操作成功');
  798. }
  799. if ($param["type"] == 4) {
  800. $idarr = $this->model->where("id", $param["project_id"])->value("operate_team");
  801. $idarr = explode(",", $idarr);
  802. $key = array_search($param["id"], $idarr);
  803. unset($idarr[$key]);
  804. $str = implode(',', $idarr);
  805. $this->model->where("id", $param["project_id"])->update(["operate_team" => $str]);
  806. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  807. remove_user($param["id"]);
  808. add_project_log("移除项目成员",$param["project_id"],$name,5);
  809. return to_assign(0, '操作成功');
  810. }
  811. return to_assign(0, '操作失败');
  812. }
  813. // 公司接口
  814. public function remove_user_company()
  815. {
  816. $param = get_params();
  817. if ($param["type"] == 3) {
  818. $this->model->where("id", $param["project_id"])->update(["operate_head" => 0,"operate_head_name"=>null]);
  819. $operate_team = $this->model->where("id", $param["project_id"])->value("operate_team");
  820. if(empty($operate_team)){
  821. $this->model->where("id", $param["project_id"])->update(["project_status" => 4]);
  822. }
  823. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  824. $content = get_login_admin("nickname")."移除了作业负责人".$name;
  825. add_project_log("移除项目负责人",$param["project_id"],$content,5);
  826. remove_user($param["id"]);
  827. return to_assign(0, '操作成功');
  828. }
  829. if ($param["type"] == 4) {
  830. $idarr = $this->model->where("id", $param["project_id"])->value("operate_team");
  831. $idarr = explode(",", $idarr);
  832. $key = array_search($param["id"], $idarr);
  833. unset($idarr[$key]);
  834. $str = implode(',', $idarr);
  835. $this->model->where("id", $param["project_id"])->update(["operate_team" => $str]);
  836. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  837. $operate_head = $this->model->where("id", $param["project_id"])->value("operate_head");
  838. if($operate_head==0&&empty($str)){
  839. $this->model->where("id", $param["project_id"])->update(["project_status" => 4]);
  840. }
  841. add_project_log("移除项目成员",$param["project_id"],$name,5);
  842. remove_user($param["id"]);
  843. return to_assign(0, '操作成功');
  844. }
  845. return to_assign(0, '操作失败');
  846. }
  847. // 公司接口
  848. public function add_company_user()
  849. {
  850. //都没做原来就有的校验
  851. $param = get_params();
  852. if ($param["type"] == 1) {
  853. $a=$this->model->where("id", $param["project_id"])->value("operate_head");
  854. if($a){
  855. return to_assign(1, '已有负责人,请移除后再添加');
  856. }
  857. $b=$this->model->where("id", $param["project_id"])->value("review_head");
  858. if($b==$param["id"]){
  859. return to_assign(1, '已是评审单位负责人,请移除后再添加');
  860. }
  861. $c = $this->model->where("id", $param["project_id"])->value("operate_team");
  862. if($c){
  863. $c = explode(",", $c);
  864. if(in_array($param["id"],$c)){
  865. return to_assign(1, '已是作业成员,不可再添加');
  866. }
  867. }
  868. $this->model->where("id", $param["project_id"])->update(["operate_head" => $param["id"],"project_status" => 5]);
  869. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  870. add_user($param["id"],$param["project_id"]);
  871. add_project_log("新增了作业负责人",$param["project_id"],$name,5);
  872. return to_assign(0, '操作成功');
  873. } elseif ($param["type"] == 2) {
  874. $a=$this->model->where("id", $param["project_id"])->value("sent_review_head");
  875. if($a){
  876. return to_assign(1, '已有负责人,请移除后再添加');
  877. }
  878. $data=[
  879. "sent_review_unit" =>get_admin($param["id"])["unit_name"],
  880. "sent_review_unit_name" =>Db::name("department")->where("id",get_admin($param["id"])["unit_name"])->value("title"),
  881. "sent_review_head" => $param["id"],
  882. "sent_review_head_name" => get_admin($param["id"])["nickname"],
  883. "sent_review_phone"=>get_admin($param["id"])["mobile"]
  884. ];
  885. $this->model->where('id', $param["project_id"])->update($data);
  886. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  887. add_user($param["id"],$param["project_id"]);
  888. add_project_log("新增了送审单位负责人",$param["project_id"],$name,5);
  889. return to_assign(0, "操作成功");
  890. }
  891. }
  892. // 财政局接口
  893. public function add_user()
  894. {
  895. $param = get_params();
  896. if ($param["type"] == 1) {
  897. $a=$this->model->where("id", $param["project_id"])->value("operate_head");
  898. if($a){
  899. return to_assign(1, '已有负责人,请移除后再添加');
  900. }
  901. $b=$this->model->where("id", $param["project_id"])->value("review_head");
  902. if($b==$param["id"]){
  903. return to_assign(1, '已是评审单位负责人,请移除后再添加');
  904. }
  905. $c = $this->model->where("id", $param["project_id"])->value("operate_team");
  906. if($c){
  907. $c = explode(",", $c);
  908. if(in_array($param["id"],$c)){
  909. return to_assign(1, '已是作业成员,不可再添加');
  910. }
  911. }
  912. $this->model->where("id", $param["project_id"])->update(["operate_head" => $param["id"]]);
  913. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  914. add_user($param["id"],$param["project_id"]);
  915. add_project_log("新增了作业负责人",$param["project_id"],$name,5);
  916. return to_assign(0, '操作成功');
  917. } elseif ($param["type"] == 2) {
  918. $a=$this->model->where("id", $param["project_id"])->value("sent_review_head");
  919. if($a){
  920. return to_assign(1, '已有负责人,请移除后再添加');
  921. }
  922. $data=[
  923. "sent_review_unit" =>get_admin($param["id"])["unit_name"],
  924. "sent_review_unit_name" =>Db::name("department")->where("id",get_admin($param["id"])["unit_name"])->value("title"),
  925. "sent_review_head" => $param["id"],
  926. "sent_review_head_name" => get_admin($param["id"])["nickname"],
  927. "sent_review_phone"=>get_admin($param["id"])["mobile"]
  928. ];
  929. $this->model->where('id', $param["project_id"])->update($data);
  930. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  931. add_project_log("新增了送审单位负责人",$param["project_id"],$name,5);
  932. add_user($param["id"],$param["project_id"]);
  933. return to_assign(0, "操作成功");
  934. }
  935. }
  936. public function add_user_company_head(){
  937. $param = get_params();
  938. $handle = $this->Pushmessage->handleParam($param);
  939. $param = $handle['param'];
  940. $a=$this->model->where("id", $param["project_id"])->value("review_head");
  941. if($a){
  942. return to_assign(1, '已有联系人,请移除后再添加');
  943. }
  944. $a=$this->model->where("id", $param["project_id"])->field("operate_head,operate_team")->find();
  945. $b = $a["operate_head"];
  946. if($b==$param["id"]){
  947. return to_assign(1, '已是作业负责人,请移除后再添加');
  948. }
  949. $c = $a["operate_team"];
  950. if($c){
  951. $c = explode(",", $c);
  952. if(in_array($param["id"],$c)){
  953. return to_assign(1, '已是作业成员,不可再添加');
  954. }
  955. }
  956. $name = Db::name("admin")->where("id",$param["id"])->field("nickname,mobile")->find();
  957. $this->model->where("id", $param["project_id"])->update(["review_head" => $param["id"],"review_head_name"=>$name["nickname"],"review_head_phone"=>$name["mobile"]]);
  958. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], (array)$param['id']);
  959. add_project_log("新增项目成员",$param["project_id"],$name["nickname"],5);
  960. add_user($param["id"],$param["project_id"]);
  961. return to_assign(0, '操作成功');
  962. }
  963. // 公司接口
  964. public function add_user_company_type1()
  965. {
  966. $param = get_params();
  967. $handle = $this->Pushmessage->handleParam($param);
  968. $param = $handle['param'];
  969. if ($param["type"] == 1) {
  970. $a=$this->model->where("id", $param["project_id"])->value("operate_head");
  971. if($a){
  972. return to_assign(1, '已有负责人,请移除后再添加');
  973. }
  974. $a=$this->model->where("id", $param["project_id"])->field("review_head,operate_team")->find();
  975. $b = $a["review_head"];
  976. if($b==$param["id"]){
  977. return to_assign(1, '已是评审单位负责人,请移除后再添加');
  978. }
  979. $c = $a["operate_team"];
  980. if($c){
  981. $c = explode(",", $c);
  982. if(in_array($param["id"],$c)){
  983. return to_assign(1, '已是作业成员,不可再添加');
  984. }
  985. }
  986. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  987. $this->model->where("id", $param["project_id"])->update(["operate_head" => $param["id"],"project_status" => 5,"operate_head_name"=>$name]);
  988. $content = get_login_admin("nickname")."新增了作业负责人".$name;
  989. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], (array)$param['id']);
  990. add_project_log("新增项目成员",$param["project_id"],$content,5);
  991. add_user($param["id"],$param["project_id"]);
  992. return to_assign(0, '操作成功');
  993. } elseif ($param["type"] == 2) {
  994. $b=$this->model->where("id", $param["project_id"])->value("review_head");
  995. if($b==$param["id"]){
  996. return to_assign(1, '已是评审单位负责人,请移除后再添加');
  997. }
  998. $a=$this->model->where("id", $param["project_id"])->value("operate_head");
  999. if($a==$param["id"]){
  1000. return to_assign(1, '已是负责人,不可再添加');
  1001. }
  1002. $ids = $this->model->where("id", $param["project_id"])->value("operate_team");
  1003. if($ids){
  1004. $idarr = explode(",", $ids);
  1005. if(in_array($param["id"],$idarr)){
  1006. return to_assign(1, '已存在,不可再添加');
  1007. }
  1008. }
  1009. $ids = !empty($ids)?$ids:0;
  1010. if ($ids == 0) {
  1011. $ids = $param["id"];
  1012. } else {
  1013. $ids = $ids . "," . $param["id"];
  1014. }
  1015. $this->model->where('id', $param["project_id"])->update(["operate_team" => $ids,"project_status" => 5]);
  1016. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  1017. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], (array)$param['id']);
  1018. add_project_log("新增项目成员",$param["project_id"],$name,5);
  1019. add_user($param["id"],$param["project_id"]);
  1020. return to_assign(0, "操作成功");
  1021. }elseif ($param["type"] == 3) {
  1022. $a=$this->model->where("id", $param["project_id"])->value("review_head");
  1023. if($a){
  1024. return to_assign(1, '已有联系人,请移除后再添加');
  1025. }
  1026. $a=$this->model->where("id", $param["project_id"])->field("operate_head,operate_team")->find();
  1027. $b = $a["operate_head"];
  1028. if($b==$param["id"]){
  1029. return to_assign(1, '已是作业负责人,请移除后再添加');
  1030. }
  1031. $c = $a["operate_team"];
  1032. if($c){
  1033. $c = explode(",", $c);
  1034. if(in_array($param["id"],$c)){
  1035. return to_assign(1, '已是作业成员,不可再添加');
  1036. }
  1037. }
  1038. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  1039. $this->model->where("id", $param["project_id"])->update(["operate_head" => $param["id"],"operate_head_name"=>$name]);
  1040. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], (array)$param['id']);
  1041. add_project_log("新增项目成员",$param["project_id"],$name,5);
  1042. add_user($param["id"],$param["project_id"]);
  1043. return to_assign(0, '操作成功');
  1044. }
  1045. }
  1046. // 公司接口
  1047. public function add_user_company_type2()
  1048. {
  1049. $param = get_params();
  1050. $handle = $this->Pushmessage->handleParam($param);
  1051. $param = $handle['param'];
  1052. if ($param["type"] == 1) {
  1053. $a=$this->model->where("id", $param["project_id"])->value("operate_head");
  1054. if($a){
  1055. return to_assign(1, '已有负责人,请移除后再添加');
  1056. }
  1057. $b=$this->model->where("id", $param["project_id"])->value("review_head");
  1058. if($b==$param["id"]){
  1059. return to_assign(1, '已是评审单位负责人,请移除后再添加');
  1060. }
  1061. $c = $this->model->where("id", $param["project_id"])->value("operate_team");
  1062. if($c){
  1063. $c = explode(",", $c);
  1064. if(in_array($param["id"],$c)){
  1065. return to_assign(1, '已是作业成员,不可再添加');
  1066. }
  1067. }
  1068. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  1069. $this->model->where("id", $param["project_id"])->update(["operate_head" => $param["id"],"project_status" => 5,"operate_head_name"=>$name]);
  1070. $content = get_login_admin("nickname")."新增了作业负责人".$name;
  1071. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], (array)$param['id']);
  1072. add_project_log("新增项目成员",$param["project_id"],$content,5);
  1073. add_user($param["id"],$param["project_id"]);
  1074. return to_assign(0, '操作成功');
  1075. } elseif ($param["type"] == 2) {
  1076. $b=$this->model->where("id", $param["project_id"])->value("review_head");
  1077. if($b==$param["id"]){
  1078. return to_assign(1, '已是评审单位负责人,请移除后再添加');
  1079. }
  1080. $a=$this->model->where("id", $param["project_id"])->value("operate_head");
  1081. if($a==$param["id"]){
  1082. return to_assign(1, '已是作业负责人,请移除后再添加');
  1083. }
  1084. $ids = $this->model->where("id", $param["project_id"])->value("operate_team");
  1085. if($ids){
  1086. $idarr = explode(",", $ids);
  1087. if(in_array($param["id"],$idarr)){
  1088. return to_assign(1, '已存在,不可再添加');
  1089. }
  1090. }
  1091. $ids = !empty($ids)?$ids:0;
  1092. if ($ids == 0) {
  1093. $ids = $param["id"];
  1094. } else {
  1095. $ids = $ids . "," . $param["id"];
  1096. }
  1097. $this->model->where('id', $param["project_id"])->update(["operate_team" => $ids,"project_status" => 5]);
  1098. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], (array)$param['id']);
  1099. $name = Db::name("admin")->where("id",$param["id"])->value("nickname");
  1100. $content = get_login_admin("nickname")."新增了作业成员".$name;
  1101. $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], (array)$param['id']);
  1102. add_project_log("新增项目成员",$param["project_id"],$content,5);
  1103. add_user($param["id"],$param["project_id"]);
  1104. return to_assign(0, "操作成功");
  1105. }
  1106. }
  1107. public function add_entrust_people(){
  1108. if (request()->isAjax()) {
  1109. $param = get_params();
  1110. $id = isset($param["id"])?$param["id"]:0;
  1111. $project_id = isset($param["project_id"])?$param["project_id"]:0;
  1112. $selfData = get_admin($id);
  1113. $data = [
  1114. "id" => $project_id,
  1115. "entrust_maker" => $id,
  1116. "entrust_maker_name" => $selfData["nickname"],
  1117. "entrust_unit" => $selfData["unit_name"],
  1118. "entrust_unit_name" => Db::name("department")->where("id",$selfData["unit_name"])->value("title")
  1119. ];
  1120. try{
  1121. $this->model->update($data);
  1122. } catch (\Exception $e) {
  1123. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  1124. }
  1125. return to_assign(0, "操作成功");
  1126. }
  1127. }
  1128. public function add_sent_review_unit()
  1129. {
  1130. if (request()->isAjax()) {
  1131. $param = get_params();
  1132. if ($param['type'] == '1') {
  1133. $data = $this->model->where('id', $param['data']['id'])->find();
  1134. if ($data["sent_review_unit_name"] !== null ||
  1135. $data["sent_review_head_name"] !== null ||
  1136. $data["sent_review_head_email"] !== null ||
  1137. $data["sent_review_phone"] !== null
  1138. ) {
  1139. return to_assign(0, "已存在,请移除后再添加");
  1140. } else {
  1141. return to_assign(200, "请上传!!");
  1142. }
  1143. } else {
  1144. add_project_log('移除送审单位成员', $param['data']['id'], $param['data']["sent_review_head_name"], 5);
  1145. $this->model->addConstructionPeople($param['data']);
  1146. }
  1147. } else {
  1148. $param = get_params();
  1149. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1150. //关联项目id
  1151. View::assign('project_id', $project_id);
  1152. return view();
  1153. }
  1154. }
  1155. /*public function add_sent_review_unit()
  1156. {
  1157. if (request()->isAjax()) {
  1158. $param = get_params();
  1159. $id = isset($param["id"]) ? $param["id"] : 0;
  1160. $project_id = isset($param["project_id"]) ? $param["project_id"] : 0;
  1161. $a = $this->model->where("id", $project_id)->value("sent_review_head");
  1162. if ($a) {
  1163. return to_assign(1, '已有负责人,请移除后再添加');
  1164. }
  1165. $selfData = get_admin($id);
  1166. $data = [
  1167. "id" => $project_id,
  1168. "sent_review_head" => $id,
  1169. "sent_review_head_name" => $selfData["nickname"],
  1170. "sent_review_unit" => $selfData["unit_name"],
  1171. "sent_review_unit_name" => Db::name("department")->where("id", $selfData["unit_name"])->value("title"),
  1172. "sent_review_phone" => $selfData["mobile"]
  1173. ];
  1174. try {
  1175. $this->model->update($data);
  1176. } catch (\Exception $e) {
  1177. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  1178. }
  1179. return to_assign(0, "操作成功");
  1180. }
  1181. }*/
  1182. //公司
  1183. public function remove_sent_review(){
  1184. $p = get_params();
  1185. $data = [
  1186. "sent_review_unit" => null,
  1187. "sent_review_unit_name" => null,
  1188. "sent_review_head_name" => null,
  1189. "sent_review_head" => null,
  1190. "sent_review_phone" => null,
  1191. "sent_review_head_email" => null,
  1192. ];
  1193. $this->model->where("id",$p["project_id"])->update($data);
  1194. remove_user($p["id"]);
  1195. add_project_log('移除送审单位成员',$p["project_id"],$p["nickname"],5);
  1196. return to_assign(0,"操作成功");
  1197. }
  1198. //公司
  1199. public function remove_review_head(){
  1200. $p = get_params();
  1201. $data = [
  1202. "review_head" => null,
  1203. "review_head_name" => null,
  1204. "review_head_phone" => null,
  1205. ];
  1206. $this->model->where("id",$p["project_id"])->update($data);
  1207. $name= Db::name("admin")->where("id",$p["id"])->value("nickname");
  1208. remove_user($p["id"]);
  1209. add_project_log('移除送审单位成员',$p["project_id"],$name,5);
  1210. return to_assign(0,"操作成功");
  1211. }
  1212. public function get_department_tree()
  1213. {
  1214. $unit_id = get_unit(get_login_admin("unit_name"));
  1215. $department = Db::name('Department')->where(['status' => 1])->select()->toArray();
  1216. $list = get_tree($department, 0, 2);
  1217. $data['trees'] = $list;
  1218. $result = null;
  1219. for ($i = 0; $i < count($data['trees']); $i++) {
  1220. $point = $data['trees'][$i];
  1221. if ($point["id"] == $unit_id) {
  1222. $result['trees'][] = $point;
  1223. break;
  1224. }
  1225. }
  1226. // halt($result);
  1227. return json($result);
  1228. }
  1229. //获取子部门所有员工
  1230. public function get_employee()
  1231. {
  1232. $did = get_params('did');
  1233. if ($did == 1) {
  1234. $department = $did;
  1235. } else {
  1236. $department = get_department_son(get_login_admin("unit_name"));
  1237. }
  1238. // halt($department);
  1239. $employee = Db::name('admin')
  1240. ->field('a.id,a.did,a.position_id,a.mobile,a.nickname,a.status,a.thumb,a.username,d.title as department')
  1241. ->alias('a')
  1242. ->join('Department d', 'a.did = d.id')
  1243. ->where(['a.status' => 1])
  1244. ->where('a.id', ">", 1)
  1245. ->where('a.did', "in", $department)
  1246. ->select();
  1247. // $employee = $employee->map(function ($employee) {
  1248. // $employee['name'] = $employee["nickname"];
  1249. // return $employee;
  1250. // });
  1251. return to_assign(0, '', $employee);
  1252. }
  1253. public function get_yezhu_tree()
  1254. {
  1255. // $unit_id = get_unit(get_login_admin("unit_name"));
  1256. $yezhulist = Db::name('Department')->where(['status' => 1, 'type' => 1])->select()->toArray();
  1257. $list = get_tree($yezhulist, 0, 2);
  1258. $data['trees'] = $list;
  1259. return json($data);
  1260. }
  1261. //获取子部门所有员工
  1262. public function get_people($did = 1)
  1263. {
  1264. $did = get_params('did');
  1265. if ($did == 1) {
  1266. $department = $did;
  1267. } else {
  1268. $department = get_department_son($did);
  1269. }
  1270. $employee = Db::name('admin')
  1271. ->field('a.id,a.did,a.position_id,a.mobile,a.nickname,a.status,a.thumb,a.username,d.title as department')
  1272. ->alias('a')
  1273. ->join('Department d', 'a.did = d.id')
  1274. ->where(['a.status' => 1])
  1275. ->where('a.id', ">", 1)
  1276. ->where('a.did', "in", $department)
  1277. ->select();
  1278. // $employee = $employee->map(function ($employee) {
  1279. // $employee['name'] = $employee["nickname"];
  1280. // return $employee;
  1281. // });
  1282. return to_assign(0, '', $employee);
  1283. }
  1284. public function getProjectFive(){
  1285. $where = [
  1286. ['name', '=', '作业日志-公司'],
  1287. ['name', '=', '工作记录-公司'],
  1288. ['name', '=', '项目报告-公司'],
  1289. ['name', '=', '项目人员-公司'],
  1290. ['name', '=', '项目动态-公司'],
  1291. ['name', '=', '项目附件-公司'],
  1292. ['name', '=', '联系函-公司'],
  1293. ];
  1294. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  1295. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  1296. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  1297. $login_rules = explode(',', $login_rules);
  1298. $rules_id = array();
  1299. foreach($list as $key => $value){
  1300. if($value['name'] == "作业日志-公司"){
  1301. if(in_array($value['id'], $login_rules)){
  1302. $rules_id['project_comments'] = 1;
  1303. }else{
  1304. $rules_id['project_comments'] = 0;
  1305. }
  1306. }else if($value['name'] == "工作记录-公司"){
  1307. if(in_array($value['id'], $login_rules)){
  1308. $rules_id['project_record'] = 1;
  1309. }else{
  1310. $rules_id['project_record'] = 0;
  1311. }
  1312. }else if($value['name'] == "项目报告-公司"){
  1313. if(in_array($value['id'], $login_rules)){
  1314. $rules_id['project_report'] = 1;
  1315. }else{
  1316. $rules_id['project_report'] = 0;
  1317. }
  1318. }else if($value['name'] == "项目人员-公司"){
  1319. if(in_array($value['id'], $login_rules)){
  1320. $rules_id['project_user'] = 1;
  1321. }else{
  1322. $rules_id['project_user'] = 0;
  1323. }
  1324. }else if($value['name'] == "项目动态-公司"){
  1325. if(in_array($value['id'], $login_rules)){
  1326. $rules_id['project_log'] = 1;
  1327. }else{
  1328. $rules_id['project_log'] = 0;
  1329. }
  1330. }else if($value['name'] == "项目附件-公司"){
  1331. if(in_array($value['id'], $login_rules)){
  1332. $rules_id['project_file'] = 1;
  1333. }else{
  1334. $rules_id['project_file'] = 0;
  1335. }
  1336. }else if($value['name'] == "联系函-公司"){
  1337. if(in_array($value['id'], $login_rules)){
  1338. $rules_id['project_contact'] = 1;
  1339. }else{
  1340. $rules_id['project_contact'] = 0;
  1341. }
  1342. }
  1343. }
  1344. return $rules_id;
  1345. }
  1346. public function ceshi($id)
  1347. {
  1348. View::assign('detailId', $id);
  1349. return view();
  1350. }
  1351. }