Index.php 99 KB

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