request->param('keyword'); if ($keyword) { $this->assign('keyword', $keyword); $pw['keyword'] = $keyword; } $project_id = $this->request->param('project_id'); $js_ids = Db::name('js_project_relevancy')->field('js_id')->where('status', 0)->group('js_id')->select(); $js_new_ids = []; foreach ($js_ids as $vo) { $js_new_ids[] = $vo['js_id']; } $where['id'] = $js_new_ids; if ($project_id) { $this->assign('project_id', $project_id); $pw['project_id'] = $project_id; $js_ids = Db::name('js_project_relevancy')->where('project_id', $project_id)->field('js_id')->group('js_id')->where('status', 0)->select(); $js_new_ids = []; foreach ($js_ids as $vo) { $js_new_ids[] = $vo['js_id']; } $where['id'] = $js_new_ids; } $page = $this->request->param('page'); $list = $JsModel::with(['user', 'project' => function ($query) { $query->where('status', 0); },])->where($where)->where(function ($query) use ($keyword) { if ($keyword) { $query->where('name|phone', 'like', '%' . $keyword . '%'); } })->field('id,user_id,name,phone')->order('id', 'desc')->paginate(30, false, array($page, url('index'), 'query' => $pw)); if ($this->request->param('debug') == 'zl') { $list = $JsModel::where($where)->where(function ($query) use ($keyword) { if ($keyword) { $query->where('name|phone', 'like', '%' . $keyword . '%'); } })->field('id,user_id,name,phone')->order('id', 'desc')->paginate(30, false, array($page, url('index'), 'query' => $pw)); echo $JsModel::getLastSql(); var_dump($list); } $JsProjectModel = new JsProjectModel(); $js_project_list = $JsProjectModel::field('id,name')->select(); $this->assign('list', $list); $this->assign('js_project_list', $js_project_list); $this->assign('page', $list->render()); return $this->fetch(); } public function codeindex() { $pw = []; $keyword = $this->request->param('keyword'); $bstatus = $this->request->param('band_status', '-1'); $status = $this->request->param('made_type', '-1'); $user = $this->request->param('uid_bind'); $page = $this->request->param('page', 1); $where = []; if ($keyword) { $this->assign('keyword', $keyword); $pw['keyword'] = $keyword; $where[] = ['code', '=', $keyword]; } if ($bstatus !== '-1') { $pw['band_status'] = $bstatus; $where[] = $bstatus == 1 ? ['user_id', '<>', 0] : ['user_id', '=', 0]; } if ($status !== '-1') { $pw['made_type'] = $status; $where[] = ['status', '=', $status]; } if ($user) { $this->assign('uid_bind', $user); $pw['uid_bind'] = $user; // $where['uid_bind'] = $user; } $this->assign('made_type', $status); $this->assign('band_status', $bstatus); $Model = new CouponModel(); try { $list = $Model::with([($user ? 'useri' : 'user') => function ($query) use ($user) { if ($user) { $query->where('mobile', '=', $user); } }, 'optuser'])->where($where)->order('id', 'desc')->paginate(20, false, array($page, url('codeindex'), 'query' => $pw)); } catch (DbException $e) { $list = []; } $this->assign('list', $list); $this->assign('page', $list->render()); return $this->fetch(); } public function downcode() { $Model = new CouponModel(); $no = $this->request->param('no'); if ($this->request->isPost()) { //压缩打包下载 $fileG = WEB_ROOT . 'upload/'; $list = $Model->where('opt_no',$no)->where('status', 0)->select(); $file = $fileG . 'backwrm/' . time() . '.zip'; $zip = new \ZipArchive(); if ($zip->open($file, \ZipArchive::OVERWRITE) !== true) { //OVERWRITE 参数会覆写压缩包的文件 文件必须已经存在 if ($zip->open($file, \ZipArchive::CREATE) !== true) { // 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip exit ('无法打开文件,或者文件创建失败'); } } foreach ($list as $vo) { $zip->addFile($fileG . $vo['code_url'], $vo['code'] . '.png'); } // var_dump($zip);exit(); $zip->close(); header("Cache-Control: max-age=0"); header("Content-Description: File Transfer"); header('Content-disposition: attachment; filename=' . basename($file)); // 文件名 header("Content-Type: application/zip"); // zip格式的 header("Content-Transfer-Encoding: binary"); // 告诉浏览器,这是二进制文件 header('Content-Length: ' . filesize($file)); // 告诉浏览器,文件大小 @readfile($file);//输出文件; @unlink($file); exit(); } $info = $Model->where('status', 0)->count(); $this->assign('info', $info); return $this->fetch(); } public function codeedit() { $id = $this->request->param('id'); $status = $this->request->param('status', 0); $Model = new CouponModel(); if ($this->request->isPost()) { $data = $this->request->post(); $data['status'] = $status; $Model->where('id', $id)->update($data); $this->success('操作成功'); } $info = $Model->where('id', $id)->find(); $this->assign('info', $info); return $this->fetch(); } public function codeadd() { if ($this->request->isPost()) { $Model = new CouponModel(); $num = $this->request->param('num'); $no = $this->request->param('no'); if (empty($num)) { $this->error('请输入数量'); } $Model->add_cdk($num, $no, session('ADMIN_ID')); $this->success('添加成功'); } return $this->fetch(); } public function selectproject() { $id = $this->request->param('id'); $info = JsModel::with(['project' => function ($query) { $query->where('status', 0); }])->where('id', $id)->find(); $this->assign('info', $info); $this->assign('id', $id); return $this->fetch(); } public function setProject() { $car_ids = $this->request->param('car_ids/a'); foreach ($car_ids as $v) { Db::name('js_project_relevancy')->where('id', $v)->update(['status' => 1, 'chuli_time' => time()]); } return json(['code' => 1]); } public function setall() { $ids = $this->request->param('ids/a'); foreach ($ids as $v) { Db::name('js_project_relevancy')->where(['js_id' => $v, 'status' => 0])->update(['status' => 1, 'chuli_time' => time()]); } $this->success('操作成功'); } public function delete() { $id = $this->request->param('id'); Db::name('js_project_relevancy')->where(['js_id' => $id, 'status' => 0])->delete(); $this->success('删除成功'); } }