8.6
liugl
2020-08-06 a0b3598842d57f5dfb5736e8a4fff5a9d70191a5
app/src/main/java/com/okgoincar/base/MoneyBroadCastReceiver.kt
@@ -3,60 +3,115 @@
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.os.Handler
import android.os.Looper
import cn.sinata.rxnetty.netStatus.NetUtils
import cn.sinata.xldutils.netstatus.NetUtils
import cn.sinata.xldutils.utils.toast
import com.google.gson.Gson
import com.okgoincar.bean.LoginBean
import com.okgoincar.bean.LocalOrderBean
import com.okgoincar.netUtls.Api
import com.okgoincar.netUtls.callNet
import com.okgoincar.netUtls.getMapByAny
import com.okgoincar.netUtls.getToken
import com.okgoincar.slab.SlabLoginActivity
import com.okgoincar.slab.SlabMainActivity
import com.okgoincar.utils.Cache.CacheKey
import com.okgoincar.utils.Cache.CacheUtil
import io.netty.util.NetUtil
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.startActivity
import java.lang.Exception
class MoneyBroadCastReceiver : BroadcastReceiver() {
    override fun onReceive(contexts: Context?, intent: Intent?) {
        if (intent == null && contexts == null){
        if (intent == null && contexts == null) {
            toast("内容获取为空,广播接收消息错误")
            return
        }
        try {
            Handler(Looper.getMainLooper()).post {
                when(intent!!.action){
                    "wisdom.intent.action.ledLight" ->{
                        val isHeavy = intent!!.getBooleanExtra("isHeavy",true)
                        if (isHeavy){
                            callStatue(contexts!!,5) //代表让订单到进行中
                when (intent!!.action) {
                    "wisdom.intent.action.ledLight" -> {
                        val isHeavy = intent!!.getBooleanExtra("isHeavy", true)
                        if (isHeavy) {
                            callStatue(contexts!!, 5) //代表让订单到进行中
                        }
                    }
                    "wisdom.intent.action.priceDevice" -> {
                        var price = intent.getDoubleExtra("price",0.0) //计价器价格,单位为元
                        var mileage = intent.getDoubleExtra("mileage",0.0) //里程,单位为km
                        callOver(contexts!!,price)
                        var price = intent.getDoubleExtra("price", 0.0) //计价器价格,单位为元
                        var mileage = intent.getDoubleExtra("mileage", 0.0) //里程,单位为km
                        callOver(contexts!!, price)
                    }
                    ConnectivityManager.CONNECTIVITY_ACTION -> {
                        if (NetUtils.isNetworkConnected(MyApplication.getInstance())){
                            callErrorOrder()
                        }
                    }
                }
            }
        }catch (e:Exception){
        } catch (e: Exception) {
        }
    }
    private fun callStatue(contexts: Context,i: Int) {
        if (MyApplication.currentOrderId.isEmpty()){
    private fun callStatue(contexts: Context, i: Int) {
        if (MyApplication.currentOrderId.isEmpty()) {
            toast("没有进行中的订单,无法开始")
            return
        }
        if (CacheKey.getLocalOrderBean() == null) { //没有数据 代表没有异常订单
            if (NetUtils.isNetworkConnected(MyApplication.getInstance())) { //有网络直接处理
                callStartOrder(contexts, i)
            } else { //无网络 存本地
                var bean = LocalOrderBean()
                bean.orderId = MyApplication.currentOrderId
                bean.startTime = System.currentTimeMillis()
                CacheKey.saveLocalOrderBean(bean)
            }
        } else { //有数据存着,并且有网络上传异常订单 如果没有网络就不处理,这个肯定是线下的单
            if (NetUtils.isNetworkConnected(MyApplication.getInstance())){
                callErrorOrder()
            }
        }
    }
    private fun callOver(contexts: Context, travelFee: Double) {
        if (MyApplication.currentOrderId.isEmpty()) {
            toast("没有进行中的订单,无法结束")
            return
        }
        if (CacheKey.getLocalOrderBean() == null) { //没有数据 代表没有异常订单
            if (NetUtils.isNetworkConnected(MyApplication.getInstance())) { //有网络直接处理
                callEndOrder(contexts, travelFee)
            } else { //无网络 存本地
                var bean = LocalOrderBean()
                bean.orderId = MyApplication.currentOrderId
                bean.endTime = System.currentTimeMillis()
                CacheKey.saveLocalOrderBean(bean)
            }
        } else { //有数据存着,并且有网络上传异常订单 如果没有网络就不处理,这个肯定是线下的单
            if (NetUtils.isNetworkConnected(MyApplication.getInstance())){
                callErrorOrder()
            }else{
               val bean =  CacheKey.getLocalOrderBean()
                bean?.let {
                    bean.endTime = System.currentTimeMillis()
                    bean.money = travelFee
                    bean.orderId = MyApplication.currentOrderId
                    CacheKey.saveLocalOrderBean(bean)
                }
            }
        }
    }
    /***
     * 上传异常订单
     */
    private fun callErrorOrder() {
    }
    fun callStartOrder(contexts: Context, i: Int) {
        var map = getMapByAny()
        map["orderId"] = MyApplication.currentOrderId
        map["orderType"] = MyApplication.currentOrderType
@@ -68,11 +123,9 @@
        }
    }
    private fun callOver(contexts: Context,travelFee:Double){
        if (MyApplication.currentOrderId.isEmpty()){
            toast("没有进行中的订单,无法结束")
            return
        }
    fun callEndOrder(contexts: Context, travelFee: Double) {
        var map = getMapByAny()
        map["orderId"] = MyApplication.currentOrderId
        map["orderType"] = MyApplication.currentOrderType
@@ -80,10 +133,9 @@
        map["lat"] = MyApplication.getLocation().latitude
        map["lon"] = MyApplication.getLocation().longitude
        map["type"] = 1
        callNet(contexts,Api.confirmFees_,map){
        callNet(contexts, Api.confirmFees_, map) {
            EventBus.getDefault().post(BaseEvent(BaseEvent.SURE_MONEY))
        }
    }
}