Appropriation.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <?php
  2. namespace app\admin\controller\project;
  3. use app\admin\BaseController;
  4. use app\admin\controller\field\Field;
  5. use app\admin\model\CostProject as CostProjectModel;
  6. use app\admin\model\ProjectAudit;
  7. use app\admin\model\ProjectFile;
  8. use think\App;
  9. use app\admin\model\Appropriation as AppropriationModel;
  10. use think\db\exception\DbException;
  11. use think\facade\Db;
  12. use think\facade\View;
  13. class Appropriation extends BaseController
  14. {
  15. public function __construct(App $app)
  16. {
  17. parent::__construct($app);
  18. $this->Field = new Field($this->app);
  19. $this->Costmodel = new CostProjectModel();
  20. $this->filemodel = new ProjectFile();
  21. $this->model = new AppropriationModel();
  22. $this->uid = get_login_admin("id");
  23. $this->nickname = get_login_admin("nickname");
  24. }
  25. public function datalist()
  26. {
  27. if (request()->isAjax()) {
  28. $param = get_params();
  29. $where = [];
  30. if(!empty($param["keywords"])){
  31. $where[] = ["review_unit_name","like","%".$param["keywords"]."%"];
  32. }
  33. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  34. $order = empty($param['order']) ? 'id desc' : $param['order'];
  35. $list = $this->model->where("entrust_unit", get_login_admin("unit_name"))
  36. ->where("status",">",0)
  37. ->where($where)
  38. ->order($order)->paginate($rows, false, ['query' => $param])
  39. ->each(function ($item) {
  40. $data = Db::name("appropriation_project")->alias("a")->join("cost_project c","a.project_id=c.id","left")
  41. ->where("a.uid","not null")->where("a.uid",$item->id)
  42. ->where("c.entrust_unit",get_login_admin("unit_name"))->column("c.project_name,c.sent_review_cost");
  43. if (!empty($data)) {
  44. $a = 0;
  45. $project_name = '';
  46. $appropriation_amount = 0;
  47. foreach ($data as $key => $value) {
  48. $a += 1;
  49. $project_name .= $a . "." . $value["project_name"] . ",";
  50. $appropriation_amount += $value["sent_review_cost"];
  51. }
  52. $item->a = count($data);
  53. $item->appropriation_amount = $appropriation_amount;
  54. $item->project_names = $project_name;
  55. }
  56. });
  57. return table_assign(0, '', $list);
  58. } else{
  59. // $field = $this->Field->get_field_rules_new($this->uid);
  60. // $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;
  61. $where[] = ["delete_time", "=", 0];
  62. $where[] = ["entrust_unit", "=", get_login_admin('unit_name')];
  63. $where[] = ["project_status", ">", 2];
  64. $where[] = ["project_status", "<>", 9];
  65. // $where2[] = ["delete_time", "=", 0];
  66. // $where2[] = ["entrust_unit", "=", get_login_admin('unit_name')];
  67. // $where2[] = ["project_status", ">", 2];
  68. // $where2[] = ["project_status", "<>", 8];
  69. // if ($see_auth == 3) {
  70. // $where[] = ["entrust_maker", "=", $this->uid];
  71. // $where2[] = ["entrust_approver", "=", $this->uid];
  72. // } elseif ($see_auth == 0) {
  73. // $where[] = ["entrust_maker", "=", $this->uid];
  74. // $where2[] = ["entrust_approver", "=", $this->uid];
  75. //
  76. // }
  77. $list = $this->Costmodel->where($where)->column("sent_review_cost");
  78. $data = Db::name("appropriation")->alias("a")->leftJoin("appropriation_project p","a.id=p.uid")->leftJoin("cost_project c","p.project_id=c.id")
  79. ->where("p.uid","not null")
  80. ->where("a.status","2")
  81. ->where("c.entrust_unit",get_login_admin("unit_name"))->column("c.id");
  82. $appropriation = $this->model->where([["entrust_unit","=", get_login_admin("unit_name")],["status","=",2]])->paginate(10000, false, ['query' => []]);
  83. $sent_review_cost = 0.00;
  84. $invoicing_amount = 0.00;
  85. $appropriation_amount = 0.00;
  86. foreach ($list as $item=>$value){
  87. //送审服务费
  88. $sent_review_cost += (float)sprintf("%01.2f", $value);
  89. $sent_review_cost = number_format($sent_review_cost, 2, '.', '');
  90. }
  91. foreach ($appropriation as $item=>$value){
  92. if($value["invoice_status"]==1){
  93. //开票金额
  94. $invoicing_amount += (float)$value["invoicing_amount"];
  95. $invoicing_amount = number_format($invoicing_amount, 2, '.', '');
  96. }
  97. }
  98. $invoicing_amount = number_format($invoicing_amount, 2, '.', '');
  99. $list_ids = $this->Costmodel->where($where)->column("id,sent_review_cost");
  100. foreach ($list_ids as $item=>$value){
  101. //已请款
  102. if(in_array($value["id"],$data)){
  103. $appropriation_amount += (float)$value["sent_review_cost"];
  104. $appropriation_amount = number_format($appropriation_amount, 2, '.', '');
  105. }
  106. }
  107. $appropriation_amount = number_format($appropriation_amount, 2, '.', '');
  108. //未请款
  109. $not_appropriation_amount = number_format($sent_review_cost-$appropriation_amount,2,'.','');
  110. //未开票
  111. $not_invoicing_amount = number_format($sent_review_cost-$invoicing_amount,2,'.','');
  112. View::assign("sent_review_cost",$sent_review_cost);
  113. View::assign("appropriation_amount",$appropriation_amount);
  114. View::assign("not_appropriation_amount",$not_appropriation_amount);
  115. View::assign("invoicing_amount",$invoicing_amount);
  116. View::assign("not_invoicing_amount",$not_invoicing_amount);
  117. return view();
  118. }
  119. }
  120. public function datalist_company()
  121. {
  122. if (request()->isAjax()) {
  123. $param = get_params();
  124. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  125. $order = empty($param['order']) ? 'id desc' : $param['order'];
  126. $where = [];
  127. if(!empty($param["keywords"])){
  128. $where[] = ["entrust_unit_name","like","%".$param["keywords"]."%"];
  129. }
  130. $list = $this->model->where("review_unit", get_login_admin("unit_name"))
  131. ->where($where)
  132. ->order($order)->paginate($rows, false, ['query' => $param])
  133. ->each(function ($item) {
  134. $item->invoice_detail = Db::name("ProjectFile")->alias("p")->where([["p.topic_id","=",$item->id],["p.module","=","appropriation"]])
  135. ->join("file f","p.file_id=f.id")->value("name");
  136. $data = Db::name("appropriation_project")->alias("a")->join("cost_project c","a.project_id=c.id","left")
  137. ->where("a.uid","not null")->where("a.uid",$item->id)
  138. ->where("c.review_unit",get_login_admin("unit_name"))->column("c.project_name,c.sent_review_cost");
  139. if (!empty($data)) {
  140. $a = 0;
  141. $project_name = '';
  142. $appropriation_amount = 0;
  143. foreach ($data as $key => $value) {
  144. $a += 1;
  145. $project_name .= $a . "." . $value["project_name"] . ",";
  146. $appropriation_amount += $value["sent_review_cost"];
  147. }
  148. $item->a = count($data);
  149. $item->appropriation_amount = $appropriation_amount;
  150. $item->project_names = $project_name;
  151. }
  152. });
  153. return table_assign(0, '', $list);
  154. } else {
  155. $inarr = array();
  156. $review_unit = $this->Costmodel->where("review_unit", get_login_admin("unit_name"))->field('id,review_head,operate_head,operate_team')->select()->toArray();
  157. for ($i = 0; $i < count($review_unit); $i++) {
  158. $a = $review_unit[$i];
  159. $ids = $a["review_head"] . ',' . $a["operate_head"] . ',' . $a["operate_team"];
  160. $ids = explode(",", $ids);
  161. $c = in_array($this->uid, $ids);
  162. if ($c) {
  163. $inarr[] = $a["id"];
  164. }
  165. }
  166. $where = [
  167. ["cp_cost_project.delete_time", "=", 0],
  168. ["project_status", ">", 3],
  169. ["project_status", "<>", 9],
  170. ["review_unit","=",get_login_admin("unit_name")]
  171. ];
  172. $field = $this->Field->get_field_rules_New($this->uid);
  173. $see_auth = isset($field["see_auth"])?$field["see_auth"]:3;
  174. $this->see_auth = $see_auth;
  175. if($see_auth==3){
  176. $list = $this->Costmodel->where($where)->whereIn("id", $inarr)->column("sent_review_cost");
  177. $list_ids = $this->Costmodel->where($where)->whereIn("id", $inarr)->column("id,sent_review_cost");
  178. }elseif ($see_auth==0){
  179. $list = $this->Costmodel->where($where)->whereIn("id", $inarr)->column("sent_review_cost");
  180. $list_ids = $this->Costmodel->where($where)->whereIn("id", $inarr)->column("id,sent_review_cost");
  181. }else{
  182. $list = $this->Costmodel->where($where)->column("sent_review_cost");
  183. $list_ids = $this->Costmodel->where($where)->column("id,sent_review_cost");
  184. }
  185. $data = Db::name("appropriation")->alias("a")->leftJoin("appropriation_project p","a.id=p.uid")->leftJoin("cost_project c","p.project_id=c.id")
  186. ->where("p.uid","not null")
  187. ->where("a.status","2")
  188. ->where("c.review_unit",get_login_admin("unit_name"))->column("c.id");
  189. $appropriation = $this->model->where("review_unit", get_login_admin("unit_name"))->where("status","=",2)->select();
  190. $sent_review_cost = 0;
  191. $invoicing_amount = 0;
  192. $appropriation_amount = 0;
  193. foreach ($list as $item=>$value){
  194. //送审服务费
  195. $sent_review_cost += (float)$value;
  196. $sent_review_cost = number_format($sent_review_cost, 2, '.', '');
  197. }
  198. foreach ($appropriation as $item=>$value){
  199. if($value["invoice_status"]==1){
  200. //开票金额
  201. $invoicing_amount += (float)$value["invoicing_amount"];
  202. $invoicing_amount = number_format($invoicing_amount, 2, '.', '');
  203. }
  204. }
  205. $invoicing_amount = number_format($invoicing_amount, 2, '.', '');
  206. foreach ($list_ids as $item=>$value){
  207. //已请款
  208. if(in_array($value["id"],$data)){
  209. $appropriation_amount += (float)$value["sent_review_cost"];
  210. $appropriation_amount = number_format($appropriation_amount, 2, '.', '');
  211. }
  212. }
  213. $appropriation_amount = number_format($appropriation_amount, 2, '.', '');
  214. //未请款
  215. $not_appropriation_amount = number_format($sent_review_cost-$appropriation_amount, 2, '.', '');
  216. //未开票
  217. $not_invoicing_amount = number_format($sent_review_cost-$invoicing_amount, 2, '.', '');
  218. View::assign("sent_review_cost",$sent_review_cost);
  219. View::assign("appropriation_amount",$appropriation_amount);
  220. View::assign("not_appropriation_amount",$not_appropriation_amount);
  221. View::assign("invoicing_amount",$invoicing_amount);
  222. View::assign("not_invoicing_amount",$not_invoicing_amount);
  223. return view();
  224. }
  225. }
  226. public function add()
  227. {
  228. if (request()->isAjax()) {
  229. $params = get_params();
  230. $params["appropriation_time"] = time();
  231. $params["maker_id"] = $this->uid;
  232. $params["maker_name"] = $this->nickname;
  233. $params["review_unit"] = get_login_admin("unit_name");
  234. $params["review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
  235. if(empty($params["id"])){
  236. $insertGetId = $this->model->strict(false)->insertGetId($params);
  237. if (empty($params["project_ids"])) {
  238. return to_assign(1, "请添加项目");
  239. } else {
  240. Db::name("appropriation_project")->whereIn("id", $params["project_ids"])->update(["uid" => $insertGetId]);
  241. }
  242. }else{
  243. $params["status"] = -1;
  244. $this->model->where("id",$params["id"])->strict(false)->update($params);
  245. $insertGetId = $params["id"];
  246. if (!empty($params["project_ids"])) {
  247. Db::name("appropriation_project")->whereIn("id", $params["project_ids"])->update(["uid" => $insertGetId]);
  248. }else {
  249. $params["project_ids"] = Db::name("appropriation_project")->where("uid",$insertGetId)->column("id");
  250. }
  251. }
  252. if (!empty($params["file_ids"])) {
  253. $this->filemodel->whereIn("id", $params["file_ids"])->update(["topic_id" => $insertGetId, "module" => "appropriation"]);
  254. }
  255. $project_names= '';
  256. if(!empty($params["project_ids"])){
  257. $project = Db::name("appropriation_project")->where("uid", $insertGetId)->select();
  258. if (!$project->isEmpty()) {
  259. $a = 0;
  260. $project_name = '';
  261. foreach ($project as $key => $value) {
  262. $a += 1;
  263. $project_name .= $a . "." . $value["project_name"] . ",";
  264. }
  265. $project_names = $project_name;
  266. }
  267. }
  268. if (!empty($params["first"])) {
  269. $auditData = [
  270. "project_id" => $insertGetId,
  271. "project_name" => $project_names,
  272. "project_type" =>"请款审核",
  273. "audit_name" => "请款一审",
  274. "audit_type" => 10,
  275. "sponsor" => get_login_admin("nickname"),
  276. "sponsor_id" => $this->uid,
  277. "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"),
  278. "approver" => $params["first"],
  279. "approver_name" => get_admin($params["first"])["nickname"],
  280. "create_time" => time()
  281. ];
  282. $auditDataArr[] = $auditData;
  283. } else {
  284. return to_assign(1, "请选择审批人");
  285. }
  286. if (!empty($params["second"])) {
  287. $auditData = [
  288. "project_id" => $insertGetId,
  289. "project_name" => $project_names,
  290. "project_type" =>"请款审核",
  291. "audit_name" => "请款二审",
  292. "audit_type" => 11,
  293. "audit_status"=>5,
  294. "sponsor" => get_login_admin("nickname"),
  295. "sponsor_id" => $this->uid,
  296. "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"),
  297. "approver" => $params["second"],
  298. "approver_name" => get_admin($params["second"])["nickname"],
  299. "create_time" => time()
  300. ];
  301. $auditDataArr[] = $auditData;
  302. }
  303. if (!empty($params["third"])) {
  304. $auditData = [
  305. "project_id" => $insertGetId,
  306. "project_name" => $project_names,
  307. "project_type" =>"请款审核",
  308. "audit_name" => "请款三审",
  309. "audit_type" => 12,
  310. "audit_status"=>5,
  311. "sponsor" => get_login_admin("nickname"),
  312. "sponsor_id" => $this->uid,
  313. "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"),
  314. "approver" => $params["third"],
  315. "approver_name" => get_admin($params["third"])["nickname"],
  316. "create_time" => time()
  317. ];
  318. $auditDataArr[] = $auditData;
  319. }
  320. if (!empty($auditDataArr)) {
  321. $ProjectAudit = new ProjectAudit();
  322. try {
  323. $ProjectAudit->saveAll($auditDataArr);
  324. } catch (\Exception $e) {
  325. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  326. }
  327. }
  328. return to_assign(0, "操作成功");
  329. } else {
  330. return view();
  331. }
  332. }
  333. public function save()
  334. {
  335. if (request()->isAjax()) {
  336. $params = get_params();
  337. $params["appropriation_time"] = time();
  338. $params["maker_id"] = $this->uid;
  339. $params["maker_name"] = $this->nickname;
  340. $params["review_unit"] = get_login_admin("unit_name");
  341. $params["review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
  342. if(empty($params["id"])){//新建
  343. $params["status"] = 0;
  344. $insertGetId = $this->model->strict(false)->insertGetId($params);
  345. if (empty($params["project_ids"])) {
  346. return to_assign(1, "请添加项目");
  347. } else {
  348. Db::name("appropriation_project")->whereIn("id", $params["project_ids"])->update(["uid" => $insertGetId]);
  349. }
  350. if (!empty($params["file_ids"])) {
  351. $this->filemodel->whereIn("id", $params["file_ids"])->update(["topic_id" => $insertGetId, "module" => "appropriation"]);
  352. }
  353. }else{//编辑保存
  354. $this->model->where("id",$params["id"])->strict(false)->update($params);
  355. if (!empty($params["project_ids"])) {
  356. Db::name("appropriation_project")->whereIn("id", $params["project_ids"])->update(["uid" => $params["id"]]);
  357. }
  358. if (!empty($params["file_ids"])) {
  359. $this->filemodel->whereIn("id", $params["file_ids"])->update(["topic_id" => $params["id"], "module" => "appropriation"]);
  360. }
  361. }
  362. return to_assign(0, "操作成功");
  363. } else {
  364. return view();
  365. }
  366. }
  367. public function c_edit()
  368. {
  369. $params = get_params();
  370. if (request()->isAjax()) {
  371. $a= time();
  372. $id = isset($params["id"]) ? $params["id"] : $a;
  373. if($id==$a){
  374. $datas = array();
  375. $datas["data"] = null;
  376. return table_assign(0, "无项目", $datas);
  377. }
  378. $project = Db::name("appropriation_project")->alias("a")->join("cost_project c",'c.id=a.project_id',"left")->where("a.uid", $id)->field("a.*,c.sent_review_cost")->select();
  379. $data = [];
  380. foreach ($project as $item=>$value){
  381. $value["appropriation_amount"] = $value["sent_review_cost"];
  382. $data[] = $value;
  383. }
  384. $datas["data"] = $data;
  385. $datas["total"] = count($data);
  386. return table_assign(0, "", $datas);
  387. } else {
  388. $a= time();
  389. $id = isset($params["id"]) ? $params["id"] : $a;
  390. $detail = Db::name("appropriation")->where("id",$id)->find();
  391. $file_array = Db::name('ProjectFile')
  392. ->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')
  393. ->alias('mf')
  394. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  395. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  396. ->order('mf.create_time desc')
  397. ->where(array('mf.topic_id' => $id, 'mf.module' => 'appropriation'))
  398. ->select()->toArray();
  399. View::assign('id',$id);
  400. View::assign('detail',$detail);
  401. View::assign('file_array',$file_array);
  402. return view();
  403. }
  404. }
  405. public function edit_company()
  406. {
  407. $params = get_params();
  408. if (request()->isAjax()) {
  409. $a= time();
  410. $id = isset($params["id"]) ? $params["id"] : $a;
  411. if($id==$a){
  412. $datas = array();
  413. $datas["data"] = null;
  414. return table_assign(0, "无项目", $datas);
  415. }
  416. $project = Db::name("appropriation_project")->where("uid", $id)->select();
  417. $datas["data"] = $project;
  418. $datas["total"] = count($project);
  419. return table_assign(0, "", $datas);
  420. } else {
  421. $a= time();
  422. $id = isset($params["id"]) ? $params["id"] : $a;
  423. $detail = Db::name("appropriation")->where("id",$id)->find();
  424. $file_array = Db::name('ProjectFile')
  425. ->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')
  426. ->alias('mf')
  427. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  428. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  429. ->order('mf.create_time desc')
  430. ->where(array('mf.topic_id' => $id, 'mf.module' => 'appropriation'))
  431. ->select()->toArray();
  432. View::assign('id',$id);
  433. View::assign('detail',$detail);
  434. View::assign('file_array',$file_array);
  435. return view();
  436. }
  437. }
  438. public function c_read()
  439. {
  440. $params = get_params();
  441. if (request()->isAjax()) {
  442. $a= time();
  443. $id = isset($params["id"]) ? $params["id"] : $a;
  444. if($id==$a){
  445. $datas = array();
  446. $datas["data"] = null;
  447. return table_assign(0, "无项目", $datas);
  448. }
  449. $project = Db::name("appropriation_project")->where("uid", $id)->select();
  450. $datas["data"] = $project;
  451. $datas["total"] = count($project);
  452. return table_assign(0, "", $datas);
  453. }else {
  454. $a = time();
  455. $id = isset($params["id"]) ? $params["id"] : $a;
  456. $detail = Db::name("appropriation")->where("id", $id)->find();
  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')
  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' => 'appropriation'))
  464. ->select()->toArray();
  465. View::assign('id', $id);
  466. View::assign('detail', $detail);
  467. View::assign('file_array', $file_array);
  468. $audit = Db::name("project_audit")->where("project_id",$id)->select();
  469. // halt($audit);
  470. View::assign('audit', $audit);
  471. return view();
  472. }
  473. }
  474. public function read()
  475. {
  476. $params = get_params();
  477. if (request()->isAjax()) {
  478. $a= time();
  479. $id = isset($params["id"]) ? $params["id"] : $a;
  480. if($id==$a){
  481. $datas = array();
  482. $datas["data"] = null;
  483. return table_assign(0, "无项目", $datas);
  484. }
  485. $project = Db::name("appropriation_project")->where("uid", $id)->select();
  486. $datas["data"] = $project;
  487. $datas["total"] = count($project);
  488. return table_assign(0, "", $datas);
  489. }else {
  490. $a = time();
  491. $id = isset($params["id"]) ? $params["id"] : $a;
  492. $detail = Db::name("appropriation")->where("id", $id)->find();
  493. $file_array = Db::name('ProjectFile')
  494. ->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')
  495. ->alias('mf')
  496. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  497. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  498. ->order('mf.create_time desc')
  499. ->where(array('mf.topic_id' => $id, 'mf.module' => 'appropriation'))
  500. ->select()->toArray();
  501. View::assign('id', $id);
  502. View::assign('detail', $detail);
  503. View::assign('file_array', $file_array);
  504. $audit = Db::name("project_audit")->where("project_id",$id)->select();
  505. // halt($audit);
  506. View::assign('audit', $audit);
  507. return view();
  508. }
  509. }
  510. public function cc_edit(){
  511. if (request()->isAjax()) {
  512. $params = get_params();
  513. $id = isset($params["id"]) ? $params["id"] : 0;
  514. $params["audit_time"] = time();
  515. $params["status"] = 2;
  516. $this->model->where("id",$id)->update($params);
  517. return to_assign(0,"操作成功");
  518. }
  519. }
  520. public function disagree(){
  521. if (request()->isAjax()) {
  522. $params = get_params();
  523. $id = isset($params["id"]) ? $params["id"] : 0;
  524. if(isset($params['reason'])){
  525. $reason = $params['reason'];
  526. }else{
  527. $reason = '';
  528. }
  529. $this->model->where("id",$id)->update(["status"=>3,"reason"=>$reason]);
  530. return to_assign(0,"操作成功");
  531. }
  532. }
  533. public function add_project()
  534. {
  535. $params = get_params();
  536. try {
  537. $where = [
  538. ["unit_id","=",get_login_admin("unit_name")],
  539. ["create_time","<",time()-300],
  540. ["uid","=",null]
  541. ];
  542. Db::name("appropriation_project")->where($where)->delete();
  543. $params["create_time"] = time();
  544. $params["unit_id"] = get_login_admin("unit_name");
  545. $insertGetId = Db::name("appropriation_project")->strict(false)->insertGetId($params);
  546. } catch (DbException $e) {
  547. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  548. }
  549. return to_assign(0, '操作成功', $insertGetId);
  550. }
  551. public function del_project()
  552. {
  553. $params = get_params();
  554. $id = isset($params["id"]) ? $params["id"] : 0;
  555. try {
  556. Db::name("appropriation_project")->where("id", $id)->delete();
  557. } catch (DbException $e) {
  558. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  559. }
  560. return to_assign(0, '操作成功');
  561. }
  562. public function project_list()
  563. {
  564. $params = get_params();
  565. $ids = isset($params["id"]) ? $params["id"] : array();
  566. $data = Db::name("appropriation_project")->whereIn("id", $ids)->select();
  567. $datas["data"] = $data;
  568. $datas["total"] = count($data);
  569. return table_assign(0, "", $datas);
  570. }
  571. public function project_list_c()
  572. {
  573. $params = get_params();
  574. $ids = isset($params["id"]) ? $params["id"] : array();
  575. $data = Db::name("appropriation_project")->whereIn("id", $ids)->select();
  576. $datas["data"] = $data;
  577. $datas["total"] = count($data);
  578. return table_assign(0, "", $datas);
  579. }
  580. public function edit()
  581. {
  582. $params = get_params();
  583. $id = isset($params["id"]) ? $params["id"] : 0;
  584. $params["refund_time"] = time();
  585. try {
  586. Db::name("appropriation_project")->where("id", $id)->update($params);
  587. } catch (DbException $e) {
  588. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  589. }
  590. return to_assign(0, '操作成功');
  591. }
  592. public function edit_c()
  593. {
  594. $params = get_params();
  595. $id = isset($params["id"]) ? $params["id"] : 0;
  596. try {
  597. Db::name("appropriation_project")->where("id", $id)->update($params);
  598. } catch (DbException $e) {
  599. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  600. }
  601. return to_assign(0, '操作成功');
  602. }
  603. }