Index.php 98 KB

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