Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MiYaFastCashier
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiangjiantao
MiYaFastCashier
Commits
024adc72
Commit
024adc72
authored
Apr 06, 2022
by
zhaopengxiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
流水订单生成、存储、修改逻辑抽出来,由类进行统一管理,初始化清除昨日订单记录
parent
ae0d5536
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
164 additions
and
61 deletions
+164
-61
BaseApplication.kt
app/src/main/java/com/miya/fastcashier/BaseApplication.kt
+19
-0
PrintService.kt
...rc/main/java/com/miya/fastcashier/service/PrintService.kt
+19
-39
AliPayCodeActivity.kt
...c/main/java/com/miya/fastcashier/ui/AliPayCodeActivity.kt
+3
-5
MainActivity.kt
app/src/main/java/com/miya/fastcashier/ui/MainActivity.kt
+2
-0
PayActivity.kt
app/src/main/java/com/miya/fastcashier/ui/PayActivity.kt
+3
-6
SettingActivity.kt
app/src/main/java/com/miya/fastcashier/ui/SettingActivity.kt
+9
-6
WxPayCodeActivity.kt
...rc/main/java/com/miya/fastcashier/ui/WxPayCodeActivity.kt
+3
-5
DateUtils.java
app/src/main/java/com/miya/fastcashier/utils/DateUtils.java
+10
-0
OrderRecordManageKit.kt
...com/miya/fastcashier/utils/manage/OrderRecordManageKit.kt
+96
-0
No files found.
app/src/main/java/com/miya/fastcashier/BaseApplication.kt
View file @
024adc72
...
...
@@ -3,7 +3,9 @@ package com.miya.fastcashier
import
android.app.Activity
import
android.app.Application
import
android.content.Context
import
android.content.Intent
import
android.os.Bundle
import
android.view.Gravity
import
androidx.multidex.MultiDexApplication
import
com.elvishew.xlog.LogConfiguration
import
com.elvishew.xlog.LogLevel
...
...
@@ -15,9 +17,13 @@ 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.service.AccountService
import
com.miya.fastcashier.ui.LoginActivity
import
com.miya.fastcashier.ui.dialog.CommonDialog
import
com.miya.fastcashier.utils.ContextUtils
import
com.miya.fastcashier.utils.DateUtils
import
com.miya.fastcashier.utils.DensityUtils
import
com.miya.fastcashier.utils.manage.OrderRecordManageKit
import
com.miya.print.PrinterManager
import
com.sdy.miya.moblie.component.pay.core.utils.PayLogFileUtils
import
com.tencent.mmkv.MMKV
...
...
@@ -26,6 +32,12 @@ import java.util.*
class
BaseApplication
:
MultiDexApplication
()
{
companion
object
{
private
lateinit
var
instance
:
BaseApplication
fun
getApplication
()
=
instance
}
override
fun
onCreate
()
{
super
.
onCreate
()
ContextUtils
.
init
(
this
)
...
...
@@ -112,4 +124,11 @@ class BaseApplication : MultiDexApplication() {
})
}
fun
resetConfig
()
{
MMKV
.
defaultMMKV
().
clearAll
()
//清除本地订单昨天的流水信息
OrderRecordManageKit
.
clearOrderDataYeaterday
()
//清除本地个人信息
AccountService
.
clear
()
}
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/service/PrintService.kt
View file @
024adc72
package
com.miya.fastcashier.service
import
android.text.TextUtils
import
com.blankj.utilcode.util.LogUtils
import
com.esc.LogUlit
import
com.miya.fastcashier.beans.SelfCashierAccountInfo
import
com.miya.fastcashier.beans.ViewOrderStatisticsInfo
import
com.miya.fastcashier.utils.DateUtils
import
com.miya.fastcashier.utils.MiYaPayPlantformPayWayEnum
import
com.miya.fastcashier.utils.StringPriceFormat
import
com.miya.fastcashier.utils.isEmpty
import
com.miya.fastcashier.utils.manage.OrderRecordManageKit
import
com.miya.print.BuildConfig
import
com.miya.print.IPrinter
import
com.miya.print.PrinterManager
...
...
@@ -63,19 +66,20 @@ object PrintService {
this
.
payServiceResponse
=
payServiceResponse
//记录流水号,退款要用
setSerialNoByOrderNo
(
payServiceResponse
.
shopTradeNo
,
getSerialNumber
())
val
serialNumber
=
OrderRecordManageKit
.
getSerialNumber
()
OrderRecordManageKit
.
setSerialNoByOrderNo
(
payServiceResponse
.
shopTradeNo
,
serialNumber
)
val
printer
=
PrinterManager
.
getInstance
().
printer
printer
.
beginPrint
()
//检查打印机状态
printer
.
printerStatus
printer
.
set58mm
()
//
if (BuildConfig.DEBUG) {
// printCashier(printer, payServiceResponse, selfCashierAccountInfo
)
//
} else {
printCashier
(
printer
,
payServiceResponse
,
selfCashierAccountInfo
)
printCustomer
(
printer
,
payServiceResponse
,
selfCashierAccountInfo
)
//
}
if
(
BuildConfig
.
DEBUG
)
{
printCashier
(
printer
,
payServiceResponse
,
selfCashierAccountInfo
,
serialNumber
)
}
else
{
printCashier
(
printer
,
payServiceResponse
,
selfCashierAccountInfo
,
serialNumber
)
printCustomer
(
printer
,
payServiceResponse
,
selfCashierAccountInfo
,
serialNumber
)
}
printer
.
feedPaper
()
printer
.
endPrint
()
}
...
...
@@ -204,7 +208,8 @@ object PrintService {
private
fun
printCashier
(
printer
:
IPrinter
,
payServiceResponse
:
PayServiceResponse
,
selfCashierAccountInfo
:
SelfCashierAccountInfo
selfCashierAccountInfo
:
SelfCashierAccountInfo
,
serialNumber
:
String
)
{
val
shopInfo
=
selfCashierAccountInfo
.
shopInfo
...
...
@@ -223,7 +228,7 @@ object PrintService {
)
printer
.
printText
(
Page58MmPrintUtils
.
printDivideLineString
())
printer
.
printText
(
"日期/时间:${DateUtils.format18(Date())}"
)
printer
.
printText
(
"流水号:${
getSerialNumber()
}"
)
printer
.
printText
(
"流水号:${
serialNumber
}"
)
printer
.
printText
(
"商户订单号:"
)
printer
.
printText
(
payServiceResponse
.
shopTradeNo
)
printer
.
printText
(
"支付平台交易号:"
)
...
...
@@ -274,7 +279,8 @@ object PrintService {
private
fun
printCustomer
(
printer
:
IPrinter
,
payServiceResponse
:
PayServiceResponse
,
selfCashierAccountInfo
:
SelfCashierAccountInfo
selfCashierAccountInfo
:
SelfCashierAccountInfo
,
serialNumber
:
String
)
{
val
shopInfo
=
selfCashierAccountInfo
.
shopInfo
printer
.
printText
(
IPrinter
.
ALIGN_CENTER
,
3
,
shopInfo
.
storeName
,
true
)
...
...
@@ -294,7 +300,7 @@ object PrintService {
)
printer
.
printText
(
Page58MmPrintUtils
.
printDivideLineString
())
printer
.
printText
(
"日期/时间:${DateUtils.format18(Date())}"
)
printer
.
printText
(
"流水号:${
getSerialNumber()
}"
)
printer
.
printText
(
"流水号:${
serialNumber
}"
)
printer
.
printText
(
"商户订单号:"
)
printer
.
printText
(
payServiceResponse
.
shopTradeNo
)
printer
.
printText
(
"支付平台交易号:"
)
...
...
@@ -360,7 +366,7 @@ object PrintService {
)
printer
.
printText
(
Page58MmPrintUtils
.
printDivideLineString
())
printer
.
printText
(
"日期/时间:${DateUtils.format18(Date())}"
)
printer
.
printText
(
"流水号:${getSerialNoByOrderNo(payServiceResponse.shopTradeNo)}"
)
printer
.
printText
(
"流水号:${
OrderRecordManageKit.
getSerialNoByOrderNo(payServiceResponse.shopTradeNo)}"
)
printer
.
printText
(
"商户订单号:"
)
printer
.
printText
(
payServiceResponse
.
shopTradeNo
)
printer
.
printText
(
"支付平台交易号:"
)
...
...
@@ -433,7 +439,7 @@ object PrintService {
)
printer
.
printText
(
Page58MmPrintUtils
.
printDivideLineString
())
printer
.
printText
(
"日期/时间:${DateUtils.format18(Date())}"
)
printer
.
printText
(
"流水号:${getSerialNoByOrderNo(payServiceResponse.shopTradeNo)}"
)
printer
.
printText
(
"流水号:${
OrderRecordManageKit.
getSerialNoByOrderNo(payServiceResponse.shopTradeNo)}"
)
printer
.
printText
(
"商户订单号:"
)
printer
.
printText
(
payServiceResponse
.
refundOrderNo
)
printer
.
printText
(
"支付平台交易号:"
)
...
...
@@ -475,30 +481,4 @@ object PrintService {
}
printer
.
printText
(
"\n\n"
)
}
private
fun
getSerialNumber
():
String
{
val
today
=
DateUtils
.
format8
(
Date
())
val
kv
=
MMKV
.
defaultMMKV
()
val
no
=
kv
.
getInt
(
today
,
0
).
toString
()
var
listNo
=
no
for
(
index
in
1
..
(
5
-
no
.
length
))
{
listNo
=
"0$listNo"
}
return
listNo
;
}
/**
* 根据订单号获取流水号
* //todo 定期删除机制
*/
private
fun
getSerialNoByOrderNo
(
orderNo
:
String
):
String
{
return
MMKV
.
defaultMMKV
().
getString
(
orderNo
,
"00000"
).
toString
()
}
private
fun
setSerialNoByOrderNo
(
orderNo
:
String
,
serialNo
:
String
)
{
MMKV
.
defaultMMKV
().
putString
(
orderNo
,
serialNo
);
}
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/ui/AliPayCodeActivity.kt
View file @
024adc72
...
...
@@ -20,11 +20,13 @@ import com.miya.fastcashier.R.mipmap.ic_wxpay
import
com.miya.fastcashier.databinding.ActivityAliPayCodeBinding
import
com.miya.fastcashier.databinding.ActivityPayCodeBinding
import
com.miya.fastcashier.databinding.ActivityPriceInputBinding
import
com.miya.fastcashier.service.PrintService
import
com.miya.fastcashier.ui.dialog.PayChooseDialog
import
com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.DateUtils
import
com.miya.fastcashier.utils.StringPriceFormat
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.manage.OrderRecordManageKit
import
com.miya.fastcashier.viewmodel.PayViewModel
import
com.miya.print.utils.BitmapUtils
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
...
...
@@ -83,11 +85,7 @@ class AliPayCodeActivity : AppCompatActivity() {
result
.
getOrNull
().
also
{
it
?.
let
{
it1
->
//自增流水
val
today
=
DateUtils
.
format8
(
Date
())
var
no
=
kv
.
getInt
(
today
,
0
);
kv
.
putInt
(
DateUtils
.
format8
(
Date
()),++
no
)
OrderRecordManageKit
.
setSerialNumber
()
val
intent
=
Intent
()
intent
.
setClass
(
this
@AliPayCodeActivity
,
PayResultActivity
::
class
.
java
)
...
...
app/src/main/java/com/miya/fastcashier/ui/MainActivity.kt
View file @
024adc72
...
...
@@ -20,6 +20,7 @@ import com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.DateSelectHelper
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.manage.AccountPasswordManageKit
import
com.miya.fastcashier.utils.manage.OrderRecordManageKit
import
com.miya.fastcashier.viewmodel.MainViewModel
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import
com.tencent.mmkv.MMKV
...
...
@@ -101,6 +102,7 @@ class MainActivity : BaseActivity() {
initData
()
checkAccountPassword
()
OrderRecordManageKit
.
clearOrderDataYeaterday
()
}
private
fun
toRefund
()
{
...
...
app/src/main/java/com/miya/fastcashier/ui/PayActivity.kt
View file @
024adc72
...
...
@@ -6,10 +6,12 @@ import android.view.KeyEvent
import
android.widget.Toast
import
androidx.lifecycle.ViewModelProvider
import
com.miya.fastcashier.databinding.ActivityPayBinding
import
com.miya.fastcashier.service.PrintService
import
com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.DateUtils
import
com.miya.fastcashier.utils.ScanGunKeyEventHelper
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.manage.OrderRecordManageKit
import
com.miya.fastcashier.viewmodel.PayViewModel
import
com.tencent.mmkv.MMKV
import
java.util.*
...
...
@@ -24,7 +26,6 @@ class PayActivity : BaseActivity() {
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
val
kv
=
MMKV
.
defaultMMKV
()
binding
=
ActivityPayBinding
.
inflate
(
layoutInflater
)
setContentView
(
binding
.
root
)
viewModel
=
ViewModelProvider
(
this
).
get
(
PayViewModel
::
class
.
java
)
...
...
@@ -39,11 +40,7 @@ class PayActivity : BaseActivity() {
it
.
message
?.
let
{
it1
->
CenterToasty
.
error
(
this
,
it1
,
Toast
.
LENGTH_LONG
).
show
()
}
}
payResult
.
onSuccess
{
//自增流水
val
today
=
DateUtils
.
format8
(
Date
())
var
no
=
kv
.
getInt
(
today
,
0
);
kv
.
putInt
(
DateUtils
.
format8
(
Date
()),
++
no
)
OrderRecordManageKit
.
setSerialNumber
()
val
intent
=
Intent
()
intent
.
setClass
(
this
@PayActivity
,
PayResultActivity
::
class
.
java
)
...
...
app/src/main/java/com/miya/fastcashier/ui/SettingActivity.kt
View file @
024adc72
...
...
@@ -6,6 +6,7 @@ import androidx.appcompat.app.AppCompatActivity
import
android.os.Bundle
import
android.view.Gravity
import
com.blankj.utilcode.util.ToastUtils
import
com.miya.fastcashier.BaseApplication
import
com.miya.fastcashier.R
import
com.miya.fastcashier.databinding.ActivitySettingBinding
import
com.miya.fastcashier.service.AccountService
...
...
@@ -15,10 +16,10 @@ import com.tencent.mmkv.MMKV
class
SettingActivity
:
BaseActivity
()
{
private
lateinit
var
viewBinding
:
ActivitySettingBinding
private
lateinit
var
viewBinding
:
ActivitySettingBinding
private
var
alertDialog
:
CommonDialog
?
=
null
companion
object
{
companion
object
{
@JvmStatic
fun
start
(
context
:
Context
)
{
val
intent
=
Intent
(
context
,
SettingActivity
::
class
.
java
)
...
...
@@ -34,7 +35,7 @@ class SettingActivity : BaseActivity() {
init
()
}
private
fun
init
(){
private
fun
init
()
{
viewBinding
.
llBack
.
clickWithTrigger
{
finish
()
}
viewBinding
.
vLoginOut
.
clickWithTrigger
{
loginOut
()
}
viewBinding
.
vUpdatePassword
.
clickWithTrigger
{
ResetAuthorizePasswordActivity
.
start
(
this
)
}
...
...
@@ -57,9 +58,11 @@ class SettingActivity : BaseActivity() {
alertDialog
!!
.
dismiss
()
alertDialog
=
null
run
{
MMKV
.
defaultMMKV
().
clearAll
()
AccountService
.
clear
()
LoginActivity
.
start
(
this
@SettingActivity
,
Intent
.
FLAG_ACTIVITY_CLEAR_TASK
)
BaseApplication
.
getApplication
().
resetConfig
()
LoginActivity
.
start
(
this
@SettingActivity
,
Intent
.
FLAG_ACTIVITY_CLEAR_TASK
)
finish
()
}
}
...
...
app/src/main/java/com/miya/fastcashier/ui/WxPayCodeActivity.kt
View file @
024adc72
...
...
@@ -20,11 +20,13 @@ import com.miya.fastcashier.R.mipmap.ic_wxpay
import
com.miya.fastcashier.databinding.ActivityPayCodeBinding
import
com.miya.fastcashier.databinding.ActivityPriceInputBinding
import
com.miya.fastcashier.databinding.ActivityWxPayCodeBinding
import
com.miya.fastcashier.service.PrintService
import
com.miya.fastcashier.ui.dialog.PayChooseDialog
import
com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.DateUtils
import
com.miya.fastcashier.utils.StringPriceFormat
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.manage.OrderRecordManageKit
import
com.miya.fastcashier.viewmodel.PayViewModel
import
com.miya.print.utils.BitmapUtils
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
...
...
@@ -83,11 +85,7 @@ class WxPayCodeActivity : AppCompatActivity() {
result
.
getOrNull
().
also
{
it
?.
let
{
it1
->
//自增流水
val
today
=
DateUtils
.
format8
(
Date
())
var
no
=
kv
.
getInt
(
today
,
0
);
kv
.
putInt
(
DateUtils
.
format8
(
Date
()),++
no
)
OrderRecordManageKit
.
setSerialNumber
()
val
intent
=
Intent
()
intent
.
setClass
(
this
@WxPayCodeActivity
,
PayResultActivity
::
class
.
java
)
...
...
app/src/main/java/com/miya/fastcashier/utils/DateUtils.java
View file @
024adc72
...
...
@@ -153,6 +153,16 @@ public class DateUtils {
return
today
;
}
/**
* 得到前一天
*/
public
static
String
getYestedayFormat8
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
DATE
,
-
1
);
//得到前一天
Date
date
=
calendar
.
getTime
();
return
format8
(
date
);
}
/**
* 根据时间的字符串转成Date对象
...
...
app/src/main/java/com/miya/fastcashier/utils/manage/OrderRecordManageKit.kt
0 → 100644
View file @
024adc72
package
com.miya.fastcashier.utils.manage
import
android.util.Log
import
com.blankj.utilcode.util.LogUtils
import
com.miya.fastcashier.utils.DateUtils
import
com.tencent.mmkv.MMKV
import
java.util.*
/**
* 类描述:订单流水记录MMKV管理
*/
class
OrderRecordManageKit
{
companion
object
{
private
val
MMKV_ID
=
"fastcashier_order"
/**
* 根据本地记录生成流水单号
*/
fun
getSerialNumber
():
String
{
val
today
=
DateUtils
.
format8
(
Date
())
val
no
=
getOrderMMKV
().
getInt
(
today
,
0
).
toString
()
var
listNo
=
no
//真是流水单号需满足五位
for
(
index
in
1
..
(
5
-
no
.
length
))
{
listNo
=
"0$listNo"
}
return
listNo
;
}
/**
* 自增流水序列号,真实流水号需要getSerialNumber()进行拼凑
*/
fun
setSerialNumber
()
{
val
today
=
DateUtils
.
format8
(
Date
())
var
no
=
getOrderMMKV
().
getInt
(
today
,
0
);
getOrderMMKV
().
putInt
(
DateUtils
.
format8
(
Date
()),
++
no
)
}
/**
* 根据订单号获取流水号
*/
fun
getSerialNoByOrderNo
(
orderNo
:
String
):
String
{
return
getOrderMMKV
().
getString
(
orderNo
,
"00000"
).
toString
()
}
fun
setSerialNoByOrderNo
(
orderNo
:
String
,
serialNo
:
String
)
{
getOrderMMKV
().
putString
(
orderNo
,
serialNo
)
}
/**
* 清除前一天的本地订单流水记录
*/
fun
clearOrderDataYeaterday
()
{
val
yeaterdayRecordExist
:
Boolean
=
isYeaterdayOrderRecordExist
();
if
(
yeaterdayRecordExist
)
{
clearByTime
(
getYesterdayOrderMMKV
())
}
}
/**
* 清除全部订单记录
*/
fun
clearAll
()
{
clearByTime
(
getOrderMMKV
())
clearByTime
(
getYesterdayOrderMMKV
())
}
/**
* 清除指定日期记录
*/
fun
clearByTime
(
mmkv
:
MMKV
)
{
mmkv
.
clearAll
()
}
/**
* 是否存在前一天的本地订单记录
*/
private
fun
isYeaterdayOrderRecordExist
():
Boolean
{
val
actualSize
=
getYesterdayOrderMMKV
().
actualSize
()
LogUtils
.
e
(
"Yeaterday actualSize"
,
"$actualSize"
)
return
actualSize
>
0
}
private
fun
getOrderMMKV
():
MMKV
{
val
MMKV_ID_WITHDAY
=
MMKV_ID
.
plus
(
DateUtils
.
format8
(
Date
()))
return
MMKV
.
mmkvWithID
(
MMKV_ID_WITHDAY
)
}
private
fun
getYesterdayOrderMMKV
():
MMKV
{
val
yesteday
=
DateUtils
.
getYestedayFormat8
()
val
MMKV_ID_YESTERDAY
=
MMKV_ID
.
plus
(
yesteday
)
return
MMKV
.
mmkvWithID
(
MMKV_ID_YESTERDAY
)
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment