Cost.php 63 KB

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