CostCompany.php 69 KB

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