From 97a999d30c3547bec28974eb68780e13ba22aabb Mon Sep 17 00:00:00 2001 From: zhaocheng <578322713@qq.com> Date: Tue, 16 Mar 2021 15:21:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Index.php.bak | 498 ---------------------------- app/controller/Task.php | 15 + app/controller/Task.php.bak | 605 ----------------------------------- app/view/task/index.html | 24 +- app/view/task/index.html.bak | 444 ------------------------- 5 files changed, 29 insertions(+), 1557 deletions(-) delete mode 100644 app/controller/Index.php.bak delete mode 100644 app/controller/Task.php.bak delete mode 100644 app/view/task/index.html.bak diff --git a/app/controller/Index.php.bak b/app/controller/Index.php.bak deleted file mode 100644 index 03d2511..0000000 --- a/app/controller/Index.php.bak +++ /dev/null @@ -1,498 +0,0 @@ -model = new CarInfoT; - } - - /** - * 显示资源列表 - * - * @return string - * @throws \Exception - */ - public function index() - { - $peer_phone_count = PeerPhoneT::count(); - $repeat_frame_count = RepeatFrameT::count(); - $this->assign('peer_phone_count', $peer_phone_count); - $this->assign('repeat_frame_count', $repeat_frame_count); - return $this->fetch(); - } - - /** - * @return Json - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function carInfo(){ - $params = $this->request->param(); - $page = $this->request->param('page', 1); - $limit = $this->request->param('limit', 20); - if ($page <= 1) { - $page = 1; - } - $offset = ($page - 1) * $limit; - $map = $this->getQueryCondition($params); - $jobs_name = ['0' => '']; - if (isset($params['is_check_peer_phone']) && $params['is_check_peer_phone'] > 0) { - $params['data_check'] = 'car_phone_check'; - } - if ((isset($params['is_check_repeat_frame']) && $params['is_check_repeat_frame'] > 0) || - isset($params['is_delete_frame']) && $params['is_delete_frame'] > 0) { - $params['data_check'] = 'car_frame_check'; - } - if(isset($params['data_check']) && $params['data_check'] == 'car_frame_check'){ - $query = $this->model->rightJoin('repeat_frame_t','repeat_frame_t.car_frame_no = car_info_t.car_frame_no')->field('car_info_t.*')->where($map)->order('repeat_frame_t.car_frame_no desc'); - if (isset($params['is_check_repeat_frame']) && $params['is_check_repeat_frame'] > 0) { - $jobs_info = JobsT::find($params['is_check_repeat_frame']); - $job_info_payload = json_decode($jobs_info->payload,true)['data']['params']; - if(isset($job_info_payload['export_date1']) && $job_info_payload['export_date1'] != ''){ - $query = $query->where('car_info_t.register_date', '>=', $job_info_payload['export_date1']); - } - if(isset($job_info_payload['export_date2']) && $job_info_payload['export_date2'] != ''){ - $query = $query->where('car_info_t.register_date', '<=', $job_info_payload['export_date2']); - } - $query = $query->where([ - ['repeat_frame_t.source', '=', $params['is_check_repeat_frame']]]); - } else if (isset($params['is_delete_frame']) && $params['is_delete_frame'] > 0) { - $query = $query->where('repeat_frame_t.is_delete', '=', $params['is_delete_frame']); - } - }else if(isset($params['data_check']) && $params['data_check'] == 'car_phone_check'){ - $query = $this->model->rightJoin('peer_phone_t','peer_phone_t.phone = car_info_t.car_phone')->field('car_info_t.*')->where($map)->order('peer_phone_t.phone desc'); - if (isset($params['is_check_peer_phone']) && $params['is_check_peer_phone'] > 0) { - $jobs_info = JobsT::find($params['is_check_peer_phone']); - $job_info_payload = json_decode($jobs_info->payload, true)['data']['params']; - if (isset($job_info_payload['export_date1']) && $job_info_payload['export_date1'] != '') { - $query = $query->where('car_info_t.register_date', '>=', $job_info_payload['export_date1']); - } - if (isset($job_info_payload['export_date2']) && $job_info_payload['export_date2'] != '') { - $query = $query->where('car_info_t.register_date', '<=', $job_info_payload['export_date2']); - } - $query = $query->where('peer_phone_t.source', '=', $params['is_check_peer_phone'])->where('car_info_t.car_number', 'REGEXP', '^[1-9][[:digit:]]{7}((0[[:digit:]])|(1[0-2]))(([0|1|2][[:digit:]])|3[0-1])[[:digit:]]{3}$|^[1-9][[:digit:]]{5}[1-9][[:digit:]]{3}((0[[:digit:]])|(1[0-2]))(([0|1|2][[:digit:]])|3[0-1])[[:digit:]]{3}([0-9]|X)$'); - } - } else if (isset($params['export_name']) && $params['export_name'] != '') { - $export_name = JobsT::where('queue', 'like', '%' . $params['export_name'] . '%')->column('queue,download_times', 'id'); - $ids = array_keys($export_name); - $query = $this->model->where($map)->where(function ($query) use ($ids) { - $query->whereOr(['car_info_t.is_export_bhx' => $ids, 'car_info_t.is_export_bmc' => $ids]); - })->field('*')->order('is_export_bhx desc,is_export_bmc desc'); - } else { - $query = $this->model->where($map)->order('id desc'); - } - $map_or1 = []; - $map_or2 = []; - $insurer_month1 = $params['insurer_month1']??''; - $insurer_day1 = $params['insurer_day1']??''; - $insurer_month2 = $params['insurer_month2']??''; - $insurer_day2 = $params['insurer_day2']??''; - if($insurer_month1 != '' && $insurer_day1 == '') { - $map_or1[] = [Db::raw('month(car_info_t.insurer1_date)'), '>=', $insurer_month1]; - $map_or2[] = [Db::raw('month(car_info_t.insurer2_date)'), '>=', $insurer_month1]; - } else if ($insurer_month1 == '' && $insurer_day1 != '') { - $map_or1[] = [Db::raw('day(car_info_t.insurer1_date)'), '>=', $insurer_day1]; - $map_or2[] = [Db::raw('day(car_info_t.insurer2_date)'), '>=', $insurer_day1]; - } else if ($insurer_month1 != '' && $insurer_day1 != '') { - $map_or1[] = [Db::raw('DATE_FORMAT(car_info_t.insurer1_date,"%m-%d")'), '>=', substr('0' . $insurer_month1, -2) . '-' . substr('0' . $insurer_day1, -2)]; - $map_or2[] = [Db::raw('DATE_FORMAT(car_info_t.insurer2_date,"%m-%d")'), '>=', substr('0' . $insurer_month1, -2) . '-' . substr('0' . $insurer_day1, -2)]; - } - if($insurer_month2 != '' && $insurer_day2 == '') { - $map_or1[] = [Db::raw('month(car_info_t.insurer1_date)'), '<=', $insurer_month2]; - $map_or2[] = [Db::raw('month(car_info_t.insurer2_date)'), '<=', $insurer_month2]; - } else if ($insurer_month2 == '' && $insurer_day2 != '') { - $map_or1[] = [Db::raw('day(car_info_t.insurer1_date)'), '<=', $insurer_day2]; - $map_or2[] = [Db::raw('day(car_info_t.insurer2_date)'), '<=', $insurer_day2]; - } else if ($insurer_month2 != '' && $insurer_day2 != '') { - $map_or1[] = [Db::raw('DATE_FORMAT(car_info_t.insurer1_date,"%m-%d")'), '<=', substr('0' . $insurer_month2, -2) . '-' . substr('0' . $insurer_day2, -2)]; - $map_or2[] = [Db::raw('DATE_FORMAT(car_info_t.insurer2_date,"%m-%d")'), '<=', substr('0' . $insurer_month2, -2) . '-' . substr('0' . $insurer_day2, -2)]; - } - if(count($map_or1) > 0){ - $map_or1 = array_merge([['car_info_t.insurer1_date', '<>', '']],$map_or1); - } - if(count($map_or2) > 0){ - $map_or2 = array_merge([['car_info_t.insurer1_date', '=', ''],['car_info_t.insurer2_date', '<>', '']],$map_or2); - } - if (count($map_or1) > 0 && count($map_or2) > 0) { - $query = $query->where(function ($query) use ($map_or1, $map_or2) { - if (count($map_or1) > 0 && count($map_or2) > 0) { - $query->whereOr([$map_or1, $map_or2]); - } - }); - } - if (isset($params['data_filter']) && !empty($params['data_filter'])) { - $map = $this->getAddStatusQuery(array_flip($params['data_filter'])); - if(count($map) > 1 ){ - $query = $query->where(function ($query) use ($map) { - if (count($map) > 0){ - $query->whereOr($map); - } - }); - }else { - $query = $query->where($map); - } - } - $count = $query->count(); - $list = $query->limit($offset, $limit)->select()->toArray(); - if(isset($export_name) && count($export_name) > 0 ){ - $jobs_name = $jobs_name + $export_name; - } - foreach ($list as &$item) { - $item['export_bhx_name'] = $jobs_name[$item['is_export_bhx']]['queue'] ?? ''; - $item['export_bmc_name'] = $jobs_name[$item['is_export_bmc']]['queue'] ?? ''; - $item['bhx_download_times'] = $jobs_name[$item['is_export_bhx']]['download_times'] ?? 0; - $item['bmc_download_times'] = $jobs_name[$item['is_export_bmc']]['download_times'] ?? 0; - } - $this->layui_data['data'] = $list; - $this->layui_data['count'] = $count; - return json($this->layui_data); - } - - /** - * 显示编辑资源表单页. - * - * @param int $id - * @return string - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function edit($id) - { - $car_info = $this->model->find($id); - if($this->request->isGet()){ - $this->assign('info', $car_info); - return $this->fetch(); - }else if($this->request->isPost()){ - $data = $this->request->param(); - $car_info->car_no = $data['car_no'] ?? $car_info->car_no; - $car_info->car_frame_no = $data['car_frame_no'] ?? $car_info->car_frame_no; - $car_info->engine_no = $data['engine_no'] ?? $car_info->engine_no; - $car_info->factory_model = $data['factory_model'] ?? $car_info->factory_model; - $car_info->register_date = $data['register_date'] ?? $car_info->register_date; - $car_info->purchase_price = $data['purchase_price'] ?? $car_info->purchase_price; - $car_info->company = $data['company'] ?? $car_info->company; - $car_info->insurer1_date = $data['insurer1_date'] ?? $car_info->insurer1_date; - $car_info->insurer2_date = $data['insurer2_date'] ?? $car_info->insurer2_date; - $car_info->car_man = $data['car_man'] ?? $car_info->car_man; - $car_info->car_number = $data['car_number'] ?? $car_info->car_number; - $car_info->car_phone = $data['car_phone'] ?? $car_info->car_phone; - $car_info->id_man = $data['id_man'] ?? $car_info->id_man; - $car_info->id_number = $data['id_number'] ?? $car_info->id_number; - $car_info->update_timestamp = date('Y-m-d H:i:s'); - if($car_info->save()){ - return json($this->json_data); - }else { - $this->json_data['code'] = 0; - $this->json_data['msg'] = '保存失败'; - return json($this->layui_data); - } - } - - } - - /** - * 删除指定资源 - * @param $id - * @return Json - */ - public function delete($id) - { - // - $this->json_data['code'] = intval($this->model->destroy($id)); - $this->json_data['msg'] = $this->json_data['code'] ? '删除成功' : '删除失败'; - return json($this->json_data); - } - - /** - * 批量删除 - * @return Json - * @throws \Exception - */ - public function deletes() - { - // - $params = $this->request->param(); - $map = $this->getQueryCondition($params); - if($this->model->where($map)->delete()){ - $this->json_data['msg'] = '删除成功'; - }else { - $this->json_data['code'] = 0; - $this->json_data['msg'] = '删除失败'; - } - return json($this->json_data); - } - - /** - * 清除数据 - * @return Json - */ - public function truncate(){ - $ret = Db::execute("truncate table car_info_t"); - if($ret === false){ - $this->json_data['code'] = 0; - $this->json_data['msg'] = '删除失败'; - }else { - $this->json_data['msg'] = '删除成功'; - } - return json($this->json_data); - } - - /** - * @param $id - * @return Json - */ - public function clearPhone($id){ - $this->json_data['code'] = $this->model->where('id', $id)->update(['car_phone' => '']); - $this->json_data['msg'] = $this->json_data['code'] ? '操作成功' : '操作失败'; - return json($this->json_data); - } - - /** - * 保存更新的资源 - * - * @param int $id - * @param $field - * @param $value - * @return \think\Response - */ - public function update($id, $field, $value) - { - $this->json_data['code'] = $this->model->where('id', $id)->update([$field => $value]); - $this->json_data['msg'] = $this->json_data['code'] ? '更新成功' : '更新失败'; - return json($this->json_data); - } - - public function login(){ - $password = $this->request->param('password',''); - if ($password === 'wuwei088277') { - session('login_time', time()); - session('last_action', time()); - }else { - $this->json_data['code'] = 0; - $this->json_data['msg'] = '密码错误'; - } - return json($this->json_data); - } - - /** - * @param $params - * @return array - */ - private function getQueryCondition($params) - { - $map = []; - if (isset($params['car_man']) && $params['car_man'] != '') { - $car_man = explode(',', str_replace(',', '', $params['car_man'])); - array_walk($car_man, function (&$value) { - $value = '%' . $value . '%'; - }); - $map[] = ['car_info_t.car_man', 'like', $car_man]; - } - if (isset($params['factory_model']) && $params['factory_model'] != '') { - $factory_model = explode(',', str_replace(',', '', $params['factory_model'])); - array_walk($factory_model, function (&$value) { - $value = '%' . $value . '%'; - }); - $map[] = ['car_info_t.factory_model', 'like', $factory_model]; - } - if (isset($params['car_frame_no']) && $params['car_frame_no'] != '') { - $map[] = ['car_info_t.car_frame_no', '=', $params['car_frame_no']]; - } - if (isset($params['car_no']) && $params['car_no'] != '') { - $map[] = ['car_info_t.car_no', '=', $params['car_no']]; - } - if (isset($params['car_number']) && $params['car_number'] != '') { - $map[] = ['car_info_t.car_number', '=', $params['car_number']]; - } - if (isset($params['car_phone']) && $params['car_phone'] != '') { - $map[] = ['car_info_t.car_phone', '=', $params['car_phone']]; - } - if (isset($params['register_date']) && $params['register_date'] != '') { - $map[] = ['car_info_t.register_date', '=', $params['register_date']]; - } - if (isset($params['car_phone_empty']) && $params['car_phone_empty'] == 'yes') { - $map[] = ['car_info_t.car_phone', '<>', '']; - } - if (isset($params['car_phone_empty']) && $params['car_phone_empty'] == 'no') { - $map[] = ['car_info_t.car_phone', '=', '']; - } - if (isset($params['car_phone_repeat']) && $params['car_phone_repeat'] == 'yes') { - $map[] = ['car_info_t.id', '=', 'peer_phone_t.id']; - } - if (isset($params['is_update_bhx']) && $params['is_update_bhx'] > 0 ) { - $map[] = ['car_info_t.is_update_bhx', '=', $params['is_update_bhx']]; - } - if (isset($params['is_export_bhx']) && $params['is_export_bhx'] > 0 ) { - $map[] = ['car_info_t.is_export_bhx', '=', $params['is_export_bhx']]; - } - if (isset($params['is_export_bmc']) && $params['is_export_bmc'] > 0 ) { - $map[] = ['car_info_t.is_export_bmc', '=', $params['is_export_bmc']]; - } - if (isset($params['is_export_failed']) && $params['is_export_failed'] > 0 ) { - $map[] = ['car_info_t.is_export_failed', '=', $params['is_export_failed']]; - } - if (isset($params['is_export_failed_bmc']) && $params['is_export_failed_bmc'] > 0 ) { - $map[] = ['car_info_t.is_export_failed_bmc', '=', $params['is_export_failed_bmc']]; - } - if (isset($params['is_export_none_bmc']) && $params['is_export_none_bmc'] > 0 ) { - $map[] = ['car_info_t.is_export_none_bmc', '=', $params['is_export_none_bmc']]; - } - - if (isset($params['source']) && $params['source'] > 0 ) { - $map[] = ['car_info_t.source', '=', $params['source']]; - } - if(isset($params['register_date1']) && $params['register_date1'] != ''){ - $map[] = ['car_info_t.register_date', '>=', $params['register_date1']]; - } - if(isset($params['register_date2']) && $params['register_date2'] != ''){ - $map[] = ['car_info_t.register_date', '<=', $params['register_date2']]; - } - if (isset($params['price1']) && $params['price1'] != '') { - $map[] = ['car_info_t.purchase_price', '>=', $params['price1'] * 10000]; - } - if (isset($params['price2']) && $params['price2'] != '') { - $map[] = ['car_info_t.purchase_price', '<=', $params['price2'] * 10000]; - } - return $map; - } - - /** - * 添加状态筛选 - * @param $data_filter - * @return array - */ - private function getAddStatusQuery($data_filter) - { - $tree = new Tree(); - $tree->setNode(1, isset($data_filter['bhx']) ? [['car_info_t.is_export_bhx', '>', 0]] : []); - $tree->setNode(2, isset($data_filter['none']) ? [['car_info_t.is_export_bhx', '=', 0]] : []); - if(isset($data_filter['bhx_success'])){ - $tree->setNode(3, [[ - ['car_info_t.is_export_bhx', '>', 0], - ['car_info_t.is_update_bhx', '>', 0], - ]],1); - $tree->setNode(1, [], 0); - }else { - $tree->setNode(3, [],1); - } - if(isset($data_filter['bhx_failed'])){ - $tree->setNode(4, [[ - ['car_info_t.is_export_bhx', '>', 0], - ['car_info_t.is_update_bhx', '<', 0], - ]],1); - $tree->setNode(1, [], 0); - }else { - $tree->setNode(4, [],1); - } - if(isset($data_filter['bhx_none'])){ - $tree->setNode(5, [[ - ['car_info_t.is_export_bhx', '>', 0], - ['car_info_t.is_update_bhx', '=', 0], - ]],1); - $tree->setNode(1, [], 0); - }else { - $tree->setNode(5, [],1); - } - if(isset($data_filter['none_bmc'])){ - $tree->setNode(6, [[ - ['car_info_t.is_export_bhx', '=', 0], - ['car_info_t.is_export_none_bmc', '>', 0], - ]],2); - $tree->setNode(2, [], 0); - }else { - $tree->setNode(6, [],2); - } - if(isset($data_filter['none_none'])){ - $tree->setNode(7, [[ - ['car_info_t.is_export_bhx', '=', 0], - ['car_info_t.is_export_none_bmc', '=', 0], - ]],2); - $tree->setNode(2, [], 0); - }else { - $tree->setNode(7, [],2); - } - if(isset($data_filter['bhx_success_bmc'])){ - $tree->setNode(8, [[ - ['car_info_t.is_export_bhx', '>', 0], - ['car_info_t.is_update_bhx', '>', 0], - ['car_info_t.is_export_bmc', '>', 0], - ]],3); - $tree->setNode(3, [], 0); - }else { - $tree->setNode(8, [],3); - } - if(isset($data_filter['bhx_success_none'])){ - $tree->setNode(9, [[ - ['car_info_t.is_export_bhx', '>', 0], - ['car_info_t.is_update_bhx', '>', 0], - ['car_info_t.is_export_bmc', '=', 0], - ]],3); - $tree->setNode(3, [], 0); - }else { - $tree->setNode(9, [],3); - } - if(isset($data_filter['bhx_failed_bmc'])){ - $tree->setNode(10, [[ - ['car_info_t.is_export_bhx', '>', 0], - ['car_info_t.is_update_bhx', '=', -1], - ['car_info_t.is_export_bmc', '=', 0], - ['car_info_t.is_export_failed', '=', 0], - ['car_info_t.is_export_failed_bmc', '>', 0], - ]],4); - $tree->setNode(4, [], 0); - }else { - $tree->setNode(10, [],4); - } - if(isset($data_filter['bhx_failed_bhx'])){ - $tree->setNode(11, [[ - ['car_info_t.is_export_bhx', '>', 0], - ['car_info_t.is_export_bhx', '>', 0], - ['car_info_t.is_update_bhx', '=', -1], - ['car_info_t.is_export_bmc', '=', 0], - ['car_info_t.is_export_failed', '>', 0], - ]],4); - $tree->setNode(4, [], 0); - }else { - $tree->setNode(11, [],4); - } - if(isset($data_filter['bhx_failed_none'])){ - $tree->setNode(12, [[ - ['car_info_t.is_export_bhx', '>', 0], - ['car_info_t.is_update_bhx', '=', -1], - ['car_info_t.is_export_bmc', '=', 0], - ['car_info_t.is_export_failed', '=', 0], - ['car_info_t.is_export_failed_bmc', '=', 0], - ]],4); - $tree->setNode(4, [], 0); - }else { - $tree->setNode(12, [],4); - } - - $map = $tree->getAllChildrenNodes(0, function ($value) { - return count($value) > 0; - }, function ($value) { - return $value; - }); - return array_column(array_filter($map), null); - } -} diff --git a/app/controller/Task.php b/app/controller/Task.php index 8326513..e4f5220 100644 --- a/app/controller/Task.php +++ b/app/controller/Task.php @@ -203,6 +203,21 @@ class Task extends BaseController $where[] = ['is_export_failed_bmc', '=', 0]; $where[] = ['is_export_none_bmc', '=', 0]; } + if ($params['export_type'] == 'success_bmc') { + $where[] = ['is_export_bhx', '>', 0]; + $where[] = ['is_update_bhx', '>', 0]; + $where[] = ['is_export_bmc', '>', 0]; + $insurer_date1 = $params['insurer_date1']??''; + $insurer_date2 = $params['insurer_date2']??''; + if($insurer_date1!=''){ + $map_or1[] = ['car_info_t.insurer1_date', '>=', $insurer_date1]; + $map_or2[] = ['car_info_t.insurer2_date', '>=', $insurer_date1]; + } + if($insurer_date2!=''){ + $map_or1[] = ['car_info_t.insurer1_date', '<=', $insurer_date2]; + $map_or2[] = ['car_info_t.insurer2_date', '<=', $insurer_date2]; + } + } } $insurer_month1 = $params['insurer_month1']??''; $insurer_day1 = $params['insurer_day1']??''; diff --git a/app/controller/Task.php.bak b/app/controller/Task.php.bak deleted file mode 100644 index d46e193..0000000 --- a/app/controller/Task.php.bak +++ /dev/null @@ -1,605 +0,0 @@ -model = new JobsT; - } - - /** - * 显示资源列表 - * - * @return string - * @throws \Exception - */ - public function index() - { - return $this->fetch(); - } - - /** - * @return \think\response\Json - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function taskInfo(){ - $page = $this->request->param('page', 1); - $limit = $this->request->param('limit', 20); - $queue = $this->request->param('queue', ''); - if ($page <= 1) { - $page = 1; - } - $offset = ($page - 1) * $limit; - $query = $this->model->field(['id','payload','remark', 'type', 'queue', 'download_times', - "(case `status` when 2 then '100' else '0' end)" => 'process', - 'date_format(from_unixtime(create_time),"%Y-%m-%d %H:%i:%s") as create_timestamp', - "(case `type` when 1 then '导入' when 2 then '导出' when 3 then '同行电话' when 4 then '重复车架号' when 5 then '更新车辆信息' when 6 then '清除重复电话' when 7 then '删除重复数据' else '' end)" => 'type_txt', - "(case `status` when 0 then '排队中' when 1 then '处理中' when 2 then '已完成' when 3 then '失败' else '' end)" => 'status', 'create_time']); - if($queue != ''){ - $query = $query->where('queue','like','%'. $queue .'%')->whereOr('payload','like','%'. str_replace(['\\','"'],['_',''],json_encode($queue)) .'%'); - } - $count = $query->count(); - $list = $query->limit($offset, (int)$limit)->order('id desc')->select()->toArray(); - foreach ($list as &$item){ - if($item['type'] == 1 || $item['type'] == 5){ - $item['type_txt'] = json_decode($item['payload'],true)['data']['params']['original_filename'] ?? ''; - } - if ($item['type'] == 2) { - $item['type_txt'] = $item['queue'] != 'default' ? $item['queue']: $item['type_txt']; - } - if($item['type'] == 3){ - $item['info_num'] = PeerPhoneT::where(['source' => $item['id']])->count(); - } - if($item['type'] == 4){ - $item['info_num'] = RepeatFrameT::where(['source' => $item['id'], 'is_delete' => 0])->count(); - } - } - $this->layui_data['data'] = $list; - $this->layui_data['count'] = $count; - return json($this->layui_data); - } - - /** - * 显示创建资源表单页. - * - */ - public function create() - { - - } - - /** - * 保存新建的资源 - * - * @return \think\Response - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function save() - { - $params = $this->request->param(); - $type = $this->request->param('task_type', '0'); - $original_filename = $this->request->param('original_filename'); - $filename = $this->request->param('filename'); - $peer_phone_number = $this->request->param('peer_phone_number'); - $queue = $this->request->param('queue', ''); - if(isset($params['source_id']) && $params['source_id'] > 0) { - $job_info = JobsT::find($params['source_id']); - $job_info_payload = json_decode($job_info->payload,true)['data']['params']; - $params = []; - $params['export_type'] = 'repeat'; - $params['export_limit'] = 0; - $params['export_table'] = $job_info->type == 3? 'peer_phone_t': ($job_info->type == 4?'repeat_frame_t':''); - $params['source_id'] = $job_info->id; - $params['export_date1'] = $job_info_payload['export_date1']; - $params['export_date2'] = $job_info_payload['export_date2']; - } - if (($type == 1 || $type == 5) && ( $filename == '' || ($filename != '' && !file_exists(public_path('public/storage') . $filename)))) { - $this->json_data['code'] = 0; - $this->json_data['msg'] = '导入文件不存在'; - return json($this->json_data); - } else if ($type == 1 || $type == 5) { - $original_filename = basename($original_filename); - $original_filename = str_replace(strrchr($original_filename, '.'), '', $original_filename); - $params['original_filename'] = $original_filename; - } - if ($type == 2 && (!isset($params['source_id']) || $params['source_id'] <= 0) && $params['export_date1'] == '' && $params['export_date2'] == '') { - $this->json_data['code'] = 0; - $this->json_data['msg'] = '请先填写注册日期'; - return json($this->json_data); - } else if ($type == 2 && isset($params['export_type']) && $params['export_type'] != '' && !in_array($params['export_type'], ['bhx', 'bmc', 'failed', 'repeat', 'failed_bmc', 'none_bmc'])) { - $this->json_data['code'] = 0; - $this->json_data['msg'] = '导出类型错误,请选择正确的导出类型'; - return json($this->json_data); - } else if ($type == 2) { - $where = []; - $map_or1 = []; - $map_or2 = []; - if(isset($params['export_date1']) && $params['export_date1'] != ''){ - $where[] = ['car_info_t.register_date', '>=', $params['export_date1']]; - } - if(isset($params['export_date2']) && $params['export_date2'] != ''){ - $where[] = ['car_info_t.register_date', '<=', $params['export_date2']]; - } - if (isset($params['price1']) && $params['price1'] != '') { - $where[] = ['car_info_t.purchase_price', '>=', $params['price1'] * 10000]; - } - if (isset($params['price2']) && $params['price2'] != '') { - $where[] = ['car_info_t.purchase_price', '<=', $params['price2'] * 10000]; - } - if(isset($params['empty_phone_check']) && $params['empty_phone_check'] == 'yes'){ - $where[] = ['car_phone', '<>', '']; - } - if(isset($params['export_field'])){ - foreach ($params['export_field'] as $item){ - $where[] = [$item, '<>', '']; - } - } - if(isset($params['export_type']) && $params['export_type'] != '' && $params['export_limit'] != 0){ - if($params['export_type'] == 'bhx'){ - $where[] = ['is_export_bhx', '=', 0]; - $where[] = ['is_update_bhx', '=', 0]; - $where[] = ['is_export_bmc', '=', 0]; - $where[] = ['is_export_failed', '=', 0]; - $where[] = ['is_export_failed_bmc', '=', 0]; - } - if($params['export_type'] == 'bmc'){ - $where[] = ['is_export_bhx', '>', 0]; - $where[] = ['is_update_bhx', '>', 0]; - $where[] = ['is_export_bmc', '=', 0]; - } - if ($params['export_type'] == 'failed') { - $where[] = ['is_export_bhx', '>', 0]; - $where[] = ['is_update_bhx', '<', 0]; - $where[] = ['is_export_bmc', '=', 0]; - $where[] = ['is_export_failed', '=', 0]; - } - if ($params['export_type'] == 'failed_bmc') { - $where[] = ['is_export_bhx', '>', 0]; - $where[] = ['is_update_bhx', '<', 0]; - $where[] = ['is_export_bmc', '=', 0]; - $where[] = ['is_export_failed_bmc', '=', 0]; - } - if ($params['export_type'] == 'none_bmc') { - $where[] = ['is_export_bhx', '=', 0]; - $where[] = ['is_update_bhx', '=', 0]; - $where[] = ['is_export_bmc', '=', 0]; - $where[] = ['is_export_failed', '=', 0]; - $where[] = ['is_export_failed_bmc', '=', 0]; - $where[] = ['is_export_none_bmc', '=', 0]; - } - } - $insurer_month1 = $params['insurer_month1']??''; - $insurer_day1 = $params['insurer_day1']??''; - $insurer_month2 = $params['insurer_month2']??''; - $insurer_day2 = $params['insurer_day2']??''; - if($insurer_month1 != '' && $insurer_day1 == '') { - $map_or1[] = [Db::raw('month(car_info_t.insurer1_date)'), '>=', $insurer_month1]; - $map_or2[] = [Db::raw('month(car_info_t.insurer2_date)'), '>=', $insurer_month1]; - } else if ($insurer_month1 == '' && $insurer_day1 != '') { - $map_or1[] = [Db::raw('day(car_info_t.insurer1_date)'), '>=', $insurer_day1]; - $map_or2[] = [Db::raw('day(car_info_t.insurer2_date)'), '>=', $insurer_day1]; - } else if ($insurer_month1 != '' && $insurer_day1 != '') { - $map_or1[] = [Db::raw('DATE_FORMAT(car_info_t.insurer1_date,"%m-%d")'), '>=', substr('0' . $insurer_month1, -2) . '-' . substr('0' . $insurer_day1, -2)]; - $map_or2[] = [Db::raw('DATE_FORMAT(car_info_t.insurer2_date,"%m-%d")'), '>=', substr('0' . $insurer_month1, -2) . '-' . substr('0' . $insurer_day1, -2)]; - } - if($insurer_month2 != '' && $insurer_day2 == '') { - $map_or1[] = [Db::raw('month(car_info_t.insurer1_date)'), '<=', $insurer_month2]; - $map_or2[] = [Db::raw('month(car_info_t.insurer2_date)'), '<=', $insurer_month2]; - } else if ($insurer_month2 == '' && $insurer_day2 != '') { - $map_or1[] = [Db::raw('day(car_info_t.insurer1_date)'), '<=', $insurer_day2]; - $map_or2[] = [Db::raw('day(car_info_t.insurer2_date)'), '<=', $insurer_day2]; - } else if ($insurer_month2 != '' && $insurer_day2 != '') { - $map_or1[] = [Db::raw('DATE_FORMAT(car_info_t.insurer1_date,"%m-%d")'), '<=', substr('0' . $insurer_month2, -2) . '-' . substr('0' . $insurer_day2, -2)]; - $map_or2[] = [Db::raw('DATE_FORMAT(car_info_t.insurer2_date,"%m-%d")'), '<=', substr('0' . $insurer_month2, -2) . '-' . substr('0' . $insurer_day2, -2)]; - } - if(count($map_or1) > 0){ - $map_or1 = array_merge([['car_info_t.insurer1_date', '<>', '']],$map_or1); - } - if(count($map_or2) > 0){ - $map_or2 = array_merge([['car_info_t.insurer1_date', '=', ''],['car_info_t.insurer2_date', '<>', '']],$map_or2); - } - $query = CarInfoT::where($where)->where(function ($query) use ($map_or1, $map_or2) { - if (count($map_or1) > 0 && count($map_or2) > 0){ - $query->whereOr([$map_or1, $map_or2]); - } - }); - $count = $query->count(); - if ($count < $params['export_limit']) { - $this->json_data['code'] = 0; - $this->json_data['msg'] = '当前导出数量为' . $count . ', 不足' . $params['export_limit'] . ',请检查条件'; - return json($this->json_data); - } - } - if ($type == 3 && $peer_phone_number <= 0) { - $this->json_data['code'] = 0; - $this->json_data['msg'] = '请填写正确的个人电话重复数'; - return json($this->json_data); - } - if ($type == 3 || $type == 4) { - $where = []; - if($params['export_date1'] != ''){ - $where[] = ['car_info_t.register_date', '>=', $params['export_date1']]; - } - if($params['export_date2'] != ''){ - $where[] = ['car_info_t.register_date', '<=', $params['export_date2']]; - } - $count = CarInfoT::where($where)->count(); - if ($count <= 0) { - $this->json_data['code'] = 0; - $this->json_data['msg'] = '当前待处理数据为空,请检查条件'; - return json($this->json_data); - } - } - $action = [ - '1'=>'import', - '2'=>'export', - '3'=>'peerPhones', - '4'=>'carFrameNo', - '5'=>'carInfoUpdate', - '6'=>'deletePeerPhones', - '7'=>'deleteCarFrameNo', - ]; - $id = Queue::push( - 'app\jobs\DelayQueue', - ['params' => $params, 'controller' => 'service\\CarInfoHandle', 'action' => $action[$type]], - $queue, $type); - if (!$id) { - $this->json_data['code'] = 0; - $this->json_data['msg'] = '任务创建失败'; - } - return json($this->json_data); - } - - /** - * 显示指定的资源 - * - * @param int $id - * @return \think\Response - */ - public function read($id) - { - // - } - - /** - * 显示编辑资源表单页. - * - * @param int $id - * @return \think\Response - */ - public function edit($id) - { - // - } - - /** - * 保存更新的资源 - * - * @param \think\Request $request - * @param int $id - * @return \think\Response - */ - public function update(Request $request, $id) - { - // - } - - /** - * 删除指定资源 - * - * @param int $id - * @return \think\Response - */ - public function delete($id) - { - // - } - - /** - * @return Json - */ - public function upload(){ - $file = request()->file('file'); - $savename = Filesystem::disk('public')->putFile('uploads', $file); - $filename = public_path('public\storage') . $savename; - if ($this->checkUploadTpl($filename, $this->request->param('task_type'))) { - $this->json_data['msg'] = '上传成功'; - $this->json_data['original_filename'] = $file->getOriginalName(); - $this->json_data['filename'] = $savename; - } else { - @unlink($filename); - $this->json_data['code'] = 0; - $this->json_data['msg'] = '上传文件[' . $file->getOriginalName() . ']与模板不匹配,请检查文件重新上传'; - } - return json($this->json_data); - } - - public function clearSubTable(){ - Db::startTrans(); - try { - Db::execute("truncate table jobs_t;"); - Db::execute("truncate table peer_phone_t;"); - Db::execute("truncate table repeat_frame_t;"); - $this->json_data['msg'] = '删除成功'; - Db::commit(); - } catch (\Exception $e) { - Db::rollback(); - $this->json_data['code'] = 0; - $this->json_data['msg'] = '删除失败'; - } - return json($this->json_data); - } - - public function download($id) - { - $job_info = JobsT::find($id); - $job_info->download_times = Db::raw('download_times+1'); - $downloadName = $this->downloadName($job_info); - $job_info->save(); - return download(root_path(). 'public' . $job_info->remark, $downloadName); - } - - public function process(){ - $list = JobsT::where('status', '=', 1) - ->whereOr('create_time', '>=', strtotime(date('Y-m-d'))) - ->order('create_time desc') - ->select(); - foreach ($list as $item) { - $process = cache('shell_process_' . $item['id']); - if($item->status == 1 || $process){ - $this->json_data['data'][] = [ - 'id' => $item['id'], - 'process' => $process, - ]; - } - if($process >= 100){ - Cache::delete('shell_process_' . $item['id']); - } - } - return json($this->json_data); - } - - /** - * 导出名称 - * @return \think\response\Json - */ - public function exportName() - { - $export_date1 = $this->request->param('export_date1'); - $export_date2 = $this->request->param('export_date2'); - if ($export_date1 == '' || $export_date2 == '') { - $this->json_data['code'] = 0; - $this->json_data['msg'] = '注册日期范围不能为空'; - return json($this->json_data); - } - $type = $this->request->param('export_type'); - $export_limit = $this->request->param('export_limit'); - $name = ''; - if ($type == 'bhx') { - $name = '导出清洗'; - } else if ($type == 'failed') { - $name = '导出清洗失败'; - } else if ($type == 'bmc') { - $name = '导出清洗成功至上传'; - } else if ($type == 'failed_bmc') { - $name = '导出清洗失败至上传'; - } else if ($type == 'none_bmc') { - $name = '导出未处理至上传'; - } - $count = ExportLogT::where('name','like', $name . $export_date1 . '—' . $export_date2 . '%')->count(); - $name .= $export_date1 . '—' . $export_date2 . '第' . ($count + 1) . '批' . $export_limit . '条'; - $this->json_data['name'] = $name; - return json($this->json_data); - } - - /** - * 任务操作 - * @param $jobId - * @return \think\response\Json - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function taskBtn($jobId){ - $job_info = JobsT::find($jobId); - if($job_info->type == 2){ - $this->json_data['btns'] = '下载文件'; - }else if($job_info->type == 3 && PeerPhoneT::where(['source' => $job_info->id])->count() > 0){ - $this->json_data['btns'] = ' - - - '; - }else if($job_info->type == 4 && RepeatFrameT::where(['source' => $job_info->id, 'is_delete' => 0])->count() > 0){ - $this->json_data['btns'] = ' - - - '; - } - return json($this->json_data); - } - - public function exportNum(){ - $params = $this->request->param(); - $where = []; - $map_or1 = []; - $map_or2 = []; - if(isset($params['export_date1']) && $params['export_date1'] != ''){ - $where[] = ['car_info_t.register_date', '>=', $params['export_date1']]; - } - if(isset($params['export_date2']) && $params['export_date2'] != ''){ - $where[] = ['car_info_t.register_date', '<=', $params['export_date2']]; - } - if (isset($params['price1']) && $params['price1'] != '') { - $where[] = ['car_info_t.purchase_price', '>=', $params['price1'] * 10000]; - } - if (isset($params['price2']) && $params['price2'] != '') { - $where[] = ['car_info_t.purchase_price', '<=', $params['price2'] * 10000]; - } - if(isset($params['empty_phone_check']) && $params['empty_phone_check'] == 'yes'){ - $where[] = ['car_phone', '<>', '']; - } - if(isset($params['export_field'])){ - foreach ($params['export_field'] as $item){ - $where[] = [$item, '<>', '']; - } - } - if(isset($params['export_type']) && $params['export_type'] != ''){ - if($params['export_type'] == 'bhx'){ - $where[] = ['is_export_bhx', '=', 0]; - $where[] = ['is_update_bhx', '=', 0]; - $where[] = ['is_export_bmc', '=', 0]; - $where[] = ['is_export_failed', '=', 0]; - $where[] = ['is_export_failed_bmc', '=', 0]; - } - if($params['export_type'] == 'bmc'){ - $where[] = ['is_export_bhx', '>', 0]; - $where[] = ['is_update_bhx', '>', 0]; - $where[] = ['is_export_bmc', '=', 0]; - } - if ($params['export_type'] == 'failed') { - $where[] = ['is_export_bhx', '>', 0]; - $where[] = ['is_update_bhx', '<', 0]; - $where[] = ['is_export_bmc', '=', 0]; - $where[] = ['is_export_failed', '=', 0]; - } - if ($params['export_type'] == 'failed_bmc') { - $where[] = ['is_export_bhx', '>', 0]; - $where[] = ['is_update_bhx', '<', 0]; - $where[] = ['is_export_bmc', '=', 0]; - $where[] = ['is_export_failed_bmc', '=', 0]; - } - if ($params['export_type'] == 'none_bmc') { - $where[] = ['is_export_bhx', '=', 0]; - $where[] = ['is_update_bhx', '=', 0]; - $where[] = ['is_export_bmc', '=', 0]; - $where[] = ['is_export_failed', '=', 0]; - $where[] = ['is_export_failed_bmc', '=', 0]; - $where[] = ['is_export_none_bmc', '=', 0]; - } - } - $insurer_month1 = $params['insurer_month1']??''; - $insurer_day1 = $params['insurer_day1']??''; - $insurer_month2 = $params['insurer_month2']??''; - $insurer_day2 = $params['insurer_day2']??''; - if($insurer_month1 != '' && $insurer_day1 == '') { - $map_or1[] = [Db::raw('month(car_info_t.insurer1_date)'), '>=', $insurer_month1]; - $map_or2[] = [Db::raw('month(car_info_t.insurer2_date)'), '>=', $insurer_month1]; - } else if ($insurer_month1 == '' && $insurer_day1 != '') { - $map_or1[] = [Db::raw('day(car_info_t.insurer1_date)'), '>=', $insurer_day1]; - $map_or2[] = [Db::raw('day(car_info_t.insurer2_date)'), '>=', $insurer_day1]; - } else if ($insurer_month1 != '' && $insurer_day1 != '') { - $map_or1[] = [Db::raw('DATE_FORMAT(car_info_t.insurer1_date,"%m-%d")'), '>=', substr('0' . $insurer_month1, -2) . '-' . substr('0' . $insurer_day1, -2)]; - $map_or2[] = [Db::raw('DATE_FORMAT(car_info_t.insurer2_date,"%m-%d")'), '>=', substr('0' . $insurer_month1, -2) . '-' . substr('0' . $insurer_day1, -2)]; - } - if($insurer_month2 != '' && $insurer_day2 == '') { - $map_or1[] = [Db::raw('month(car_info_t.insurer1_date)'), '<=', $insurer_month2]; - $map_or2[] = [Db::raw('month(car_info_t.insurer2_date)'), '<=', $insurer_month2]; - } else if ($insurer_month2 == '' && $insurer_day2 != '') { - $map_or1[] = [Db::raw('day(car_info_t.insurer1_date)'), '<=', $insurer_day2]; - $map_or2[] = [Db::raw('day(car_info_t.insurer2_date)'), '<=', $insurer_day2]; - } else if ($insurer_month2 != '' && $insurer_day2 != '') { - $map_or1[] = [Db::raw('DATE_FORMAT(car_info_t.insurer1_date,"%m-%d")'), '<=', substr('0' . $insurer_month2, -2) . '-' . substr('0' . $insurer_day2, -2)]; - $map_or2[] = [Db::raw('DATE_FORMAT(car_info_t.insurer2_date,"%m-%d")'), '<=', substr('0' . $insurer_month2, -2) . '-' . substr('0' . $insurer_day2, -2)]; - } - if(count($map_or1) > 0){ - $map_or1 = array_merge([['car_info_t.insurer1_date', '<>', '']],$map_or1); - } - if(count($map_or2) > 0){ - $map_or2 = array_merge([['car_info_t.insurer1_date', '=', ''],['car_info_t.insurer2_date', '<>', '']],$map_or2); - } - $query = CarInfoT::where($where)->where(function ($query) use ($map_or1, $map_or2) { - if (count($map_or1) > 0 && count($map_or2) > 0){ - $query->whereOr([$map_or1, $map_or2]); - } - }); - $this->json_data['data'] = $query->count(); - return json($this->json_data); - } - - public function checkIsExistName($name,$type){ - if($name == ''){ - $this->json_data['code'] = 0; - $this->json_data['msg'] = '文件名为空,请检查'; - return json($this->json_data); - } - if($type == 'update'){ - $name = basename($name); - $name = str_replace(strrchr($name, '.'), '', $name); - } - $count = $this->model->where('queue', '=', $name) - ->whereOr('payload', 'like', '%' . str_replace(['\\', '"'], ['_', ''], json_encode($name)) . '%') - ->count(); - if ($count > 0) { - $this->json_data['msg'] = $type == 'upload' ? '当前文件已处理,确定继续?' : '当前任务名已存在,是否继续'; - }else { - $this->json_data['code'] = 2; - } - return json($this->json_data); - } - - private function downloadName(JobsT $job_info){ - $job_params = json_decode($job_info->payload,true)['data']['params']; - list(,$ext) = explode('.', $job_info->remark); - $downloadName = $job_params['export_date1'] . '-' . $job_params['export_date2']; - if($job_info->queue != 'default'){ - $downloadName = $job_info->queue; - }else if($job_params['export_type'] == 'repeat' && $job_params['export_table'] == 'repeat_frame_t'){ - $downloadName = '重复车架' . $downloadName; - } else if($job_params['export_type'] == 'repeat' && $job_params['export_table'] == 'peer_phone_t'){ - $downloadName = '重复电话' . $downloadName; - } - $downloadName .= '.' . $ext; - return $downloadName; - } - - private function checkUploadTpl($file, $type) - { - $path_info = pathinfo($file); - if ($type == 1 && $path_info['extension'] == 'csv') { - $title = \file\FileSystem::getFileBlockData($file,0,1); - $tpl_title = ['税号', '初登日期', '车主', '证件号', '电话号码', '车架号', '车牌号', '发动机号', '车型', '新车购置价']; - // $tpl_title = ['区域', '购车日期', '客户姓名', '证件号码', '联系方式', '车架号', '车牌号', '发动机号', '品牌型号', '新车购置价', '保险公司', '商业止保日期', '交强止保日期', '被保险人', '被保险人证件号']; - $title = explode(',', trim($title[0])); - if (count(array_diff($tpl_title, $title)) > 0) { - return false; - } - } else if ($type == 5 && $path_info['extension'] == 'xlsx') { - $spreadsheetReader = Excel::loadFile($file); - $sheet = $spreadsheetReader->getSheet(0); - $highestColumn = $sheet->getHighestColumn(); // e.g 'F' - $title = $sheet->rangeToArray("A1:{$highestColumn}1")[0]; - $tpl_title = ['车牌号','车主','品牌型号','发动机号','车架号','注册日期','上年承保公司','商业险到期日期','交强险到期日期','被保险人姓名','被保险人证件号']; - if (count(array_diff($tpl_title, $title)) > 0) { - return false; - } - } - return true; - } -} \ No newline at end of file diff --git a/app/view/task/index.html b/app/view/task/index.html index 507cf60..b4a3d14 100644 --- a/app/view/task/index.html +++ b/app/view/task/index.html @@ -56,22 +56,32 @@
-
+
- +
- +
+ +
+
+ +
+
-
+
+ +
+
@@ -174,9 +184,6 @@
-
-
-
{/block} {block name="script"} @@ -256,10 +263,7 @@ }); layui.form.on('radio(export_type)', function(data){ - if(['bmc','failed_bmc','none_bmc'].indexOf(data.value) != -1){ - $('#sub_export_type').hide(); - $('#sub_export_type').find(':input').attr('disabled',true); - }else if(data.value == 'success_bmc'){ + if(['bmc','failed_bmc','none_bmc','success_bmc'].indexOf(data.value) != -1){ $('#sub_export_type').hide(); $('#sub_export_type').find(':input').attr('disabled',true); }else { diff --git a/app/view/task/index.html.bak b/app/view/task/index.html.bak deleted file mode 100644 index 05c2ab8..0000000 --- a/app/view/task/index.html.bak +++ /dev/null @@ -1,444 +0,0 @@ -{extend name="public/layout" /} -{block name="header"} -{/block} -{block name="body"} -
-
-
-
- -
- - - - - -
-
-
- -
- - -
-
- -
- [下载车辆信息导入模板] -
- - - -
-
-
- -
- -
-
- -
-
-
- - -
-
-
-
-
-
-
-{/block} -{block name="script"} - - - - -{/block} \ No newline at end of file