Index.php 99 KB

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