Index.php 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 勾股工作室
  4. * @license https://opensource.org/licenses/Apache-2.0
  5. * @link https://www.gougucms.com
  6. */
  7. declare (strict_types=1);
  8. namespace app\mobile\controller;
  9. use app\admin\BaseController;
  10. use app\admin\controller\field\Field;
  11. use app\admin\model\Admin;
  12. use app\admin\model\Admin as AdminList;
  13. use app\admin\model\Appointment as AppointmentModel;
  14. use app\admin\model\Contact;
  15. use app\admin\model\Contact as ContactModel;
  16. use app\admin\model\CostProject as CostProjectModel;
  17. use app\admin\model\ProjectAudit as AuditModel;
  18. use app\admin\model\ProjectRecord;
  19. use think\App;
  20. use think\facade\Db;
  21. use think\facade\Request;
  22. use think\facade\Session;
  23. use think\facade\View;
  24. use app\admin\model\Appropriation as AppropriationModel;
  25. use app\admin\controller\datastat\Datastat;
  26. class Index
  27. {
  28. /**
  29. * 构造函数
  30. */
  31. public function __construct(App $app)
  32. {
  33. $this->Datastat = new Datastat($app);
  34. $this->AppropriationModel = new AppropriationModel();
  35. $this->Field = new Field($app);
  36. $this->model = new CostProjectModel();
  37. $this->Adminmodel = new Admin();
  38. $this->Auditmodel = new AuditModel();
  39. $this->ContactModel = new ContactModel();
  40. $this->AppointmentModel = new AppointmentModel();
  41. $this->uid = get_login_admin('id');
  42. $this->unit = get_login_admin('unit_name');
  43. $this->user_tpe = Db::name("department")->where("id", $this->unit)->value("type");
  44. // $session_admin = get_config('app.session_admin');
  45. // $request = Request::instance();
  46. // if (!Session::has($session_admin) && $request->url() !== '/mobile/index/login.html') {
  47. // redirect('/mobile/index/login.html')->send();
  48. // exit;
  49. // }
  50. }
  51. /**
  52. * 财评首页
  53. * 通用
  54. */
  55. public function main()
  56. {
  57. // halt(session::get('gougu_admin'));
  58. if (session::get(get_config('app.session_admin')) == NULL) {
  59. $param = get_params();
  60. if ($param == NULL) {
  61. redirect('/mobile/index/login.html')->send();
  62. } else { // 微信登录 但session为空
  63. $session_admin = get_config('app.session_admin');
  64. $admin = Db::name('Admin')->where('id', $param['admin'])->find();
  65. Session::set($session_admin, $admin); // null
  66. $token = make_token();
  67. set_cache($token, $admin, 7200);
  68. $admin['token'] = $token;
  69. $this->uid = $param['admin'];
  70. $this->unit = Db::name('Admin')->where('id', $this->uid)->value('unit_name');
  71. }
  72. }
  73. //0->财政局,1->业主,2->公司
  74. if ($this->user_tpe == 0) {
  75. $sent_review_amount = Db::name("cost_project")->where([
  76. ["entrust_unit", "=", get_login_admin("unit_name")],
  77. ['delete_time', '=', 0],
  78. ["project_status", ">", 2],
  79. ["project_status", "<>", 9],
  80. ])->field("sent_review_amount,sent_review_cost,review_add_reduce_rate,authorize_amount,engineering_type1")->select();
  81. } else if ($this->user_tpe == 2) {
  82. $sent_review_amount = Db::name("cost_project")->where([
  83. ["review_unit", "=", $this->unit],
  84. ['delete_time', '=', 0],
  85. ["project_status", ">", 3]
  86. ])->field("sent_review_amount,sent_review_cost,review_add_reduce_rate,authorize_amount,engineering_type1")->select();
  87. } else if ($this->user_tpe == 1) {
  88. $sent_review_amount = Db::name("cost_project")->where([
  89. ["sent_review_unit", "=", get_login_admin("unit_name")],
  90. ['delete_time', '=', 0],
  91. ["project_status", ">", 2],
  92. ["project_status", "<>", 9],
  93. ])->field("sent_review_amount,sent_review_cost,review_add_reduce_rate,authorize_amount,engineering_type1")->select();
  94. }
  95. //engineering_type1=1是预算,2是结算
  96. $amount = [
  97. //送审总额
  98. 'sent_review_amount' => 0,
  99. //评审服务费
  100. 'sent_review_cost' => 0,
  101. //审定总额
  102. 'authorize_amount' => 0,
  103. //总审减率
  104. 'review_add_reduce_rate' => 0
  105. ];
  106. $sent_review_amount_tol = [
  107. "sent_review_amount_type1" => 0,
  108. "sent_review_amount_type2" => 0,
  109. "authorize_amount_type1" => 0,
  110. "authorize_amount_type2" => 0,
  111. "review_add_reduce_rate_type1" => 0,
  112. "review_add_reduce_rate_type2" => 0
  113. ];
  114. for ($i = 0; $i < count($sent_review_amount); $i++) {
  115. $a = $sent_review_amount[$i];
  116. if ($a['engineering_type1'] == 1) {
  117. if ((int)$a["sent_review_amount"]) {
  118. //预算总额
  119. $sent_review_amount_tol["sent_review_amount_type1"] += $a["sent_review_amount"];
  120. }
  121. if ((int)$a["authorize_amount"]) {
  122. //审定
  123. $sent_review_amount_tol["authorize_amount_type1"] += $a["authorize_amount"];
  124. }
  125. } elseif ($a['engineering_type1'] == 2) {
  126. if ((int)$a["sent_review_amount"]) {
  127. //结算总额
  128. $sent_review_amount_tol["sent_review_amount_type2"] += $a["sent_review_amount"];
  129. }
  130. if ((int)$a["authorize_amount"]) {
  131. //审定
  132. $sent_review_amount_tol["authorize_amount_type2"] += $a["authorize_amount"];
  133. }
  134. }
  135. }
  136. //什么率的
  137. $sentReviewAmount = 0;
  138. $authorizeAmount = 0;
  139. $sent_review_amount_type1 = 0;
  140. $authorize_amount_type1 = 0;
  141. $sent_review_amount_type2 = 0;
  142. $authorize_amount_type2 = 0;
  143. for ($i = 0; $i < count($sent_review_amount); $i++) {
  144. $a = $sent_review_amount[$i];
  145. if ($a['engineering_type1'] == 1 && (int)$a["authorize_amount"]) {
  146. if ((int)$a["sent_review_amount"]) {
  147. //预算总额
  148. $sent_review_amount_type1 += $a["sent_review_amount"];
  149. //审定
  150. $authorize_amount_type1 += $a["authorize_amount"];
  151. }
  152. } elseif ($a['engineering_type1'] == 2) {
  153. if ((int)$a["sent_review_amount"] && (int)$a["authorize_amount"]) {
  154. //结算总额
  155. $sent_review_amount_type2 += $a["sent_review_amount"];
  156. //审定
  157. $authorize_amount_type2 += $a["authorize_amount"];
  158. }
  159. }
  160. if ((int)$a["sent_review_amount"] && (int)$a["authorize_amount"]) {
  161. //结算总额
  162. $sentReviewAmount += $a["sent_review_amount"];
  163. //审定
  164. $authorizeAmount += $a["authorize_amount"];
  165. }
  166. }
  167. if ((int)$sent_review_amount_type1 && (int)$authorize_amount_type1) {
  168. //预算核增减率
  169. $sent_review_amount_tol["review_add_reduce_rate_type1"] = sprintf("%.4f", ($authorize_amount_type1 - $sent_review_amount_type1) / $sent_review_amount_type1) * 100;
  170. }
  171. if ($sent_review_amount_type2 && $authorize_amount_type2) {
  172. //结算核增减率
  173. $sent_review_amount_tol["review_add_reduce_rate_type2"] = sprintf("%.4f", ($authorize_amount_type2 - $sent_review_amount_type2) / $sent_review_amount_type2) * 100;
  174. }
  175. if ((int)$sentReviewAmount && (int)$authorizeAmount) {
  176. $amount['review_add_reduce_rate'] = (sprintf("%.4f", ($authorizeAmount - $sentReviewAmount) / $sentReviewAmount)) * 100;
  177. }
  178. for ($i = 0; $i < count($sent_review_amount); $i++) {
  179. $a = $sent_review_amount[$i];
  180. if ((int)$a['sent_review_amount']) {
  181. $amount["sent_review_amount"] += $a['sent_review_amount'];
  182. }
  183. if ((int)$a['sent_review_cost']) {
  184. $amount["sent_review_cost"] += $a['sent_review_cost'];
  185. }
  186. if ((int)$a['authorize_amount']) {
  187. $amount["authorize_amount"] += $a['authorize_amount'];
  188. }
  189. }
  190. //评审服务费,上半年服务费用,下半年服务费用 start
  191. $currentTime = time();
  192. $year = date('Y', $currentTime);
  193. // 计算上半年时间范围
  194. $firstHalfStart = strtotime($year . '-01-01');
  195. $firstHalfEnd = strtotime($year . '-06-30 23:59:59');
  196. // 计算下半年时间范围
  197. $secondHalfStart = strtotime($year . '-07-01');
  198. $secondHalfEnd = strtotime($year . '-12-31 23:59:59');
  199. if ($this->user_tpe == 0) {
  200. $first_sent_review_cost = Db::name("cost_project")->where([
  201. ['delete_time', '=', 0],
  202. ["project_status", ">", 2],
  203. ["project_status", "<>", 9],
  204. ["entrust_unit", "=", get_login_admin("unit_name")]
  205. ])->whereBetween('create_time', [$firstHalfStart, $firstHalfEnd])->field("sent_review_cost")->select();
  206. if (!$first_sent_review_cost->isEmpty()) {
  207. $first_sent_review_cost->toArray();
  208. } else {
  209. $first_sent_review_cost = [];
  210. }
  211. $second_sent_review_cost = Db::name("cost_project")->where([
  212. ['delete_time', '=', 0],
  213. ["project_status", ">", 2],
  214. ["project_status", "<>", 9],
  215. ["entrust_unit", "=", get_login_admin("unit_name")]
  216. ])->whereBetween('create_time', [$secondHalfStart, $secondHalfEnd])->field("sent_review_cost")->select();
  217. if (!$second_sent_review_cost->isEmpty()) {
  218. $second_sent_review_cost->toArray();
  219. } else {
  220. $second_sent_review_cost = [];
  221. }
  222. } else if ($this->user_tpe == 2) {
  223. $first_sent_review_cost = Db::name("cost_project")->where([
  224. ['project_status', '>', 3],
  225. ["review_unit", "=", get_login_admin("unit_name")],
  226. ["project_status", "<>", 7],
  227. ["project_status", "<>", 9]
  228. ])->
  229. whereBetween('create_time', [$firstHalfStart, $firstHalfEnd])->field("sent_review_cost")->select();
  230. if (!$first_sent_review_cost->isEmpty()) {
  231. $first_sent_review_cost->toArray();
  232. } else {
  233. $first_sent_review_cost = [];
  234. }
  235. $second_sent_review_cost = Db::name("cost_project")->where([
  236. ['project_status', '>', 3],
  237. ["review_unit", "=", get_login_admin("unit_name")],
  238. ["project_status", "<>", 7],
  239. ["project_status", "<>", 9]
  240. ])->
  241. whereBetween('create_time', [$secondHalfStart, $secondHalfEnd])->field("sent_review_cost")->select();
  242. if (!$second_sent_review_cost->isEmpty()) {
  243. $second_sent_review_cost->toArray();
  244. } else {
  245. $second_sent_review_cost = [];
  246. }
  247. } else if ($this->user_tpe == 1) {
  248. $first_sent_review_cost = Db::name("cost_project")->where([
  249. ['project_status', '>', 2], ["sent_review_unit", "=", $this->unit]
  250. ])->
  251. whereBetween('create_time', [$firstHalfStart, $firstHalfEnd])->field("sent_review_cost")->select();
  252. if (!$first_sent_review_cost->isEmpty()) {
  253. $first_sent_review_cost->toArray();
  254. } else {
  255. $first_sent_review_cost = [];
  256. }
  257. $second_sent_review_cost = Db::name("cost_project")->where([
  258. ['project_status', '>', 2], ["sent_review_unit", "=", $this->unit]
  259. ])->
  260. whereBetween('create_time', [$secondHalfStart, $secondHalfEnd])->field("sent_review_cost")->select();
  261. if (!$second_sent_review_cost->isEmpty()) {
  262. $second_sent_review_cost->toArray();
  263. } else {
  264. $second_sent_review_cost = [];
  265. }
  266. }
  267. $sent_review_cost = [
  268. 'first_sent_review_cost' => 0,
  269. 'second_sent_review_cost' => 0
  270. ];
  271. for ($i = 0; $i < count($first_sent_review_cost); $i++) {
  272. $a = $first_sent_review_cost[$i];
  273. $sent_review_cost["first_sent_review_cost"] += $a['sent_review_cost'];
  274. }
  275. for ($i = 0; $i < count($second_sent_review_cost); $i++) {
  276. $a = $second_sent_review_cost[$i];
  277. $sent_review_cost["second_sent_review_cost"] += $a['sent_review_cost'];
  278. }
  279. //评审服务费,上半年服务费用,下半年服务费用 end
  280. //项目数量,正在作业,已归档
  281. $num = Db::name("cost_project")->where([
  282. ["entrust_unit", "=", $this->unit],
  283. ['delete_time', '=', 0],
  284. ["project_status", '>', 2],
  285. ])->count();
  286. if ($this->user_tpe == 0) {
  287. $where = [
  288. ["entrust_unit", "=", $this->unit],
  289. ['delete_time', '=', 0],
  290. ["project_status", '>', 2],
  291. ];
  292. } else if ($this->user_tpe == 2) {
  293. $where = [
  294. ["review_unit", "=", $this->unit],
  295. ['delete_time', '=', 0],
  296. ["project_status", '>', 2],
  297. ];
  298. }
  299. if($this->user_tpe == 1){
  300. $data = Db::name("cost_project")
  301. ->where(function($query) {
  302. $query->where([
  303. ["sent_review_unit", "=", get_login_admin("unit_name")],
  304. ['delete_time', '=', 0],
  305. ["proprietor_status", '>', 1],
  306. ["project_status", '=', 0],
  307. ]);
  308. })
  309. ->whereOr(function($query) {
  310. $query->where([
  311. ["sent_review_unit", "=", get_login_admin("unit_name")],
  312. ['delete_time', '=', 0],
  313. ["project_status", '>', 0],
  314. ]);
  315. })
  316. ->select();
  317. }else{
  318. $data = Db::name("cost_project")->where($where)->select();
  319. }
  320. // halt($data);
  321. $num_project = [
  322. 'num' => 0,
  323. "yu" => 0,
  324. "jie" => 0,
  325. "zuo" => 0,
  326. "gui" => 0,
  327. "tui" => 0,
  328. ];
  329. foreach ($data as $key => $value) {
  330. $num_project["num"] += 1;
  331. if ($value["project_status"] < 6 && $value["project_status"] > 3) {
  332. $num_project["zuo"] += 1;
  333. }
  334. if ($value["project_status"] < 8 && $value["project_status"] > 3) {
  335. if ($value["engineering_type1"] == 1) {
  336. $num_project["yu"] += 1;
  337. }
  338. if ($value["engineering_type1"] == 2) {
  339. $num_project["jie"] += 1;
  340. }
  341. }
  342. if ($value["project_status"] == 8) {
  343. $num_project["gui"] += 1;
  344. }
  345. if ($value["project_status"] == 9) {
  346. $num_project["tui"] += 1;
  347. }
  348. }
  349. $sent_review_cost_real = [];
  350. foreach ($sent_review_cost as $item => $value) {
  351. $sent_review_cost_real[$item] = number_format($value / 10000, 2, ".", "");
  352. }
  353. $sent_review_amount_tol_real = [];
  354. foreach ($sent_review_amount_tol as $item => $value) {
  355. if (!($item == "review_add_reduce_rate_type1" || $item == "review_add_reduce_rate_type2")) {
  356. $sent_review_amount_tol_real[$item] = number_format($value / 10000, 2, ".", "");
  357. } else {
  358. $sent_review_amount_tol_real[$item] = number_format($value, 2, ".", "");
  359. }
  360. }
  361. $amount_real = [];
  362. foreach ($amount as $item => $value) {
  363. if ($item == "review_add_reduce_rate") {
  364. $amount_real[$item] = number_format($value, 2, ".", "");
  365. } else {
  366. $amount_real[$item] = number_format($value / 10000, 2, ".", "");
  367. }
  368. }
  369. $red = $this->Auditmodel->where("approver", $this->uid)->where("audit_status", 1)->count();
  370. $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select();
  371. $red_kan = 0;
  372. foreach ($red_id as $item => $value) {
  373. if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) {
  374. $red_kan = 1;
  375. }
  376. }
  377. $unread_id = Db::name("admin")->where("id", $this->uid)->value("unread");
  378. if (empty($unread_id)) {
  379. $unread_id = 0;
  380. } else {
  381. $unread_id = 1;
  382. }
  383. $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type");
  384. View::assign('unit_type', $unit_type);
  385. View::assign("red_kan", $red_kan);
  386. View::assign("sent_review_cost", $sent_review_cost_real);
  387. View::assign("amount", $amount_real);
  388. View::assign("num", $num);
  389. View::assign("num_project", $num_project);
  390. View::assign("sent_review_amount_tol", $sent_review_amount_tol_real);
  391. View::assign("red", $red);
  392. View::assign("red_notice", $unread_id);
  393. return View();
  394. }
  395. /**
  396. * 公司首页
  397. */
  398. public function main_company()
  399. {
  400. $sent_review_amount = Db::name("cost_project")->where([
  401. ["review_unit", "=", get_login_admin("unit_name")],
  402. ['delete_time', '=', 0],
  403. ['project_status', '>', 3],
  404. ])->field("sent_review_amount,sent_review_cost,review_add_reduce_rate,authorize_amount,engineering_type1")->select();
  405. //engineering_type1=1是预算,2是结算
  406. $amount = [
  407. //送审总额
  408. 'sent_review_amount' => 0,
  409. //评审服务费
  410. 'sent_review_cost' => 0,
  411. //审定总额
  412. 'authorize_amount' => 0,
  413. //总审减率
  414. 'review_add_reduce_rate' => 0
  415. ];
  416. $sent_review_amount_tol = [
  417. "sent_review_amount_type1" => 0,
  418. "sent_review_amount_type2" => 0,
  419. "authorize_amount_type1" => 0,
  420. "authorize_amount_type2" => 0,
  421. "review_add_reduce_rate_type1" => 0,
  422. "review_add_reduce_rate_type2" => 0
  423. ];
  424. for ($i = 0; $i < count($sent_review_amount); $i++) {
  425. $a = $sent_review_amount[$i];
  426. if ($a['engineering_type1'] == 1) {
  427. if ((int)$a["sent_review_amount"] && (int)$a["authorize_amount"]) {
  428. //预算总额
  429. $sent_review_amount_tol["sent_review_amount_type1"] += $a["sent_review_amount"];
  430. //审定
  431. $sent_review_amount_tol["authorize_amount_type1"] += $a["authorize_amount"];
  432. }
  433. } elseif ($a['engineering_type1'] == 2) {
  434. if ((int)$a["sent_review_amount"] && (int)$a["authorize_amount"]) {
  435. //结算总额
  436. $sent_review_amount_tol["sent_review_amount_type2"] += $a["sent_review_amount"];
  437. //审定
  438. $sent_review_amount_tol["authorize_amount_type2"] += $a["authorize_amount"];
  439. }
  440. }
  441. }
  442. if ((int)$sent_review_amount_tol["sent_review_amount_type1"] && (int)$sent_review_amount_tol["authorize_amount_type1"]) {
  443. //预算核增减率
  444. $sent_review_amount_tol["review_add_reduce_rate_type1"] = (sprintf("%.4f", ($sent_review_amount_tol["authorize_amount_type1"] - $sent_review_amount_tol["sent_review_amount_type1"]) / $sent_review_amount_tol["sent_review_amount_type1"])) * 100;
  445. }
  446. if ((int)$sent_review_amount_tol["sent_review_amount_type2"] && (int)$sent_review_amount_tol["authorize_amount_type2"]) {
  447. //结算核增减率
  448. $sent_review_amount_tol["review_add_reduce_rate_type2"] = (sprintf("%.4f", ($sent_review_amount_tol["authorize_amount_type2"] - $sent_review_amount_tol["sent_review_amount_type2"]) / $sent_review_amount_tol["sent_review_amount_type2"])) * 100;
  449. }
  450. for ($i = 0; $i < count($sent_review_amount); $i++) {
  451. $a = $sent_review_amount[$i];
  452. if ((int)$a['sent_review_amount'] && (int)$a['sent_review_cost'] && (int)$a['authorize_amount']) {
  453. $amount["sent_review_amount"] += $a['sent_review_amount'];
  454. $amount["sent_review_cost"] += $a['sent_review_cost'];
  455. $amount["authorize_amount"] += $a['authorize_amount'];
  456. }
  457. }
  458. if ((int)$amount['sent_review_amount'] && (int)$amount["authorize_amount"]) {
  459. $amount['review_add_reduce_rate'] = (sprintf("%.4f", ($amount["authorize_amount"] - $amount["sent_review_amount"]) / $amount["sent_review_amount"])) * 100;
  460. }
  461. //评审服务费,上半年服务费用,下半年服务费用 start
  462. $currentTime = time();
  463. $year = date('Y', $currentTime);
  464. // 计算上半年时间范围
  465. $firstHalfStart = strtotime($year . '-01-01');
  466. $firstHalfEnd = strtotime($year . '-06-30 23:59:59');
  467. // 计算下半年时间范围
  468. $secondHalfStart = strtotime($year . '-07-01');
  469. $secondHalfEnd = strtotime($year . '-12-31 23:59:59');
  470. $first_sent_review_cost = Db::name("cost_project")->where([
  471. ['project_status', '>', 2], ["review_unit", "=", get_login_admin("unit_name")]
  472. ])->
  473. whereBetween('create_time', [$firstHalfStart, $firstHalfEnd])->field("sent_review_cost")->select()->toArray();
  474. $second_sent_review_cost = Db::name("cost_project")->where([
  475. ['project_status', '>', 2], ["review_unit", "=", get_login_admin("unit_name")]
  476. ])->
  477. whereBetween('create_time', [$secondHalfStart, $secondHalfEnd])->field("sent_review_cost")->select()->toArray();
  478. $sent_review_cost = [
  479. 'first_sent_review_cost' => 0,
  480. 'second_sent_review_cost' => 0
  481. ];
  482. for ($i = 0; $i < count($first_sent_review_cost); $i++) {
  483. $a = $first_sent_review_cost[$i];
  484. $sent_review_cost["first_sent_review_cost"] += $a['sent_review_cost'];
  485. }
  486. for ($i = 0; $i < count($second_sent_review_cost); $i++) {
  487. $a = $second_sent_review_cost[$i];
  488. $sent_review_cost["second_sent_review_cost"] += $a['sent_review_cost'];
  489. }
  490. //评审服务费,上半年服务费用,下半年服务费用 end
  491. //项目数量,正在作业,已归档
  492. $num = Db::name("cost_project")->where([
  493. ["review_unit", "=", get_login_admin("unit_name")],
  494. ['delete_time', '=', 0],
  495. ["project_status", '>', 3],
  496. ])->count();
  497. $where = [
  498. ["review_unit", "=", get_login_admin("unit_name")],
  499. ['delete_time', '=', 0],
  500. ["project_status", ">", 3]
  501. ];
  502. $data = Db::name("cost_project")->where($where)->select();
  503. $num_project = [
  504. 'num' => 0,
  505. "yu" => 0,
  506. "jie" => 0,
  507. "zuo" => 0,
  508. "gui" => 0,
  509. "tui" => 0,
  510. ];
  511. foreach ($data as $key => $value) {
  512. $num_project["num"] += 1;
  513. if ($value["project_status"] < 6 && $value["project_status"] > 3) {
  514. $num_project["zuo"] += 1;
  515. }
  516. if ($value["engineering_type1"] == 1) {
  517. $num_project["yu"] += 1;
  518. }
  519. if ($value["engineering_type1"] == 2) {
  520. $num_project["jie"] += 1;
  521. }
  522. if ($value["project_status"] == 8) {
  523. $num_project["gui"] += 1;
  524. }
  525. if ($value["project_status"] == 9) {
  526. $num_project["tui"] += 1;
  527. }
  528. }
  529. $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select();
  530. $red_kan = 0;
  531. foreach ($red_id as $item => $value) {
  532. if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) {
  533. $red_kan = 1;
  534. }
  535. }
  536. View::assign("red_kan", $red_kan);
  537. View::assign("sent_review_cost", $sent_review_cost);
  538. View::assign("amount", $amount);
  539. View::assign("num", $num);
  540. View::assign("num_project", $num_project);
  541. View::assign("sent_review_amount_tol", $sent_review_amount_tol);
  542. return View();
  543. }
  544. /**
  545. * cp看板列表
  546. */
  547. public function kan_list()
  548. {
  549. //根据所登录的账号,查询跟本身有关的项目
  550. //2是公司,0是财政局,1是业主
  551. $param = get_params();
  552. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  553. $order = empty($param['order']) ? 'id desc' : $param['order'];
  554. if (isset($param["project_start_time"])) {
  555. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  556. }
  557. if (isset($param["project_end_time"])) {
  558. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  559. }
  560. $where3 = [];//搜索条件
  561. if (!empty($param['project_status'])) {
  562. $where3[] = ['project_status', '=', $param['project_status']];
  563. }
  564. if (!empty($param['province'])) {
  565. $where3[] = ['province', '=', $param['province']];
  566. }
  567. if (!empty($param['city'])) {
  568. $where3[] = ['city', '=', $param['city']];
  569. }
  570. if (!empty($param['area'])) {
  571. $where3[] = ['area', '=', $param['area']];
  572. }
  573. if (!empty($param['project_end_time'])) {
  574. $where3[] = ['project_end_time', '<', $param['project_end_time']];
  575. }
  576. if (!empty($param['project_start_time'])) {
  577. $where3[] = ['project_start_time', '>', $param['project_start_time']];
  578. }
  579. if (!empty($param['keyword'])) {
  580. $keyword = $param['keyword'];
  581. $where3[] = ['project_num|project_name|review_unit', 'like', '%' . $keyword . '%'];
  582. }
  583. if (!empty($param['review_unit_name'])) {
  584. $where3[] = ['review_unit_name', 'like', '%' . $param['review_unit_name'] . '%'];
  585. }
  586. if (!empty($param['sent_review_unit_name'])) {
  587. $where3[] = ['sent_review_unit_name', 'like', '%' . $param['sent_review_unit_name'] . '%'];
  588. }
  589. if (!empty($param['entrust_unit_name'])) {
  590. $where3[] = ['entrust_unit_name', 'like', '%' . $param['entrust_unit_name'] . '%'];
  591. }
  592. $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type");
  593. $inarr = array();
  594. if ($unit_type == 0) {
  595. $where[] = ["delete_time", "=", 0];
  596. $where[] = ["project_status", ">", 0];
  597. $where[] = ["entrust_unit", "=", get_login_admin('unit_name')];
  598. $where2[] = ["delete_time", "=", 0];
  599. $where2[] = ["project_status", ">", 0];
  600. $where2[] = ["entrust_unit", "=", get_login_admin('unit_name')];
  601. //项目可见的权限
  602. $field = $this->Field->get_field_rules_new($this->uid);
  603. //1全部-可查看可编辑,2全部-可查看,0与我有关
  604. $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;
  605. if ($see_auth == 3) {
  606. $where[] = ["entrust_maker", "=", $this->uid];
  607. $where2[] = ["entrust_approver", "=", $this->uid];
  608. $where2[] = ["project_status", ">", 1];
  609. } elseif ($see_auth == 0) {
  610. $where[] = ["entrust_maker", "=", $this->uid];
  611. $where[] = ["project_status", ">", 0];
  612. $where2[] = ["entrust_approver", "=", $this->uid];
  613. $where2[] = ["project_status", ">", 1];
  614. }
  615. $list = $this->model->where($where3)
  616. ->where(function ($query) use ($where,$where2) {
  617. // 第一组条件(entrust_maker)
  618. $query->where(function ($q1) use ($where) {
  619. $q1->where($where);
  620. });
  621. // 使用 OR 连接第二组条件(entrust_approver)
  622. $query->whereOr(function ($q2) use ($where2) {
  623. $q2->where($where2);
  624. });
  625. })
  626. ->order("create_time desc")->paginate(9999, false, ['query' => $param])
  627. ->each(function ($item) {
  628. $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
  629. if ($red) {
  630. if ($red["detail"] || $red["comment"] || $red["report"] || $red["user"] || $red["contact"]) {
  631. $item->red = 1;
  632. } else {
  633. $item->red = 0;
  634. }
  635. } else {
  636. $item->red = 0;
  637. }
  638. if (($item->province && $item->city && $item->area)) {
  639. $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
  640. }
  641. })->toArray();
  642. } elseif ($unit_type == 2) {
  643. $order = empty($param['order']) ? 'project_receive_time desc,id desc' : $param['order'];
  644. $where = [
  645. ["delete_time", "=", 0],
  646. ["project_status", ">", 3],
  647. ["review_unit", "=", get_login_admin("unit_name")]
  648. ];
  649. $review_unit = $this->model->where($where)->where($where3)->field('id,review_head,operate_head,operate_team')->select()->toArray();
  650. for ($i = 0; $i < count($review_unit); $i++) {
  651. $a = $review_unit[$i];
  652. $ids = $a["review_head"] . ',' . $a["operate_head"] . ',' . $a["operate_team"];
  653. $ids = explode(",", $ids);
  654. $c = in_array($this->uid, $ids);
  655. if ($c) {
  656. $inarr[] = $a["id"];
  657. }
  658. }
  659. $field = $this->Field->get_field_rules_New($this->uid);
  660. $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;
  661. $this->see_auth = $see_auth;
  662. if ($see_auth == 3) {
  663. $list = $this->model
  664. ->where($where)->where($where3)->whereIn("id", $inarr)
  665. ->order($order)->paginate(9999, false, ['query' => $param])
  666. ->each(function ($item) {
  667. $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
  668. if ($red) {
  669. if ($red["detail"] || $red["comment"] || $red["report"] || $red["record"] || $red["user"] || $red["contact"]) {
  670. $item->red = 1;
  671. } else {
  672. $item->red = 0;
  673. }
  674. } else {
  675. $item->red = 0;
  676. }
  677. })->toArray();
  678. } elseif ($see_auth == 0) {
  679. $list = $this->model
  680. ->where($where)->where($where3)->whereIn("id", $inarr)
  681. ->order($order)->paginate(9999, false, ['query' => $param])
  682. ->each(function ($item) {
  683. $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
  684. if ($red) {
  685. if ($red["detail"] || $red["comment"] || $red["report"] || $red["record"] || $red["user"] || $red["contact"]) {
  686. $item->red = 1;
  687. } else {
  688. $item->red = 0;
  689. }
  690. } else {
  691. $item->red = 0;
  692. }
  693. })->toArray();
  694. } else {
  695. $list = $this->model
  696. ->where($where)
  697. ->order($order)->where($where3)->paginate(9999, false, ['query' => $param])
  698. ->each(function ($item) {
  699. $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
  700. if ($red) {
  701. if ($red["detail"] || $red["comment"] || $red["report"] || $red["record"] || $red["user"] || $red["contact"]) {
  702. $item->red = 1;
  703. } else {
  704. $item->red = 0;
  705. }
  706. } else {
  707. $item->red = 0;
  708. }
  709. })->toArray();
  710. }
  711. } elseif ($unit_type == 1) {
  712. $field = $this->Field->get_field_rules_New($this->uid);
  713. $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;
  714. if ($see_auth == 0 || $see_auth == 3) {
  715. $where = [
  716. ["delete_time", "=", 0],
  717. ["sent_review_unit", "=", get_login_admin("unit_name")],
  718. ["sent_review_head", "=", $this->uid]
  719. ];
  720. } else {
  721. $where = [
  722. ["delete_time", "=", 0],
  723. ["sent_review_unit", "=", get_login_admin("unit_name")]
  724. ];
  725. }
  726. $list = $this->model
  727. ->where($where)
  728. ->order($order)->where($where3)->paginate(9999, false, ['query' => $param])
  729. ->each(function ($item) {
  730. $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
  731. if ($red) {
  732. if ($red["detail"] || $red["comment"] || $red["report"] || $red["record"] || $red["user"] || $red["contact"]) {
  733. $item->red = 1;
  734. } else {
  735. $item->red = 0;
  736. }
  737. } else {
  738. $item->red = 0;
  739. }
  740. })->toArray();
  741. } else {
  742. $list["data"] = [];
  743. }
  744. $data = $list["data"];
  745. $real_list = array_values(array_column($data, NULL, 'id'));
  746. $red = $this->Auditmodel->where("approver", $this->uid)->where("audit_status", 1)->count();
  747. $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select();
  748. $red_kan = 0;
  749. foreach ($red_id as $item => $value) {
  750. if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) {
  751. $red_kan = 1;
  752. }
  753. }
  754. View::assign("red_kan", $red_kan);
  755. View::assign("detail", $real_list);
  756. View::assign("red", $red);
  757. View::assign("unit_type", $unit_type);
  758. return view();
  759. }
  760. public function pending_invite()
  761. {
  762. $param = get_params();
  763. $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type");
  764. $where1 = [];
  765. //2是公司,0是财政局,1是业主
  766. if ($unit_type == 0) {
  767. if (!empty($param['invite_keyword'])) {
  768. $keyword = $param['invite_keyword'];
  769. $where1[] = ['review_unit_name', 'like', '%' . $keyword . '%'];
  770. }
  771. $order = empty($param['order']) ? 'id desc' : $param['order'];
  772. $Appropriationlist = $this->AppropriationModel->where("entrust_unit", get_login_admin("unit_name"))
  773. ->where("status",">",0)->where($where1)
  774. ->order( $order)->paginate(9999, false, ['query' => $param])
  775. ->each(function ($item) {
  776. $data = Db::name("appropriation_project")->alias("a")->join("cost_project c","a.project_id=c.id","left")
  777. ->where("a.uid","not null")->where("a.uid",$item->id)
  778. ->where("c.entrust_unit",get_login_admin("unit_name"))->column("c.project_name,c.sent_review_cost");
  779. if (!empty($data)) {
  780. $a = 0;
  781. $project_name = [];
  782. $appropriation_amount = 0;
  783. foreach ($data as $key => $value) {
  784. $a += 1;
  785. $project_name[] = $a . "." . $value["project_name"];
  786. $appropriation_amount += $value["sent_review_cost"];
  787. }
  788. $item->a = count($data);
  789. $item->appropriation_amount = $appropriation_amount;
  790. $item->project_names = $project_name;
  791. }
  792. });
  793. } else if($unit_type == 2) {
  794. $where = [
  795. ["a.approver", "=", $this->uid],
  796. ["a.audit_type", ">", 3],
  797. ["a.audit_status", "<", 5]
  798. ];
  799. $order = empty($param['order']) ? 'id desc' : $param['order'];
  800. if (!empty($param['invite_keyword'])) {
  801. $keyword = $param['invite_keyword'];
  802. $where[] = ['entrust_unit_name', 'like', '%' . $keyword . '%'];
  803. }
  804. $Appropriationlist = $this->Auditmodel->alias('a')->join("cost_project c", "a.project_id=c.id", 'left')
  805. ->field("a.*,c.project_status,c.sent_review_amount,c.engineering_type,c.review_unit_name")->where($where)->order($order)
  806. ->paginate(9999, false, ['query' => $param])
  807. ->where('audit_type','in',[10,11,12])
  808. ->each(function ($item){
  809. switch ($item["audit_type"]) {
  810. case 10:
  811. $item->else_name = "请款一级审核";
  812. break;
  813. case 11:
  814. $item->else_name = "请款二级审核";
  815. break;
  816. case 12:
  817. $item->else_name = "请款三级审核";
  818. break;
  819. }
  820. });
  821. }else{
  822. $Appropriationlist = [];
  823. }
  824. $app_red = 0;
  825. if($this->user_tpe==0){
  826. $app_where=[
  827. ["status","=",1],
  828. ["entrust_unit","=",get_login_admin("unit_name")]
  829. ];
  830. if(Db::name("appropriation")->where($app_where)->count()>0){$app_red=1;}
  831. }else if($this->user_tpe==2){
  832. //10请款一审,11请款二审,12,请款三审
  833. $app_where=[
  834. ["audit_type",">",9],
  835. ["audit_type","<",13],
  836. ["audit_status","=",1],
  837. ["approver","=",$this->uid]
  838. ];
  839. if($this->Auditmodel->where($app_where)->count()>0){$app_red=1;}
  840. }
  841. //红点
  842. $where = [
  843. ["approver", "=", $this->uid],
  844. ["audit_status", "<", 5]
  845. ];
  846. $list = $this->Auditmodel->alias("a")->join("cost_project c", "a.project_id=c.id", "left")
  847. ->where($where)->field("a.*,c.project_num,c.project_status,c.engineering_type,c.sent_review_amount")
  848. ->paginate(9999, false, ['query' => $param])
  849. ->each(function ($item, $key) {
  850. $item->approver_name = Db::name("admin")->where("id", $item->approver)->value("nickname");
  851. })->toArray();
  852. $red = 0;
  853. foreach ($list["data"] as $item => $value) {
  854. if ($value["audit_status"] == 1) {
  855. $red = 1;
  856. }
  857. }
  858. $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select();
  859. $red_kan = 0;
  860. foreach ($red_id as $item => $value) {
  861. if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) {
  862. $red_kan = 1;
  863. }
  864. }
  865. View::assign('unit_type', $unit_type);
  866. View::assign('list', $Appropriationlist);
  867. View::assign("red_kan", $red_kan);
  868. View::assign('red', $red);
  869. View::assign('app_red', $app_red);
  870. return view();
  871. }
  872. /**
  873. * cp待办列表
  874. */
  875. public function pending()
  876. {
  877. $param = get_params();
  878. //1项目,2报告,3联系函,4公司一级审核,5公司二级审核,6公司三级审核,7联系函一审,8联系过二审,9联系函三审,10请款一审,11请款二审,12,请款三审,14报告四审,15报告五审
  879. $where = [
  880. ["approver", "=", $this->uid],
  881. ["audit_status", "<", 5],
  882. ["audit_type", "<>", 10],
  883. ["audit_type", "<>", 11],
  884. ["audit_type", "<>", 12],
  885. ];
  886. if (!empty($param['project_status'])) {
  887. $where[] = ['c.project_status', '=', $param['project_status']];
  888. }
  889. if (!empty($param['province'])) {
  890. $where[] = ['c.province', '=', $param['province']];
  891. }
  892. if (!empty($param['city'])) {
  893. $where[] = ['c.city', '=', $param['city']];
  894. }
  895. if (!empty($param['area'])) {
  896. $where[] = ['c.area', '=', $param['area']];
  897. }
  898. if (!empty($param['project_end_time'])) {
  899. $where[] = ['c.project_end_time', '<', $param['project_end_time']];
  900. }
  901. if (!empty($param['project_start_time'])) {
  902. $where[] = ['c.project_start_time', '>', $param['project_start_time']];
  903. }
  904. if (!empty($param['keyword'])) {
  905. $keyword = $param['keyword'];
  906. $where[] = ['c.project_num|c.project_name|c.review_unit', 'like', '%' . $keyword . '%'];
  907. }
  908. if (!empty($param['list_keyword'])) {
  909. $keyword = $param['list_keyword'];
  910. $where[] = ['c.project_name', 'like', '%' . $keyword . '%'];
  911. }
  912. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  913. $order = empty($param['order']) ? 'id desc' : $param['order'];
  914. $app_red = 0;
  915. if($this->user_tpe==0){
  916. $app_where=[
  917. ["status","=",1],
  918. ["entrust_unit","=",get_login_admin("unit_name")]
  919. ];
  920. if(Db::name("appropriation")->where($app_where)->count()>0){$app_red=1;}
  921. }else if($this->user_tpe==2){
  922. //10请款一审,11请款二审,12,请款三审
  923. $app_where=[
  924. ["audit_type",">",9],
  925. ["audit_type","<",13],
  926. ["audit_status","=",1],
  927. ["approver","=",$this->uid]
  928. ];
  929. if($this->Auditmodel->where($app_where)->count()>0){$app_red=1;}
  930. }
  931. $list = $this->Auditmodel->alias("a")->join("cost_project c", "a.project_id=c.id", "left")->where($where)->field("a.*,c.project_num,c.project_status,c.engineering_type,c.sent_review_amount")
  932. ->order($order)->paginate(9999, false, ['query' => $param])
  933. ->each(function ($item, $key) {
  934. $item->approver_name = Db::name("admin")->where("id", $item->approver)->value("nickname");
  935. })->toArray();
  936. $red = 0;
  937. foreach ($list["data"] as $item => $value) {
  938. if ($value["audit_status"] == 1) {
  939. $red = 1;
  940. }
  941. }
  942. $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select();
  943. $red_kan = 0;
  944. foreach ($red_id as $item => $value) {
  945. if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) {
  946. $red_kan = 1;
  947. }
  948. }
  949. $real_list = [];
  950. foreach ($list["data"] as $item => $value) {
  951. if (in_array($value["audit_type"], [2,4, 5, 6,14,15])) {
  952. $a = Db::name("project_report")->where("id", $value["else_id"])->field("title,status")->find();
  953. $value["else_name"] = $a["title"];
  954. $value["else_status"] = $a["status"];
  955. } elseif (in_array($value["audit_type"], [3,7, 8, 9])) {
  956. $a = Db::name("contact")->where("id", $value["else_id"])->field("title,status")->find();
  957. $value["else_name"] = $a["title"];
  958. $value["else_status"] = $a["status"];
  959. }
  960. //,14报告四审,15报告五审
  961. if (in_array($value["audit_type"], [4, 5, 6,14,15])) {
  962. switch ($value["audit_type"]) {
  963. case 4:
  964. $value["audit_name"] = "报告一审";
  965. break;
  966. case 5:
  967. $value["audit_name"] = "报告二审";
  968. break;
  969. case 6:
  970. $value["audit_name"] = "报告三审";
  971. break;
  972. case 14:
  973. $value["audit_name"] = "报告四审";
  974. break;
  975. case 15:
  976. $value["audit_name"] = "报告五审";
  977. break;
  978. }
  979. } elseif (in_array($value["audit_type"], [7, 8, 9])) {
  980. switch ($value["audit_type"]) {
  981. case 7:
  982. $value["audit_name"] = "联系函一审";
  983. break;
  984. case 8:
  985. $value["audit_name"] = "联系函二审";
  986. break;
  987. case 9:
  988. $value["audit_name"] = "联系函三审";
  989. break;
  990. }
  991. } elseif (in_array($value["audit_type"], [10, 11, 12])) {
  992. switch ($value["audit_type"]) {
  993. case 10:
  994. $value["audit_name"] = "请款一审";
  995. break;
  996. case 11:
  997. $value["audit_name"] = "请款二审";
  998. break;
  999. case 12:
  1000. $value["audit_name"] = "请款三审";
  1001. break;
  1002. }
  1003. }
  1004. $real_list[] = $value;
  1005. }
  1006. $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type");
  1007. // halt($real_list);
  1008. View::assign("red_kan", $red_kan);
  1009. View::assign('app_red', $app_red);
  1010. View::assign('red', $red);
  1011. View::assign('list', $real_list);
  1012. View::assign('unit_type', $unit_type);
  1013. // halt($real_list);
  1014. return view();
  1015. }
  1016. /**
  1017. *个人资料
  1018. */
  1019. public function person()
  1020. {
  1021. $person = get_login_admin();
  1022. $red = $this->Auditmodel->where("approver", $this->uid)->where("audit_status", 1)->count();
  1023. $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select();
  1024. $red_kan = 0;
  1025. foreach ($red_id as $item => $value) {
  1026. if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) {
  1027. $red_kan = 1;
  1028. }
  1029. }
  1030. View::assign("red_kan", $red_kan);
  1031. View::assign('red', $red);
  1032. View::assign('person', $person);
  1033. return view();
  1034. }
  1035. /**
  1036. * cp看板内容
  1037. */
  1038. public function detail()
  1039. {
  1040. $param = get_params();
  1041. $id = isset($param['id']) ? $param['id'] : 0;
  1042. $type = isset($param['type']) ? $param['type'] : 0;
  1043. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  1044. $order = empty($param['order']) ? 'a.id desc' : $param['order'];
  1045. $detail = $this->model->getCostProjectById($id);
  1046. $comment = Db::name("project_comment")->where("project_id", $id)->order('create_time', 'desc')->select();
  1047. $file_array = Db::name('ProjectFile')
  1048. ->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')
  1049. ->alias('mf')
  1050. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  1051. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  1052. ->order('mf.create_time desc')
  1053. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  1054. ->select()->toArray();
  1055. $report = Db::name("project_report")
  1056. ->where([["project_id", "=", $id]])
  1057. ->alias("r")->join("admin a", "r.maker_id = a.id")
  1058. ->field("r.*,a.nickname")
  1059. ->select();
  1060. $contact = $this->ContactModel->where([['project_id', '=', $id]])
  1061. ->field('a.*,u.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id')
  1062. ->alias('a')
  1063. ->join('file f', "a.file = f.id", "left")
  1064. ->join('Admin u', 'a.maker_id = u.id', "left")
  1065. ->order($order)
  1066. ->paginate(9999, false, ['query' => $param])
  1067. ->each(function ($item, $key) {
  1068. })->toArray();
  1069. $contact = $contact['data'];
  1070. $where = [
  1071. ["cp_project_record.delete_time", "=", 0],
  1072. ["project_id", "=", $id],
  1073. ["maker_id", "=", get_login_admin('id')]
  1074. ];
  1075. $record = Db::name('project_record')->where($where)
  1076. ->field('a.*,u.nickname as admin_name')
  1077. ->alias('a')
  1078. ->join('Admin u', 'a.maker_id = u.id', "left")
  1079. ->order($order)
  1080. ->select();
  1081. //2是公司,0是财政局,1是业主
  1082. $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type");
  1083. if ($unit_type == 0) {
  1084. $person = self::user($id);
  1085. View::assign('project_five', self::getProjectFive());
  1086. } elseif ($unit_type == 2) {
  1087. $person = self::user($id);
  1088. View::assign('project_five', self::getProjectFiveCompany());
  1089. } else {
  1090. $person = 0;
  1091. View::assign('project_five', self::getProjectFiveYezhu());
  1092. }
  1093. $appropriation_uid = Db::name("appropriation_project")->where("project_id", $id)->value("uid");
  1094. if (empty($appropriation_uid)) {
  1095. $appropriation_data = [];
  1096. $appropriation_file_array = [];
  1097. } else {
  1098. $where = [
  1099. ["id", "=", $appropriation_uid],
  1100. ["status", ">", 0]
  1101. ];
  1102. //请款
  1103. $appropriation = Db::name("appropriation")->where($where)->find();
  1104. if (!empty($appropriation)) {
  1105. $projects = Db::name("appropriation_project")->alias("a")
  1106. ->leftJoin("cost_project c", "a.project_id=c.id")
  1107. ->where("uid", $appropriation["id"])->column("c.project_name,c.sent_review_cost");
  1108. $data = [];
  1109. $appropriation_amount = 0;
  1110. for ($i = 0; $i < count($projects); $i++) {
  1111. $v = $projects[$i];
  1112. $b = $i + 1;
  1113. $appropriation_amount += $v["sent_review_cost"];
  1114. $data[] = $b . "." . $v["project_name"];
  1115. }
  1116. $appropriation_data = $appropriation;
  1117. $appropriation_data["appropriation_amount"] = $appropriation_amount;
  1118. $appropriation_data["project_name"] = $data;
  1119. $appropriation_file_array = Db::name('ProjectFile')
  1120. ->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')
  1121. ->alias('mf')
  1122. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  1123. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  1124. ->order('mf.create_time desc')
  1125. ->where(array('mf.topic_id' => $appropriation_uid, 'mf.module' => 'appropriation'))
  1126. ->select()->toArray();
  1127. } else {
  1128. $appropriation_data = [];
  1129. $appropriation_file_array = [];
  1130. }
  1131. }
  1132. $project_log = self::project_log($id);
  1133. $red = Db::name("new_msg")->where([["uid", '=', $this->uid], ["project_id", "=", $id]])->field('detail,comment,report,user,contact')->find();
  1134. if (empty($red)) {
  1135. $red = ["detail" => 0, "comment" => 0, "report" => 0, "user" => 0, "contact" => 0];
  1136. }
  1137. $field = $this->Field->get_field_rules_new($this->uid);
  1138. $fields = [];
  1139. foreach ($field as $k=>$v){
  1140. if($v==1){
  1141. $fields[$k] = true;
  1142. }else{
  1143. $fields[$k] = false;
  1144. }
  1145. }
  1146. if($this->user_tpe==2){
  1147. $fields["sent_review_approver_amount"] = false;
  1148. $fields["construction_approver_amount"] = false;
  1149. }
  1150. $appointmentList = $this->AppointmentModel->where("project_id",$id)->paginate(9999, false, ['query' => $param])
  1151. ->order("create_time","desc")
  1152. ->each(function ($item) {
  1153. if($item->sponsor_unit==get_login_admin("unit_name")){
  1154. $item->operate = false;
  1155. }else{
  1156. $item->operate = true;
  1157. }
  1158. });;
  1159. // halt($appointmentList->toArray());
  1160. View::assign('field', $fields);
  1161. if (!empty($detail)) {
  1162. View::assign('appointmentList', $appointmentList);
  1163. View::assign('project_log', $project_log);
  1164. View::assign('project_id', $id);
  1165. View::assign('comment', $comment);
  1166. View::assign('record', $record);
  1167. View::assign('contact', $contact);
  1168. View::assign('detail', $detail);
  1169. View::assign('appropriation', $appropriation_data);
  1170. View::assign('file_array', $file_array);
  1171. View::assign('appropriation_file_array', $appropriation_file_array);
  1172. View::assign('report', $report);
  1173. View::assign('person', $person);
  1174. View::assign('red', $red);
  1175. View::assign('unit_type', $unit_type);
  1176. return view();
  1177. } else {
  1178. throw new \think\exception\HttpException(404, '找不到页面');
  1179. }
  1180. }
  1181. /**
  1182. * cp代办内容
  1183. */
  1184. public function pdetail()
  1185. {
  1186. $param = get_params();
  1187. $id = isset($param['id']) ? $param['id'] : 0;
  1188. $type = isset($param['type']) ? $param['type'] : 0;
  1189. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  1190. $order = empty($param['order']) ? 'a.id desc' : $param['order'];
  1191. $detail = $this->model->getCostProjectById($id);
  1192. $comment = Db::name("project_comment")->where("project_id", $id)->order('create_time', 'desc')->select();
  1193. $file_array = Db::name('ProjectFile')
  1194. ->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')
  1195. ->alias('mf')
  1196. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  1197. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  1198. ->order('mf.create_time desc')
  1199. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  1200. ->select()->toArray();
  1201. $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();
  1202. $contact = $this->ContactModel->where([['project_id', '=', $id]])
  1203. ->field('a.*,u.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id')
  1204. ->alias('a')
  1205. ->join('file f', "a.file = f.id", "left")
  1206. ->join('Admin u', 'a.maker_id = u.id', "left")
  1207. ->order($order)
  1208. ->paginate(9999, false, ['query' => $param])
  1209. ->each(function ($item, $key) {
  1210. })->toArray();
  1211. $contact = $contact['data'];
  1212. $where = [
  1213. ["cp_project_record.delete_time", "=", 0],
  1214. ["project_id", "=", $id],
  1215. ["maker_id", "=", get_login_admin('id')]
  1216. ];
  1217. $record = Db::name('project_record')->where($where)
  1218. ->field('a.*,u.nickname as admin_name')
  1219. ->alias('a')
  1220. ->join('Admin u', 'a.maker_id = u.id', "left")
  1221. ->order($order)
  1222. ->select();
  1223. //2是公司,0是财政局,1是业主
  1224. $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type");
  1225. if ($unit_type == 0) {
  1226. $person = self::user($id);
  1227. View::assign('project_five', self::getProjectFive());
  1228. } elseif ($unit_type == 2) {
  1229. $person = self::user($id);
  1230. View::assign('project_five', self::getProjectFiveCompany());
  1231. } else {
  1232. $person = 0;
  1233. View::assign('project_five', self::getProjectFiveYezhu());
  1234. }
  1235. $field = $this->Field->get_field_rules_new($this->uid);
  1236. $fields = [];
  1237. foreach ($field as $k=>$v){
  1238. if($v==1){
  1239. $fields[$k] = true;
  1240. }else{
  1241. $fields[$k] = false;
  1242. }
  1243. }
  1244. if($this->user_tpe==2){
  1245. $fields["sent_review_approver_amount"] = false;
  1246. $fields["construction_approver_amount"] = false;
  1247. }
  1248. View::assign('field', $fields);
  1249. $project_log = self::project_log($id);
  1250. // halt($detail);
  1251. if (!empty($detail)) {
  1252. View::assign('project_log', $project_log);
  1253. View::assign('project_id', $id);
  1254. View::assign('comment', $comment);
  1255. View::assign('record', $record);
  1256. View::assign('contact', $contact);
  1257. View::assign('detail', $detail);
  1258. View::assign('file_array', $file_array);
  1259. View::assign('report', $report);
  1260. View::assign('person', $person);
  1261. return view();
  1262. } else {
  1263. echo '<div style="text-align:center;color:red;margin-top:20%;font-size:425%"><span>项目不存在!</span><br><span>已被删除</span></div>';
  1264. // throw new \think\exception\HttpException(404, '项目不存在');
  1265. }
  1266. }
  1267. /**
  1268. * cp看板报告内容
  1269. */
  1270. public function report_detail()
  1271. {
  1272. $param = get_params();
  1273. $id = isset($param['id']) ? $param['id'] : 0;
  1274. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1275. $detail = Db::name('ProjectReport')->where(['id' => $id])->find();
  1276. if (empty($detail)) {
  1277. if (empty($detail)) {
  1278. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';
  1279. exit;
  1280. }
  1281. } else {
  1282. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  1283. $detail["maker_name"] = $maker_name;
  1284. $file_array = Db::name('ProjectReport')
  1285. ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  1286. ->alias('r')
  1287. ->join('File f', 'r.file = f.id')
  1288. ->join('Admin a', 'r.maker_id = a.id', 'LEFT')
  1289. ->order('r.create_time desc')
  1290. ->where(array('r.id' => $id))
  1291. ->select()->toArray();
  1292. View::assign('file_array', $file_array);
  1293. View::assign('project_id', $project_id);
  1294. View::assign('detail', $detail);
  1295. return view();
  1296. }
  1297. }
  1298. /**
  1299. * cp待办报告内容
  1300. */
  1301. public function report_pdetail()
  1302. {
  1303. $param = get_params();
  1304. $id = isset($param['id']) ? $param['id'] : 0;
  1305. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1306. $detail = Db::name('ProjectReport')->where(['id' => $id])->find();
  1307. if (empty($detail)) {
  1308. if (empty($detail)) {
  1309. echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';
  1310. exit;
  1311. }
  1312. } else {
  1313. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  1314. $detail["maker_name"] = $maker_name;
  1315. $file_array = Db::name('ProjectReport')
  1316. ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  1317. ->alias('r')
  1318. ->join('File f', 'r.file = f.id')
  1319. ->join('Admin a', 'r.maker_id = a.id', 'LEFT')
  1320. ->order('r.create_time desc')
  1321. ->where(array('r.id' => $id))
  1322. ->select()->toArray();
  1323. View::assign('file_array', $file_array);
  1324. View::assign('project_id', $project_id);
  1325. View::assign('detail', $detail);
  1326. return view();
  1327. }
  1328. }
  1329. /**
  1330. *项目日志
  1331. */
  1332. public function project_log($project_id)
  1333. {
  1334. // $project_id = 24;
  1335. $login_admin = get_login_admin();
  1336. $where = array();
  1337. if ($login_admin['user_type'] == 2) {
  1338. $where = [
  1339. ['project_status', '>=', 3],
  1340. ['unit_name', '=', $login_admin['unit_name']],
  1341. ];
  1342. } else {
  1343. if ($login_admin['permission'] != 1) {
  1344. $where = [
  1345. ['unit_name', '=', $login_admin['unit_name']],
  1346. ];
  1347. }
  1348. }
  1349. // dump($where);
  1350. $project_log = Db::name('ProjectLog')->where($where)->where('project_id', $project_id)->order('create_time', 'desc')->select()->toArray();
  1351. foreach ($project_log as $key => $value) {
  1352. $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
  1353. }
  1354. // dump($project_log);
  1355. // View::assign('project_log', $project_log);
  1356. // return View();
  1357. return $project_log;
  1358. }
  1359. /**
  1360. *
  1361. */
  1362. public function sift()
  1363. {
  1364. return view();
  1365. }
  1366. /**
  1367. *项目人员
  1368. */
  1369. public function user($id)
  1370. {
  1371. $ids = $this->model->where("id", $id)->field("entrust_maker,review_head,operate_head,operate_team")->find();
  1372. if (empty($ids)) {
  1373. return [];
  1374. } else {
  1375. $ids->toArray();
  1376. }
  1377. $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"] . ',' . $ids["entrust_maker"];
  1378. $idarr = explode(",", $idarr);
  1379. $param = [];
  1380. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  1381. $list = $this->Adminmodel->whereIn("id", $idarr)->field("id,nickname,unit_name,mobile,email")->paginate(9999, false, ['query' => $param])
  1382. // field("a.id,a.nickname,a.unit_name,a.mobile,a.email,d.title,d.type")->join('department d', 'a.unit_name = d.id', 'LEFT')
  1383. ->each(function ($item) {
  1384. //获取单位的邮箱,单位信息页没做
  1385. $item->email = Db::name('department')->where(['id' => $item->unit_name])->value('email');
  1386. $type = Db::name('department')->where(['id' => $item->unit_name])->value('type');
  1387. $item->unit_name = Db::name('department')->where(['id' => $item->unit_name])->value('title');
  1388. // dump($type);
  1389. if ($type == 0) {
  1390. $item->unit_type = "委托单位";
  1391. } elseif ($type == 1) {
  1392. $item->unit_type = "送审单位";
  1393. } elseif ($type == 2) {
  1394. $item->unit_type = "评审机构";
  1395. } else {
  1396. $item->unit_type = "施工单位";
  1397. }
  1398. })->toArray();
  1399. $list = $list["data"];
  1400. $time_id = time();
  1401. $shigong = $this->model->where('id', $id)->find();
  1402. if ($shigong["construction_unit"] !== null ||
  1403. $shigong["construction_head"] !== null ||
  1404. $shigong["construction_email"] !== null ||
  1405. $shigong["construction_phone"] !== null
  1406. ) {
  1407. $shigongdata["id"] = $time_id;
  1408. $shigongdata["nickname"] = $shigong["construction_unit"];
  1409. $shigongdata["unit_name"] = $shigong["construction_head"];
  1410. $shigongdata["email"] = $shigong["construction_email"];
  1411. $shigongdata["mobile"] = $shigong["construction_phone"];
  1412. $shigongdata["unit_type"] = "施工单位";
  1413. array_push($list, $shigongdata);
  1414. }
  1415. $time_id_sent = time() - 200;
  1416. if ($shigong["sent_review_unit"] !== null ||
  1417. $shigong["sent_review_head"] !== null ||
  1418. $shigong["sent_review_phone"] !== null ||
  1419. $shigong["sent_review_head_email"] !== null
  1420. ) {
  1421. $sent_review_data["id"] = $time_id_sent;
  1422. $sent_review_data["nickname"] = $shigong["sent_review_head_name"];
  1423. $sent_review_data["unit_name"] = $shigong["sent_review_unit_name"];
  1424. $sent_review_data["email"] = $shigong["sent_review_head_email"];
  1425. $sent_review_data["mobile"] = $shigong["sent_review_phone"];
  1426. $sent_review_data["unit_type"] = "送审单位";
  1427. array_push($list, $sent_review_data);
  1428. }
  1429. if (empty($ids['operate_team'])) {
  1430. $operate_team[] = '0';
  1431. } else {
  1432. $operate_team = explode(',', $ids['operate_team']);
  1433. }
  1434. for ($i = 0; $i < count($list); $i++) {
  1435. if ($list[$i]['id'] == $ids['entrust_maker']) {
  1436. // dump($list[$i]['id'],$ids['entrust_maker']);
  1437. $list[$i]["type"] = 1;
  1438. } elseif ($list[$i]['id'] == $ids['review_head']) {
  1439. $list[$i]["type"] = 2;
  1440. } elseif ($list[$i]['id'] == $ids['operate_head']) {
  1441. $list[$i]["type"] = 3;
  1442. } elseif (in_array($list[$i]['id'], $operate_team)) {
  1443. $list[$i]["type"] = 4;
  1444. } elseif ($list[$i]['id'] == $time_id) {
  1445. $list[$i]["type"] = 5;
  1446. } elseif ($list[$i]['id'] !== time() - 1000) {
  1447. $list[$i]["type"] = 6;
  1448. }
  1449. }
  1450. $type = array_column($list, 'type');
  1451. array_multisort($type, SORT_ASC, $list);
  1452. return $list;
  1453. }
  1454. /**
  1455. * 修改个人资料
  1456. */
  1457. public function revise()
  1458. {
  1459. $person = get_login_admin();
  1460. View::assign('person', $person);
  1461. return view();
  1462. }
  1463. /**
  1464. * 消息通知
  1465. * 通用
  1466. */
  1467. public function notice()
  1468. {
  1469. $unread_id = Db::name("admin")->where("id", $this->uid)->value("unread");
  1470. if (empty($unread_id)) {
  1471. $unread_ids = [];
  1472. } else {
  1473. $unread_ids = explode(",", $unread_id);
  1474. }
  1475. $list = Db::name("ProjectMsg")->where("uid", $this->uid)->select();
  1476. if (is_object($list)) {
  1477. $data = $list->toArray();
  1478. }
  1479. $real_data = [];
  1480. foreach ($data as $item => $v) {
  1481. if (in_array($v["id"], $unread_ids)) {
  1482. $v["red"] = 1;
  1483. $real_data[] = $v;
  1484. } else {
  1485. $v["red"] = 0;
  1486. $real_data[] = $v;
  1487. }
  1488. }
  1489. Db::name("admin")->where("id", $this->uid)->update(["unread" => null]);
  1490. View::assign("msg", $real_data);
  1491. return view();
  1492. }
  1493. public function notice_content()
  1494. {
  1495. return view();
  1496. }
  1497. /**
  1498. * 工作记录
  1499. */
  1500. public function record()
  1501. {
  1502. $param = get_params();
  1503. $id = isset($param['id']) ? $param['id'] : 0;
  1504. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1505. $detail = (new ProjectRecord())->detail($id);
  1506. if (empty($detail)) {
  1507. if (empty($detail)) {
  1508. echo '<div style="text-align:center;color:red;margin-top:20%;">该记录不存在</div>';
  1509. exit;
  1510. }
  1511. return '';
  1512. }
  1513. $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname");
  1514. $detail["maker_name"] = $maker_name;
  1515. View::assign('detail', $detail);
  1516. View::assign('project_id', $project_id);
  1517. return view();
  1518. }
  1519. /**
  1520. * 编辑工作记录
  1521. */
  1522. public function record_edit()
  1523. {
  1524. $param = get_params();
  1525. $id = isset($param['id']) ? $param['id'] : 0;//记录id
  1526. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1527. $project = Db::name("cost_project")->where("id", $project_id)->value("project_name");
  1528. $detail = (new ProjectRecord())->getRecordById($id);
  1529. if (!empty($detail)) {
  1530. View::assign('id', $id);
  1531. View::assign('user_type', $this->user_tpe);
  1532. View::assign('project_id', $project_id);
  1533. View::assign('project', $project);
  1534. View::assign('detail', $detail);
  1535. return view();
  1536. } else {
  1537. throw new \think\exception\HttpException(404, '页面不存在');
  1538. }
  1539. }
  1540. /**
  1541. * 添加工作记录
  1542. */
  1543. public function record_add()
  1544. {
  1545. $param = get_params();
  1546. $id = isset($param['id']) ? $param['id'] : 0;//记录id
  1547. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1548. $project = Db::name("cost_project")->where("id", $project_id)->value("project_name");
  1549. View::assign('id', $id);
  1550. View::assign('user_type', $this->user_tpe);
  1551. View::assign('project_id', $project_id);
  1552. View::assign('project', $project);
  1553. return view();
  1554. }
  1555. public function appointment_add()
  1556. {
  1557. $param = get_params();
  1558. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1559. View::assign('user_type', $this->user_tpe);
  1560. View::assign('project_id', $project_id);
  1561. return view();
  1562. }
  1563. /**
  1564. * 临期表格
  1565. */
  1566. public function pending_advent()
  1567. {
  1568. $param = get_params();
  1569. $where = [
  1570. ["delete_time", "=", 0],
  1571. ['project_end_time', '<', strtotime('15 days')],
  1572. ['project_end_time', '>', time()],
  1573. ];
  1574. $where2 = [
  1575. ["delete_time", "=", 0],
  1576. ['project_end_time', '<', strtotime('15 days')],
  1577. ['project_end_time', '>', time()],
  1578. ["project_status", ">", 1]
  1579. ];
  1580. $where3[] = ["project_status", "<", 8];
  1581. if (!empty($param['project_status'])) {
  1582. $where3[] = ['project_status', '=', $param['project_status']];
  1583. }
  1584. if (!empty($param['province'])) {
  1585. $where3[] = ['province', '=', $param['province']];
  1586. }
  1587. if (!empty($param['city'])) {
  1588. $where3[] = ['city', '=', $param['city']];
  1589. }
  1590. if (!empty($param['area'])) {
  1591. $where3[] = ['area', '=', $param['area']];
  1592. }
  1593. if (!empty($param['project_end_time'])) {
  1594. $where3[] = ['project_end_time', '<', $param['project_end_time']];
  1595. }
  1596. if (!empty($param['project_start_time'])) {
  1597. $where3[] = ['project_start_time', '>', $param['project_start_time']];
  1598. }
  1599. if (!empty($param['keyword'])) {
  1600. $keyword = $param['keyword'];
  1601. $where3[] = ['project_name', 'like', '%' . $keyword . '%'];
  1602. }
  1603. if ($this->user_tpe == 0) {
  1604. $where[] = ["entrust_maker", "=", $this->uid];
  1605. $where2[] = ["entrust_approver", "=", $this->uid];
  1606. } else if ($this->user_tpe == 2) {
  1607. $inarr = array();
  1608. $review_unit = $this->model->where("review_unit", get_login_admin("unit_name"))->field('id,review_head,operate_head,operate_team')->select()->toArray();
  1609. for ($i = 0; $i < count($review_unit); $i++) {
  1610. $a = $review_unit[$i];
  1611. $ids = $a["review_head"] . ',' . $a["operate_head"] . ',' . $a["operate_team"];
  1612. $ids = explode(",", $ids);
  1613. $c = in_array($this->uid, $ids);
  1614. if ($c) {
  1615. $inarr[] = $a["id"];
  1616. }
  1617. }
  1618. $where3[] = ["id","in", $inarr];
  1619. } else if ($this->user_tpe == 1) {
  1620. $where[] = ["entrust_maker", "=", $this->uid];
  1621. $where2[] = ["entrust_approver", "=", $this->uid];
  1622. }
  1623. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  1624. $order = empty($param['order']) ? 'id desc' : $param['order'];
  1625. $advent_list = $this->model->where($where3)->where(function ($query) use ($where,$where2) {
  1626. // 第一组条件(entrust_maker)
  1627. $query->where(function ($q1) use ($where) {
  1628. $q1->where($where);
  1629. });
  1630. // 使用 OR 连接第二组条件(entrust_approver)
  1631. $query->whereOr(function ($q2) use ($where2) {
  1632. $q2->where($where2);
  1633. });
  1634. })
  1635. ->order($order)
  1636. ->paginate(9999, false, ['query' => $param])
  1637. ->each(function ($item) {
  1638. $c = $item->project_end_time - time();
  1639. $item->advent_time = floor($c / 86400) . "天";
  1640. });
  1641. $list = $this->Auditmodel->alias("a")->join("cost_project c", "a.project_id=c.id", "left")->where("approver", $this->uid)->field("a.*,c.project_num,c.project_status,c.engineering_type,c.sent_review_amount")
  1642. ->order($order)->paginate(9999, false, ['query' => $param])
  1643. ->each(function ($item, $key) {
  1644. $item->approver_name = Db::name("admin")->where("id", $item->approver)->value("nickname");
  1645. })->toArray();
  1646. $red = 0;
  1647. foreach ($list["data"] as $item => $value) {
  1648. if ($value["audit_status"] == 1) {
  1649. $red = 1;
  1650. }
  1651. }
  1652. $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select();
  1653. $red_kan = 0;
  1654. foreach ($red_id as $item => $value) {
  1655. if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) {
  1656. $red_kan = 1;
  1657. }
  1658. }
  1659. $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type");
  1660. View::assign('unit_type', $unit_type);
  1661. View::assign("red_kan", $red_kan);
  1662. View::assign('red', $red);
  1663. View::assign('advent_list', $advent_list);
  1664. return view();
  1665. }
  1666. /**
  1667. * 逾期项目
  1668. */
  1669. public function pending_late()
  1670. {
  1671. $param = get_params();
  1672. $where = [
  1673. ["delete_time", "=", 0],
  1674. ['project_end_time', '<', time()],
  1675. ];
  1676. $where2 = [
  1677. ["delete_time", "=", 0],
  1678. ['project_end_time', '<', time()],
  1679. ["project_status", ">", 1]
  1680. ];
  1681. if (!empty($param['project_status'])) {
  1682. $where[] = ['project_status', '=', $param['project_status']];
  1683. $where2[] = ['project_status', '=', $param['project_status']];
  1684. }
  1685. if (!empty($param['province'])) {
  1686. $where[] = ['province', '=', $param['province']];
  1687. $where2[] = ['province', '=', $param['province']];
  1688. }
  1689. if (!empty($param['city'])) {
  1690. $where[] = ['city', '=', $param['city']];
  1691. $where2[] = ['city', '=', $param['city']];
  1692. }
  1693. if (!empty($param['area'])) {
  1694. $where[] = ['area', '=', $param['area']];
  1695. $where2[] = ['area', '=', $param['area']];
  1696. }
  1697. if (!empty($param['project_end_time'])) {
  1698. $where[] = ['project_end_time', '<', $param['project_end_time']];
  1699. $where2[] = ['project_end_time', '<', $param['project_end_time']];
  1700. }
  1701. if (!empty($param['project_start_time'])) {
  1702. $where[] = ['project_start_time', '>', $param['project_start_time']];
  1703. $where2[] = ['project_start_time', '>', $param['project_start_time']];
  1704. }
  1705. $where3[] = ["project_status", "<", 8];
  1706. if (!empty($param['keyword'])) {
  1707. $keyword = $param['keyword'];
  1708. $where3[] = ['project_name', 'like', '%' . $keyword . '%'];
  1709. }
  1710. if ($this->user_tpe == 0) {
  1711. $where[] = ["entrust_maker", "=", $this->uid];
  1712. $where2[] = ["entrust_approver", "=", $this->uid];
  1713. } else if ($this->user_tpe == 2) {
  1714. $inarr = array();
  1715. $review_unit = $this->model->where("review_unit", get_login_admin("unit_name"))->field('id,review_head,operate_head,operate_team')->select()->toArray();
  1716. for ($i = 0; $i < count($review_unit); $i++) {
  1717. $a = $review_unit[$i];
  1718. $ids = $a["review_head"] . ',' . $a["operate_head"] . ',' . $a["operate_team"];
  1719. $ids = explode(",", $ids);
  1720. $c = in_array($this->uid, $ids);
  1721. if ($c) {
  1722. $inarr[] = $a["id"];
  1723. }
  1724. }
  1725. $where3[] = ["id","in", $inarr];
  1726. } else if ($this->user_tpe == 1) {
  1727. }
  1728. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  1729. $order = empty($param['order']) ? 'id desc' : $param['order'];
  1730. // halt($where,$where2);
  1731. $late_list = $this->model->where($where3)
  1732. ->where(function ($query) use ($where,$where2) {
  1733. // 第一组条件(entrust_maker)
  1734. $query->where(function ($q1) use ($where) {
  1735. $q1->where($where);
  1736. });
  1737. // 使用 OR 连接第二组条件(entrust_approver)
  1738. $query->whereOr(function ($q2) use ($where2) {
  1739. $q2->where($where2);
  1740. });
  1741. })->order($order)->paginate(9999, false, ['query' => $param])
  1742. ->each(function ($item) {
  1743. $c = time() - $item->project_end_time;
  1744. $item->advent_time = floor($c / 86400) . "天";
  1745. });
  1746. // halt($late_list->toArray());
  1747. $list = $this->Auditmodel->alias("a")->join("cost_project c", "a.project_id=c.id", "left")->where("approver", $this->uid)->field("a.*,c.project_num,c.project_status,c.engineering_type,c.sent_review_amount")
  1748. ->order($order)->paginate(9999, false, ['query' => $param])
  1749. ->each(function ($item, $key) {
  1750. $item->approver_name = Db::name("admin")->where("id", $item->approver)->value("nickname");
  1751. })->toArray();
  1752. $red = 0;
  1753. foreach ($list["data"] as $item => $value) {
  1754. if ($value["audit_status"] == 1) {
  1755. $red = 1;
  1756. }
  1757. }
  1758. $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select();
  1759. $red_kan = 0;
  1760. foreach ($red_id as $item => $value) {
  1761. if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) {
  1762. $red_kan = 1;
  1763. }
  1764. }
  1765. $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type");
  1766. View::assign('unit_type', $unit_type);
  1767. View::assign("red_kan", $red_kan);
  1768. View::assign('red', $red);
  1769. View::assign('late_list', $late_list);
  1770. return view();
  1771. }
  1772. /**
  1773. * 邀请函
  1774. */
  1775. public function invite()
  1776. {
  1777. $param = get_params();
  1778. $id = isset($param['id']) ? $param['id'] : 0;//记录id
  1779. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1780. $project = Db::name("cost_project")->where("id", $project_id)->value("project_name");
  1781. $detail = (new Contact())->detail($id);
  1782. $file_array = Db::name('contact')
  1783. ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id")
  1784. ->alias('r')
  1785. ->join('File f', 'r.file = f.id')
  1786. ->join('Admin a', 'r.maker_id = a.id', 'LEFT')
  1787. ->order('r.create_time desc')
  1788. ->where(array('r.id' => $id))
  1789. ->select()->toArray();
  1790. if (!empty($detail)) {
  1791. View::assign('id', $id);
  1792. View::assign('project_id', $project_id);
  1793. View::assign('project', $project);
  1794. View::assign('detail', $detail);
  1795. View::assign('file_array', $file_array);
  1796. return view();
  1797. } else {
  1798. throw new \think\exception\HttpException(404, '页面不存在');
  1799. }
  1800. }
  1801. public function cost_detail()
  1802. {
  1803. return view();
  1804. }
  1805. public function login()
  1806. {
  1807. return view();
  1808. }
  1809. /**
  1810. * 关联账号
  1811. * 通用
  1812. *
  1813. */
  1814. public function associated()
  1815. {
  1816. $param = get_params();
  1817. $id = get_login_admin("id");
  1818. $acct_connect = Db::name('Admin')->where('id', $id)->value('acct_connect');
  1819. $where = array();
  1820. $where[] = ['status', '>=', 0];
  1821. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  1822. $admins = AdminList::where($where)->with('Department')
  1823. ->where('id', 'in', $acct_connect)
  1824. ->order('create_time asc')
  1825. ->paginate(9999, false, ['query' => $param])
  1826. ->each(function ($item, $key) {
  1827. $groupId = Db::name('AdminGroupAccess')->where(['uid' => $item->id])->column('group_id');
  1828. $groupName = Db::name('AdminGroup')->where('id', 'in', $groupId)->column('title');
  1829. $item->groupName = implode(',', $groupName);
  1830. $item->last_login_time = empty($item->last_login_time) ? '-' : date('Y-m-d H:i', $item->last_login_time);
  1831. })->toArray();
  1832. View::assign('admin', $admins["data"]);
  1833. return view();
  1834. }
  1835. // cp请款函内容
  1836. public function request_detail()
  1837. {
  1838. $param = get_params();
  1839. return view();
  1840. }
  1841. /**
  1842. * 查看审批进度
  1843. */
  1844. public function progress()
  1845. {
  1846. $param = get_params();
  1847. $id = isset($param['id']) ? $param['id'] : 0;
  1848. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  1849. $order = empty($param['order']) ? 'id desc' : $param['order'];
  1850. $list = $this->Auditmodel->alias('a')->join("cost_project c", "a.project_id=c.id", 'left')
  1851. ->field("a.*,c.project_status,c.sent_review_amount,c.engineering_type,c.review_unit_name")->where('else_id', $id)->order('create_time', "sec")
  1852. ->select()
  1853. ->each(function ($item) {
  1854. switch ($item["audit_type"]) {
  1855. case 4:
  1856. $item->else_name = "报告一级审核";
  1857. break;
  1858. case 5:
  1859. $item->else_name = "报告二级审核";
  1860. break;
  1861. case 6:
  1862. $item->else_name = "报告三级审核";
  1863. break;
  1864. }
  1865. });
  1866. View::assign('list', $list);
  1867. return view();
  1868. }
  1869. /**
  1870. * 通讯录
  1871. */
  1872. /**
  1873. * 通讯录
  1874. */
  1875. public function contacts()
  1876. {
  1877. $param = get_params();
  1878. $where = [];
  1879. if (!empty($param["keyword"])) {
  1880. $where = [["a.nickname|d.title", "like", "%" . $param["keyword"] . "%"]];
  1881. }
  1882. //0:财政局;1:业主;2:公司
  1883. if ($this->user_tpe == 0) {
  1884. //财评内部
  1885. $list = Db::name("admin")->alias("a")
  1886. ->where("a.unit_name", get_login_admin("unit_name"))
  1887. ->where("a.status", 1)
  1888. ->where($where)
  1889. ->join("department d", "a.did=d.id", "left")
  1890. ->field("a.id,d.title,a.nickname,a.mobile,a.email")->select();
  1891. } else if ($this->user_tpe == 1) {
  1892. //业主内部
  1893. $list = Db::name("admin")->alias("a")
  1894. ->where("a.unit_name", get_login_admin("unit_name"))
  1895. ->where("a.status", 1)
  1896. ->where($where)
  1897. ->join("department d", "a.did=d.id", "left")
  1898. ->field("a.id,d.title,a.nickname,a.mobile,a.email")
  1899. ->select();
  1900. } else if ($this->user_tpe == 2) {
  1901. $list = Db::name("admin")->alias("a")
  1902. ->where("a.unit_name", get_login_admin("unit_name"))
  1903. ->where("a.status", 1)
  1904. ->where($where)
  1905. ->join("department d", "a.did=d.id", "left")
  1906. ->field("a.id,d.title,a.nickname,a.mobile,a.email")
  1907. ->select();
  1908. }
  1909. View::assign('list', $list);
  1910. return view();
  1911. }
  1912. public function contacts_exterior()
  1913. {
  1914. $param = get_params();
  1915. $where = [];
  1916. if (!empty($param["keyword"])) {
  1917. $where = [["a.nickname|d.title", "like", "%" . $param["keyword"] . "%"]];
  1918. }
  1919. //0:财政局;1:业主;2:公司
  1920. if ($this->user_tpe == 0) {
  1921. //公司负责人
  1922. $list_company = Db::name('department')->alias('d')->join("admin a", "d.leader_id=a.id")
  1923. ->where([["d.type", "=", 2], ["pid", "=", 0], ["d.status", "=", 1]])
  1924. ->where($where)->field("d.id,d.title,d.type,a.nickname,a.mobile,a.email")
  1925. ->select()->toArray();
  1926. $list_proprietor = Db::name('department')->alias('d')->join("admin a", "d.leader_id=a.id")
  1927. ->where([["d.type", "=", 1], ["pid", "=", 0], ["d.status", "=", 1]])
  1928. ->where($where)
  1929. ->field("d.id,d.title,d.type,a.nickname,a.mobile,a.email")
  1930. ->select()->toArray();
  1931. $list_exterior = array_merge($list_company,$list_proprietor);
  1932. } else if ($this->user_tpe == 1) {
  1933. //公司负责人
  1934. $list_company = Db::name('department')->alias('d')->join("admin a", "d.leader_id=a.id")
  1935. ->where([["d.type", "=", 2], ["pid", "=", 0], ["d.status", "=", 1]])
  1936. ->where($where)->field("d.id,d.title,d.type,a.nickname,a.mobile,a.email")
  1937. ->select()->toArray();
  1938. //财评负责人
  1939. $list_entrust = Db::name('department')->alias('d')->join("admin a", "d.leader_id=a.id")
  1940. ->where([["d.type", "=", 0], ["pid", "=", 0], ["d.status", "=", 1]])
  1941. ->where($where)
  1942. ->field("d.id,d.title,d.type,a.nickname,a.mobile,a.email")
  1943. ->select()->toArray();
  1944. $list_exterior = array_merge($list_company,$list_entrust);
  1945. } else if ($this->user_tpe == 2) {
  1946. //公司内部通讯录
  1947. $list_entrust = Db::name('department')->alias('d')->join("admin a", "d.leader_id=a.id")
  1948. ->where([["d.type", "=", 0], ["pid", "=", 0], ["d.status", "=", 1]])
  1949. ->where($where)
  1950. ->field("d.id,d.title,d.type,a.nickname,a.mobile,a.email")
  1951. ->select()->toArray();
  1952. $list_proprietor = Db::name('department')->alias('d')->join("admin a", "d.leader_id=a.id")
  1953. ->where([["d.type", "=", 1], ["pid", "=", 0], ["d.status", "=", 1]])
  1954. ->where($where)
  1955. ->field("d.id,d.title,d.type,a.nickname,a.mobile,a.email")
  1956. ->select()->toArray();
  1957. $list_exterior = array_merge($list_proprietor,$list_entrust);
  1958. }
  1959. View::assign('list_exterior', $list_exterior);
  1960. return view();
  1961. }
  1962. public function getProjectFive()
  1963. {
  1964. $where = [
  1965. ['name', '=', '作业日志-财政局'],
  1966. ['name', '=', '工作记录-财政局'],
  1967. ['name', '=', '项目报告-财政局'],
  1968. ['name', '=', '项目人员-财政局'],
  1969. ['name', '=', '项目动态-财政局'],
  1970. ['name', '=', '项目附件-财政局'],
  1971. ['name', '=', '联系函-财政局'],
  1972. ];
  1973. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  1974. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  1975. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  1976. $login_rules = explode(',', $login_rules);
  1977. $rules_id = array();
  1978. foreach ($list as $key => $value) {
  1979. if ($value['name'] == "作业日志-财政局") {
  1980. if (in_array($value['id'], $login_rules)) {
  1981. $rules_id['project_comments'] = 1;
  1982. } else {
  1983. $rules_id['project_comments'] = 0;
  1984. }
  1985. } else if ($value['name'] == "工作记录-财政局") {
  1986. if (in_array($value['id'], $login_rules)) {
  1987. $rules_id['project_record'] = 1;
  1988. } else {
  1989. $rules_id['project_record'] = 0;
  1990. }
  1991. } else if ($value['name'] == "项目报告-财政局") {
  1992. if (in_array($value['id'], $login_rules)) {
  1993. $rules_id['project_report'] = 1;
  1994. } else {
  1995. $rules_id['project_report'] = 0;
  1996. }
  1997. } else if ($value['name'] == "项目人员-财政局") {
  1998. if (in_array($value['id'], $login_rules)) {
  1999. $rules_id['project_user'] = 1;
  2000. } else {
  2001. $rules_id['project_user'] = 0;
  2002. }
  2003. } else if ($value['name'] == "项目动态-财政局") {
  2004. if (in_array($value['id'], $login_rules)) {
  2005. $rules_id['project_log'] = 1;
  2006. } else {
  2007. $rules_id['project_log'] = 0;
  2008. }
  2009. } else if ($value['name'] == "项目附件-财政局") {
  2010. if (in_array($value['id'], $login_rules)) {
  2011. $rules_id['project_file'] = 1;
  2012. } else {
  2013. $rules_id['project_file'] = 0;
  2014. }
  2015. } else if ($value['name'] == "联系函-财政局") {
  2016. if (in_array($value['id'], $login_rules)) {
  2017. $rules_id['project_contact'] = 1;
  2018. } else {
  2019. $rules_id['project_contact'] = 0;
  2020. }
  2021. }
  2022. }
  2023. return $rules_id;
  2024. }
  2025. public function getProjectFiveCompany()
  2026. {
  2027. $where = [
  2028. ['name', '=', '作业日志-公司'],
  2029. ['name', '=', '工作记录-公司'],
  2030. ['name', '=', '项目报告-公司'],
  2031. ['name', '=', '项目人员-公司'],
  2032. ['name', '=', '项目动态-公司'],
  2033. ['name', '=', '项目附件-公司'],
  2034. ['name', '=', '联系函-公司'],
  2035. ];
  2036. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  2037. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  2038. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  2039. $login_rules = explode(',', $login_rules);
  2040. $rules_id = array();
  2041. foreach ($list as $key => $value) {
  2042. if ($value['name'] == "作业日志-公司") {
  2043. if (in_array($value['id'], $login_rules)) {
  2044. $rules_id['project_comments'] = 1;
  2045. } else {
  2046. $rules_id['project_comments'] = 0;
  2047. }
  2048. } else if ($value['name'] == "工作记录-公司") {
  2049. if (in_array($value['id'], $login_rules)) {
  2050. $rules_id['project_record'] = 1;
  2051. } else {
  2052. $rules_id['project_record'] = 0;
  2053. }
  2054. } else if ($value['name'] == "项目报告-公司") {
  2055. if (in_array($value['id'], $login_rules)) {
  2056. $rules_id['project_report'] = 1;
  2057. } else {
  2058. $rules_id['project_report'] = 0;
  2059. }
  2060. } else if ($value['name'] == "项目人员-公司") {
  2061. if (in_array($value['id'], $login_rules)) {
  2062. $rules_id['project_user'] = 1;
  2063. } else {
  2064. $rules_id['project_user'] = 0;
  2065. }
  2066. } else if ($value['name'] == "项目动态-公司") {
  2067. if (in_array($value['id'], $login_rules)) {
  2068. $rules_id['project_log'] = 1;
  2069. } else {
  2070. $rules_id['project_log'] = 0;
  2071. }
  2072. } else if ($value['name'] == "项目附件-公司") {
  2073. if (in_array($value['id'], $login_rules)) {
  2074. $rules_id['project_file'] = 1;
  2075. } else {
  2076. $rules_id['project_file'] = 0;
  2077. }
  2078. } else if ($value['name'] == "联系函-公司") {
  2079. if (in_array($value['id'], $login_rules)) {
  2080. $rules_id['project_contact'] = 1;
  2081. } else {
  2082. $rules_id['project_contact'] = 0;
  2083. }
  2084. }
  2085. }
  2086. return $rules_id;
  2087. }
  2088. public function getProjectFiveYezhu()
  2089. {
  2090. $where = [
  2091. ['name', '=', '作业日志-业主'],
  2092. ['name', '=', '工作记录-业主'],
  2093. ['name', '=', '项目报告-业主'],
  2094. ['name', '=', '项目人员-业主'],
  2095. ['name', '=', '项目动态-业主'],
  2096. ['name', '=', '项目附件-业主'],
  2097. ['name', '=', '联系函-业主'],
  2098. ];
  2099. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  2100. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  2101. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  2102. $login_rules = explode(',', $login_rules);
  2103. $rules_id = array();
  2104. foreach ($list as $key => $value) {
  2105. if ($value['name'] == "作业日志-业主") {
  2106. if (in_array($value['id'], $login_rules)) {
  2107. $rules_id['project_comments'] = 1;
  2108. } else {
  2109. $rules_id['project_comments'] = 0;
  2110. }
  2111. } else if ($value['name'] == "工作记录-业主") {
  2112. if (in_array($value['id'], $login_rules)) {
  2113. $rules_id['project_record'] = 1;
  2114. } else {
  2115. $rules_id['project_record'] = 0;
  2116. }
  2117. } else if ($value['name'] == "项目报告-业主") {
  2118. if (in_array($value['id'], $login_rules)) {
  2119. $rules_id['project_report'] = 1;
  2120. } else {
  2121. $rules_id['project_report'] = 0;
  2122. }
  2123. } else if ($value['name'] == "项目人员-业主") {
  2124. if (in_array($value['id'], $login_rules)) {
  2125. $rules_id['project_user'] = 1;
  2126. } else {
  2127. $rules_id['project_user'] = 0;
  2128. }
  2129. } else if ($value['name'] == "项目动态-业主") {
  2130. if (in_array($value['id'], $login_rules)) {
  2131. $rules_id['project_log'] = 1;
  2132. } else {
  2133. $rules_id['project_log'] = 0;
  2134. }
  2135. } else if ($value['name'] == "项目附件-业主") {
  2136. if (in_array($value['id'], $login_rules)) {
  2137. $rules_id['project_file'] = 1;
  2138. } else {
  2139. $rules_id['project_file'] = 0;
  2140. }
  2141. } else if ($value['name'] == "联系函-业主") {
  2142. if (in_array($value['id'], $login_rules)) {
  2143. $rules_id['project_contact'] = 1;
  2144. } else {
  2145. $rules_id['project_contact'] = 0;
  2146. }
  2147. }
  2148. }
  2149. return $rules_id;
  2150. }
  2151. public function read_company()
  2152. {
  2153. $param = get_params();
  2154. $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type");
  2155. // halt($param);
  2156. $a = time();
  2157. $id = isset($param["project_id"]) ? $param["project_id"] : $a;
  2158. if ($id == $a) {
  2159. $datas = array();
  2160. $datas["data"] = null;
  2161. return table_assign(0, "无项目", $datas);
  2162. }
  2163. $project = Db::name("appropriation_project")->where("uid", $id)->select();
  2164. $datas["data"] = $project;
  2165. $datas["total"] = count($project);
  2166. if ($param["type"] > 9) {
  2167. $a = time();
  2168. $id = isset($param["project_id"]) ? $param["project_id"] : $a;
  2169. $detail = Db::name("appropriation")->where("id", $id)->find();
  2170. $file_array = Db::name('ProjectFile')
  2171. ->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')
  2172. ->alias('mf')
  2173. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  2174. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  2175. ->order('mf.create_time desc')
  2176. ->where(array('mf.topic_id' => $id, 'mf.module' => 'appropriation'))
  2177. ->select()->toArray();
  2178. $where = [
  2179. ["approver", "=", $this->uid],
  2180. ["audit_status", "<", 5]
  2181. ];
  2182. $list = $this->Auditmodel->alias("a")->join("cost_project c", "a.project_id=c.id", "left")
  2183. ->where($where)->where('audit_status',1)->where('audit_type','in',[10,11,12])
  2184. ->field("a.*,c.project_num,c.project_status,c.engineering_type,c.sent_review_amount")
  2185. ->paginate(9999, false, ['query' => $param])
  2186. ->each(function ($item, $key) {
  2187. $item->approver_name = Db::name("admin")->where("id", $item->approver)->value("nickname");
  2188. })->toArray();
  2189. // halt($list);
  2190. $red = 0;
  2191. foreach ($list["data"] as $item => $value) {
  2192. if ($value["audit_status"] == 1) {
  2193. $red = 1;
  2194. }
  2195. }
  2196. $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select();
  2197. $red_kan = 0;
  2198. foreach ($red_id as $item => $value) {
  2199. if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) {
  2200. $red_kan = 1;
  2201. }
  2202. }
  2203. if($unit_type == 2){
  2204. $auditdata = $this->Auditmodel->where('id',$param['id'])->find();
  2205. $detail['audit_status'] = $auditdata['audit_status'];
  2206. View::assign('auditdata', $auditdata);
  2207. }else{
  2208. $detail['audit_status'] = 0;
  2209. }
  2210. // halt($audit_status,$id);
  2211. // halt($list);
  2212. View::assign('unit_type', $unit_type);
  2213. View::assign('datas', $datas['data']);
  2214. View::assign('id', $id);
  2215. View::assign('detail', $detail);
  2216. View::assign("red_kan", $red_kan);
  2217. View::assign('red', $red);
  2218. View::assign('file_array', $file_array);
  2219. return view();
  2220. }
  2221. }
  2222. public function datastat(){
  2223. return View();
  2224. }
  2225. public function contract()
  2226. {
  2227. return view();
  2228. }
  2229. public function contract_detail()
  2230. {
  2231. return view();
  2232. }
  2233. public function data_statistics($today = 2024)
  2234. {
  2235. $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type");
  2236. if($unit_type == 2){
  2237. $all_sent_review_cost_company = $this->Datastat->sent_review_cost_company($today);
  2238. $review_poportion_company = $this->Datastat->review_poportion_company();
  2239. $sent_poportion_company = $this->Datastat->sent_poportion_company();
  2240. View::assign('all_sent_review_cost_company', $all_sent_review_cost_company);
  2241. View::assign('review_poportion_company', $review_poportion_company);
  2242. View::assign('sent_poportion_company', $sent_poportion_company);
  2243. }elseif($unit_type == 0){
  2244. $all_sent_review_cost = $this->Datastat->sent_review_cost($today);
  2245. $review_poportion = $this->Datastat->review_poportion();
  2246. $sent_poportion = $this->Datastat->sent_poportion();
  2247. View::assign('sent', $all_sent_review_cost);
  2248. View::assign('review_poportion', $review_poportion);
  2249. View::assign('sent_poportion', $sent_poportion);
  2250. }
  2251. View::assign('unit_type', $unit_type);
  2252. return view();
  2253. }
  2254. public function data_statistics_member($today = 2024)
  2255. {
  2256. $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type");
  2257. $cost_project_member = $this->Datastat->cost_project_member($today);
  2258. $cost_month_member = $this->Datastat->cost_month_member($today);
  2259. View::assign('unit_type', $unit_type);
  2260. View::assign('cost_project_member', $cost_project_member);
  2261. View::assign('cost_month_member', $cost_month_member);
  2262. return View();
  2263. }
  2264. }