|
|
|
<?php
|
|
|
|
namespace app\controller;
|
|
|
|
|
|
|
|
use app\BaseController;
|
|
|
|
use library\Tree;
|
|
|
|
use think\facade\Db;
|
|
|
|
use think\response\Json;
|
|
|
|
|
|
|
|
class Repeat extends BaseController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 显示资源列表
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return $this->fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Json
|
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
|
* @throws \think\db\exception\DbException
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
|
*/
|
|
|
|
public function data(){
|
|
|
|
$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);
|
|
|
|
$query = Db::table('repeat_data_t')->alias('car_info_t')->field('car_info_t.*')
|
|
|
|
->where($map)
|
|
|
|
->order('repeat_data_t.car_frame_no desc');
|
|
|
|
if (isset($params['is_delete_frame']) && $params['is_delete_frame'] > 0) {
|
|
|
|
$query = $query->where('repeat_data_t.repeat_id', '=', $params['is_delete_frame']);
|
|
|
|
}
|
|
|
|
$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();
|
|
|
|
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 = Db::table('repeat_data_t')->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 $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['tag']) && $params['tag'] != '') {
|
|
|
|
$tags = explode(',', str_replace(',', '', $params['tag']));
|
|
|
|
array_walk($tags, function (&$value) {
|
|
|
|
$value = '%' . $value . '%';
|
|
|
|
});
|
|
|
|
$map[] = ['car_info_t.tag', 'like', $tags];
|
|
|
|
}
|
|
|
|
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', '<', 0],
|
|
|
|
['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', '<', 0],
|
|
|
|
['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', '<', 0],
|
|
|
|
['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);
|
|
|
|
}
|
|
|
|
}
|