ExecByRelaComNo.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\Db;
  4. use think\facade\Validate;
  5. use think\facade\Cache;
  6. //预约版本(业务公司)
  7. class ExecByRelaComNo extends Base
  8. {
  9. private $redis_key = 'cxreport_relaComNo';
  10. public function list()
  11. {
  12. $post = $this->post;
  13. // $token = isset($post['token']) ? trim($post['token']) : "";
  14. // if ($token == "") {
  15. // return json_show(101, 'token不能为空');
  16. // }
  17. $where = ['type' => 0];
  18. $page = isset($post['page']) ? intval($post['page']) : 1;
  19. $size = isset($post['size']) ? intval($post['size']) : 10;
  20. $count = Db::name("exec_rela_com_no")->where($where)->count();
  21. $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
  22. $page = $page >= $total ? intval($total) : $page;
  23. $list = Db::name("exec_rela_com_no")->where($where)->page($page, $size)->select();
  24. return json_show(0, "获取成功", ["list" => $list, "count" => $count]);
  25. }
  26. public function nowlist()
  27. {
  28. $param = $this->request->only(['relaComNo', 'page' => 1, 'size' => 10, 'type' => 1], 'post', 'trim');
  29. $val = Validate::rule([
  30. 'relaComNo' => 'require',
  31. 'page' => 'require|number|gt:0',
  32. 'size' => 'require|number|gt:0|lt:99999',
  33. 'type' => 'require|number|in:1,2,3',
  34. ]);
  35. if (!$val->check($param)) return json_show(1005, $val->getError());
  36. $count = Db::name("exec_rela_com_no")
  37. ->where(['relaComNo' => $param['relaComNo'], 'type' => $param['type']])
  38. ->count('id');
  39. $list = Db::name("exec_rela_com_no")
  40. ->where(['relaComNo' => $param['relaComNo'], 'type' => $param['type']])
  41. ->page($param['page'], $param['size'])
  42. ->order('id')
  43. ->select()
  44. ->toArray();
  45. return json_show(0, "获取成功", ["list" => $list, "count" => $count]);
  46. }
  47. public function save()
  48. {
  49. $param = $this->request->only(['start', 'end', 'id', 'relaComNo'], 'post', 'trim');
  50. $val = Validate::rule([
  51. 'start' => 'require|date|elt:end',
  52. 'end' => 'require|date|egt:start',
  53. 'id' => 'require|number|gt:0',
  54. 'relaComNo' => 'require',
  55. ]);
  56. if ($val->check($param) == false) return json_show(1004, $val->getError());
  57. $temp = \app\admin\common\User::getIns()->handle('getCodeAndName', ['code' => $param['relaComNo']]);
  58. if (!isset($temp['data'][$param['relaComNo']]) || $temp['data'][$param['relaComNo']] == '') return json_show(1004, '业务公司编码不存在');
  59. else $param['relaComName'] = $temp['data'][$param['relaComNo']];
  60. // $post = $this->post;
  61. // $token = isset($post['token']) ? trim($post['token']) : "";
  62. // if ($token == "") {
  63. // return json_show(101, 'token不能为空');
  64. // }
  65. // $userinfo = GetUserInfo($token);
  66. // if (!isset($userinfo['code']) || $userinfo['code'] != 0) {
  67. // return json_show(101, '未能获取用户信息');
  68. // }
  69. // $start = isset($post['start']) && $post['start'] != "" ? $post['start'] . " 00:00:00" : '';
  70. // $end = isset($post['end']) && $post['end'] != "" ? $post['end'] . " 23:59:59" : '';
  71. // $id = isset($post['id']) && $post['id'] !== '' ? intval($post['id']) : "";
  72. // if ($id == "") {
  73. // return json_show(1004, "参数id不能为空");
  74. // }
  75. $info = Db::name("exec_rela_com_no")->where(["id" => $param['id']])->find();
  76. if (empty($info)) return json_show(1004, "未找到下载数据");
  77. // if($info['type']==1){
  78. // $num = Db::name("exec_rela_com_no")->where(["type" =>1,"status"=>1])->where("id","<>",$id)->count();
  79. // if($num>0){
  80. // return json_show(1004, "已有脚本在运行");
  81. // }
  82. // }
  83. if ($info['relaComNo'] == $param['relaComNo'] && $info['start'] == $param['start'] && $info['end'] == $param['end']) return json_show(1004, "数据已提交");
  84. // if ($start != "") {
  85. // $info['start'] = $start;
  86. // }
  87. // if ($end != "") {
  88. // $info['end'] = $end;
  89. // }
  90. if (is_file(root_path() . 'public' . $info['down_url'])) {
  91. @unlink(root_path() . "public" . $info['down_url']);
  92. }
  93. $info['relaComNo'] = $param['relaComNo'];
  94. $info['relaComName'] = $param['relaComName'];
  95. $info['status'] = 1;
  96. $info['apply_id'] = $this->uid;
  97. $info['apply_name'] = $this->uname;
  98. $info['down_url'] = '';
  99. $info['remark'] = '';
  100. $info['updatetime'] = date("Y-m-d H:i:s");
  101. $info['addtime'] = date("Y-m-d H:i:s");
  102. $info['expiretime'] = date("Y-m-d H:i:s", time() + 7 * 24 * 3600);
  103. $info['start'] = $param['start'] . ' 00:00:00';
  104. $info['end'] = $param['end'] . ' 23:59:59';
  105. $up = Db::name("exec_rela_com_no")
  106. ->where('id', $param['id'])
  107. ->update($info);
  108. if ($up) {
  109. Cache::store("redis")->handler()->lPush($this->redis_key, json_encode($info));
  110. return json_show(0, "编辑成功");
  111. } else return json_show(0, "编辑失败");
  112. // return $up ? json_show(0, "编辑成功") : json_show(1004, "编辑失败");
  113. }
  114. public function down()
  115. {
  116. $post = $this->post;
  117. // $token = isset($post['token']) ? trim($post['token']) : "";
  118. // if ($token == "") {
  119. // return json_show(101, 'token不能为空');
  120. // }
  121. $id = isset($post['id']) && $post['id'] !== '' ? intval($post['id']) : "";
  122. if ($id == "") {
  123. return json_show(1004, "参数id不能为空");
  124. }
  125. $info = Db::name("exec_rela_com_no")->where(["id" => $id])->find();
  126. if (empty($info)) {
  127. return json_show(1004, "未找到下载数据");
  128. }
  129. // if ($info['type'] == 1) {
  130. // $num = Db::name("exec_rela_com_no")->where(["type" => 1, "status" => 1])->count();
  131. // if ($num > 0) {
  132. // return json_show(1004, "已有脚本在运行");
  133. // }
  134. // }
  135. // $effetc = VerifyTokens($token);
  136. // if(!empty($effetc) && $effetc['code']!=0){
  137. // return json_show($effetc['code'],$effetc['message']);
  138. // }
  139. // $userinfo = GetUserInfo($token);
  140. // if (!isset($userinfo['code']) || $userinfo['code'] != 0) {
  141. // return json_show(101, '未能获取用户信息');
  142. // }
  143. $info['status'] = 1;
  144. $info['down_url'] = '';
  145. $info['remark'] = '';
  146. $info['apply_id'] = $this->uid;
  147. $info['apply_name'] = $this->uname;
  148. $info['expiretime'] = date("Y-m-d H:i:s", time() + 7 * 24 * 3600);
  149. $info['updatetime'] = date("Y-m-d H:i:s");
  150. $info['addtime'] = date("Y-m-d H:i:s");
  151. $up = Db::name("exec_rela_com_no")->save($info);
  152. $redis = Cache::store("redis")->handler()->lPush($this->redis_key, json_encode($info));
  153. return $up ? json_show(0, "编辑成功") : json_show(1004, "编辑失败");
  154. }
  155. }