add 购买守护使用优惠卷

This commit is contained in:
zlzw 2023-03-31 17:26:28 +08:00
parent 0177a1314d
commit 9eed92302d
6 changed files with 142 additions and 48 deletions

View File

@ -19,7 +19,7 @@ public class DiscountsModel extends BaseModel {
public static final int TYPE_MONTH=7;//月守护 public static final int TYPE_MONTH=7;//月守护
public static final int TYPE_YEARS=8;//月守护 public static final int TYPE_YEARS=8;//月守护
@SerializedName("userCouponID") @SerializedName("userCouponId")
private int userCouponID; private int userCouponID;
@SerializedName("num") @SerializedName("num")
private int num; private int num;

View File

@ -3,6 +3,7 @@ package com.yunbao.common.utils;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.text.TextUtils; import android.text.TextUtils;
@ -13,6 +14,7 @@ import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.yunbao.common.BuildConfig;
import com.yunbao.common.CommonAppContext; import com.yunbao.common.CommonAppContext;
import com.yunbao.common.R; import com.yunbao.common.R;
@ -76,7 +78,16 @@ public class ToastUtil {
dialog.show(); dialog.show();
new Handler(Looper.getMainLooper()).postDelayed(dialog::dismiss, delayMillis); new Handler(Looper.getMainLooper()).postDelayed(dialog::dismiss, delayMillis);
} }
public static void showDebug(String s){
if(BuildConfig.DEBUG){
show(s);
}
}
public static void showDebug(int s){
if(BuildConfig.DEBUG){
show(s);
}
}
public static void show(String s) { public static void show(String s) {
if (TextUtils.isEmpty(s)) { if (TextUtils.isEmpty(s)) {
return; return;

View File

@ -1104,6 +1104,8 @@
<string name="replacement_reset_confirmed_hint">重置後將會清空當前心願單列表\n無論心願單是否完成</string> <string name="replacement_reset_confirmed_hint">重置後將會清空當前心願單列表\n無論心願單是否完成</string>
<string name="replacement_reset_confirmed_sure">確定重置</string> <string name="replacement_reset_confirmed_sure">確定重置</string>
<string name="replacement_reset_confirmed_cancel">返回列表</string> <string name="replacement_reset_confirmed_cancel">返回列表</string>
<string name="live_use_discount_content">您有一張%s是否使用使用後開通花費鉆石%s返還金豆%s</string>
<string name="live_use_discount_no">不使用</string>
<string name="live_use_discount_yes">使用</string>
</resources> </resources>

View File

@ -3,10 +3,12 @@ package com.yunbao.live.dialog;
import android.app.Dialog; import android.app.Dialog;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
@ -138,7 +140,9 @@ public class LiveGuardBuyDialogFragment extends AbsDialogFragment implements Vie
mBuyList = JSON.parseArray(obj.getString("list"), GuardBuyBean.class); mBuyList = JSON.parseArray(obj.getString("list"), GuardBuyBean.class);
try { try {
mCoinVal = obj.getLongValue("coin"); mCoinVal = obj.getLongValue("coin");
}catch (Exception e){e.printStackTrace();} } catch (Exception e) {
e.printStackTrace();
}
mCoin.setText(String.valueOf(mCoinVal)); mCoin.setText(String.valueOf(mCoinVal));
int buyListSize = mBuyList.size(); int buyListSize = mBuyList.size();
@ -321,7 +325,7 @@ public class LiveGuardBuyDialogFragment extends AbsDialogFragment implements Vie
if (mTargetBuyBean == null) { if (mTargetBuyBean == null) {
return; return;
} }
LiveHttpUtil.buyGuard(mLiveUid, mStream, mTargetBuyBean.getId(), new HttpCallback() { LiveHttpUtil.buyGuard(mLiveUid, mStream, mTargetBuyBean.getId(), -1, new HttpCallback() {
@Override @Override
public void onSuccess(int code, String msg, String[] info) { public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) { if (code == 0 && info.length > 0) {

View File

@ -2,6 +2,7 @@ package com.yunbao.live.dialog;
import android.app.Dialog; import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
@ -29,6 +30,7 @@ import com.yunbao.common.bean.UserBean;
import com.yunbao.common.dialog.AbsDialogFragment; import com.yunbao.common.dialog.AbsDialogFragment;
import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.RouteUtil; import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.ToastUtil;
@ -363,15 +365,8 @@ public class LiveNewGuardBuyDialogFragment extends AbsDialogFragment implements
if (mTargetBuyBean == null) { if (mTargetBuyBean == null) {
return; return;
} }
DialogUitl.showSimpleDialog(mContext,
String.format(WordUtil.getString(R.string.guard_buy_tip_3), mTargetBuyBean.getCoin(), mCoinName, mTargetBuyBean.getShopName()),
new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
doBuyGuard(); doBuyGuard();
}
});
} }
/** /**
@ -393,8 +388,84 @@ public class LiveNewGuardBuyDialogFragment extends AbsDialogFragment implements
discountType = DiscountsModel.TYPE_YEARS; discountType = DiscountsModel.TYPE_YEARS;
break; break;
} }
if (discountType == 0) {
buy();
} else {
LiveNetManager.get(mContext)
.getDiscountInfo(discountType, new com.yunbao.common.http.base.HttpCallback<List<DiscountsModel>>() {
@Override
public void onSuccess(List<DiscountsModel> data) {
if (data == null || data.isEmpty()) {
buy();
return;
}
DiscountsModel bean = null;
//寻找折扣力度最大的
for (DiscountsModel datum : data) {
if (bean == null) {
bean = datum;
} else if (datum.getDiscount() < bean.getDiscount()) {
bean = datum;
}
}
String str = String.format(WordUtil.getString(R.string.live_use_discount_content),
bean.getName(),
"###",//占位符
"###"
);
double coin = (mTargetBuyBean.getCoin() * (bean.getDiscount() / 10));
//千分位计算 12000 > 12,000
String coinStr = coin + "";
if (coin >= 1000) {
coinStr = ((int) coin / 1000) + "," + ((int) coin % 1000);
}
CharSequence content = Html.fromHtml(str.replace("###",
" <font color='#FF8E43'>" + coinStr + "</font> "));
final int cid = bean.getUserCouponID();
Dialog dialog = new DialogUitl.Builder(mContext)
.setHtmlCode(content)
.setView(R.layout.dialog_live_random_pk)
.setTitle(WordUtil.getString(R.string.dialog_tip))
.setCancelString(WordUtil.getString(R.string.live_use_discount_no))
.setConfrimString(WordUtil.getString(R.string.live_use_discount_yes))
.setClickCallback(new DialogUitl.SimpleCallback2() {
@Override
public void onCancelClick() {
buy();
}
LiveHttpUtil.buyGuard(mLiveUid, mStream, mTargetBuyBean.getId(), new HttpCallback() { @Override
public void onConfirmClick(Dialog dialog, String content) {
buy(cid);
}
}).build();
dialog.show();
}
@Override
public void onError(String error) {
}
});
}
}
private void buy() {
DialogUitl.showSimpleDialog(mContext,
String.format(WordUtil.getString(R.string.guard_buy_tip_3), mTargetBuyBean.getCoin(), mCoinName, mTargetBuyBean.getShopName()),
new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
buy(-1);
}
});
}
private void buy(int cid) {
LiveHttpUtil.buyGuard(mLiveUid, mStream, mTargetBuyBean.getId(), cid, new HttpCallback() {
@Override @Override
public void onSuccess(int code, String msg, String[] info) { public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) { if (code == 0 && info.length > 0) {

View File

@ -2,6 +2,7 @@ package com.yunbao.live.http;
import android.text.TextUtils; import android.text.TextUtils;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest; import com.lzy.okgo.request.PostRequest;
import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext; import com.yunbao.common.CommonAppContext;
@ -322,12 +323,16 @@ public class LiveHttpUtil {
/** /**
* 购买守护接口 * 购买守护接口
*/ */
public static void buyGuard(String liveUid, String stream, int guardId, HttpCallback callback) { public static void buyGuard(String liveUid, String stream, int guardId, int cid, HttpCallback callback) {
HttpClient.getInstance().get("Guard.buyGuard", LiveHttpConsts.BUY_GUARD) GetRequest<JsonBean> request = HttpClient.getInstance().get("Guard.buyGuard", LiveHttpConsts.BUY_GUARD)
.params("liveuid", liveUid) .params("liveuid", liveUid)
.params("stream", stream) .params("stream", stream)
.params("guardid", guardId) .params("guardid", guardId);
.execute(callback); if (cid != -1) {
request = request.params("userCouponId", cid);
}
request.execute(callback);
} }
@ -611,6 +616,7 @@ public class LiveHttpUtil {
/** /**
* 观众给主播送礼物 * 观众给主播送礼物
*
* @param isContactGift 是否为联系方式礼物 * @param isContactGift 是否为联系方式礼物
*/ */
public static void sendGift(String by, String liveUid, String stream, int giftId, String giftCount, int isContactGift, HttpCallback callback) { public static void sendGift(String by, String liveUid, String stream, int giftId, String giftCount, int isContactGift, HttpCallback callback) {