Commit 4e7d35ad authored by gaodapeng's avatar gaodapeng

修改,优化,开发,自测

parent 023bc895
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
......@@ -63,7 +64,7 @@ dependencies {
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.github.GrenderG:Toasty:1.5.2'
annotationProcessor 'androidx.room:room-compiler:2.4.0'
kapt 'androidx.room:room-compiler:2.4.0'
implementation 'androidx.room:room-runtime:2.4.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation files('libs/Pay-Platform.jar')
......
......@@ -15,6 +15,7 @@ import com.elvishew.xlog.printer.Printer
import com.elvishew.xlog.printer.file.FilePrinter
import com.elvishew.xlog.printer.file.backup.NeverBackupStrategy
import com.elvishew.xlog.printer.file.naming.DateFileNameGenerator
import com.miya.fastcashier.utils.ContextUtils
import com.miya.fastcashier.utils.DateUtils
import com.miya.fastcashier.utils.DensityUtils
import com.miya.print.PrinterManager
......@@ -27,6 +28,7 @@ import java.util.*
class BaseApplication : MultiDexApplication() {
override fun onCreate() {
super.onCreate()
ContextUtils.init(this)
//打印机初始化
PrinterManager.getInstance().init(this)
//屏幕适配
......
package com.miya.fastcashier.beans
import android.text.TextUtils
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.miya.fastcashier.dao.DatabaseKeeper
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
/**
* 封装层的
*/
@Entity(tableName = "pay_data")
data class ViewPayOrderData(
@PrimaryKey//以订单号为主键
val orderNo: String,//订单号
val tradStatus: String? = null,
val tradeNo: String? = null,//交易流水号
val tradPrice: String? = null,//总价格
val chanelTag: String? = null,//支付方式
val buyerId: String? = null,//支付者id
val couponMessage: String? = null,
val chanelOrderTradeTime: String? = null,//支付时间
val miyaResponseTime: String? = null,//返回支付时间
val miyaOrderDesc: String? = null,
val vipShopTag: String? = null,
val buyerAccount: String? = null,//支付者账户
val memberCardNumber: String? = null,//会员卡
val platformName: String? = null,
val refundOrderNo: String? = null,//退款订单号
val oriOrderPrice: String? = null,//订单原价
val refundPrice: String? = null,//退款价格
val payQrCode: String? = null,//支付条码
) {
companion object {
fun create(payServiceResponse: PayServiceResponse): ViewPayOrderData {
return ViewPayOrderData(
orderNo = payServiceResponse.shopTradeNo,
tradStatus = payServiceResponse.tradStatus,
tradeNo = payServiceResponse.chanelSerialNumber,
tradPrice = payServiceResponse.tradPrice,
chanelTag = payServiceResponse.chanelTag,
buyerId = payServiceResponse.buyerId,
couponMessage = payServiceResponse.couponMessage,
chanelOrderTradeTime = payServiceResponse.chanelOrderTradeTime,
miyaResponseTime = payServiceResponse.miyaResponseTime,
miyaOrderDesc = payServiceResponse.miyaOrderDesc,
vipShopTag = payServiceResponse.vipShopTag,
buyerAccount = payServiceResponse.buyerAccount,
memberCardNumber = payServiceResponse.memberCardNumber,
platformName = payServiceResponse.platformName,
refundOrderNo = payServiceResponse.refundOrderNo,
oriOrderPrice = payServiceResponse.oriOrderPrice,
refundPrice = payServiceResponse.refundPrice,
payQrCode = payServiceResponse.payQrCode
)
}
fun insert(payServiceResponse: PayServiceResponse) {
if (TextUtils.isEmpty(payServiceResponse.shopTradeNo)) {
return
}
DatabaseKeeper.payDatabase.payDataDao()
.insertOne(create(payServiceResponse))
}
fun update() {
//TODO
}
}
}
\ No newline at end of file
package com.miya.fastcashier.dao
import androidx.room.*
import com.miya.fastcashier.beans.ViewPayOrderData
@Dao
interface PayDataDao {
@Query("SELECT COUNT(*) FROM pay_data")
fun getSize(): Int
@Query("SELECT * FROM pay_data")
fun getAll(): MutableList<ViewPayOrderData>
@Query("SELECT * FROM pay_data LIMIT 20")
fun getOnePage(): MutableList<ViewPayOrderData>
@Query("SELECT ceil(COUNT(*))/10")
fun getPageNum(): Int
@Insert
fun insertAll(list: MutableList<ViewPayOrderData>)
@Insert
fun insertOne(data: ViewPayOrderData)
@Update
fun updateOne(data: ViewPayOrderData)
@Delete
fun delete(user: ViewPayOrderData)
}
\ No newline at end of file
package com.miya.fastcashier.dao
import androidx.room.Database
import androidx.room.RoomDatabase
import com.miya.fastcashier.beans.ViewPayOrderData
import androidx.room.Room
import com.miya.fastcashier.utils.ContextUtils
@Database(entities = [ViewPayOrderData::class],exportSchema=false, version = 1)
abstract class PayDatabase : RoomDatabase() {
abstract fun payDataDao(): PayDataDao
}
class DatabaseKeeper {
companion object {
val payDatabase: PayDatabase by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
Room.databaseBuilder(
ContextUtils.getContext(),
PayDatabase::class.java, "pay_data"
).build()
}
}
}
......@@ -98,7 +98,6 @@ object PayRepository {
checkNotNull(signKey) { "refundByOrderNo signKey is null" }
checkNotNull(saasid) { "refundByOrderNo saasid is null" }
checkNotNull(marketid) { "refundByOrderNo marketid is null" }
checkNotNull(version) { "refundByOrderNo version is null" }
checkNotNull(oriOrderNo) { "refundByOrderNo oriOrderNo is null" }
checkNotNull(refundOrderNo) { "refundByOrderNo refundOrderNo is null" }
checkNotNull(refundPrice) { "refundByOrderNo refundPrice is null" }
......
......@@ -26,7 +26,7 @@ class PayActivity : BaseActivity() {
private lateinit var binding: ActivityPayBinding
private var scanGunKeyEventHelper: ScanGunKeyEventHelper = ScanGunKeyEventHelper()
private lateinit var price:String
private lateinit var price: String
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -39,32 +39,33 @@ class PayActivity : BaseActivity() {
val tvPayPrice = binding.tvPayPrice
tvPayPrice.text = "¥${price.toDouble()}"
viewModel.payResultLiveData.observe(this, { payResult ->
viewModel.payResultLiveData.observe(this, { payResult ->
dismissProgressDialog()
payResult.onFailure {
it.message?.let { it1 -> CenterToasty.error(this, it1,Toast.LENGTH_LONG).show() }
it.message?.let { it1 -> CenterToasty.error(this, it1, Toast.LENGTH_LONG).show() }
}
payResult.onSuccess {
payResult.onSuccess {
//自增流水
val today = DateUtils.format8(Date())
var no = kv.getInt(today,0);
kv.putInt(DateUtils.format8(Date()),++no)
var no = kv.getInt(today, 0);
kv.putInt(DateUtils.format8(Date()), ++no)
val intent = Intent()
intent.setClass(this@PayActivity, PayResultActivity::class.java)
intent.putExtra("payServiceResponse",it)
intent.putExtra("payServiceResponse", it)
startActivity(intent)
}
})
val tvBack = binding.tvBack
val ivBack = binding.ivBack
val tvBack = binding.clTitle.tvBack
val ivBack = binding.clTitle.ivBack
tvBack.clickWithTrigger { finish() }
ivBack.clickWithTrigger { finish() }
scanGunKeyEventHelper.setOnBarCodeCatchListener {
showProgressDialog("正在支付..")
viewModel.pay(price,it)
viewModel.pay(price, it)
}
}
......
......@@ -11,11 +11,12 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayoutMediator
import com.miya.fastcashier.R
import com.miya.fastcashier.beans.ViewPayOrderData
import com.miya.fastcashier.databinding.ActivitySearchOrderBinding
import com.miya.fastcashier.databinding.FragmentSearchOrderBinding
import com.miya.fastcashier.databinding.ItemSearchOrderListBinding
import com.miya.fastcashier.utils.MiYaPayPlantformPayWayEnum
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import com.miya.fastcashier.utils.clickWithTrigger
/**
* 查单列表
......@@ -27,17 +28,8 @@ class SearchOrderActivity : BaseActivity() {
super.onCreate(savedInstanceState)
binding = ActivitySearchOrderBinding.inflate(LayoutInflater.from(this))
setContentView(binding.root)
TabLayoutMediator(
binding.tlIndicator,
binding.vpPage
) { tab, position ->
when (position) {
0 -> tab.text = "微信"
1 -> tab.text = "支付宝"
else -> tab.text = ""
}
}.attach()
binding.title.tvBack.clickWithTrigger { finish() }
binding.title.ivBack.clickWithTrigger { finish() }
binding.vpPage.adapter = object : FragmentStateAdapter(this) {
override fun getItemCount(): Int {
......@@ -51,7 +43,22 @@ class SearchOrderActivity : BaseActivity() {
}
}
}
TabLayoutMediator(
binding.tlIndicator,
binding.vpPage
) { tab, position ->
when (position) {
0 -> tab.text = "微信"
1 -> tab.text = "支付宝"
else -> tab.text = ""
}
}.attach()
}
}
......@@ -96,7 +103,10 @@ class SearchOrderFragment(payType: MiYaPayPlantformPayWayEnum.MiyaPayType) : Fra
}
}
class SearchOrderListAdapter(val context: Context, private val list: MutableList<PayServiceResponse>) :
class SearchOrderListAdapter(
val context: Context,
private val list: MutableList<ViewPayOrderData>
) :
RecyclerView.Adapter<SearchOrderViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchOrderViewHolder {
return SearchOrderViewHolder(
......@@ -118,7 +128,7 @@ class SearchOrderListAdapter(val context: Context, private val list: MutableList
class SearchOrderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val binding: ItemSearchOrderListBinding = ItemSearchOrderListBinding.bind(itemView)
fun setData(data: PayServiceResponse) {
fun setData(data: ViewPayOrderData) {
binding.tvDate.text = data.chanelOrderTradeTime
}
......
package com.miya.fastcashier.utils;
import android.content.Context;
/**
* 描述: 上下文相关工具类
*/
public class ContextUtils {
private static Context context;
private ContextUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* 初始化工具类
*
* @param context 上下文
*/
public static void init(Context context) {
ContextUtils.context = context.getApplicationContext();
}
/**
* 获取ApplicationContext
*
* @return ApplicationContext
*/
public static Context getContext() {
if (context != null) return context;
throw new NullPointerException("u should init first");
}
}
\ No newline at end of file
......@@ -10,6 +10,8 @@ import com.blankj.utilcode.util.NumberUtils
import com.elvishew.xlog.XLog
import com.miya.fastcashier.beans.LoginRequest
import com.miya.fastcashier.beans.SelfCashierAccountInfo
import com.miya.fastcashier.beans.ViewPayOrderData
import com.miya.fastcashier.dao.DatabaseKeeper
import com.miya.fastcashier.repository.PayRepository
import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.service.LoginService
......@@ -34,18 +36,22 @@ class PayViewModel : ViewModel() {
fun refund(payServiceResponse: PayServiceResponse) {
XLog.d("开始退款:${JSON.toJSONString(payServiceResponse)}")
viewModelScope.launch(Dispatchers.IO) {
//保存到数据库
ViewPayOrderData.insert(payServiceResponse)
//退款
var refundPayServiceResponse: PayServiceResponse? = null
try {
val refundParams = HashMap<String, String>()
refundParams["oriOrderNo"] = payServiceResponse.shopTradeNo;
val refundOrderNo = AccountService.getAccountInfo()?.shopInfo?.saasid + System.currentTimeMillis()
refundParams["refundOrderNo"] = refundOrderNo;
refundParams["refundPrice"] = payServiceResponse.tradPrice;
val refundOrderNo =
AccountService.getAccountInfo()?.shopInfo?.saasid + System.currentTimeMillis()
refundParams["refundOrderNo"] = refundOrderNo
refundParams["refundPrice"] = payServiceResponse.tradPrice
refundPayServiceResponse = PayRepository.refundByOrderNo(refundParams)
refundLiveData.postValue(Result.success(refundPayServiceResponse))
XLog.d("退款成功:${JSON.toJSONString(refundPayServiceResponse)}")
} catch (e: Exception) {
e.printStackTrace()
XLog.d("退款异常:${e.message}")
refundLiveData.postValue(Result.failure(e))
}
......@@ -54,12 +60,16 @@ class PayViewModel : ViewModel() {
try {
XLog.d("开始退款打印")
AccountService.getAccountInfo()
?.let { refundPayServiceResponse?.let { it1 ->
PrintService.refundPrint(it,
it1
)
} }
}catch (e: Exception){
?.let {
refundPayServiceResponse?.let { it1 ->
PrintService.refundPrint(
it,
it1
)
}
}
} catch (e: Exception) {
e.printStackTrace()
XLog.d("退款打印异常${e.message}")
refundLiveData.postValue(Result.failure(e))
}
......@@ -84,12 +94,13 @@ class PayViewModel : ViewModel() {
try {
priceFen = price.toDouble().times(100).toInt().toString()
} catch (e: java.lang.Exception) {
e.printStackTrace()
payServiceResponseLiveData.value = Result.failure(ParamInvalidException("金额有误!"))
return
}
val sassid = AccountService.getAccountInfo()?.shopInfo?.saasid
val orderNo = sassid + System.currentTimeMillis()
val orderNo = sassid + System.currentTimeMillis()
XLog.d("主扫码订单号${orderNo}")
viewModelScope.launch(Dispatchers.IO) {
......@@ -98,6 +109,7 @@ class PayViewModel : ViewModel() {
payServiceResponseLiveData.postValue(Result.success(payServiceResponse))
XLog.d("生成付款码成功${JSON.toJSONString(payServiceResponse)}")
} catch (e: Exception) {
e.printStackTrace()
XLog.d("生成付款码异常${e.message}")
payServiceResponseLiveData.postValue(Result.failure(e))
}
......@@ -113,7 +125,8 @@ class PayViewModel : ViewModel() {
while (isActive) {
try {
XLog.d("支付查询订单号:${payServiceResponse.shopTradeNo}")
val payServiceResponseResult = PayRepository.payResultQuery(payServiceResponse.shopTradeNo)
val payServiceResponseResult =
PayRepository.payResultQuery(payServiceResponse.shopTradeNo)
XLog.d("支付查询结果:${JSON.toJSONString(payServiceResponseResult)}")
payResultLiveData.postValue(Result.success(payServiceResponseResult))
break
......@@ -132,13 +145,14 @@ class PayViewModel : ViewModel() {
* 订单查询,退款查询
*/
fun payResultQuery(orderNo: String) {
viewModelScope.launch(Dispatchers.IO){
viewModelScope.launch(Dispatchers.IO) {
try {
XLog.d("开始退款支付查询:${orderNo}")
val payServiceResponseResult = PayRepository.payResultQuery(orderNo)
XLog.d("退款支付查询成功:${JSON.toJSONString(payServiceResponseResult)}")
payResultLiveData.postValue(Result.success(payServiceResponseResult))
} catch (e: Exception) {
e.printStackTrace()
XLog.d("退款支付查询异常:${e.message}")
payResultLiveData.postValue(Result.failure(e))
}
......@@ -149,7 +163,7 @@ class PayViewModel : ViewModel() {
/**
* 金额是元,首先要转成分
*/
fun pay(price:String,payCode:String){
fun pay(price: String, payCode: String) {
XLog.d("被扫开始")
if (TextUtils.isEmpty(price)) {
payResultLiveData.value = Result.failure(ParamInvalidException("请输入金额!"))
......@@ -165,23 +179,27 @@ class PayViewModel : ViewModel() {
try {
priceFen = price.toDouble().times(100).toInt().toString()
} catch (e: java.lang.Exception) {
e.printStackTrace()
payResultLiveData.value = Result.failure(ParamInvalidException("金额有误!"))
return
}
val sassid = AccountService.getAccountInfo()?.shopInfo?.saasid
val orderNo = sassid + System.currentTimeMillis()
val orderNo = sassid + System.currentTimeMillis()
XLog.d("被扫参数 orderNo = ${orderNo} price = ${priceFen} payCode = ${payCode}" )
XLog.d("被扫参数 orderNo = $orderNo price = $priceFen payCode = $payCode")
viewModelScope.launch(Dispatchers.IO) {
try {
//0代表不分类别付款
val payServiceResponse = PayRepository.pay(orderNo, priceFen,payCode, "0")
val payServiceResponse = PayRepository.pay(orderNo, priceFen, payCode, "0")
//保存到数据库
ViewPayOrderData.insert(payServiceResponse)
payResultLiveData.postValue(Result.success(payServiceResponse))
XLog.d("被扫支付成功${JSON.toJSONString(payServiceResponse)}" )
XLog.d("被扫支付成功${JSON.toJSONString(payServiceResponse)}")
} catch (e: Exception) {
e.printStackTrace()
payResultLiveData.postValue(Result.failure(e))
XLog.d("被扫支付异常${JSON.toJSONString(e.message)}" )
XLog.d("被扫支付异常${JSON.toJSONString(e.message)}")
}
}
......
package com.miya.fastcashier.viewmodel
import androidx.lifecycle.MutableLiveData
import com.miya.fastcashier.beans.ViewPayOrderData
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
class SearchOrderViewModel {
val payDataLiveData: MutableLiveData<Result<List<ViewPayOrderData>>> = MutableLiveData()
fun getPayData() {
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:endColor="#D73672"
android:startColor="#FF4B8A" />
<corners android:radius="40px" />
</shape>
\ No newline at end of file
......@@ -8,7 +8,9 @@
android:focusableInTouchMode="true"
tools:context=".ui.PriceInputActivity">
<include layout="@layout/title" />
<include
android:id="@+id/clTitle"
layout="@layout/title" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
......
......@@ -4,19 +4,27 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/title" />
<include
android:id="@+id/title"
layout="@layout/title" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tlIndicator"
android:layout_width="match_parent"
android:layout_height="85dp"
android:layout_marginTop="87dp"
app:layout_constraintTop_toTopOf="parent" />
android:background="@color/white"
app:layout_constraintTop_toTopOf="parent"
app:tabIndicator="@drawable/app_search_indicator"
app:tabIndicatorFullWidth="false"
app:tabIndicatorHeight="5dp"
app:tabTextAppearance="@style/tabText" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/vpPage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/tlIndicator" />
......
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/vBg"
......@@ -42,4 +44,4 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/tvBack" />
</merge>
\ No newline at end of file
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<resources>
<style name="BottomInAndOutStyle">
<item name="android:windowEnterAnimation">@anim/in_bottom</item>
<item name="android:windowExitAnimation">@anim/out_bottom</item>
......@@ -15,4 +16,11 @@
<item name="DialogSpotColor">@android:color/white</item>
<item name="DialogSpotCount">4</item>
</style>
<style name="tabText">
<item name="android:textSize">32sp</item>
<item name="android:textColor">@color/color_333333</item>
<item name="android:lines">1</item>
<item name="android:maxLines">1</item>
</style>
</resources>
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