package com.sifang.modules.order.utils;

import com.google.common.collect.Maps;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public class OrderUtils {



    /**
     * 获取购买渠道信息
     *//*
    public static List<Record> getOrderMall(){
        return Db.find(" SELECT * FROM crm_order_mall a WHERE a.status='0' ORDER BY a.sort ASC ");
    }*/

    /**
     * 根据联系方式查询历史工单信息
    */
    public static List<Record> getOrderByMobile(String mobile){
        String sql = " SELECT a.*,DATE_FORMAT(a.repair_time,'%Y-%m-%d ') repairTime FROM crm_order a  WHERE (a.customer_mobile like '%"+mobile.trim()+"%' or a.customer_telephone like '%"+mobile+"%')  and a.status!='6'  ORDER BY a.create_time DESC ";

        return Db.find(sql);
    }

    /**
     * 根据联系方式查询历史工单信息
     */
    public static long getOrderCountByMobile(String mobile){
        String sql = " SELECT count(*) FROM crm_order a  WHERE (a.customer_mobile like '%"+mobile.trim()+"%' or a.customer_telephone like '%"+mobile+"%') and a.status!='6'  ";
        return Db.queryLong(sql);
    }

    /**
     * 获取服务措施
    */
    public static List<Record> getOrderServiceMeasures(String type){
        String sql = " SELECT a.* FROM crm_order_service_measures a  WHERE a.service_type=? ";
        return Db.find(sql,type);
    }

    /**
     * 厂家端获取添加的备件物流信息
    */
    public Record getFactoryFitting(String orderId){
        String sql =" SELECT logistics_names,logistics_number FROM crm_platform_fitting_apply WHERE order_id=? AND site_id IS NULL AND STATUS IN('2','3') LIMIT 1   ";
        return Db.findFirst(sql,orderId);
    }



}
