Index.php 100 KB

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