Api.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <?php
  2. namespace app\admin\controller\project;
  3. use app\admin\controller\field\Field;
  4. use app\api\BaseController;
  5. use HTMLPurifier_Config;
  6. use HTMLPurifier;
  7. use think\App;
  8. use think\facade\Db;
  9. use think\facade\View;
  10. use Qiniu\Auth;
  11. use Qiniu\Storage\UploadManager;
  12. class Api extends BaseController
  13. {
  14. public function __construct(App $app)
  15. {
  16. parent::__construct($app);
  17. $this->uid = get_login_admin("id");
  18. $this->Field = new Field($this->app);
  19. }
  20. /**
  21. * 财政文件上传
  22. */
  23. public function add_file()
  24. {
  25. $param = get_params();
  26. $param['create_time'] = time();
  27. $param['admin_id'] = $this->uid;
  28. $param['module'] = 'project';
  29. $fid = Db::name('project_file')->strict(false)->field(true)->insertGetId($param);
  30. $content = Db::name("file")->where("id", $param["file_id"])->value("name");
  31. if (isset($param["topic_id"])) {
  32. add_project_log("上传文件", $param["topic_id"], $content, 1);
  33. }
  34. $file_array = Db::name('file')
  35. ->field("f.id,f.name,f.filesize,f.filepath,f.fileext,f.admin_id,f.create_time,a.nickname as admin_name")
  36. ->alias("f")
  37. ->join('Admin a', 'f.admin_id = a.id', 'LEFT')
  38. ->order('f.create_time desc')
  39. ->where(array('f.id' => $param["file_id"]))
  40. ->select()->toArray();
  41. $file_array[0]["id"] = $fid;
  42. return json($file_array);
  43. }
  44. /**
  45. * 公司文件上传
  46. */
  47. public function add_file_company()
  48. {
  49. $param = get_params();
  50. $param['create_time'] = time();
  51. $param['admin_id'] = $this->uid;
  52. $param['module'] = 'project';
  53. $fid = Db::name('project_file')->strict(false)->field(true)->insertGetId($param);
  54. $content = Db::name("file")->where("id", $param["file_id"])->value("name");
  55. if (isset($param["topic_id"])) {
  56. add_project_log("上传文件", $param["topic_id"], $content, 1);
  57. }
  58. $file_array = Db::name('file')
  59. ->field("f.id,f.name,f.filesize,f.filepath,f.fileext,f.admin_id,f.create_time,a.nickname as admin_name")
  60. ->alias("f")
  61. ->join('Admin a', 'f.admin_id = a.id', 'LEFT')
  62. ->order('f.create_time desc')
  63. ->where(array('f.id' => $param["file_id"]))
  64. ->select()->toArray();
  65. $file_array[0]["id"] = $fid;
  66. return json($file_array);
  67. }
  68. public function add_file_proprietor()
  69. {
  70. $param = get_params();
  71. $param['create_time'] = time();
  72. $param['admin_id'] = $this->uid;
  73. $param['module'] = 'project';
  74. $fid = Db::name('project_file')->strict(false)->field(true)->insertGetId($param);
  75. $content = Db::name("file")->where("id", $param["file_id"])->value("name");
  76. if (isset($param["topic_id"])) {
  77. add_project_log("上传文件", $param["topic_id"], $content, 1);
  78. }
  79. $file_array = Db::name('file')
  80. ->field("f.id,f.name,f.filesize,f.filepath,f.fileext,f.admin_id,f.create_time,a.nickname as admin_name")
  81. ->alias("f")
  82. ->join('Admin a', 'f.admin_id = a.id', 'LEFT')
  83. ->order('f.create_time desc')
  84. ->where(array('f.id' => $param["file_id"]))
  85. ->select()->toArray();
  86. $file_array[0]["id"] = $fid;
  87. return json($file_array);
  88. }
  89. /**
  90. * 财政删除文件
  91. */
  92. public function delete_file()
  93. {
  94. if (request()->isDelete()) {
  95. $id = get_params("id");
  96. $detail = Db::name('ProjectFile')->where('id', $id)->find();
  97. if (Db::name('ProjectFile')->where('id', $id)->delete() !== false) {
  98. $file_data = Db::name("file")->where('id', $detail["file_id"])->find();
  99. if(!$file_data){
  100. return to_assign(1,"没有该数据!!");
  101. }
  102. $accessKey = 'va_jSLgv-VlomxzMU-6lroagyFoUWxayoxsq7FRg';
  103. $secretKey = 'vVXEUwrvq-H5YIJNzu3u46aM92IE91x6tGjIRonL';
  104. //构建鉴权对象
  105. //在七牛的存储空间
  106. $bucket = 'yiguancaiping';
  107. $key = $file_data['filename'];
  108. $auth = new Auth($accessKey, $secretKey);
  109. $config = new \Qiniu\Config();
  110. $bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
  111. $err = $bucketManager->delete($bucket, $key);
  112. if ($err) {
  113. $content = $file_data['name'];
  114. add_project_log("删除文件", $detail["topic_id"], $content, 1);
  115. return to_assign(0, "删除成功");
  116. }
  117. } else {
  118. return to_assign(0, "删除失败");
  119. }
  120. } else {
  121. return to_assign(1, "错误的请求");
  122. }
  123. }
  124. /**
  125. * 公司删除文件
  126. */
  127. public function delete_file_company()
  128. {
  129. if (request()->isDelete()) {
  130. $id = get_params("id");
  131. $detail = Db::name('ProjectFile')->where('id', $id)->find();
  132. if (Db::name('ProjectFile')->where('id', $id)->delete() !== false) {
  133. $file_data = Db::name("file")->where('id', $detail["file_id"])->find();
  134. $accessKey = 'va_jSLgv-VlomxzMU-6lroagyFoUWxayoxsq7FRg';
  135. $secretKey = 'vVXEUwrvq-H5YIJNzu3u46aM92IE91x6tGjIRonL';
  136. //构建鉴权对象
  137. //在七牛的存储空间
  138. $bucket = 'yiguancaiping';
  139. $key = $file_data['filename'];
  140. $auth = new Auth($accessKey, $secretKey);
  141. $config = new \Qiniu\Config();
  142. $bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
  143. $err = $bucketManager->delete($bucket, $key);
  144. if ($err) {
  145. $content = $file_data['name'];
  146. add_project_log("删除文件", $detail["topic_id"], $content, 1);
  147. return to_assign(0, "删除成功");
  148. }
  149. } else {
  150. return to_assign(0, "删除失败");
  151. }
  152. } else {
  153. return to_assign(1, "错误的请求");
  154. }
  155. }
  156. public function delete_file_proprietor()
  157. {
  158. if (request()->isDelete()) {
  159. $id = get_params("id");
  160. $detail = Db::name('ProjectFile')->where('id', $id)->find();
  161. if (Db::name('ProjectFile')->where('id', $id)->delete() !== false) {
  162. $file_data = Db::name("file")->where('id', $detail["file_id"])->find();
  163. $accessKey = 'va_jSLgv-VlomxzMU-6lroagyFoUWxayoxsq7FRg';
  164. $secretKey = 'vVXEUwrvq-H5YIJNzu3u46aM92IE91x6tGjIRonL';
  165. //构建鉴权对象
  166. //在七牛的存储空间
  167. $bucket = 'yiguancaiping';
  168. $key = $file_data['filename'];
  169. $auth = new Auth($accessKey, $secretKey);
  170. $config = new \Qiniu\Config();
  171. $bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
  172. $err = $bucketManager->delete($bucket, $key);
  173. if ($err) {
  174. $content = $file_data['name'];
  175. add_project_log("删除文件", $detail["topic_id"], $content, 1);
  176. return to_assign(0, "删除成功");
  177. }
  178. } else {
  179. return to_assign(0, "删除失败");
  180. }
  181. } else {
  182. return to_assign(1, "错误的请求");
  183. }
  184. }
  185. public function test()
  186. {
  187. $str = "'a"."bac'";
  188. $a = "a";
  189. $a = preg_match('/["\']/', $str);
  190. return cleanHtml($a);
  191. }
  192. /**
  193. * 清除小红点
  194. */
  195. public function eliminate()
  196. {
  197. $param = get_params();
  198. $type = isset($param['type']) ? $param['type'] : 0;
  199. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  200. if ($type&&$project_id) {
  201. switch ($type) {
  202. case 1:
  203. $key = "detail";
  204. break;
  205. case 2:
  206. $key = "comment";
  207. break;
  208. case 3:
  209. $key = "record";
  210. break;
  211. case 4:
  212. $key = "report";
  213. break;
  214. case 5:
  215. $key = "user";
  216. break;
  217. case 6:
  218. $key = "contact";
  219. break;
  220. }
  221. if (!empty($key)) {
  222. Db::name("new_msg")->where("uid", $this->uid)->where("project_id",$project_id)->update([$key => 0]);
  223. }
  224. }
  225. }
  226. /**
  227. * 请款的项目
  228. * 仅请款用
  229. */
  230. public function get_project()
  231. {
  232. $param = get_params();
  233. $where[] = ["delete_time", "=", 0];
  234. $where[] = ["review_unit", "=", get_login_admin('unit_name')];
  235. $where[] = ["project_status", ">", 2];
  236. $where[] = ["project_status", "<", 9];
  237. if (!empty($param['keywords'])) {
  238. $keyword = $param['keywords'];
  239. $where[] = ['project_name|entrust_unit_name', 'like', '%' . $keyword . '%'];
  240. }
  241. $inarr = array();
  242. $review_unit = Db::name("cost_project")->where("review_unit", get_login_admin("unit_name"))->field('id,review_head,operate_head,operate_team')->select()->toArray();
  243. for ($i = 0; $i < count($review_unit); $i++) {
  244. $a = $review_unit[$i];
  245. $ids = $a["review_head"] . ',' . $a["operate_head"] . ',' . $a["operate_team"];
  246. $ids = explode(",", $ids);
  247. $c = in_array($this->uid, $ids);
  248. if ($c) {
  249. $inarr[] = $a["id"];
  250. }
  251. }
  252. //$inarr没去重,应该不要紧
  253. //项目可见的权限
  254. $field = $this->Field->get_field_rules_new($this->uid);
  255. //1全部-可查看可编辑,2全部-可查看,0与我有关
  256. $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;
  257. if ($see_auth == 3) {
  258. $list = Db::name("cost_project")->whereIn("id", $inarr)->where($where)->field("id,project_name,entrust_unit,entrust_unit_name,sent_review_cost")->select();
  259. } elseif ($see_auth == 0) {
  260. $list = Db::name("cost_project")->whereIn("id", $inarr)->where($where)->field("id,project_name,entrust_unit,entrust_unit_name,sent_review_cost")->select();
  261. } else {
  262. $list = Db::name("cost_project")->where($where)->field("id,project_name,entrust_unit,entrust_unit_name,sent_review_cost")->select();
  263. }
  264. if (is_object($list)) {
  265. $list = $list->toArray();
  266. }
  267. //已经存在的项目,不能二次请款,项目状态3拒绝
  268. $ids1 = Db::name('appropriation_project')->where('uid', 'NOT NULL')->column("project_id");
  269. $ids2 = Db::name('appropriation_project')->alias("p")->leftJoin("appropriation a","p.uid=a.id")
  270. ->where('a.status', '3')->whereOr('a.status', '-2')->column("p.project_id");
  271. // $project_id = array_column($ids,"project_id");
  272. // halt($list,$ids);
  273. $ids = array_diff($ids1,$ids2);
  274. $real_list = [];
  275. foreach ($list as $item=>$value){
  276. if(!in_array($value["id"],$ids)){
  277. $real_list[] = $value;
  278. }
  279. }
  280. $real_real_list = [];
  281. foreach ($real_list as $item=>$value){
  282. if($value["entrust_unit"]!=""){
  283. $real_real_list[] = $value;
  284. }
  285. }
  286. $data["data"] = $real_real_list;
  287. $data["total"] = count($real_real_list);
  288. return table_assign(0, "", $data);
  289. }
  290. /**
  291. * 通用查询
  292. */
  293. public function get_self_project(){
  294. $param = get_params();
  295. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  296. $unit_type = get_login_admin("user_type");
  297. if ($unit_type == 0) {
  298. $where = [
  299. ["delete_time", "=", 0],
  300. ["project_status", ">", 2],
  301. ["entrust_unit", "=", get_login_admin('unit_name')]
  302. ];
  303. $data = Db::name("cost_project")->where($where)
  304. ->field("id,project_name,project_status,entrust_unit_name,review_unit_name")
  305. ->paginate($rows, false, ['query' => $param]);
  306. } elseif ($unit_type == 2) {
  307. $where =[
  308. ["delete_time", "=", 0],
  309. ["project_status", ">", 3],
  310. ["project_status", "<", 6],
  311. ["review_unit", "=", get_login_admin("unit_name")]
  312. ];
  313. $data = Db::name("cost_project")->where($where)
  314. ->field("id,project_name,project_status,entrust_unit_name,review_unit_name")
  315. ->paginate($rows, false, ['query' => $param]);
  316. }else{
  317. $where =[
  318. ["delete_time", "=", 0],
  319. ["project_status", ">", 3],
  320. ["project_status", "<", 6],
  321. ["sent_review_unit", "=", get_login_admin("unit_name")]
  322. ];
  323. $data = Db::name("cost_project")->where($where)
  324. ->field("id,project_name,project_status,entrust_unit_name,review_unit_name")
  325. ->paginate($rows, false, ['query' => $param]);
  326. }
  327. return table_assign(0, '',$data);
  328. }
  329. public function get_department_tree()
  330. {
  331. $unit_id = get_unit(get_login_admin("unit_name"));
  332. $department = Db::name('Department')->where(['status' => 1])->select()->toArray();
  333. $list = get_tree($department, 0, 2);
  334. $data['trees'] = $list;
  335. $result = null;
  336. for ($i = 0; $i < count($data['trees']); $i++) {
  337. $point = $data['trees'][$i];
  338. if ($point["id"] == $unit_id) {
  339. $result['trees'][] = $point;
  340. break;
  341. }
  342. }
  343. return json($result);
  344. }
  345. //获取子部门所有员工
  346. public function get_employee($did = 1)
  347. {
  348. $did = get_params('did');
  349. if ($did == 1) {
  350. $department = $did;
  351. } else {
  352. $department = get_department_son(get_login_admin("unit_name"));
  353. }
  354. $employee = Db::name('admin')
  355. ->field('a.id,a.did,a.position_id,a.mobile,a.nickname,a.status,a.thumb,a.username,d.title as department')
  356. ->alias('a')
  357. ->join('Department d', 'a.did = d.id')
  358. ->where(['a.status' => 1])
  359. ->where('a.id', ">", 1)
  360. ->where('a.did', "in", $department)
  361. ->select();
  362. return to_assign(0, '', $employee);
  363. }
  364. public function get_entrust(){
  365. $param = get_params();
  366. $where = [
  367. "status" =>1,
  368. "type" => 0,
  369. "pid" => 0,
  370. ];
  371. if(!empty($param["keywords"])){
  372. $where[] = ["title","like",'%' . $param['keywords'] . '%'] ;
  373. }
  374. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  375. $list = Db::name("department")->where($where)-> field("id,title,address")->paginate($rows, false, ['query' => $param]);
  376. return table_assign(0, '',$list);
  377. }
  378. public function get_entrust_people(){
  379. $param = get_params();
  380. $unit_id = isset($param["unit_id"])?$param["unit_id"]:0;
  381. $where[] = ["unit_name","=",$unit_id];
  382. $where[] = ["status","=",1];
  383. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  384. if(!empty($param["keywords"])){
  385. $where[] = ["nickname","like",'%' . $param['keywords'] . '%'] ;
  386. }
  387. $list = Db::name("admin")->where($where)->field("id,nickname")
  388. ->paginate($rows, false, ['query' => $param]);
  389. return table_assign(0, '',$list);
  390. }
  391. //获取送审单位
  392. public function get_sent_review(){
  393. $param = get_params();
  394. $where = [
  395. "status" =>1,
  396. "type" => 1,
  397. "pid" => 0,
  398. ];
  399. if(!empty($param["keywords"])){
  400. $where[] = ["title","like",'%' . $param['keywords'] . '%'] ;
  401. }
  402. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  403. $list = Db::name("department")->where($where)-> field("id,title,address")->paginate($rows, false, ['query' => $param]);
  404. return table_assign(0, '',$list);
  405. }
  406. public function get_sent_review_people(){
  407. $param = get_params();
  408. $unit_id = isset($param["unit_id"])?$param["unit_id"]:0;
  409. $where[] = ["unit_name","=",$unit_id];
  410. $where[] = ["status","=",1];
  411. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  412. if(!empty($param["keywords"])){
  413. $where[] = ["nickname","like",'%' . $param['keywords'] . '%'] ;
  414. }
  415. $list = Db::name("admin")->where($where)->field("id,nickname")
  416. ->paginate($rows, false, ['query' => $param]);
  417. return table_assign(0, '',$list);
  418. }
  419. /**
  420. * 修改项目报告状态
  421. */
  422. public function set_status(){
  423. if(request()->isPost()){
  424. $param = get_params();
  425. $id = isset($param["project_id"])?$param["project_id"]:0;
  426. try {
  427. Db::name("cost_project")->where('id',$id)->update(["report_status"=>$param["report_status"]]);
  428. } catch (\Exception $e) {
  429. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  430. }
  431. //0初稿中,1对数中,2定案中,3定案完成
  432. $name="";
  433. switch ($param["report_status"]){
  434. case 0:
  435. $name = "初稿中";
  436. break;
  437. case 1:
  438. $name = "对数中";
  439. break;
  440. case 2:
  441. $name = "定案中";
  442. break;
  443. case 3:
  444. $name = "定案结束";
  445. break;
  446. }
  447. if($name!==""){
  448. $content = get_login_admin("nickname")."修改报告状态为".$name;
  449. add_project_log("编辑状态", $id,$content);
  450. }
  451. return to_assign(0,"操作成功");
  452. }
  453. }
  454. public function get_file(){
  455. $param = get_params();
  456. $id = isset($param['id']) ? $param['id'] : 0;
  457. $file_array = Db::name('ProjectFile')
  458. ->field('mf.id,mf.topic_id,mf.admin_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.nickname as admin_name,mf.remark')
  459. ->alias('mf')
  460. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  461. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  462. ->order('mf.create_time desc')
  463. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  464. ->paginate(9999, false, ['query' => $param]);
  465. return table_assign(0, '', $file_array);
  466. }
  467. //
  468. }