CostCompany.php 66 KB

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