empty($post['date_type']) ? '1' : $post['date_type'],//时间类型 1、创建时间 2、赔款时间
'start_date' => empty($post['start_date']) ? '' : $post['start_date'],//开始时间
'end_date' => empty($post['end_date']) ? '' : $post['end_date'],//接收时间
'org_id' => empty($post['org_id']) ? '' : $post['org_id'],//渠道商ID
'more_search' => empty($post['more_search ']) ? '' : $post['more_search '],//更多查询条件
'current_page' => empty($post['current_page']) ? '1' : $post['current_page'],//当前页
'page_size' => empty($post['page_size']) ? '10' : $post['page_size'],//每页展示条数
);
$where = array();
$dateCol = $param['date_type'] == 1 ? 'a.create_time' : 'a.date';
if (!empty($param['start_date'])) {
$where[] = " {$dateCol} >= {$param['start_date']} ";
}
if (!empty($param['end_date'])) {
$where[] = " {$dateCol} < date_add('{$param['end_date']}', INTERVAL 1 day) ";
}
if (!empty($param['org_id'])) {
$where[] = " b.OUTSIDE_SALE_ORG_ID = {$param['org_id']} ";
}
if (!empty($param['more_search'])) {
$where[] = " (a.order_id like '%{$param['more_search']}%' or b.PARENT_PROD_NAME like '%{$param['more_search']}%') ";
}
$whereStr = ' ';
if (count($where)) {
$whereStr .= 'where ' . implode(' and ', $where);
}
if ($param['current_page'] == 1) {
$sql = "SELECT count(1) cnt
FROM order_finance_reparations a
JOIN order_main b ON a.order_id = b.ORDER_ID
JOIN base_supplier c ON b.OUTSIDE_SALE_ORG_ID = c.ID
{$whereStr}";
$getTotal = $this->query($sql);
$data['page']['total_count'] = $getTotal[0]['cnt'];
$data['page']['total_page'] = (string)ceil($getTotal[0]['cnt'] / $param['page_size']);
}
$sql2 = "SELECT a.date,a.order_id,c.SUPPLIER_NAME ,a.reparations,a.memo,a.create_time,a.memo_title,
ifnull((SELECT CONCAT(b.PARENT_PROD_NAME, '
',PROD_START_STATION_RES_NAME,' - ',PROD_END_STATION_RES_NAME) from order_main WHERE PARENT_ORDER_ID = b.ORDER_ID LIMIT 1),b.PARENT_PROD_NAME )'PARENT_PROD_NAME'
FROM order_finance_reparations a
JOIN order_main b ON a.order_id = b.ORDER_ID
JOIN base_supplier c ON b.OUTSIDE_SALE_ORG_ID = c.ID
{$whereStr}
ORDER BY a.create_time DESC
";
$list = $this->query($sql2);
$json['code'] = '0';
$json['info'] = '获取列表成功';
$data['order_list'] = $list;
$data['page']['page_size'] = $param['page_size'];
$data['page']['current_page'] = $param['current_page'];
$json['data'] = $data;
return $json;
}
//获取订单信息
public function getOrderInfo($post)
{
$order_id = empty($post['order_id']) ? '' : $post['order_id'];
if (!preg_match('/^[1-9][0-9]{0,10}$/', $order_id)) {
$json['code'] = '1';
$json['info'] = 'params error';
return $json;
}
$sql = "SELECT IFNULL(b.reparations,0) 'reparations',memo_id,
IFNULL(b.date,'') 'date',IFNULL(b.memo,'') 'memo',ifnull(b.memo_title, '') 'memo_title',
ifnull((SELECT CONCAT(a.PARENT_PROD_NAME, '
',PROD_START_STATION_RES_NAME,' - ',PROD_END_STATION_RES_NAME) from order_main WHERE PARENT_ORDER_ID = b.ORDER_ID LIMIT 1),a.PARENT_PROD_NAME )'PARENT_PROD_NAME'
from order_main a
LEFT JOIN order_finance_reparations b on a.order_id = b.order_id
where a.ORDER_ID= {$order_id}";
$info = $this->query($sql);
if (empty($info[0])) {
$json['code'] = '1';
$json['info'] = '订单不存在!请核对订单号!';
return $json;
}
$json['code'] = '0';
$json['info'] = '获取信息成功';
$json['data'] = $info[0];
return $json;
}
//设置订单的赔款
public function setReparations($post)
{
$param = array(
'order_id' => empty($post['order_id']) ? '' : $post['order_id'],//订单ID
'reparations' => empty($post['reparations']) ? 0 : $post['reparations'],//金额
'date' => empty($post['date']) ? '' : $post['date'],//赔款日期
'memo_id' => empty($post['memo_id'])?'':$post['memo_id'],//原因ID
'memo' => empty($post['memo']) ? '' : $post['memo'],//赔款备注 原因
'memo_title' => empty($post['memo_title']) ? '' : $post['memo_title'],//赔款备注 标题
);
if (!preg_match('/^[1-9][0-9]{0,10}$/', $param['order_id'])) {
$json['code'] = '1';
$json['info'] = '参数错误,请联系开发人员!001';
return $json;
}
if (empty($param['date']) || empty($param['reparations'])) {
$json['code'] = '1';
$json['info'] = '请选择赔款日期或填写赔款金额!';
return $json;
}
$sql = "REPLACE INTO `order_finance_reparations` ( `order_id`,`reparations`,`user_id`, `memo`,`date`,`create_time`,memo_title,memo_id)
VALUES
('{$param['order_id']}','{$param['reparations']}','{$_SESSION['user_id']}','{$param['memo']}'
,'{$param['date']}',now(),'{$param['memo_title']}','{$param['memo_id']}');";
$this->insert($sql);
$json['code'] = '0';
$json['info'] = '设置订单赔款金额成功!';
return $json;
}
//删除定的赔款记录
public function del($post)
{
$param = array(
'order_id' => empty($post['order_id']) ? '' : $post['order_id'],//订单ID
);
if (!preg_match('/^[1-9][0-9]{0,10}$/', $param['order_id'])) {
$json['code'] = '1';
$json['info'] = '参数错误,请联系开发人员!001';
return $json;
}
$sql = "DELETE from order_finance_reparations WHERE order_id = {$param['order_id']}";
$flag = $this->edit($sql);
if ($flag) {
$json['code'] = '0';
$json['info'] = '删除成功!';
return $json;
} else {
$json['code'] = '0';
$json['info'] = '删除失败!';
return $json;
}
}
/**
* 获取原因列表
*/
public function getMemoArr()
{
$return = array();
$return[] = array('memo_id'=>1,'memo_title'=>'漏单','memo'=>'漏单:目前的紧急处理方案是退客人现场购票的金额。');
$return[] = array('memo_id'=>2,'memo_title'=>'产品问题','memo'=>'产品问题:赔付方案需要与运营沟通。');
$return[] = array('memo_id'=>3,'memo_title'=>'客人问题','memo'=>'客人问题:包括未收到短信,未找到车,未接到司机电话等。');
$return[] = array('memo_id'=>4,'memo_title'=>'下错单','memo'=>'下错单:上下站点问题,时间问题。');
$return[] = array('memo_id'=>5,'memo_title'=>'汽车晚点','memo'=>'汽车晚点:');
$return[] = array('memo_id'=>6,'memo_title'=>'交通管制','memo'=>'交通管制:');
$return[] = array('memo_id'=>7,'memo_title'=>'并班原因','memo'=>'并班原因:');
$return[] = array('memo_id'=>8,'memo_title'=>'车队原因','memo'=>'车队原因:');
$return[] = array('memo_id'=>9,'memo_title'=>'司机原因','memo'=>'司机原因:');
$return[] = array('memo_id'=>10000,'memo_title'=>'其他','memo'=>'其他。');
$json['code'] = '0';
$json['info'] = '获取列表成功';
$json['list'] = $return;
return $json;
}
}