CostCompany.php 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664
  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. $param = get_params();
  1109. $handle = $this->Pushmessage->handleParam($param);
  1110. $param = $handle['param'];
  1111. if (request()->isAjax()) {
  1112. $param = get_params();
  1113. $id = isset($param["id"])?$param["id"]:0;
  1114. $project_id = isset($param["project_id"])?$param["project_id"]:0;
  1115. $selfData = get_admin($id);
  1116. $data = [
  1117. "id" => $project_id,
  1118. "entrust_maker" => $id,
  1119. "entrust_maker_name" => $selfData["nickname"],
  1120. "entrust_unit" => $selfData["unit_name"],
  1121. "entrust_unit_name" => Db::name("department")->where("id",$selfData["unit_name"])->value("title")
  1122. ];
  1123. try{
  1124. $this->model->update($data);
  1125. } catch (\Exception $e) {
  1126. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  1127. }
  1128. return to_assign(0, "操作成功");
  1129. }
  1130. }
  1131. public function add_sent_review_unit()
  1132. {
  1133. $param = get_params();
  1134. $handle = $this->Pushmessage->handleParam($param);
  1135. $param = $handle['param'];
  1136. if (request()->isAjax()) {
  1137. $a = $this->model->where("id", $param["project_id"])->find();
  1138. if($a["sent_review_head"]){
  1139. return to_assign(1, '送审单位负责人已经存在,请移除后再添加');
  1140. }
  1141. $user = Db::name("admin")->where("id",$param["id"])->find();
  1142. $department = Db::name("department")->where("id",$user["unit_name"])->find();
  1143. $this->model->where("id",
  1144. $param["project_id"])
  1145. ->update(
  1146. [
  1147. "sent_review_head" => $param["id"],
  1148. "sent_review_head_name"=>$user['nickname'],
  1149. "sent_review_phone"=> $user["mobile"],
  1150. "sent_review_unit_name"=>$department["title"],
  1151. "sent_review_unit"=> $department["id"]
  1152. ]
  1153. );
  1154. $content = get_login_admin("nickname") . "新增了送审单位负责人". $user['nickname'];
  1155. add_project_log("新增项目成员",$param["project_id"],$content,5);
  1156. add_user($param["id"],$param["project_id"]);
  1157. return to_assign(0, '操作成功');
  1158. } else {
  1159. $param = get_params();
  1160. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1161. //关联项目id
  1162. View::assign('project_id', $project_id);
  1163. return view();
  1164. }
  1165. }
  1166. /*public function add_sent_review_unit()
  1167. {
  1168. if (request()->isAjax()) {
  1169. $param = get_params();
  1170. $id = isset($param["id"]) ? $param["id"] : 0;
  1171. $project_id = isset($param["project_id"]) ? $param["project_id"] : 0;
  1172. $a = $this->model->where("id", $project_id)->value("sent_review_head");
  1173. if ($a) {
  1174. return to_assign(1, '已有负责人,请移除后再添加');
  1175. }
  1176. $selfData = get_admin($id);
  1177. $data = [
  1178. "id" => $project_id,
  1179. "sent_review_head" => $id,
  1180. "sent_review_head_name" => $selfData["nickname"],
  1181. "sent_review_unit" => $selfData["unit_name"],
  1182. "sent_review_unit_name" => Db::name("department")->where("id", $selfData["unit_name"])->value("title"),
  1183. "sent_review_phone" => $selfData["mobile"]
  1184. ];
  1185. try {
  1186. $this->model->update($data);
  1187. } catch (\Exception $e) {
  1188. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  1189. }
  1190. return to_assign(0, "操作成功");
  1191. }
  1192. }*/
  1193. //公司
  1194. public function remove_sent_review(){
  1195. $p = get_params();
  1196. $data = [
  1197. "sent_review_unit" => null,
  1198. "sent_review_unit_name" => null,
  1199. "sent_review_head_name" => null,
  1200. "sent_review_head" => null,
  1201. "sent_review_phone" => null,
  1202. "sent_review_head_email" => null,
  1203. ];
  1204. $this->model->where("id",$p["project_id"])->update($data);
  1205. remove_user($p["id"]);
  1206. add_project_log('移除送审单位成员',$p["project_id"],$p["nickname"],5);
  1207. return to_assign(0,"操作成功");
  1208. }
  1209. //公司
  1210. public function remove_review_head(){
  1211. $p = get_params();
  1212. $data = [
  1213. "review_head" => null,
  1214. "review_head_name" => null,
  1215. "review_head_phone" => null,
  1216. ];
  1217. $this->model->where("id",$p["project_id"])->update($data);
  1218. $name= Db::name("admin")->where("id",$p["id"])->value("nickname");
  1219. remove_user($p["id"]);
  1220. add_project_log('移除送审单位成员',$p["project_id"],$name,5);
  1221. return to_assign(0,"操作成功");
  1222. }
  1223. public function get_department_tree()
  1224. {
  1225. $unit_id = get_unit(get_login_admin("unit_name"));
  1226. $department = Db::name('Department')->where(['status' => 1])->select()->toArray();
  1227. $list = get_tree($department, 0, 2);
  1228. $data['trees'] = $list;
  1229. $result = null;
  1230. for ($i = 0; $i < count($data['trees']); $i++) {
  1231. $point = $data['trees'][$i];
  1232. if ($point["id"] == $unit_id) {
  1233. $result['trees'][] = $point;
  1234. break;
  1235. }
  1236. }
  1237. // halt($result);
  1238. return json($result);
  1239. }
  1240. public function get_department_tree_proprietor($project_id)
  1241. {
  1242. $project = $this->model->where("id" , $project_id)->find();
  1243. $entrust_unit = $project["entrust_unit"];
  1244. $department = Db::name('Department')->where(['status' => 1 , "entrust_unit" => $entrust_unit])->select()->toArray();
  1245. $list = get_tree($department, 0, 2);
  1246. $data['trees'] = $list;
  1247. $result = null;
  1248. for ($i = 0; $i < count($data['trees']); $i++) {
  1249. $point = $data['trees'][$i];
  1250. $result['trees'][] = $point;
  1251. }
  1252. return json($result);
  1253. }
  1254. //获取子部门所有员工
  1255. public function get_employee_proprietor()
  1256. {
  1257. $did = get_params('did');
  1258. if ($did == 1) {
  1259. $department = $did;
  1260. } else {
  1261. $department = get_department_son($did);
  1262. }
  1263. // halt($department);
  1264. $employee = Db::name('admin')
  1265. ->field('a.id,a.did,a.position_id,a.mobile,a.nickname,a.status,a.thumb,a.username,d.title as department')
  1266. ->alias('a')
  1267. ->join('Department d', 'a.did = d.id')
  1268. ->where(['a.status' => 1])
  1269. ->where('a.id', ">", 1)
  1270. ->where('a.did', "in", $department)
  1271. ->select();
  1272. return to_assign(0, '', $employee);
  1273. }
  1274. //获取子部门所有员工
  1275. public function get_employee()
  1276. {
  1277. $did = get_params('did');
  1278. if ($did == 1) {
  1279. $department = $did;
  1280. } else {
  1281. $department = get_department_son(get_login_admin("unit_name"));
  1282. }
  1283. // halt($department);
  1284. $employee = Db::name('admin')
  1285. ->field('a.id,a.did,a.position_id,a.mobile,a.nickname,a.status,a.thumb,a.username,d.title as department')
  1286. ->alias('a')
  1287. ->join('Department d', 'a.did = d.id')
  1288. ->where(['a.status' => 1])
  1289. ->where('a.id', ">", 1)
  1290. ->where('a.did', "in", $department)
  1291. ->select();
  1292. return to_assign(0, '', $employee);
  1293. }
  1294. public function get_yezhu_tree()
  1295. {
  1296. // $unit_id = get_unit(get_login_admin("unit_name"));
  1297. $yezhulist = Db::name('Department')->where(['status' => 1, 'type' => 1])->select()->toArray();
  1298. $list = get_tree($yezhulist, 0, 2);
  1299. $data['trees'] = $list;
  1300. return json($data);
  1301. }
  1302. //获取子部门所有员工
  1303. public function get_people($did = 1)
  1304. {
  1305. $did = get_params('did');
  1306. if ($did == 1) {
  1307. $department = $did;
  1308. } else {
  1309. $department = get_department_son($did);
  1310. }
  1311. $employee = Db::name('admin')
  1312. ->field('a.id,a.did,a.position_id,a.mobile,a.nickname,a.status,a.thumb,a.username,d.title as department')
  1313. ->alias('a')
  1314. ->join('Department d', 'a.did = d.id')
  1315. ->where(['a.status' => 1])
  1316. ->where('a.id', ">", 1)
  1317. ->where('a.did', "in", $department)
  1318. ->select();
  1319. // $employee = $employee->map(function ($employee) {
  1320. // $employee['name'] = $employee["nickname"];
  1321. // return $employee;
  1322. // });
  1323. return to_assign(0, '', $employee);
  1324. }
  1325. public function getProjectFive(){
  1326. $where = [
  1327. ['name', '=', '作业日志-公司'],
  1328. ['name', '=', '工作记录-公司'],
  1329. ['name', '=', '项目报告-公司'],
  1330. ['name', '=', '项目人员-公司'],
  1331. ['name', '=', '项目动态-公司'],
  1332. ['name', '=', '项目附件-公司'],
  1333. ['name', '=', '联系函-公司'],
  1334. ];
  1335. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  1336. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  1337. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  1338. $login_rules = explode(',', $login_rules);
  1339. $rules_id = array();
  1340. foreach($list as $key => $value){
  1341. if($value['name'] == "作业日志-公司"){
  1342. if(in_array($value['id'], $login_rules)){
  1343. $rules_id['project_comments'] = 1;
  1344. }else{
  1345. $rules_id['project_comments'] = 0;
  1346. }
  1347. }else if($value['name'] == "工作记录-公司"){
  1348. if(in_array($value['id'], $login_rules)){
  1349. $rules_id['project_record'] = 1;
  1350. }else{
  1351. $rules_id['project_record'] = 0;
  1352. }
  1353. }else if($value['name'] == "项目报告-公司"){
  1354. if(in_array($value['id'], $login_rules)){
  1355. $rules_id['project_report'] = 1;
  1356. }else{
  1357. $rules_id['project_report'] = 0;
  1358. }
  1359. }else if($value['name'] == "项目人员-公司"){
  1360. if(in_array($value['id'], $login_rules)){
  1361. $rules_id['project_user'] = 1;
  1362. }else{
  1363. $rules_id['project_user'] = 0;
  1364. }
  1365. }else if($value['name'] == "项目动态-公司"){
  1366. if(in_array($value['id'], $login_rules)){
  1367. $rules_id['project_log'] = 1;
  1368. }else{
  1369. $rules_id['project_log'] = 0;
  1370. }
  1371. }else if($value['name'] == "项目附件-公司"){
  1372. if(in_array($value['id'], $login_rules)){
  1373. $rules_id['project_file'] = 1;
  1374. }else{
  1375. $rules_id['project_file'] = 0;
  1376. }
  1377. }else if($value['name'] == "联系函-公司"){
  1378. if(in_array($value['id'], $login_rules)){
  1379. $rules_id['project_contact'] = 1;
  1380. }else{
  1381. $rules_id['project_contact'] = 0;
  1382. }
  1383. }
  1384. }
  1385. return $rules_id;
  1386. }
  1387. public function ceshi($id)
  1388. {
  1389. View::assign('detailId', $id);
  1390. return view();
  1391. }
  1392. }