CostCompany.php 69 KB

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