CostCompany.php 69 KB

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