Index.php 99 KB

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