master
zhaocheng 4 years ago
parent d84493c92d
commit 97a999d30c
  1. 498
      app/controller/Index.php.bak
  2. 15
      app/controller/Task.php
  3. 605
      app/controller/Task.php.bak
  4. 24
      app/view/task/index.html
  5. 444
      app/view/task/index.html.bak

@ -1,498 +0,0 @@
<?php
namespace app\controller;
use app\BaseController;
use app\model\CarInfoT;
use app\model\JobsT;
use app\model\PeerPhoneT;
use app\model\RepeatFrameT;
use library\Tree;
use think\facade\Db;
use think\facade\Filesystem;
use think\response\Json;
class Index extends BaseController
{
/**
* @var CarInfoT
*/
private $model;
public function initialize()
{
parent::initialize(); // TODO: Change the autogenerated stub
$this->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);
}
}

@ -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']??'';

@ -1,605 +0,0 @@
<?php
declare (strict_types = 1);
namespace app\controller;
use app\BaseController;
use app\model\CarInfoT;
use app\model\ExportLogT;
use app\model\JobsT;
use app\model\PeerPhoneT;
use app\model\RepeatFrameT;
use excel\Excel;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Filesystem;
use think\facade\Queue;
use think\Request;
use think\response\Json;
class Task extends BaseController
{
/**
* @var JobsT
*/
private $model;
public function initialize()
{
parent::initialize(); // TODO: Change the autogenerated stub
$this->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'] = '<a class="layui-btn" href="' . url('task/download', ['id' => $job_info->id]) . '">下载文件</a>';
}else if($job_info->type == 3 && PeerPhoneT::where(['source' => $job_info->id])->count() > 0){
$this->json_data['btns'] = '
<button type="button" class="layui-btn" onclick="task_create(2,' . $job_info->id . ')">导出</button>
<button type="button" class="layui-btn layui-btn-danger" onclick="task_create(6,' . $job_info->id . ')">清除重复电话</button>
';
}else if($job_info->type == 4 && RepeatFrameT::where(['source' => $job_info->id, 'is_delete' => 0])->count() > 0){
$this->json_data['btns'] = '
<button type="button" class="layui-btn" onclick="task_create(2,' . $job_info->id . ')">导出</button>
<button type="button" class="layui-btn layui-btn-danger" onclick="task_create(7,' . $job_info->id . ')">删除重复数据</button>
';
}
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;
}
}

@ -56,22 +56,32 @@
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label" style="width: 140px;">导出类型</label>
<div class="layui-input-inline" style="width: 780px;">
<div class="layui-input-inline" style="width: 580px;">
<input type="radio" lay-filter="export_type" name="export_type" value="bhx" class="layui-input" title="导出清洗" checked>
<input type="radio" lay-filter="export_type" name="export_type" value="failed" class="layui-input" title="导出清洗失败">
<input type="radio" lay-filter="export_type" name="export_type" value="bmc" class="layui-input" title="导出清洗成功至上传">
<input type="radio" lay-filter="export_type" name="export_type" value="success_bmc" class="layui-input" title="导出清洗成功">
<input type="radio" lay-filter="export_type" name="export_type" value="success_bmc" class="layui-input" title="导出清洗成功再次清洗">
<!-- <input type="radio" lay-filter="export_type" name="export_type" value="failed_bmc" class="layui-input" title="导出清洗失败至上传">
<input type="radio" lay-filter="export_type" name="export_type" value="none_bmc" class="layui-input" title="导出未处理至上传">
-->
</div>
</div>
<div class="layui-inline" id="sub_export_type">
<label class="layui-form-label" style="width: 100px;">导出字段</label>
<label class="layui-form-label" style="width: 60px;">导出字段</label>
<div class="layui-input-inline" style="width: 210px;">
<input type="checkbox" name="export_field[]" lay-filter="export_field" value="car_no" title="车牌号">
<input type="checkbox" name="export_field[]" lay-filter="export_field" value="car_frame_no" title="车架号" checked>
</div>
<label class="layui-form-label" style="width: 60px;">保险日期</label>
<div class="layui-inline">
<div class="layui-input-inline" style="width:auto;">
<input type="text" name="insurer_date1" class="layui-input export-date1" style="display: inline-block; width: 100px;">
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline" style="width:auto;">
<input type="text" name="insurer_date2" class="layui-input export-date2" style="display: inline-block; width: 100px;">
</div>
</div>
</div>
</div>
<div class="layui-form-item">
@ -174,9 +184,6 @@
</div>
</div>
</div>
<div class="layui-card-body layui-form">
<table class="layui-hide" id="task-info" lay-filter="task-info"></table>
</div>
</div>
{/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 {

@ -1,444 +0,0 @@
{extend name="public/layout" /}
{block name="header"}
{/block}
{block name="body"}
<div class="layui-card">
<div class="layui-card-header layui-card-header-auto layui-form">
<div id="task-model-add" class="layui-form">
<div class="layui-form-item active">
<label class="layui-form-label" style="width: 140px;">任务类型</label>
<div class="layui-input-block">
<input type="radio" lay-filter="task_type" name="task_type" value="1" title="导入处理" checked>
<input type="radio" lay-filter="task_type" name="task_type" value="2" title="导出处理">
<input type="radio" lay-filter="task_type" name="task_type" value="3" title="重复电话处理">
<input type="radio" lay-filter="task_type" name="task_type" value="4" title="重复车架处理">
<input type="radio" lay-filter="task_type" name="task_type" value="5" title="更新数据">
</div>
</div>
<div class="layui-form-item task-param active" id="task-import">
<label class="layui-form-label" style="width: 140px;">上传文件</label>
<div class="layui-input-inline" style="width: 405px;">
<input type="text" name="original_filename" id="original_filename" class="layui-input" readonly>
<input type="hidden" name="filename" id="filename" autocomplete="off" class="layui-input">
</div>
<div class="layui-input-inline" style="width: 200px;">
<button type="button" class="layui-btn" id="upload">
<i class="layui-icon">&#xe67c;</i>上传CSV文件
</button>
</div>
<a href="/static/tpl.csv" download="车辆信息导入模板.csv" style="color: #009688;">[下载车辆信息导入模板]</a>
</div>
<div class="task-param" id="task-export" style="display: none;">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label" style="width: 140px;">初登日期</label>
<div class="layui-input-inline" style="width: 200px;">
<input type="text" name="export_date1" class="layui-input export-date1">
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline" style="width: 200px;">
<input type="text" name="export_date2" class="layui-input export-date2">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="width: 140px;">商业保险日期</label>
<div class="layui-input-inline">
<input type="text" name="insurer_month1" class="layui-input" style="display: inline-block; width: 60px;">
<input type="text" name="insurer_day1" class="layui-input" style="display: inline-block; width: 60px;">
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline">
<input type="text" name="insurer_month2" class="layui-input" style="display: inline-block; width: 60px;">
<input type="text" name="insurer_day2" class="layui-input" style="display: inline-block; width: 60px;">
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label" style="width: 140px;">导出类型</label>
<div class="layui-input-inline" style="width: 780px;">
<input type="radio" lay-filter="export_type" name="export_type" value="bhx" class="layui-input" title="导出清洗" checked>
<input type="radio" lay-filter="export_type" name="export_type" value="failed" class="layui-input" title="导出清洗失败">
<input type="radio" lay-filter="export_type" name="export_type" value="bmc" class="layui-input" title="导出清洗成功至上传">
<input type="radio" lay-filter="export_type" name="export_type" value="failed_bmc" class="layui-input" title="导出清洗失败至上传">
<input type="radio" lay-filter="export_type" name="export_type" value="none_bmc" class="layui-input" title="导出未处理至上传">
</div>
</div>
<div class="layui-inline" id="sub_export_type">
<label class="layui-form-label" style="width: 100px;">导出字段</label>
<div class="layui-input-inline" style="width: 210px;">
<input type="checkbox" name="export_field[]" lay-filter="export_field" value="car_no" title="车牌号" checked>
<input type="checkbox" name="export_field[]" lay-filter="export_field" value="car_frame_no" title="车架号" checked>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label" style="width: 140px;">导出数量</label>
<div class="layui-input-inline">
<input type="text" name="export_limit" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="width: 100px;">导出文件名</label>
<div class="layui-input-inline" style="width: 450px;">
<input type="text" name="queue" id="queue-name" class="layui-input" style="display:inline-block; width: 325px;">
<button type="button" class="layui-btn" onclick="getExportName(event)">生成文件名</button>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">导出总计:</label>
<div class="layui-input-inline" style="width: 120px;">
<input type="text" name="num" id="count" class="layui-input" disabled>
</div>
<div class="layui-input-inline">
<button type="button" class="layui-btn" onclick="export_num(event)">获取总数</button>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label" style="width: 140px;">新车购置价</label>
<div class="layui-input-inline" style="width: auto;">
<input type="text" name="price1" class="layui-input" style="display: inline-block; width: 60px;">
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline" style="width: auto;">
<input type="text" name="price2" class="layui-input" style="display: inline-block; width: 60px;">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="width: 140px;">空电话检测</label>
<div class="layui-input-inline" style="width: 80px;">
<input type="checkbox" name="empty_phone_check" lay-skin="switch" lay-filter="empty_phone_check" value="yes" lay-text="开启|关闭" checked>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="width: 140px;">是否EXCEL</label>
<div class="layui-input-inline" style="width: 80px;">
<input type="checkbox" name="is_excel" lay-skin="switch" value="yes" lay-text="开启|关闭" checked>
</div>
</div>
</div>
</div>
<div class="task-param" id="task-peer-phone" style="display: none;">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label" style="width: 140px;">初登日期</label>
<div class="layui-input-inline" style="width: 200px;">
<input type="text" name="export_date1" class="layui-input export-date1">
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline" style="width: 200px;">
<input type="text" name="export_date2" class="layui-input export-date2">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="width: 140px;">个人电话重复次数</label>
<div class="layui-input-inline">
<input type="number" name="peer_phone_number" required lay-verify="required" class="layui-input">
</div>
</div>
</div>
</div>
<div class="task-param" id="task-repeat_frame" style="display: none;">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label" style="width: 140px;">初登日期</label>
<div class="layui-input-inline" style="width: 200px;">
<input type="text" name="export_date1" class="layui-input export-date1">
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline" style="width: 200px;">
<input type="text" name="export_date2" class="layui-input export-date2">
</div>
</div>
</div>
</div>
</div>
<div class="layui-form-item" style="margin:24px 0 -15px;">
<div class="layui-inline" style="float: left;position: relative;z-index: 999;">
<label class="layui-form-label" style="width: 65px;"></label>
<div class="layui-input-inline" style="width: 405px">
<input type="text" name="queue" id="queue" class="layui-input">
</div>
<div class="layui-input-inline" style="">
<button type="button" class="layui-btn" onclick="search(event)">查询</button>
</div>
</div>
<div class="layui-input-block layui-text-right">
<button type="button" class="layui-btn" onclick="task_add()">立即提交</button>
<button type="button" class="layui-btn layui-btn-danger" id="clear-btn">清空数据</button>
</div>
</div>
</div>
<div class="layui-card-body layui-form">
<table class="layui-hide" id="task-info" lay-filter="task-info"></table>
</div>
</div>
{/block}
{block name="script"}
<!--Core Javascript -->
<script type="text/html" id="table-bar">
{{#
var payload = JSON.parse(d.payload);
var export_date1 = payload['data']['params']['export_date1'];
var export_date2 = payload['data']['params']['export_date2'];
var ext = d.remark.split('.')[1];
}}
{{# if(d.type == 2){ }}
{{# if(payload['data']['params']['export_limit'] > 0){ }}
{{#
var arrParam = [];
var exportUrlParam = '';
exportUrlParam += 'export_date1=' + export_date1 + '&';
exportUrlParam += 'export_date2=' + export_date2 + '&';
exportUrlParam += 'insurer_month1=' + payload['data']['params']['insurer_month1'] + '&';
exportUrlParam += 'insurer_day1=' + payload['data']['params']['insurer_day1'] + '&';
exportUrlParam += 'insurer_month2=' + payload['data']['params']['insurer_month2'] + '&';
exportUrlParam += 'insurer_day2=' + payload['data']['params']['insurer_day2'] + '&';
exportUrlParam += 'is_export_' + payload['data']['params']['export_type'] + '=' + d.id;
}}
<a class="layui-btn layui-btn-xs" href="/index/index.html?{{exportUrlParam}}">查看</a>
{{# } }}
{{# if(d.download_times > 0){ }}
<buton class="layui-btn layui-btn-xs" onclick="layer.confirm('已下载过,是否继续',function(index){layer.close(index);window.open('{:url(\'task/download\')}?id={{d.id}}');window.location.reload();});">下载文件</buton>
{{# }else { }}
<buton class="layui-btn layui-btn-xs" onclick="window.open('{:url(\'task/download\')}?id={{d.id}}');window.location.reload();">下载文件</buton>
{{# } }}
{{# }else if(d.type == 3){ }}
<a class="layui-btn layui-btn-xs" href="/index/index.html?is_check_peer_phone={{d.id}}">查看</a>
{{# if(d.info_num > 0){ }}
<button type="button" class="layui-btn layui-btn-xs" onclick="task_create(2,{{d.id}})">导出</button>
<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" onclick="task_create(6,{{d.id}})">清除重复</button>
{{# } }}
{{# }else if(d.type == 4){ }}
<a class="layui-btn layui-btn-xs" href="/index/index.html?is_check_repeat_frame={{d.id}}">查看</a>
{{# if(d.info_num > 0){ }}
<button type="button" class="layui-btn layui-btn-xs" onclick="task_create(2,{{d.id}})">导出</button>
<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" onclick="task_create(7,{{d.id}})">删除重复</button>
{{# } }}
{{# }else if(d.type == 5){ }}
<a class="layui-btn layui-btn-xs" href="/index/index.html?is_update_bhx={{d.id}}">查看</a>
{{# }else if(d.type == 7){ }}
<a class="layui-btn layui-btn-xs" href="/index/index.html?is_delete_frame={{d.id}}">查看</a>
{{# }else if(d.type == 1){ }}
<a class="layui-btn layui-btn-xs" href="/index/index.html?source={{d.id}}">查看</a>
{{# } }}
</script>
<script type="text/html" id="process-tpl">
<div class="layui-progress layui-progress-big" lay-filter="process-{{d.id}}" lay-showPercent="yes">
<div class="layui-progress-bar layui-bg-green" lay-percent="{{d.process}}%"></div>
</div>
</script>
<script>
layui.form.on('radio(task_type)', function(data){
$('#task-model-add').find('.task-param').removeClass('active').hide();
switch (+data.value) {
case 1:
$('#task-import').addClass('active').show();
break;
case 2:
$('#task-export').addClass('active').show();
break;
case 3:
$('#task-peer-phone').addClass('active').show();
break;
case 4:
$('#task-repeat_frame').addClass('active').show();
break;
case 5:
$('#task-import').addClass('active').show();
break;
}
});
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 {
$('#sub_export_type').show();
$('#sub_export_type').find(':input').removeAttr('disabled');
}
});
var tableIns = layui.table.render({
id: 'taskInfo',
elem: '#task-info',
title:'车辆信息',
url: '{:url("/task/taskInfo/")}', //数据接口
page: true, //开启分页
limit: 20,
loading: true,
cols: [[ //表头
// {type: 'checkbox', fixed: 'left'},
{field: 'id', title: '序号', fixed: 'left', width: 100},
{field: 'type_txt', title: '任务名称', sort: true, width: 400},
{field: 'process', title: '处理进度', templet: '#process-tpl'},
{field: 'remark', title: '任务结果', sort: true},
{field: 'create_timestamp', title: '创建时间', sort: true, width: 200},
{field: 'status', title: '任务状态', sort: true, width: 100},
{field: 'download_times', title: '下载次数', sort: true, width: 100},
{fixed: 'right', width: 240, align:'center', toolbar: '#table-bar'}
]],
done: function (res, curr, count) {
layui.element.render();
var timer = setInterval(function(){
$.get('{:url("task/process")}', function (ret) {
if(!ret.data || ret.data.length == 0 ){
clearInterval(timer);
delete timer;
}else {
$.each(ret.data,function(i,d){
d.process = d.process > 100 ? 100 : d.process;
layui.element.progress('process-' + d.id, +d.process + '%');
if(d.process >= 100){
layui.table.reload('taskInfo');
}
})
}
});
},3000)
}
});
//监听行工具事件
layui.table.on('tool(task-info)', function(obj){ //注:tool 是工具条事件名,test 是 table 原始容器的属性 lay-filter="对应的值"
var data = obj.data, //获得当前行数据
layEvent = obj.event; //获得 lay-event 对应的值
if(layEvent === 'detail'){
layer.confirm('确定要清楚此项手机吗', function(index){
layer.close(index);
index = layer.load();
$.post('{:url("index/clearPhone")}', {id: data.id}, function (res) {
layer.close(index);
layer.msg(res.msg,function () {
layui.table.reload('taskInfo');
});
})
});
}
});
layui.upload.render({
elem: '#upload', //绑定元素
accept: 'file',
url: '{:url("task/upload")}', //上传接口
data: {
task_type: function () {
return $("input[name='task_type']:checked").val();
}
},
done: function (res) {
if (res.code == -1) {
$('#lock-screen').css('display', 'flex');
} else if (res.code == 0) {
layer.alert(res.msg);
} else if (res.code == 1) {
$('#original_filename').val(res.original_filename);
$('#filename').val(res.filename);
return true;
}
},
error: function (res) {
//请求异常回调
layer.alert(res.msg);
}
});
$(function(){
$('.export-date1,.export-date2').each(function (i, d) {
layui.laydate.render({
elem: d,
});
});
$('#clear-btn').on('click', function () {
layer.confirm('清空数据将不能恢复,确认清空附属表吗?', function(index){
layer.close(index);
index = layer.load();
//向服务端发送删除指令
$.post('{:url("task/clearSubTable/")}', function (ret) {
layer.close(index);
layer.msg(ret.msg, function () {
layui.table.reload('taskInfo');
});
});
});
});
});
function export_num(){
if($('[name="export_date1"]').val() == '' && $('[name="export_date1"]').val() == ''){
layer.msg('请先填写初登日期');
return false;
}
$.post('{:url("task/exportNum")}', $('#task-export').find(':input').serialize(), function (ret) {
layer.msg(ret['msg']);
$('#count').val(ret.data);
});
}
function task_create(type,id = 0){
$.post('{:url("task/save")}', {task_type: type,source_id: id}, function (ret) {
layer.msg(ret['msg'],function(){
layui.table.reload('taskInfo');
});
});
}
function task_add() {
var task_type = $('[name="task_type"]:checked').val();
if (task_type == 5 || task_type == 2) {
var name = task_type == 5 ? $('#original_filename').val() : $('#queue-name').val();
var type = task_type == 5 ? 'update' : 'export';
$.get('{:url("task/checkIsExistName")}?name=' + name + '&type=' + type, function (ret) {
if (ret.code == 1) {
layer.confirm(ret.msg, function (index) {
layer.close(index);
submitForm();
});
}else if (ret.code == 0) {
layer.alert(ret.msg);
}else if (ret.code == 2) {
submitForm();
}
});
}else {
submitForm();
}
}
function submitForm(){
$.post('{:url("task/save")}', $('#task-model-add').find('.active :input').serialize(), function (ret) {
if(ret.code == 0){
layer.alert(ret.msg);
}else {
layer.msg(ret['msg'],function(){
layui.table.reload('taskInfo');
});
}
});
}
function search(event){
tableIns.reload({
page: {
curr: 1 //重新从第 1 页开始
},
where: {queue: $('#queue').val()},
}, 'data');
}
function getExportName(event) {
var target = event.target;
$.get('{:url("task/exportName")}', $('#task-export').find(':input').serialize(), function (ret) {
if(ret.code == 0){
layer.alert(ret.msg);
}else {
$(target).prev('input[name="queue"]').val(ret.name);
}
});
}
</script>
{/block}
Loading…
Cancel
Save