Api.php 17 KB

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