Cost.php 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  1. <?php
  2. //declare (strict_types=1);
  3. namespace app\admin\controller\project;
  4. use app\admin\BaseController;
  5. use app\admin\model\Admin;
  6. use app\admin\model\Department as DepartmentModel;
  7. use app\admin\model\CostProject as CostProjectModel;
  8. use app\admin\model\ProjectAudit;
  9. use app\admin\model\ProjectMsg;
  10. use app\admin\model\ProjectFile;
  11. use app\admin\validate\project\CostProjectValidate;
  12. use app\wechat\controller\Officialaccount;
  13. use think\db\Where;
  14. use think\exception\ValidateException;
  15. use think\facade\Db;
  16. use think\facade\View;
  17. use think\App;
  18. use app\admin\controller\field\Field;
  19. use app\admin\controller\Pushmessage;
  20. class Cost extends BaseController
  21. {
  22. private array $field_name = [
  23. 'project_num' => '项目编号',
  24. "project_name" => "项目名称",
  25. "project_start_time" => "项目开始时间",
  26. "project_end_time" => "项目结束时间",
  27. "review_unit" => "评审单位",
  28. "sent_review_unit" => "送审单位",
  29. "sent_review_head" => "送审单位负责人",
  30. "sent_review_phone" => "送审单位负责人电话",
  31. "construction_unit" => "施工单位",
  32. "construction_head" => "施工单位负责人",
  33. "construction_phone" => "施工单位负责人电话",
  34. "sent_review_amount" => "送审金额",
  35. "engineering_type" => '工程类型',
  36. ];
  37. /**
  38. * 构造函数
  39. */
  40. public function __construct(App $app)
  41. {
  42. parent::__construct($app);
  43. $this->Field = new Field($this->app);
  44. $this->department = new DepartmentModel();
  45. $this->model = new CostProjectModel();
  46. $this->ProjectAuditModel = new ProjectAudit ();
  47. $this->ProjectMsg = new ProjectMsg();
  48. $this->filemodel = new ProjectFile();
  49. $this->uid = get_login_admin('id');
  50. $this->Adminmodel = new Admin();
  51. $this->time = time();
  52. $this->Officialaccount = new Officialaccount();
  53. $this->Pushmessage = new Pushmessage();
  54. }
  55. /**
  56. * 数据列表
  57. */
  58. public function datalist()
  59. {
  60. if (request()->isAjax()) {
  61. $param = get_params();
  62. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  63. $order = empty($param['order']) ? 'id desc' : $param['order'];
  64. if (isset($param["project_start_time"])) {
  65. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  66. }
  67. if (isset($param["project_end_time"])) {
  68. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  69. }
  70. //项目可见的权限
  71. $field = $this->Field->get_field_rules_new($this->uid);//获取当前登录的id
  72. //1全部-可查看可编辑,2全部-可查看,0与我有关
  73. $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;//等于3
  74. $where[] = ["delete_time", "=", 0];
  75. $where[] = ["project_status", ">", 0];
  76. $where2[] = ["delete_time", "=", 0];
  77. $where2[] = ["project_status", ">", 0];
  78. if ($see_auth == 3||$see_auth == 0) {
  79. $where[] = ["entrust_maker", "=", $this->uid];
  80. $where2[] = ["entrust_approver", "=", $this->uid];
  81. $where2[] = ["project_status", ">", 1];//大于立项
  82. }
  83. $where3 =[];
  84. if (!empty($param['project_status'])) {
  85. $where3[] = ['project_status', '=', $param['project_status']];
  86. }
  87. if (!empty($param['province'])) {
  88. $where3[] = ['province', '=', $param['province']];
  89. }
  90. if (!empty($param['city'])) {
  91. $where3[] = ['city', '=', $param['city']];
  92. }
  93. if (!empty($param['area'])) {
  94. $where3[] = ['area', '=', $param['area']];
  95. }
  96. if (!empty($param['project_end_time'])) {
  97. $where3[] = ['project_end_time', '<', $param['project_end_time']];
  98. }
  99. if (!empty($param['project_start_time'])) {
  100. $where3[] = ['project_start_time', '>', $param['project_start_time']];
  101. }
  102. if (!empty($param['keyword'])) {
  103. $keyword = $param['keyword'];
  104. $where3[] = ['project_num|project_name|review_unit', 'like', '%' . $keyword . '%'];
  105. }
  106. if (!empty($param['review_head_name'])) {
  107. $where3[] = ['review_head_name', 'like', '%' . $param['review_head_name'] . '%'];
  108. }
  109. if (!empty($param['review_unit_name'])) {
  110. $where3[] = ['review_unit_name', 'like', '%' . $param['review_unit_name']. '%'];
  111. }
  112. if (!empty($param['sent_review_unit_name'])) {
  113. $where3[] = ['sent_review_unit_name', 'like', '%' . $param['sent_review_unit_name']. '%'];
  114. }
  115. $where3[] = ["entrust_unit", "=", get_login_admin('unit_name')];
  116. $this->see_auth = $see_auth;
  117. $list = $this->model
  118. ->where($where3)->where(function ($query) use ($where,$where2) {
  119. // 第一组条件(entrust_maker)
  120. $query->where(function ($q1) use ($where) {
  121. $q1->where($where);
  122. });
  123. // 使用 OR 连接第二组条件(entrust_approver)
  124. $query->whereOr(function ($q2) use ($where2) {
  125. $q2->where($where2);
  126. });
  127. })
  128. ->order($order)->paginate($rows, false, ['query' => $param])
  129. ->each(function ($item) {
  130. $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
  131. if ($red) {
  132. if ($red["detail"] || $red["comment"] || $red["report"] || $red["user"] || $red["contact"]) {
  133. $item->red = 1;
  134. }
  135. } else {
  136. $item->red = 0;
  137. }
  138. if (($item->province && $item->city && $item->area)) {
  139. $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
  140. }
  141. $item->creator = Db::name("admin")->where("id",$item->creator)->value("nickname");
  142. $item->self_id = $this->see_auth;
  143. //作业人
  144. $operate_team_names = null;
  145. $operate_team_names_ids = explode(",", $item->operate_team);
  146. for ($i = 0; $i < count($operate_team_names_ids); $i++) {
  147. $name = Db::name("admin")->where("id", $operate_team_names_ids[$i])->value("nickname");
  148. if (!($i == 0)) {
  149. $name = "," . $name;
  150. }
  151. $operate_team_names = $operate_team_names . $name;
  152. }
  153. $item->operate_team_names = $operate_team_names;
  154. });
  155. return table_assign(0, '', $list);
  156. } else {
  157. $field = $this->Field->get_field_rules_new($this->uid);
  158. $fields = [];
  159. foreach ($field as $k=>$v){
  160. if($v!=1){
  161. $fields[$k] = true;
  162. }else{
  163. $fields[$k] = false;
  164. }
  165. }
  166. View::assign('field', $fields);
  167. return view();
  168. }
  169. }
  170. /**
  171. * 数据列表
  172. */
  173. public function followProject()
  174. {
  175. if (request()->isAjax()) {
  176. $param = get_params();
  177. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  178. $order = empty($param['order']) ? 'id desc' : $param['order'];
  179. $userId = get_login_admin('id');
  180. $openid = Db::name("admin")->where('id',$userId)->value("openid");
  181. $follow_project_id = Db::name('follow_project')->where('openid',$openid)->column("project_id");
  182. // halt($openid,$follow_project_id);
  183. if (isset($param["project_start_time"])) {
  184. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  185. }
  186. if (isset($param["project_end_time"])) {
  187. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  188. }
  189. $where[] = ["delete_time", "=", 0];
  190. $where2[] = ["delete_time", "=", 0];
  191. $where3 =[];
  192. if (!empty($param['project_status'])) {
  193. $where3[] = ['project_status', '=', $param['project_status']];
  194. }
  195. if (!empty($param['province'])) {
  196. $where3[] = ['province', '=', $param['province']];
  197. }
  198. if (!empty($param['city'])) {
  199. $where3[] = ['city', '=', $param['city']];
  200. }
  201. if (!empty($param['area'])) {
  202. $where3[] = ['area', '=', $param['area']];
  203. }
  204. if (!empty($param['project_end_time'])) {
  205. $where3[] = ['project_end_time', '<', $param['project_end_time']];
  206. }
  207. if (!empty($param['project_start_time'])) {
  208. $where3[] = ['project_start_time', '>', $param['project_start_time']];
  209. }
  210. if (!empty($param['keyword'])) {
  211. $keyword = $param['keyword'];
  212. $where3[] = ['project_num|project_name|review_unit', 'like', '%' . $keyword . '%'];
  213. }
  214. if (!empty($param['review_head_name'])) {
  215. $where3[] = ['review_head_name', 'like', '%' . $param['review_head_name'] . '%'];
  216. }
  217. if (!empty($param['review_unit_name'])) {
  218. $where3[] = ['review_unit_name', 'like', '%' . $param['review_unit_name']. '%'];
  219. }
  220. if (!empty($param['sent_review_unit_name'])) {
  221. $where3[] = ['sent_review_unit_name', 'like', '%' . $param['sent_review_unit_name']. '%'];
  222. }
  223. $list = $this->model
  224. ->where('id','in',$follow_project_id)
  225. ->where($where3)->where(function ($query) use ($where,$where2) {
  226. // 第一组条件(entrust_maker)
  227. $query->where(function ($q1) use ($where) {
  228. $q1->where($where);
  229. });
  230. // 使用 OR 连接第二组条件(entrust_approver)
  231. $query->whereOr(function ($q2) use ($where2) {
  232. $q2->where($where2);
  233. });
  234. })
  235. ->order($order)->paginate($rows, false, ['query' => $param])
  236. ->each(function ($item) {
  237. if (($item->province && $item->city && $item->area)) {
  238. $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
  239. }
  240. $item->creator = Db::name("admin")->where("id",$item->creator)->value("nickname");
  241. //作业人
  242. $operate_team_names = null;
  243. $operate_team_names_ids = explode(",", $item->operate_team);
  244. for ($i = 0; $i < count($operate_team_names_ids); $i++) {
  245. $name = Db::name("admin")->where("id", $operate_team_names_ids[$i])->value("nickname");
  246. if (!($i == 0)) {
  247. $name = "," . $name;
  248. }
  249. $operate_team_names = $operate_team_names . $name;
  250. }
  251. $item->operate_team_names = $operate_team_names;
  252. });
  253. return table_assign(0, '', $list);
  254. }else {
  255. return view();
  256. }
  257. }
  258. /**
  259. * 临期
  260. */
  261. public function list()
  262. {
  263. // if (request()->isAjax()) {
  264. $param = get_params();
  265. $field = $this->Field->get_field_rules_new($this->uid);
  266. $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;
  267. $where = array();
  268. $where3 = array();
  269. if ($see_auth == 3 || $see_auth == 0) {
  270. $where = [
  271. ["entrust_maker", "=", $this->uid],
  272. ];
  273. $where3 = [
  274. ["entrust_approver", "=", $this->uid],
  275. ["project_status", ">", 1]
  276. ];
  277. }
  278. $where1 = [
  279. ["delete_time", "=", 0],
  280. ['project_end_time', '<', strtotime('15 days')],
  281. ['project_end_time', '>', time()],
  282. ["project_status", "<", 7],
  283. ["entrust_unit","=",get_login_admin("unit_name")]
  284. ];
  285. $where1 = array_merge($where, $where1);
  286. $where2 = array_merge($where1, $where3);
  287. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  288. $order = empty($param['order']) ? 'id desc' : $param['order'];
  289. $list = $this->model->whereOr([$where1, $where2])
  290. ->order($order)
  291. ->paginate(9999, false, ['query' => $param])
  292. ->each(function ($item) {
  293. });
  294. return table_assign(0, '', $list);
  295. // }
  296. }
  297. /**
  298. * 逾期
  299. */
  300. public function list2()
  301. {
  302. $param = get_params();
  303. $field = $this->Field->get_field_rules_new($this->uid);
  304. $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;
  305. $where = array();
  306. $where3 = array();
  307. if ($see_auth == 3 || $see_auth == 0) {
  308. $where = [
  309. ["entrust_maker", "=", $this->uid],
  310. ];
  311. $where3 = [
  312. ["entrust_approver", "=", $this->uid],
  313. ["project_status", ">", 1]
  314. ];
  315. }
  316. $where2 = [
  317. ["delete_time", "=", 0],
  318. ['project_end_time', '<', time()],
  319. ["project_status", "<", 7],
  320. ["entrust_unit","=",get_login_admin("unit_name")]
  321. ];
  322. $where1 = array_merge($where, $where2);
  323. $where2 = array_merge($where2, $where3);
  324. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  325. $order = empty($param['order']) ? 'id desc' : $param['order'];
  326. $list = $this->model->whereOr([$where1, $where2])
  327. ->order($order)->paginate(9999, false, ['query' => $param]);
  328. return table_assign(0, '', $list);
  329. // }
  330. }
  331. /**
  332. * 添加/保存
  333. */
  334. public function add()
  335. {
  336. if (request()->isAjax()) {
  337. $param = get_params();
  338. // halt($param);
  339. // 检验完整性
  340. try {
  341. validate(CostProjectValidate::class)->check($param);
  342. } catch (ValidateException $e) {
  343. // 验证失败 输出错误信息
  344. return to_assign(1, $e->getError());
  345. }
  346. if (isset($param["project_start_time"])) {
  347. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  348. }
  349. if (isset($param["project_end_time"])) {
  350. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  351. }
  352. $param["entrust_unit"] = get_login_admin("unit_name");
  353. $param["entrust_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
  354. $param["entrust_maker"] = $this->uid;
  355. $param["entrust_maker_name"] = get_login_admin("nickname");
  356. $param["entrust_phone"] = get_login_admin("mobile");
  357. if(($param["entrust_second_approver"])&&!empty($param["entrust_second_approver"])){
  358. $param["entrust_second_approver_name"] = get_admin($param["entrust_second_approver"])["nickname"];
  359. }
  360. $param["entrust_approver_name"] = get_admin($param["entrust_approver"])["nickname"];
  361. //送审
  362. // if(isset($param["sent_review_unit"]) && $param["sent_review_unit"] !== ""){
  363. // $sent_review_unit = Db::name("department")->where("id",$param["sent_review_unit"])->find();
  364. // $sent_review_head = Db::name("admin")->where("id",$sent_review_unit['leader_id'])->find();
  365. // $param["sent_review_head_name"] = $sent_review_head["nickname"];
  366. // $param["sent_review_phone"] = $sent_review_head["mobile"];
  367. // }
  368. $param["project_status"] = 1;
  369. $param["maker_type"] = 1;
  370. $param["creator"] = $this->uid;
  371. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  372. unset($param["file_ids"]);
  373. $file_id = [];
  374. $insertId = 0;
  375. try {
  376. $param['create_time'] = time();
  377. //插入数据到并且返回数据id值
  378. $insertId = $this->model->strict(false)->field(true)->insertGetId($param);
  379. if ($file_ids) {
  380. for ($a = 0; $a < count($file_ids); $a++) {
  381. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertId];
  382. }
  383. $this->filemodel->saveAll($file_id);
  384. }
  385. add_log('add', $insertId, $param);
  386. add_project_log("创建项目", $insertId, "创建项目");
  387. add_user($param["entrust_maker"], $insertId);
  388. add_user($param["entrust_approver"], $insertId);
  389. add_user($param["entrust_second_approver"], $insertId);
  390. } catch (\Exception $e) {
  391. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  392. }
  393. return to_assign(0, '操作成功', ['aid' => $insertId]);
  394. //有日志了
  395. } else {
  396. //拿到自身的所属于单位和职位,查询和自身单位一样的账号,
  397. $unit_name = Db::name('admin')->where('id', $this->uid)->value('unit_name');
  398. $leader_id = Db::name("department")
  399. ->where([
  400. ["delete_time", "=", 0],
  401. ["pid", "=", 0],
  402. ["type", "=", 1], //1表示业主
  403. ["entrust_unit", "=", $unit_name]
  404. ])->value('leader_id');
  405. $proprietor_unit_name = Db::name("department")
  406. ->where([
  407. ["delete_time", "=", 0],
  408. ["pid", "=", 0],
  409. ["type", "=", 1], //1表示业主
  410. ["entrust_unit", "=", $unit_name]
  411. ])->column('unit_name');
  412. $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
  413. $where = [
  414. ['status', '>=', 0],
  415. ["admin_group_id","=", $admin_group_id],
  416. ["unit_name","in",$proprietor_unit_name]
  417. ];
  418. $proprietor =Db::name("admin")->where($where)->field(["id","nickname"])->select()->toArray();
  419. $person = Db::name("admin")->where("unit_name", $unit_name)->where("status",">",0)->field(["id", "nickname"])->select()->toArray();
  420. $person = array_values($person);//返回数组所有值,索引从0
  421. $proprietor = array_values($proprietor);
  422. View::assign("person", $person);
  423. View::assign("proprietor", $proprietor);
  424. return view();
  425. }
  426. }
  427. public function getemployeelist()
  428. {
  429. if (request()->isAjax()) {
  430. $data = $this->request->param();
  431. $person = Db::name("admin")->where([["unit_name", "=", $data['id']], ["status", "=", 1]])->field(["id", "nickname", "mobile"])->select();
  432. return $person;
  433. }
  434. }
  435. /**
  436. * 提交审批
  437. */
  438. public function save()
  439. {
  440. if (request()->isAjax()) {
  441. $param = get_params();
  442. $handle = $this->Pushmessage->handleParam($param);//将财务,公司的信息与他分开
  443. $param = $handle['param'];//是项目的信息
  444. // 检验完整性
  445. try {
  446. validate(CostProjectValidate::class)->check($param);
  447. } catch (ValidateException $e) {
  448. // 验证失败 输出错误信息
  449. return to_assign(1, $e->getError());
  450. }
  451. if (isset($param["project_start_time"])) {
  452. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  453. }
  454. if (isset($param["project_end_time"])) {
  455. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  456. }
  457. $param["entrust_unit"] = get_login_admin("unit_name");
  458. $param["entrust_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
  459. $param["entrust_maker"] = $this->uid;
  460. $param["entrust_maker_name"] = get_login_admin("nickname");
  461. $param["entrust_phone"] = get_login_admin("mobile");
  462. //获取审批人员的名称,get_admin获取管理人员信息
  463. $param["entrust_approver_name"] = get_admin($param["entrust_approver"])["nickname"];
  464. if(isset($param["entrust_second_approver"])&&!empty($param["entrust_second_approver"])){
  465. $param["entrust_second_approver_name"] = get_admin($param["entrust_second_approver"])["nickname"];
  466. }
  467. //送审
  468. // if(isset($param["sent_review_unit"]) && $param["sent_review_unit"] !== ""){
  469. // $sent_review_unit = Db::name("department")->where("id",$param["sent_review_unit"])->find();
  470. // $sent_review_head = Db::name("admin")->where("id",$sent_review_unit['leader_id'])->find();
  471. // $param["sent_review_head_name"] = $sent_review_head["nickname"];
  472. // $param["sent_review_phone"] = $sent_review_head["mobile"];
  473. // }
  474. //提交后状态改变为2,待审批中
  475. $param["project_status"] = 2;
  476. $param["maker_type"] = 1;//财政
  477. //id=0代表项目创建
  478. if ($param["id"] == 0) {
  479. $file_id = [];
  480. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  481. unset($param["file_ids"]);//去除附件
  482. // try {
  483. $param['create_time'] = time();
  484. $param['update_time'] = time();
  485. $param["creator"] = $this->uid;//登录的人的id
  486. //插入创建项目到costProject,并获取自增的id就是project_id
  487. $insertGetId = $this->model->where('id', $param['id'])->strict(false)->field(true)->insertGetId($param);
  488. if ($file_ids) {//有附件上传
  489. for ($a = 0; $a < count($file_ids); $a++) {
  490. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertGetId];
  491. }
  492. $this->filemodel->saveAll($file_id);
  493. }
  494. //插入审批数据库记录,project_status=2,审批中
  495. $auditData1 = [
  496. "project_id" => $insertGetId,
  497. "project_name" => $param["project_name"],
  498. "project_type" => "造价项目",
  499. "audit_name" => "项目分配审核一审",
  500. "audit_type" => 1,
  501. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  502. "sponsor_id" => $this->uid,
  503. "sponsor_unit" => $param["review_unit_name"],
  504. "approver" => $param["entrust_approver"],
  505. "approver_name" => Db::name('admin')->where("id", $param["entrust_approver"])->value("nickname"),
  506. "create_time" => time()
  507. ];
  508. //插入
  509. ProjectAudit::create($auditData1);
  510. $MsgData1 = [
  511. "uid" => $auditData1["approver"],
  512. "project_id" => $insertGetId,
  513. "content" => get_login_admin("nickname") . "向您发起了一个" . $auditData1["audit_name"],
  514. "create_time" => time()
  515. ];
  516. $MsgGetId = $this->ProjectMsg->insertGetId($MsgData1);
  517. $unread = Db::name("admin")->where("id", $auditData1["approver"])->value("unread");
  518. if (!empty($unread)) {
  519. $unread = $unread . "," . $MsgGetId;
  520. } else {
  521. $unread = $MsgGetId;
  522. }
  523. Db::name("admin")->where("id", $auditData1["approver"])->update(["unread" => $unread]);
  524. if(empty($handle['financial'])){
  525. $handle['financial'] = (array)$param['entrust_approver'];
  526. }else{
  527. $handle['financial'] = array_merge($handle['financial'], $param['entrust_approver']);
  528. }
  529. if(empty($handle['proprietor'])){
  530. if(isset($param['sent_review_head']) && $param['sent_review_head'] != ""){
  531. $handle['proprietor'] = (array)$param['sent_review_head'];
  532. }else{
  533. $handle['proprietor'] = (array)0;
  534. }
  535. }else{
  536. if(isset($param['sent_review_head']) && $param['sent_review_head'] != ""){
  537. $handle['proprietor'] = array_merge($handle['financial'], $param['sent_review_head']);
  538. }else{
  539. $handle['proprietor'] = (array)0;
  540. }
  541. }
  542. // 发送消息,/项目id/发给的财务人员/公司人员都是int整数
  543. $this->Pushmessage->pushMessage($insertGetId, $handle['financial'], $handle['company'],$handle["proprietor"]);
  544. if(!empty($param["entrust_second_approver"])){
  545. $auditData2 = [
  546. "project_id" => $insertGetId,
  547. "project_name" => $param["project_name"],
  548. "project_type" => "造价项目",
  549. "audit_name" => "项目分配审核二审",
  550. "audit_type" => 0,
  551. "audit_status" =>5,//待启用
  552. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  553. "sponsor_id" => $this->uid,
  554. "sponsor_unit" => $param["review_unit_name"],
  555. "approver" => $param["entrust_second_approver"],
  556. "approver_name" => Db::name('admin')->where("id", $param["entrust_second_approver"])->value("nickname"),
  557. "create_time" => time()
  558. ];
  559. ProjectAudit::create($auditData2);
  560. $MsgData2 = [
  561. "uid" =>$auditData2["approver"],//显示的文本,传来的id
  562. "project_id" => $insertGetId,
  563. "content" => get_login_admin("nickname") . "向您发起了一个" . $auditData2["audit_name"],
  564. "create_time" => time()
  565. ];
  566. $MsgData3 = [
  567. "uid" =>$auditData2["approver"],//显示的文本,传来的id
  568. "project_id" => $insertGetId,
  569. "content" => "您有一个新的待审批项目等待处理。" ."项目名称:".$auditData2["project_name"]." 申请人:".get_login_admin("nickname"),
  570. "create_time" => time()
  571. ];
  572. // 插入第一条数据($MsgData2)
  573. $MsgGetId2 = $this->ProjectMsg->insertGetId($MsgData2);
  574. $unread1 = Db::name("admin")->where("id", $auditData2["approver"])->value("unread");
  575. if (!empty($unread1)) {
  576. $unread1 = $unread1. ",". $MsgGetId2;
  577. } else {
  578. $unread1 = $MsgGetId2;
  579. }
  580. Db::name("admin")->where("id", $auditData2["approver"])->update(["unread" => $unread1]);
  581. //插入第二条
  582. $MsgGetId3 = $this->ProjectMsg->insertGetId($MsgData3);
  583. $unread2 = Db::name("admin")->where("id", $auditData2["approver"])->value("unread");
  584. if (!empty($unread2)) {
  585. $unread2 = $unread2. ",". $MsgGetId3 ;
  586. } else {
  587. $unread2 = $MsgGetId3;
  588. }
  589. Db::name("admin")->where("id", $auditData2["approver"])->update(["unread" => $unread2]);
  590. // if(empty($handle['financial'])){
  591. // $handle['financial'] = (array)$param['entrust_second_approver'];
  592. // }else{
  593. // $handle['financial'] = array_merge($handle['financial'], $param['entrust_second_approver']);
  594. // }
  595. // // 发送消息,/项目id/发给的财务人员/公司人员都是int整数
  596. // $this->Pushmessage->pushMessage($insertGetId, $handle['financial'], $handle['company']);
  597. }
  598. add_log('edit', $insertGetId, $param);
  599. add_project_log("创建项目", $insertGetId, $param["project_name"]);
  600. $secondApproverName =!empty($param["entrust_second_approver"])? "第二审核:".$auditData2["approver_name"] : "";
  601. add_project_log("提交立项审批", $insertGetId, "提交立项审批, 审批人有:第一审核:". $auditData1["approver_name"]. " ". $secondApproverName);
  602. add_user($param["entrust_maker"], $insertGetId);
  603. add_user($param["entrust_approver"], $insertGetId);
  604. //新增
  605. }
  606. else {
  607. //编辑时
  608. try {
  609. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  610. unset($param["file_ids"]);
  611. $param['update_time'] = time();
  612. $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param);
  613. if ($file_ids) {
  614. for ($a = 0; $a < count($file_ids); $a++) {
  615. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $param['id']];
  616. }
  617. $this->filemodel->saveAll($file_id);
  618. }
  619. //审批记录,project_status=2,审批中,编辑时传过来的id就是已经创建好了的project_id
  620. $auditData1 = [
  621. "project_id" => $param['id'],
  622. "project_name" => $param["project_name"],
  623. "project_type" => "造价项目",
  624. "audit_name" => "项目分配审核一审",
  625. "audit_type" => 1,
  626. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  627. "sponsor_id" => $this->uid,
  628. "sponsor_unit" => $param["review_unit_name"],
  629. "approver" => $param["entrust_approver"],
  630. "approver_name" => Db::name('admin')->where("id", $param["entrust_approver"])->value("nickname"),
  631. "create_time" => time()
  632. ];
  633. ProjectAudit::create($auditData1);
  634. //审批记录消息
  635. $MsgData1 = [
  636. "uid" => $auditData1["approver"],
  637. "project_id" => $param['id'],
  638. "content" => get_login_admin("nickname") . "向您发起了一个" . $auditData1["audit_name"],
  639. "create_time" => time()
  640. ];
  641. $MsgGetId = $this->ProjectMsg->insertGetId($MsgData1);
  642. $unread = Db::name("admin")->where("id", $auditData1["approver"])->value("unread");
  643. if (!empty($unread)) {
  644. $unread = $unread . "," . $MsgGetId;
  645. } else {
  646. $unread = $MsgGetId;
  647. }
  648. Db::name("admin")->where("id", $auditData1["approver"])->update(["unread" => $unread]);
  649. add_project_log("提交立项审批", $param['id'], "提交立项审批");
  650. add_user($param["entrust_approver"], $param['id']);
  651. if(empty($handle['financial'])){
  652. $handle['financial'] = (array)$param['entrust_approver'];
  653. }else{
  654. $handle['financial'] = array_merge($handle['financial'], $param['entrust_approver']);
  655. }
  656. $this->Pushmessage->pushMessage($param['id'], $handle['financial'], $handle['company']);
  657. //二
  658. if(!empty($param["entrust_second_approver"])){
  659. $auditData2 = [
  660. "project_id" => $param['id'],
  661. "project_name" => $param["project_name"],
  662. "project_type" => "造价项目",
  663. "audit_name" => "项目分配审核二审",
  664. "audit_type" => 0,
  665. "audit_status" =>5,//待启用
  666. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  667. "sponsor_id" => $this->uid,
  668. "sponsor_unit" => $param["review_unit_name"],
  669. "approver" => $param["entrust_second_approver"],
  670. "approver_name" => Db::name('admin')->where("id", $param["entrust_second_approver"])->value("nickname"),
  671. "create_time" => time()
  672. ];
  673. ProjectAudit::create($auditData2);
  674. $MsgData2 = [
  675. "uid" =>$auditData2["approver"],//显示的文本,传来的id
  676. "project_id" => $param['id'],
  677. "content" => get_login_admin("nickname") . "向您发起了一个" . $auditData2["audit_name"],
  678. "create_time" => time()
  679. ];
  680. $MsgGetId = $this->ProjectMsg->insertGetId($MsgData2);
  681. $unread = Db::name("admin")->where("id", $auditData2["approver"])->value("unread");
  682. if (!empty($unread)) {
  683. $unread = $unread . "," . $MsgGetId;
  684. } else {
  685. $unread = $MsgGetId;
  686. }
  687. Db::name("admin")->where("id", $auditData2["approver"])->update(["unread" => $unread]);
  688. add_user($param["entrust_second_approver"], $param['id']);
  689. $MsgData3 = [
  690. "uid" =>$auditData2["approver"],//显示的文本,传来的id
  691. "project_id" => $param["id"],
  692. "content" => "您有一个新的待审批项目等待处理。" ."项目名称:".$auditData2["project_name"]." 申请人:".get_login_admin("nickname"),
  693. "create_time" => time()
  694. ];
  695. //插入第二条
  696. $MsgGetId3 = $this->ProjectMsg->insertGetId($MsgData3);
  697. $unread2 = Db::name("admin")->where("id", $auditData2["approver"])->value("unread");
  698. if (!empty($unread2)) {
  699. $unread2 = $unread2. ",". $MsgGetId3 ;
  700. } else {
  701. $unread2 = $MsgGetId3;
  702. }
  703. Db::name("admin")->where("id", $auditData2["approver"])->update(["unread" => $unread2]);
  704. //发送消息给第二个人有问题//你有一个审批待处理
  705. // if(empty($handle['financial'])){
  706. // $handle['financial'] = (array)$param['entrust_second_approver'];
  707. // }else{
  708. // $handle['financial'] = array_merge($handle['financial'], $param['entrust_second_approver']);
  709. // }
  710. // $this->Pushmessage->pushMessage($param['id'], $handle['financial'],$handle["company"]);
  711. }
  712. } catch (\Exception $e) {
  713. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  714. }
  715. }
  716. return to_assign(0, "操作成功");
  717. }
  718. }
  719. /**
  720. * 撤回
  721. */
  722. public function withdraw()
  723. {
  724. if (request()->isAjax()) {
  725. $param = get_params();
  726. $status = Db::name("cost_project")->where("id", $param["id"])->field("project_status")->select();
  727. // halt($status[0]["status"]);
  728. if ($status[0]["project_status"] < 3) {
  729. if (isset($param["project_start_time"])) {
  730. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  731. }
  732. if (isset($param["project_end_time"])) {
  733. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  734. }
  735. $param = array_merge($param, ["project_status" => 1]);
  736. try {
  737. $param['update_time'] = time();
  738. $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param);
  739. Db::name("ProjectAudit")->where([["project_id", "=", $param["id"]], ["audit_status", "in", [0,1,5]], ["audit_name", "in", ["项目分配审核一审", "项目分配审核二审"]]])->delete();
  740. add_log('edit', $param['id'], $param);
  741. add_project_log('撤回', $param['id'], "撤回");
  742. } catch (\Exception $e) {
  743. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  744. }
  745. return to_assign(0, "操作成功");
  746. } else {
  747. return to_assign(0, "已审核,无法撤回");
  748. }
  749. }
  750. }
  751. /**
  752. * 编辑|保存
  753. */
  754. public function edit()
  755. {
  756. $param = get_params();
  757. // halt($param);
  758. $type = isset($param['type']) ? $param['type'] : 0;
  759. if (request()->isAjax()) {
  760. $id = isset($param['id']) ? $param['id'] : 0;
  761. $detail = $this->model->getCostProjectById($id);
  762. if ($type == 2) {
  763. $review_unit_name = Db::name('department')->where(['id' => $detail["review_unit"]])->value('title');
  764. $unit_name = Db::name('admin')->where('id', $this->uid)->value('unit_name');
  765. $person = Db::name("admin")->where([["unit_name", "=", $unit_name], ["status", "=", 1]])->field(["id", "nickname"])->select()->toArray();
  766. $leader_id = Db::name("department")
  767. ->where([
  768. ["delete_time", "=", 0],
  769. ["pid", "=", 0],
  770. ["type", "=", 1], //1表示业主
  771. ["entrust_unit", "=", $unit_name]
  772. ])->value('leader_id');
  773. $proprietor_unit_name = Db::name("department")
  774. ->where([
  775. ["delete_time", "=", 0],
  776. ["pid", "=", 0],
  777. ["type", "=", 1], //1表示业主
  778. ["entrust_unit", "=", $unit_name]
  779. ])->column('unit_name');
  780. $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
  781. $where = [
  782. ['status', '>=', 0],
  783. ["admin_group_id","=", $admin_group_id],
  784. ["unit_name","in",$proprietor_unit_name]
  785. ];
  786. $proprietor =Db::name("admin")->where($where)->field(["id","nickname"])->select()->toArray();
  787. $review_person = Db::name("admin")->where([["unit_name", "=", $detail["review_unit"]], ["status", "=", 1]])->field(["id", "nickname"])->select();
  788. $review_name = Db::name("admin")->where("id", $detail['review_head'])->field(["id", "nickname"])->find();
  789. $audit = Db::name("project_audit")->where([["project_id", "=", $id], ["sponsor_id", "=", $this->uid]])->order('create_time', 'desc')->select();
  790. $file_array = Db::name('ProjectFile')
  791. ->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')
  792. ->alias('mf')
  793. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  794. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  795. ->order('mf.create_time desc')
  796. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  797. ->select()->toArray();
  798. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  799. $comment = Db::name("project_comment")->where("type",$comment_type)
  800. ->where("project_id", $id)->order('create_time', 'asc')->select();
  801. $project_log = self::project_log($id);
  802. View::assign('project_log', $project_log);
  803. $field = $this->Field->get_field_rules_new($this->uid);
  804. $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
  805. if ($detail["project_end_time"]!=null){
  806. $c = $detail['project_end_time'] - time();
  807. if ($c > 0) {
  808. $advent_time = floor($c / 86400) . "天";
  809. } else {
  810. $c = -$c;
  811. $advent_time = floor($c / 86400) . "天";
  812. }
  813. }else{
  814. $advent_time = null;
  815. }
  816. if (!empty($detail)) {
  817. View::assign('advent_time', $advent_time);
  818. View::assign('comment', $comment);
  819. View::assign('project_id', $id);
  820. View::assign("audit", $audit);
  821. View::assign("review_name", $review_name);
  822. View::assign("review_person", $review_person);
  823. View::assign("person", $person);
  824. View::assign("proprietor", $proprietor);
  825. View::assign('detail', $detail);
  826. View::assign('review_unit_name', $review_unit_name);
  827. View::assign('field', $field);
  828. // dump($field_edit);
  829. View::assign('field_edit', $field_edit);
  830. View::assign('file_array', $file_array);
  831. View::assign('project_five', self::getProjectFive());
  832. return view();
  833. } else {
  834. throw new \think\exception\HttpException(404, '找不到页面');
  835. }
  836. }
  837. if (isset($param["project_start_time"])) {
  838. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  839. }
  840. if (isset($param["project_end_time"])) {
  841. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  842. }
  843. //二审
  844. if(($param["entrust_second_approver"])&&!empty($param["entrust_second_approver"])){
  845. $param["entrust_second_approver_name"] = get_admin($param["entrust_second_approver"])["nickname"];
  846. }
  847. //财评送审
  848. if(isset($detail["sent_review_head"]) && $detail.proprietor_status==0){
  849. $param["sent_review_head_name"] = get_admin($param["sent_review_head"])["nickname"];
  850. $param["sent_review_unit"]=get_admin($param["sent_review_head"])["unit_name"];
  851. $param["sent_review_unit_name"]=Db::name("department")->where("id",$param["sent_review_unit"])->value("title");
  852. $param["sent_review_phone"] = get_admin($param["sent_review_head"])["mobile"];//电话
  853. }
  854. //业主创建送审
  855. if(isset($detail["sent_review_head"])&&$detail.proprietor_status==3){
  856. $param["sent_review_head_name"] = get_admin($detail["sent_review_head"])["nickname"];
  857. $param["sent_review_unit"]=get_admin($detail["sent_review_head"])["unit_name"];
  858. $param["sent_review_unit_name"]=Db::name("department")->where("id",$detail["sent_review_unit"])->value("title");
  859. $param["sent_review_phone"] = get_admin($detail["sent_review_head"])["mobile"];//电话
  860. }
  861. $field_name = array_keys($this->field_name);
  862. $ab = $this->model->where("id", $param["id"])->field($field_name)->find()->toArray();
  863. $ab["project_start_time"] = date('Y-m-d', $ab["project_start_time"]);
  864. $ab["project_end_time"] = date('Y-m-d', $ab["project_end_time"]);
  865. $c = array_intersect_key($param, $ab);
  866. if (isset($c["project_start_time"])) {
  867. $c["project_start_time"] = date('Y-m-d', $c["project_start_time"]);
  868. }
  869. if (isset($c["project_end_time"])) {
  870. $c["project_end_time"] = date('Y-m-d', $c["project_end_time"]);
  871. }
  872. $maker_name = get_login_admin("nickname");
  873. $content = '';
  874. foreach ($c as $key => $value) {
  875. if ($c[$key] !== $ab[$key]) {
  876. $value = !empty($value) ? $value : "无";
  877. $content = $content . $this->field_name[$key] . "从" . $ab[$key] . "修改为" . $value . ",";
  878. }
  879. }
  880. $content = rtrim($content, ",");
  881. if (empty($content)) {
  882. $content = "无修改";
  883. }
  884. add_project_log('编辑', $param["id"], $content, 1);
  885. $this->model->editCostProject($param);
  886. } else {//提交前
  887. $id = isset($param['id']) ? $param['id'] : 0;
  888. $detail = $this->model->getCostProjectById($id);
  889. $review_unit_name = Db::name('department')->where(['id' => $detail["review_unit"]])->value('title');
  890. $unit_name = get_login_admin("unit_name");
  891. $person = Db::name("admin")->where([["unit_name", "=", $unit_name], ["status", "=", 1]])->field(["id", "nickname"])->select()->toArray();
  892. $review_person = Db::name("admin")->where([["unit_name", "=", $detail["review_unit"]], ["status", "=", 1]])->field(["id", "nickname"])->select();
  893. $review_name = Db::name("admin")->where("id", $detail['review_head'])->field(["id", "nickname"])->find();
  894. $audit = Db::name("project_audit")->where([["project_id", "=", $id], ["sponsor_id", "=", $this->uid]])->order('create_time', 'desc')->select();
  895. $file_array = Db::name('ProjectFile')
  896. ->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')
  897. ->alias('mf')
  898. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  899. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  900. ->order('mf.create_time desc')
  901. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  902. ->select()->toArray();
  903. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  904. $comment = Db::name("project_comment")->where("type",$comment_type)
  905. ->where("project_id", $id)->order('create_time', 'asc')->select();
  906. $project_log = self::project_log($id);
  907. View::assign('project_log', $project_log);
  908. $field = $this->Field->get_field_rules_new($this->uid);
  909. $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
  910. //小红点消息
  911. $red = Db::name("new_msg")->where([["uid", '=', $this->uid], ["project_id", "=", $id]])->field('detail,comment,report,user,contact')->find();
  912. if (empty($red)) {
  913. $red = ["detail" => 0, "comment" => 0, "report" => 0, "user" => 0, "contact" => 0];
  914. }
  915. // dump($red);
  916. if ($detail['project_end_time']!=null){
  917. $c = $detail['project_end_time'] - time();
  918. if ($c > 0) {
  919. $advent_time = floor($c / 86400) . "天";
  920. } else {
  921. $c = -$c;
  922. $advent_time = floor($c / 86400) . "天";
  923. }
  924. }else{
  925. $advent_time = null;
  926. }
  927. $detail["project_end_time"] !=null?$detail["project_end_time"]:null;
  928. $detail["project_start_time"] !=null?$detail["project_start_time"]:null;
  929. //送审业主
  930. $leader_id = Db::name("department")
  931. ->where([
  932. ["delete_time", "=", 0],
  933. ["pid", "=", 0],
  934. ["type", "=", 1], //1表示业主
  935. ["entrust_unit", "=", $unit_name]
  936. ])->value('leader_id');
  937. $proprietor_unit_name = Db::name("department")
  938. ->where([
  939. ["delete_time", "=", 0],
  940. ["pid", "=", 0],
  941. ["type", "=", 1], //1表示业主
  942. ["entrust_unit", "=", $unit_name]
  943. ])->column('unit_name');
  944. // dump( $proprietor_unit_name);
  945. $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
  946. $where = [
  947. ['status', '>=', 0],
  948. ["admin_group_id","=", $admin_group_id],
  949. ["unit_name","in",$proprietor_unit_name]
  950. ];
  951. $proprietor =Db::name("admin")->where($where)->field(["id","nickname"])->select()->toArray();
  952. $proprietor = array_values($proprietor);
  953. View::assign("proprietor", $proprietor);
  954. //
  955. if (!empty($detail)) {
  956. View::assign('advent_time', $advent_time);
  957. View::assign('comment', $comment);
  958. View::assign('project_id', $id);
  959. View::assign('red', $red);
  960. View::assign("audit", $audit);
  961. View::assign("review_name", $review_name);
  962. View::assign("review_person", $review_person);
  963. View::assign("person", $person);
  964. View::assign('detail', $detail);
  965. View::assign('review_unit_name', $review_unit_name);
  966. View::assign('field', $field);
  967. // dump($field_edit);
  968. View::assign('field_edit', $field_edit);
  969. View::assign('file_array', $file_array);
  970. View::assign('project_five', self::getProjectFive());
  971. return view();
  972. } else {
  973. throw new \think\exception\HttpException(404, '找不到页面');
  974. }
  975. }
  976. }
  977. public function get_file(){
  978. $param = get_params();
  979. $id = isset($param['id']) ? $param['id'] : 0;
  980. $file_array = Db::name('ProjectFile')
  981. ->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,mf.remark')
  982. ->alias('mf')
  983. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  984. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  985. ->order('mf.create_time desc')
  986. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  987. ->paginate(9999, false, ['query' => $param]);
  988. return table_assign(0, '', $file_array);
  989. }
  990. public function project_log($project_id)
  991. {
  992. // $project_id = 24;
  993. $login_admin = get_admin(get_login_admin('id'));
  994. $where = array();
  995. if ($login_admin['user_type'] == 2) {
  996. $where = [
  997. ['project_status', '>=', 3],
  998. ['unit_name', '=', $login_admin['unit_name']],
  999. ];
  1000. } else {
  1001. if ($login_admin['permission'] != 1) {
  1002. $where = [
  1003. ['unit_name', '=', $login_admin['unit_name']],
  1004. ];
  1005. }
  1006. }
  1007. // dump($where);
  1008. $project_log = Db::name('ProjectLog')->where($where)
  1009. ->where('project_id', $project_id)
  1010. ->order('create_time', 'desc')
  1011. ->select()->toArray();
  1012. foreach ($project_log as $key => $value) {
  1013. $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
  1014. if($login_admin['user_type'] != 0){
  1015. if(str($project_log[$key]['content'], '送审单位承担审核费')){
  1016. unset($project_log[$key]);
  1017. }
  1018. if(str($project_log[$key]['content'], '施工单位负责核减超5%评审费部分')){
  1019. unset($project_log[$key]);
  1020. }
  1021. }
  1022. }
  1023. $project_log = array_values($project_log);
  1024. // dump($project_log);
  1025. // View::assign('project_log', $project_log);
  1026. // return View();
  1027. return $project_log;
  1028. }
  1029. /**
  1030. * 查看信息
  1031. */
  1032. public function read()
  1033. {
  1034. $param = get_params();
  1035. $id = isset($param['id']) ? $param['id'] : 0;
  1036. // dump($id);
  1037. $detail = $this->model->getCostProjectById($id);
  1038. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  1039. $comment = Db::name("project_comment")->where("type",$comment_type)
  1040. ->where("project_id", $id)->order('create_time', 'asc')->select();
  1041. $file_array = Db::name('ProjectFile')
  1042. ->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')
  1043. ->alias('mf')
  1044. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  1045. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  1046. ->order('mf.create_time desc')
  1047. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  1048. ->select()->toArray();
  1049. $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();
  1050. $uid = Db::name("relation")->where("uuid",$id)->column("uid");
  1051. $contract = Db::name("contract")->whereIn("id",$uid)
  1052. ->where("subject_id",get_login_admin("unit_name"))->column("id,name,type,sign_time,sign_name");
  1053. //小红点消息
  1054. $red = Db::name("new_msg")->where([["uid", '=', $this->uid], ["project_id", "=", $id]])->field('detail,comment,report,user,contact')->find();
  1055. if (empty($red)) {
  1056. $red = ["detail" => 0, "comment" => 0, "report" => 0, "user" => 0, "contact" => 0];
  1057. }
  1058. //剩余时间
  1059. $c = $detail['project_end_time'] - time();
  1060. if ($c > 0) {
  1061. $advent_time = floor($c / 86400) . "天";
  1062. } else {
  1063. $c = -$c;
  1064. $advent_time = floor($c / 86400) . "天";
  1065. }
  1066. $project_log = self::project_log($id);
  1067. View::assign('project_log', $project_log);
  1068. // halt($project_log);
  1069. // 根据用户id 查询其能显示的字段
  1070. $field = $this->Field->get_field_rules_new(get_login_admin('id'));
  1071. // dump($field);
  1072. if (!empty($detail)) {
  1073. View::assign('advent_time', $advent_time);
  1074. View::assign('project_id', $id);
  1075. View::assign('comment', $comment);
  1076. View::assign('field', $field);
  1077. View::assign('detail', $detail);
  1078. View::assign('file_array', $file_array);
  1079. View::assign('report', $report);
  1080. View::assign('contract', $contract);
  1081. View::assign('red', $red);
  1082. View::assign('project_five', self::getProjectFive());
  1083. // dump(self::getProjectFive());
  1084. return view();
  1085. } else {
  1086. throw new \think\exception\HttpException(404, '找不到页面');
  1087. }
  1088. }
  1089. /**
  1090. * 删除
  1091. * type=0,逻辑删除,默认
  1092. * type=1,物理删除
  1093. */
  1094. public function del()
  1095. {
  1096. $param = get_params();
  1097. $status = Db::name("cost_project")->where("id", $param["id"])->field("project_status")->select();
  1098. if ($status[0]["project_status"] < 3) {
  1099. $id = isset($param['id']) ? $param['id'] : 0;
  1100. $type = isset($param['type']) ? $param['type'] : 0;
  1101. add_project_log("删除项目", $id, "删除项目");
  1102. $this->model->delCostProjectById($id, $type);
  1103. } else {
  1104. return to_assign(0, "已审核,无法删除");
  1105. }
  1106. }
  1107. //获取客户列表
  1108. public function get_customer()
  1109. {
  1110. $param = get_params();
  1111. $where = array();
  1112. if (!empty($param['keywords'])) {
  1113. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  1114. }
  1115. $where = [
  1116. ["delete_time", "=", 0],
  1117. ["pid", "=", 0],
  1118. ["type", "=", 2]
  1119. ];
  1120. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  1121. $list = $this->department->field('id,title,address,leader_id')->order('id asc')->where($where)->paginate($rows, false)
  1122. ->each(function ($item) {
  1123. $item->nickname = Db::name('admin')->where(['id' => $item->leader_id])->value('nickname');
  1124. $item->mobile = Db::name('admin')->where(['id' => $item->leader_id])->value('mobile');
  1125. });
  1126. table_assign(0, '', $list);
  1127. }
  1128. //获取客户列表
  1129. public function addConstructionPeople()
  1130. {
  1131. if (request()->isAjax()) {
  1132. $param = get_params();
  1133. if ($param['type'] == '1') {
  1134. $data = $this->model->where('id', $param['data']['id'])->find();
  1135. if ($data["construction_unit"] !== null ||
  1136. $data["construction_head"] !== null ||
  1137. $data["construction_email"] !== null ||
  1138. $data["construction_phone"] !== null
  1139. ) {
  1140. return to_assign(0, "已存在!!");
  1141. } else {
  1142. return to_assign(200, "请上传!!");
  1143. }
  1144. } else {
  1145. $this->model->addConstructionPeople($param['data']);
  1146. }
  1147. add_project_log('添加施工单位人员', $param['data']['id'], '添加施工单位人员');
  1148. } else {
  1149. $param = get_params();
  1150. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1151. //关联项目id
  1152. View::assign('project_id', $project_id);
  1153. return view();
  1154. }
  1155. }
  1156. //获取业主列表
  1157. public function get_proprietor_list()
  1158. {
  1159. $param = get_params();
  1160. $where = array();
  1161. if (!empty($param['keywords'])) {
  1162. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  1163. }
  1164. $where = [
  1165. ["delete_time", "=", 0],
  1166. ["pid", "=", 0],
  1167. ["type", "=", 1],
  1168. ["entrust_unit", "=", get_admin($this->uid)['unit_name']]
  1169. ];
  1170. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  1171. $list = $this->department->field('id,title,address,leader_id')->order('id asc')->where($where)->paginate($rows, false)
  1172. ->each(function ($item) {
  1173. $item->nickname = Db::name('admin')->where(['id' => $item->leader_id])->value('nickname');
  1174. $item->mobile = Db::name('admin')->where(['id' => $item->leader_id])->value('mobile');
  1175. });
  1176. // halt($list);
  1177. table_assign(0, '', $list);
  1178. }
  1179. public function add_sent_review_unit()
  1180. {
  1181. if (request()->isAjax()) {
  1182. $param = get_params();
  1183. if ($param['type'] == '1') {
  1184. $data = $this->model->where('id', $param['data']['id'])->find();
  1185. if ($data["sent_review_unit_name"] !== null ||
  1186. $data["sent_review_head_name"] !== null ||
  1187. $data["sent_review_head_email"] !== null ||
  1188. $data["sent_review_phone"] !== null
  1189. ) {
  1190. return to_assign(0, "已存在,请移除后再添加");
  1191. } else {
  1192. return to_assign(200, "请上传!!");
  1193. }
  1194. } else {
  1195. add_project_log('移除送审单位成员', $param['data']['id'], $param['data']["sent_review_head_name"], 5);
  1196. $this->model->addConstructionPeople($param['data']);
  1197. }
  1198. add_project_log('新增送审单位成员', $param['data']['id'], '新增送审单位成员');
  1199. } else {
  1200. $param = get_params();
  1201. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1202. //关联项目id
  1203. View::assign('project_id', $project_id);
  1204. return view();
  1205. }
  1206. }
  1207. //添加送审单位
  1208. // public function add_sent_review_unit()
  1209. // {
  1210. // if (request()->isAjax()) {
  1211. // $param = get_params();
  1212. // $id = isset($param["id"]) ? $param["id"] : 0;
  1213. // $project_id = isset($param["project_id"]) ? $param["project_id"] : 0;
  1214. // $a = $this->model->where("id", $project_id)->value("sent_review_head");
  1215. // if ($a) {
  1216. // return to_assign(1, '已有负责人,请移除后再添加');
  1217. // }
  1218. // $selfData = get_admin($id);
  1219. // $data = [
  1220. // "id" => $project_id,
  1221. // "sent_review_head" => $id,
  1222. // "sent_review_head_name" => $selfData["nickname"],
  1223. // "sent_review_unit" => $selfData["unit_name"],
  1224. // "sent_review_unit_name" => Db::name("department")->where("id", $selfData["unit_name"])->value("title"),
  1225. // "sent_review_phone" => $selfData["mobile"]
  1226. // ];
  1227. // try {
  1228. // $this->model->update($data);
  1229. // } catch (\Exception $e) {
  1230. // return to_assign(1, '操作失败,原因:' . $e->getMessage());
  1231. // }
  1232. // add_project_log('添加送审单位成员', $project_id, $selfData["nickname"], 5);
  1233. // return to_assign(0, "操作成功");
  1234. // }
  1235. // }
  1236. //移除送审单位成员
  1237. public function remove_sent_review()
  1238. {
  1239. $p = get_params();
  1240. $project_id = isset($p["project_id"]) ? $p["project_id"] : 0;
  1241. $data = [
  1242. "sent_review_unit" => null,
  1243. "sent_review_unit_name" => null,
  1244. "sent_review_head_name" => null,
  1245. "sent_review_head" => null,
  1246. "sent_review_phone" => null,
  1247. "sent_review_head_email" => null,
  1248. ];
  1249. $this->model->where("id", $project_id)->update($data);
  1250. remove_user($p["id"]);
  1251. add_project_log('移除送审单位成员', $project_id, $p["nickname"], 5);
  1252. return to_assign(0, "操作成功");
  1253. }
  1254. public function project_user()
  1255. {
  1256. $param = get_params();//9.13加了一个送审人的 //委托创建人,评审负责人/操作team/
  1257. $ids = $this->model->where("id", $param["project_id"])->field("entrust_maker,review_head,operate_head,operate_team")->find()->toArray();
  1258. $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"] . ',' . $ids["entrust_maker"];
  1259. $idarr = explode(",", $idarr);
  1260. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  1261. $list = $this->Adminmodel->whereIn("id", $idarr)->field("id,nickname,unit_name,mobile,email")->paginate($rows, false, ['query' => $param])
  1262. // 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')
  1263. ->each(function ($item) {
  1264. //获取单位的邮箱,单位信息页没做
  1265. $item->email = Db::name('department')->where(['id' => $item->unit_name])->value('email');
  1266. $type = Db::name('department')->where(['id' => $item->unit_name])->value('type');
  1267. $item->unit_name = Db::name('department')->where(['id' => $item->unit_name])->value('title');
  1268. // dump($type);
  1269. if ($type == 0) {
  1270. $item->unit_type = "委托单位";
  1271. } elseif ($type == 1) {
  1272. $item->unit_type = "送审单位";
  1273. } elseif ($type == 2) {
  1274. $item->unit_type = "评审机构";
  1275. } else {
  1276. $item->unit_type = "施工单位";
  1277. }
  1278. })->toArray();
  1279. $list = $list["data"];
  1280. $time_id = time();
  1281. $shigong = $this->model->where('id', $param["project_id"])->find();
  1282. if ($shigong["construction_unit"] !== null ||
  1283. $shigong["construction_head"] !== null ||
  1284. $shigong["construction_email"] !== null ||
  1285. $shigong["construction_phone"] !== null
  1286. ) {
  1287. $shigongdata["id"] = $time_id;
  1288. $shigongdata["nickname"] = $shigong["construction_unit"];
  1289. $shigongdata["unit_name"] = $shigong["construction_head"];
  1290. $shigongdata["email"] = $shigong["construction_email"];
  1291. $shigongdata["mobile"] = $shigong["construction_phone"];
  1292. $shigongdata["unit_type"] = "施工单位";
  1293. array_push($list, $shigongdata);
  1294. }
  1295. $time_id_sent = time()-200;
  1296. if ($shigong["sent_review_unit"] !== null ||
  1297. $shigong["sent_review_head"] !== null ||
  1298. $shigong["sent_review_phone"] !== null ||
  1299. $shigong["sent_review_head_email"] !== null
  1300. ) {
  1301. $sent_review_data["id"] = $time_id_sent;
  1302. $sent_review_data["nickname"] = $shigong["sent_review_head_name"];
  1303. $sent_review_data["unit_name"] = $shigong["sent_review_unit_name"];
  1304. $sent_review_data["email"] = $shigong["sent_review_head_email"];
  1305. $sent_review_data["mobile"] = $shigong["sent_review_phone"];
  1306. $sent_review_data["unit_type"] = "送审单位";
  1307. array_push($list, $sent_review_data);
  1308. }
  1309. if (empty($ids['operate_team'])) {
  1310. $operate_team[] = '0';
  1311. } else {
  1312. $operate_team = explode(',', $ids['operate_team']);
  1313. }
  1314. for ($i = 0; $i < count($list); $i++) {
  1315. if ($list[$i]['id'] == $ids['entrust_maker']) {
  1316. // dump($list[$i]['id'],$ids['entrust_maker']);
  1317. $list[$i]["type"] = 1;
  1318. } elseif ($list[$i]['id'] == $ids['review_head']) {
  1319. $list[$i]["type"] = 2;
  1320. } elseif ($list[$i]['id'] == $ids['operate_head']) {
  1321. $list[$i]["type"] = 3;
  1322. } elseif (in_array($list[$i]['id'], $operate_team)) {
  1323. $list[$i]["type"] = 4;
  1324. } elseif ($list[$i]['id'] == $time_id) {
  1325. $list[$i]["type"] = 5;
  1326. } elseif ($list[$i]['id'] !== time() - 1000) {
  1327. $list[$i]["type"] = 6;
  1328. }
  1329. }
  1330. $type = array_column($list, 'type');
  1331. array_multisort($type, SORT_ASC, $list);
  1332. $lists["total"] = count($list);
  1333. $lists["data"] = $list;
  1334. return table_assign(0, '', $lists);
  1335. }
  1336. public function remove_construction_user()
  1337. {
  1338. $p = get_params();
  1339. $data = [
  1340. "construction_unit" => null,
  1341. "construction_head" => null,
  1342. "construction_email" => null,
  1343. "construction_phone" => null
  1344. ];
  1345. $this->model->where("id", $p["project_id"])->update($data);
  1346. add_project_log('删除施工方人员', $p["project_id"], '删除施工方人员');
  1347. return to_assign(0, "操作成功");
  1348. }
  1349. public function getProjectFive()
  1350. {
  1351. $where = [
  1352. ['name', '=', '作业日志-财政局'],
  1353. ['name', '=', '工作记录-财政局'],
  1354. ['name', '=', '项目报告-财政局'],
  1355. ['name', '=', '项目人员-财政局'],
  1356. ['name', '=', '项目动态-财政局'],
  1357. ['name', '=', '项目附件-财政局'],
  1358. ['name', '=', '联系函-财政局'],
  1359. ];
  1360. //where0r满足任意一个name值都可以
  1361. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  1362. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  1363. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  1364. $login_rules = explode(',', $login_rules);
  1365. $rules_id = array();
  1366. //in_array()用于在数组中搜索指定的值,指定值/搜索数组
  1367. foreach ($list as $key => $value) {
  1368. if ($value['name'] == "作业日志-财政局") {
  1369. if (in_array($value['id'], $login_rules)) {
  1370. $rules_id['project_comments'] = 1;
  1371. } else {
  1372. $rules_id['project_comments'] = 0;
  1373. }
  1374. } else if ($value['name'] == "工作记录-财政局") {
  1375. if (in_array($value['id'], $login_rules)) {
  1376. $rules_id['project_record'] = 1;
  1377. } else {
  1378. $rules_id['project_record'] = 0;
  1379. }
  1380. } else if ($value['name'] == "项目报告-财政局") {
  1381. if (in_array($value['id'], $login_rules)) {
  1382. $rules_id['project_report'] = 1;
  1383. } else {
  1384. $rules_id['project_report'] = 0;
  1385. }
  1386. } else if ($value['name'] == "项目人员-财政局") {
  1387. if (in_array($value['id'], $login_rules)) {
  1388. $rules_id['project_user'] = 1;
  1389. } else {
  1390. $rules_id['project_user'] = 0;
  1391. }
  1392. } else if ($value['name'] == "项目动态-财政局") {
  1393. if (in_array($value['id'], $login_rules)) {
  1394. $rules_id['project_log'] = 1;
  1395. } else {
  1396. $rules_id['project_log'] = 0;
  1397. }
  1398. } else if ($value['name'] == "项目附件-财政局") {
  1399. if (in_array($value['id'], $login_rules)) {
  1400. $rules_id['project_file'] = 1;
  1401. } else {
  1402. $rules_id['project_file'] = 0;
  1403. }
  1404. } else if ($value['name'] == "联系函-财政局") {
  1405. if (in_array($value['id'], $login_rules)) {
  1406. $rules_id['project_contact'] = 1;
  1407. } else {
  1408. $rules_id['project_contact'] = 0;
  1409. }
  1410. }
  1411. }
  1412. return $rules_id;
  1413. }
  1414. public function ceshi($id)
  1415. {
  1416. View::assign('detailId', $id);
  1417. return view();
  1418. }
  1419. }