123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- namespace app\admin\controller;
- use think\facade\Db;
- use think\facade\Validate;
- use think\facade\Cache;
- //预约版本(业务公司)
- class ExecByRelaComNo extends Base
- {
- private $redis_key = 'cxreport_relaComNo';
- public function list()
- {
- $post = $this->post;
- // $token = isset($post['token']) ? trim($post['token']) : "";
- // if ($token == "") {
- // return json_show(101, 'token不能为空');
- // }
- $where = ['type' => 0];
- $page = isset($post['page']) ? intval($post['page']) : 1;
- $size = isset($post['size']) ? intval($post['size']) : 10;
- $count = Db::name("exec_rela_com_no")->where($where)->count();
- $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
- $page = $page >= $total ? intval($total) : $page;
- $list = Db::name("exec_rela_com_no")->where($where)->page($page, $size)->select();
- return json_show(0, "获取成功", ["list" => $list, "count" => $count]);
- }
- public function nowlist()
- {
- $param = $this->request->only(['relaComNo', 'page' => 1, 'size' => 10, 'type' => 1], 'post', 'trim');
- $val = Validate::rule([
- 'relaComNo' => 'require',
- 'page' => 'require|number|gt:0',
- 'size' => 'require|number|gt:0|lt:99999',
- 'type' => 'require|number|in:1,2,3',
- ]);
- if (!$val->check($param)) return json_show(1005, $val->getError());
- $count = Db::name("exec_rela_com_no")
- ->where(['relaComNo' => $param['relaComNo'], 'type' => $param['type']])
- ->count('id');
- $list = Db::name("exec_rela_com_no")
- ->where(['relaComNo' => $param['relaComNo'], 'type' => $param['type']])
- ->page($param['page'], $param['size'])
- ->order('id')
- ->select()
- ->toArray();
- return json_show(0, "获取成功", ["list" => $list, "count" => $count]);
- }
- public function save()
- {
- $param = $this->request->only(['start', 'end', 'id', 'relaComNo'], 'post', 'trim');
- $val = Validate::rule([
- 'start' => 'require|date|elt:end',
- 'end' => 'require|date|egt:start',
- 'id' => 'require|number|gt:0',
- 'relaComNo' => 'require',
- ]);
- if ($val->check($param) == false) return json_show(1004, $val->getError());
- $temp = \app\admin\common\User::getIns()->handle('getCodeAndName', ['code' => $param['relaComNo']]);
- if (!isset($temp['data'][$param['relaComNo']]) || $temp['data'][$param['relaComNo']] == '') return json_show(1004, '业务公司编码不存在');
- else $param['relaComName'] = $temp['data'][$param['relaComNo']];
- // $post = $this->post;
- // $token = isset($post['token']) ? trim($post['token']) : "";
- // if ($token == "") {
- // return json_show(101, 'token不能为空');
- // }
- // $userinfo = GetUserInfo($token);
- // if (!isset($userinfo['code']) || $userinfo['code'] != 0) {
- // return json_show(101, '未能获取用户信息');
- // }
- // $start = isset($post['start']) && $post['start'] != "" ? $post['start'] . " 00:00:00" : '';
- // $end = isset($post['end']) && $post['end'] != "" ? $post['end'] . " 23:59:59" : '';
- // $id = isset($post['id']) && $post['id'] !== '' ? intval($post['id']) : "";
- // if ($id == "") {
- // return json_show(1004, "参数id不能为空");
- // }
- $info = Db::name("exec_rela_com_no")->where(["id" => $param['id']])->find();
- if (empty($info)) return json_show(1004, "未找到下载数据");
- // if($info['type']==1){
- // $num = Db::name("exec_rela_com_no")->where(["type" =>1,"status"=>1])->where("id","<>",$id)->count();
- // if($num>0){
- // return json_show(1004, "已有脚本在运行");
- // }
- // }
- if ($info['relaComNo'] == $param['relaComNo'] && $info['start'] == $param['start'] && $info['end'] == $param['end']) return json_show(1004, "数据已提交");
- // if ($start != "") {
- // $info['start'] = $start;
- // }
- // if ($end != "") {
- // $info['end'] = $end;
- // }
- if (is_file(root_path() . 'public' . $info['down_url'])) {
- @unlink(root_path() . "public" . $info['down_url']);
- }
- $info['relaComNo'] = $param['relaComNo'];
- $info['relaComName'] = $param['relaComName'];
- $info['status'] = 1;
- $info['apply_id'] = $this->uid;
- $info['apply_name'] = $this->uname;
- $info['down_url'] = '';
- $info['remark'] = '';
- $info['updatetime'] = date("Y-m-d H:i:s");
- $info['addtime'] = date("Y-m-d H:i:s");
- $info['expiretime'] = date("Y-m-d H:i:s", time() + 7 * 24 * 3600);
- $info['start'] = $param['start'] . ' 00:00:00';
- $info['end'] = $param['end'] . ' 23:59:59';
- $up = Db::name("exec_rela_com_no")
- ->where('id', $param['id'])
- ->update($info);
- if ($up) {
- Cache::store("redis")->handler()->lPush($this->redis_key, json_encode($info));
- return json_show(0, "编辑成功");
- } else return json_show(0, "编辑失败");
- // return $up ? json_show(0, "编辑成功") : json_show(1004, "编辑失败");
- }
- public function down()
- {
- $post = $this->post;
- // $token = isset($post['token']) ? trim($post['token']) : "";
- // if ($token == "") {
- // return json_show(101, 'token不能为空');
- // }
- $id = isset($post['id']) && $post['id'] !== '' ? intval($post['id']) : "";
- if ($id == "") {
- return json_show(1004, "参数id不能为空");
- }
- $info = Db::name("exec_rela_com_no")->where(["id" => $id])->find();
- if (empty($info)) {
- return json_show(1004, "未找到下载数据");
- }
- // if ($info['type'] == 1) {
- // $num = Db::name("exec_rela_com_no")->where(["type" => 1, "status" => 1])->count();
- // if ($num > 0) {
- // return json_show(1004, "已有脚本在运行");
- // }
- // }
- // $effetc = VerifyTokens($token);
- // if(!empty($effetc) && $effetc['code']!=0){
- // return json_show($effetc['code'],$effetc['message']);
- // }
- // $userinfo = GetUserInfo($token);
- // if (!isset($userinfo['code']) || $userinfo['code'] != 0) {
- // return json_show(101, '未能获取用户信息');
- // }
- $info['status'] = 1;
- $info['down_url'] = '';
- $info['remark'] = '';
- $info['apply_id'] = $this->uid;
- $info['apply_name'] = $this->uname;
- $info['expiretime'] = date("Y-m-d H:i:s", time() + 7 * 24 * 3600);
- $info['updatetime'] = date("Y-m-d H:i:s");
- $info['addtime'] = date("Y-m-d H:i:s");
- $up = Db::name("exec_rela_com_no")->save($info);
- $redis = Cache::store("redis")->handler()->lPush($this->redis_key, json_encode($info));
- return $up ? json_show(0, "编辑成功") : json_show(1004, "编辑失败");
- }
- }
|