Commit 33556277 authored by mengcuiguang's avatar mengcuiguang

猜骰子逻辑优化

parent 0f35d85a
...@@ -3,10 +3,11 @@ package com.mints.goodmoney.mvp.model; ...@@ -3,10 +3,11 @@ package com.mints.goodmoney.mvp.model;
import java.io.Serializable; import java.io.Serializable;
/** /**
* 首页喝水 * 猜大小 结果
*/ */
public class ShaiziBean implements Serializable { public class ShaiziBean implements Serializable {
private int randomPoint; private int randomPoint;
private int success;//0-失败 1-成功
private Long diceId; private Long diceId;
public int getRandomPoint() { public int getRandomPoint() {
...@@ -16,4 +17,8 @@ public class ShaiziBean implements Serializable { ...@@ -16,4 +17,8 @@ public class ShaiziBean implements Serializable {
public Long getDiceId() { public Long getDiceId() {
return diceId; return diceId;
} }
public int getSuccess() {
return success;
}
} }
package com.mints.goodmoney.mvp.presenters; package com.mints.goodmoney.mvp.presenters;
import android.text.TextUtils;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.common.DeviceInfo;
import com.mints.goodmoney.manager.AppHttpManager; import com.mints.goodmoney.manager.AppHttpManager;
import com.mints.goodmoney.manager.ShumeiManager;
import com.mints.goodmoney.manager.TrackManager;
import com.mints.goodmoney.mvp.model.BaseResponse; import com.mints.goodmoney.mvp.model.BaseResponse;
import com.mints.goodmoney.mvp.model.ShaiziBean; import com.mints.goodmoney.mvp.model.ShaiziBean;
import com.mints.goodmoney.mvp.model.UserBean;
import com.mints.goodmoney.mvp.model.WaterBean; import com.mints.goodmoney.mvp.model.WaterBean;
import com.mints.goodmoney.mvp.views.ShaiziView; import com.mints.goodmoney.mvp.views.ShaiziView;
import com.mints.goodmoney.mvp.views.WaterView; import com.mints.goodmoney.mvp.views.WaterView;
import com.mints.goodmoney.utils.DeviceUuidFactory;
import com.mints.goodmoney.utils.rxutil.CommonRxTask;
import com.mints.goodmoney.utils.rxutil.RxjavaUtil;
import com.mints.library.net.neterror.BaseSubscriber; import com.mints.library.net.neterror.BaseSubscriber;
import com.mints.library.net.neterror.Throwable; import com.mints.library.net.neterror.Throwable;
import java.util.HashMap; import java.util.HashMap;
public class ShaiziPresenter extends BasePresenter<ShaiziView> { public class ShaiziPresenter extends BasePresenter<ShaiziView> {
public void getRollDiceMsg(double cash,boolean isBig) { public void getRollDiceMsg(double cash,boolean isBig) {
HashMap<String, Object> vo = new HashMap<>(); HashMap<String, Object> vo = new HashMap<>();
vo.put("cash", cash); vo.put("cash", cash);
...@@ -53,6 +64,78 @@ public class ShaiziPresenter extends BasePresenter<ShaiziView> { ...@@ -53,6 +64,78 @@ public class ShaiziPresenter extends BasePresenter<ShaiziView> {
} }
}); });
} }
public void saveTerminalInfo(double curCash,long diceid) {
view.showLoading("加载中...");
DeviceInfo deviceInfo = DeviceInfo.Companion.getInstance();
RxjavaUtil.executeRxTask(new CommonRxTask<String>("") {
@Override
public void doInIOThread() {
setT(deviceInfo.getAppInfoMap());
}
@Override
public void doInUIThread() {
HashMap<String, Object> vo = new HashMap<>();
String macAddress = deviceInfo.getMacAddress();
if (!TextUtils.isEmpty(macAddress)) {
String mac = macAddress.replace(":", "");
vo.put("mac", mac);
vo.put("mac1", macAddress);
}
vo.put("imei", deviceInfo.getIMEI());
vo.put("androidid", deviceInfo.getAndroidId(null));
vo.put("os", "android");
vo.put("shumeiId", ShumeiManager.getInstance().getShumeiDeviceId());
vo.put("model", deviceInfo.getNewModel());
vo.put("uuid", new DeviceUuidFactory().getDeviceUuid());
vo.put("osversion", deviceInfo.getOSVersion());
vo.put("appversion", deviceInfo.getVersionName());
vo.put("appPkgList", getT());
if (!TextUtils.isEmpty(MintsApplication.OAID)) {
vo.put("oaid", MintsApplication.OAID);
}
vo.put("ua", deviceInfo.getUserAgent());
TrackManager.getInstance().riskinfo();
AppHttpManager.getInstance(loanApplication)
.call(loanService.saveTerminalInfo(vo),
new BaseSubscriber<BaseResponse<UserBean>>() {
@Override
public void onCompleted() {
if (isLinkView()) return;
}
@Override
public void onError(Throwable e) {
if (isLinkView()) return;
view.hideLoading();
}
@Override
public void onNext(BaseResponse<UserBean> baseResponse) {
if (isLinkView()) return;
int code = baseResponse.getStatus();
String message = baseResponse.getMessage();
switch (code) {
case 200://成功
addShaiziresult(curCash,diceid);
break;
default:
view.showToast(message);
view.hideLoading();
break;
}
}
});
}
});
}
public void addShaiziresult(double cash,long diceid) { public void addShaiziresult(double cash,long diceid) {
HashMap<String, Object> vo = new HashMap<>(); HashMap<String, Object> vo = new HashMap<>();
vo.put("payChannel","WEIXIN"); vo.put("payChannel","WEIXIN");
...@@ -60,8 +143,8 @@ public class ShaiziPresenter extends BasePresenter<ShaiziView> { ...@@ -60,8 +143,8 @@ public class ShaiziPresenter extends BasePresenter<ShaiziView> {
vo.put("diceid",diceid); vo.put("diceid",diceid);
//添加摇色子ID //添加摇色子ID
AppHttpManager.getInstance(loanApplication) AppHttpManager.getInstance(loanApplication)
.call(loanService.addShaiziresult(vo), .call(loanService.addCashoutReq(vo),
new BaseSubscriber<BaseResponse<ShaiziBean>>() { new BaseSubscriber<BaseResponse<Object>>() {
@Override @Override
public void onCompleted() { public void onCompleted() {
if (isLinkView()) return; if (isLinkView()) return;
...@@ -78,7 +161,7 @@ public class ShaiziPresenter extends BasePresenter<ShaiziView> { ...@@ -78,7 +161,7 @@ public class ShaiziPresenter extends BasePresenter<ShaiziView> {
} }
@Override @Override
public void onNext(BaseResponse<ShaiziBean> baseResponse) { public void onNext(BaseResponse<Object> baseResponse) {
if (isLinkView()) return; if (isLinkView()) return;
int code = baseResponse.getStatus(); int code = baseResponse.getStatus();
......
...@@ -238,9 +238,6 @@ public interface LoanService { ...@@ -238,9 +238,6 @@ public interface LoanService {
@POST("api/addCashoutReq") @POST("api/addCashoutReq")
Observable<BaseResponse<Object>> addCashoutReq(@Body Map<String, Object> vo); Observable<BaseResponse<Object>> addCashoutReq(@Body Map<String, Object> vo);
@POST("api/addCashoutReq")
Observable<BaseResponse<ShaiziBean>> addShaiziresult(@Body Map<String, Object> vo);
/** /**
* 提现记录 * 提现记录
* *
...@@ -642,9 +639,19 @@ public interface LoanService { ...@@ -642,9 +639,19 @@ public interface LoanService {
@POST("api/vedioPlans") @POST("api/vedioPlans")
Observable<BaseResponse<UserTaskMsgBean>> vedioPlans(); Observable<BaseResponse<UserTaskMsgBean>> vedioPlans();
/**
* 提现界面 是否弹出猜大小
*
* @return
*/
@POST("api/queryCanRollDiceMsg") @POST("api/queryCanRollDiceMsg")
Observable<BaseResponse<JsonObject>> queryCanRollDiceMsg(@Body Map<String, Object> vo); Observable<BaseResponse<JsonObject>> queryCanRollDiceMsg(@Body Map<String, Object> vo);
/**
* 猜大小界面发起竞猜 成功-提现
*
* @return
*/
@POST("api/getRollDiceMsg") @POST("api/getRollDiceMsg")
Observable<BaseResponse<ShaiziBean>> getRollDiceMsg(@Body Map<String,Object> vo); Observable<BaseResponse<ShaiziBean>> getRollDiceMsg(@Body Map<String,Object> vo);
/** /**
......
...@@ -2,31 +2,28 @@ package com.mints.goodmoney.ui.activitys ...@@ -2,31 +2,28 @@ package com.mints.goodmoney.ui.activitys
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.view.View import android.view.View
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.cmcm.cmgame.utils.boolean
import com.mints.goodmoney.R import com.mints.goodmoney.R
import com.mints.goodmoney.common.Constant import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.mvp.model.ShaiziBean import com.mints.goodmoney.mvp.model.ShaiziBean
import com.mints.goodmoney.mvp.presenters.ShaiziPresenter import com.mints.goodmoney.mvp.presenters.ShaiziPresenter
import com.mints.goodmoney.mvp.views.ShaiziView
import com.mints.goodmoney.ui.activitys.base.BaseActivity import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.goodmoney.ui.widgets.dialog.DialogListener import com.mints.goodmoney.ui.widgets.dialog.DialogListener
import com.mints.goodmoney.ui.widgets.dialog.DialogUtils import com.mints.goodmoney.ui.widgets.dialog.DialogUtils
import com.mints.goodmoney.utils.LogUtil
import com.mints.goodmoney.utils.SpanUtils import com.mints.goodmoney.utils.SpanUtils
import com.mints.goodmoney.utils.ToastUtil
import kotlinx.android.synthetic.main.activity_shaizi.* import kotlinx.android.synthetic.main.activity_shaizi.*
import java.util.* import java.util.*
class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney.mvp.views.ShaiziView { class ShaiziActivity : BaseActivity(), View.OnClickListener, ShaiziView {
private var count: Int = 0 private var count: Int = 0
private var diceId: Long? = null private var diceId: Long? = null
private var moneys: Double = 0.0 private var moneys: Double = 0.0
private val shaiziPresenter by lazy { ShaiziPresenter() } private val shaiziPresenter by lazy { ShaiziPresenter() }
private var starttime: Long? = null private var starttime: Long? = null
private var flag: Int = 0 private var shaiziFlag: Int = 0 // 骰子大小 0-小 1-大
override fun getContentViewLayoutID() = R.layout.activity_shaizi override fun getContentViewLayoutID() = R.layout.activity_shaizi
...@@ -67,7 +64,7 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney ...@@ -67,7 +64,7 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney
R.id.btn_big -> { R.id.btn_big -> {
starttime = System.currentTimeMillis() starttime = System.currentTimeMillis()
shaiziPresenter.getRollDiceMsg(moneys, true) shaiziPresenter.getRollDiceMsg(moneys, true)
flag = 1 shaiziFlag = 1
} }
R.id.btn_small -> { R.id.btn_small -> {
starttime = System.currentTimeMillis() starttime = System.currentTimeMillis()
...@@ -76,7 +73,7 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney ...@@ -76,7 +73,7 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney
} }
} }
fun startShaizi(time: Long) { fun startShaizi(time: Long, success: Int) {
Glide.with(context).asGif().load(R.drawable.shaizi).into(iv_saizi); Glide.with(context).asGif().load(R.drawable.shaizi).into(iv_saizi);
val timer = Timer() val timer = Timer()
val task: TimerTask = object : TimerTask() { val task: TimerTask = object : TimerTask() {
...@@ -90,19 +87,25 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney ...@@ -90,19 +87,25 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney
5 -> Glide.with(context).load(R.mipmap.iv_tx_sz5).into(iv_saizi); 5 -> Glide.with(context).load(R.mipmap.iv_tx_sz5).into(iv_saizi);
6 -> Glide.with(context).load(R.mipmap.iv_tx_sz6).into(iv_saizi); 6 -> Glide.with(context).load(R.mipmap.iv_tx_sz6).into(iv_saizi);
} }
if (flag == 1) {
if (count >= 4) { if(success==1){
showresultDialog("恭喜您!", "本次开奖结果为大,您的收益已翻倍!", true) showresultDialog("恭喜您!", "本次开奖结果为小,您的收益已翻倍!",true)
} else {
showresultDialog("很遗憾!", "本次开奖结果为小,您未中奖,金币已收回。",false)
}
} else { } else {
if (count <= 3) { showresultDialog("很遗憾!", "本次开奖结果为大,您未中奖,金币已收回。",false)
showresultDialog("恭喜您!", "本次开奖结果为小,您的收益已翻倍!",true)
} else {
showresultDialog("很遗憾!", "本次开奖结果为大,您未中奖,金币已收回。",false)
}
} }
// if (shaiziFlag == 1) {
// if (count >= 4) {
// showresultDialog("恭喜您!", "本次开奖结果为大,您的收益已翻倍!", true)
// } else {
// showresultDialog("很遗憾!", "本次开奖结果为小,您未中奖,金币已收回。",false)
// }
// } else {
// if (count <= 3) {
// showresultDialog("恭喜您!", "本次开奖结果为小,您的收益已翻倍!",true)
// } else {
// showresultDialog("很遗憾!", "本次开奖结果为大,您未中奖,金币已收回。",false)
// }
// }
} }
} }
} }
...@@ -118,7 +121,7 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney ...@@ -118,7 +121,7 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney
when (v?.id) { when (v?.id) {
R.id.tv_know -> { R.id.tv_know -> {
//向服务器传递 提现金额 骰子Id //向服务器传递 提现金额 骰子Id
if (b) shaiziPresenter.addShaiziresult(moneys, diceId!!) if (b) shaiziPresenter.saveTerminalInfo(moneys, diceId!!)
dialog?.dismiss() dialog?.dismiss()
finish() finish()
} }
...@@ -150,7 +153,7 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney ...@@ -150,7 +153,7 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney
//设置按钮 不可点击 //设置按钮 不可点击
setButtonstatus(false) setButtonstatus(false)
//更改按钮 背景 //更改按钮 背景
if (flag == 1) { if (shaiziFlag == 1) {
btn_big.setBackgroundResource(R.mipmap.btn_tx_down) btn_big.setBackgroundResource(R.mipmap.btn_tx_down)
} else { } else {
btn_small.setBackgroundResource(R.mipmap.btn_tx_down_small) btn_small.setBackgroundResource(R.mipmap.btn_tx_down_small)
...@@ -160,7 +163,7 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney ...@@ -160,7 +163,7 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney
diceId = data.diceId diceId = data.diceId
//执行延时,旋转骰子,显示结果 //执行延时,旋转骰子,显示结果
startShaizi(System.currentTimeMillis()) startShaizi(System.currentTimeMillis(),data.success)
} }
/** /**
...@@ -178,7 +181,7 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney ...@@ -178,7 +181,7 @@ class ShaiziActivity : BaseActivity(), View.OnClickListener, com.mints.goodmoney
//设置按钮 可点击 //设置按钮 可点击
setButtonstatus(true) setButtonstatus(true)
//改变按钮 背景 //改变按钮 背景
if (flag == 1) { if (shaiziFlag == 1) {
btn_big.setBackgroundResource(R.mipmap.btn_tx_up) btn_big.setBackgroundResource(R.mipmap.btn_tx_up)
} else { } else {
btn_small.setBackgroundResource(R.mipmap.btn_tx_up_small) btn_small.setBackgroundResource(R.mipmap.btn_tx_up_small)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment