Index.php 98 KB

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