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
1a5458da
Commit
1a5458da
authored
Mar 16, 2022
by
gaodapeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提测功能
parent
1d4c88d5
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
122 additions
and
51 deletions
+122
-51
build.gradle
app/build.gradle
+2
-2
PrintService.kt
...rc/main/java/com/miya/fastcashier/service/PrintService.kt
+48
-31
MainActivity.kt
app/src/main/java/com/miya/fastcashier/ui/MainActivity.kt
+29
-1
SearchOrderActivity.kt
.../main/java/com/miya/fastcashier/ui/SearchOrderActivity.kt
+1
-0
BaseFunction.kt
app/src/main/java/com/miya/fastcashier/utils/BaseFunction.kt
+7
-1
DateSelectHelper.kt
.../main/java/com/miya/fastcashier/utils/DateSelectHelper.kt
+4
-0
LoginViewModel.kt
...ain/java/com/miya/fastcashier/viewmodel/LoginViewModel.kt
+19
-8
MainViewModel.kt
...main/java/com/miya/fastcashier/viewmodel/MainViewModel.kt
+9
-6
PayViewModel.kt
.../main/java/com/miya/fastcashier/viewmodel/PayViewModel.kt
+1
-1
item_search_order_list.xml
app/src/main/res/layout/item_search_order_list.xml
+2
-1
No files found.
app/build.gradle
View file @
1a5458da
...
...
@@ -21,8 +21,8 @@ android {
applicationId
"com.miya.fastcashier"
minSdkVersion
19
targetSdkVersion
31
versionCode
2
versionName
"2.
0
"
versionCode
2
1
versionName
"2.
1
"
multiDexEnabled
true
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
}
...
...
app/src/main/java/com/miya/fastcashier/service/PrintService.kt
View file @
1a5458da
...
...
@@ -15,6 +15,7 @@ import com.miya.print.utils.PrintLogger
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import
com.tencent.mmkv.MMKV
import
java.lang.Exception
import
java.lang.RuntimeException
import
java.util.*
object
PrintService
{
...
...
@@ -85,13 +86,14 @@ object PrintService {
fun
printStatisticInfo
(
viewOrderStatisticsInfo
:
ViewOrderStatisticsInfo
,
selfCashierAccountInfo
:
SelfCashierAccountInfo
,
isBalance
:
Boolean
)
{
val
printer
=
PrinterManager
.
getInstance
().
printer
printer
.
beginPrint
()
//检查打印机状态
printer
.
printerStatus
printer
.
set58mm
()
doPrintStatisticInfo
(
printer
,
viewOrderStatisticsInfo
,
selfCashierAccountInfo
)
doPrintStatisticInfo
(
printer
,
viewOrderStatisticsInfo
,
selfCashierAccountInfo
,
isBalance
)
printer
.
feedPaper
()
printer
.
endPrint
()
}
...
...
@@ -100,37 +102,31 @@ object PrintService {
private
fun
doPrintStatisticInfo
(
printer
:
IPrinter
,
orderStatisticsInfo
:
ViewOrderStatisticsInfo
,
accountInfo
:
SelfCashierAccountInfo
accountInfo
:
SelfCashierAccountInfo
,
isBalance
:
Boolean
)
{
printer
.
beginPrint
()
//[小票内容优化] 去除'欢迎光临'
printer
.
printText
(
accountInfo
.
shopInfo
?.
storeName
?:
""
)
if
(
accountInfo
.
shopInfo
==
null
)
{
throw
RuntimeException
(
"无商户配置数据"
)
}
val
shopInfo
=
accountInfo
.
shopInfo
printer
.
printText
(
IPrinter
.
ALIGN_CENTER
,
3
,
accountInfo
.
shopInfo
?.
storeName
?:
""
,
true
)
if
(
isBalance
)
{
printer
.
printText
(
IPrinter
.
ALIGN_CENTER
,
3
,
"结算总计单"
,
true
)
}
else
{
printer
.
printText
(
IPrinter
.
ALIGN_CENTER
,
3
,
"交易汇总表"
,
true
)
}
printer
.
setAlign
(
IPrinter
.
ALIGN_LEFT
)
printer
.
printText
(
"商户名称:converse"
)
printer
.
printText
(
"商户编号:${shopInfo.saasid}"
)
printer
.
printText
(
"终端编号:${shopInfo.posId}"
)
printer
.
printText
(
"门店编号:${shopInfo.storeId}"
)
//统计时间
printer
.
printText
(
0
,
0
,
"开始时间:"
+
orderStatisticsInfo
.
beginDate
,
true
)
printer
.
printText
(
0
,
0
,
"结束时间:"
+
orderStatisticsInfo
.
endDate
,
true
)
// //打印分割线-居左
printer
.
printText
(
0
,
0
,
Page58MmPrintUtils
.
printDivideLineString
(),
true
)
// //打印门店号、收银机号、收银员号在一行打印显示
if
(!
TextUtils
.
isEmpty
(
accountInfo
.
shopInfo
?.
operatorId
)
)
{
printer
.
printText
(
Page58MmPrintUtils
.
printTwoData
(
"门店号:"
+
accountInfo
.
shopInfo
?.
storeId
.
toString
()
+
" 收银机号:"
+
accountInfo
.
shopInfo
?.
posId
,
"收银员号:"
+
accountInfo
.
shopInfo
?.
operatorId
)
)
}
else
{
printer
.
printText
(
Page58MmPrintUtils
.
printTwoData
(
"门店号:"
+
accountInfo
.
shopInfo
?.
storeId
,
"收银机号:"
+
accountInfo
.
shopInfo
?.
posId
)
)
}
val
totalStatistics
:
ViewOrderStatisticsInfo
.
StatisticBean
?
=
orderStatisticsInfo
.
totalStatistic
if
(
totalStatistics
!=
null
)
{
...
...
@@ -148,9 +144,10 @@ object PrintService {
)
)
}
val
typedStatisticList
:
List
<
ViewOrderStatisticsInfo
.
StatisticBean
>
=
orderStatisticsInfo
.
typeStatistic
if
(!
isEmpty
(
typedStatisticList
))
{
if
(!
isEmpty
(
orderStatisticsInfo
.
typeStatistic
))
{
val
typedStatisticList
:
List
<
ViewOrderStatisticsInfo
.
StatisticBean
>
=
orderStatisticsInfo
.
typeStatistic
var
statisticBean
:
ViewOrderStatisticsInfo
.
StatisticBean
for
(
i
in
typedStatisticList
.
indices
)
{
if
(
typedStatisticList
[
i
]
==
null
)
{
...
...
@@ -176,8 +173,28 @@ object PrintService {
""
+
StringPriceFormat
.
transStringPriceToDecimalString
(
statisticBean
.
tradeTotalAmount
.
toString
())
)
)
if
(
statisticBean
.
refundCount
>
0
)
{
printer
.
printText
(
Page58MmPrintUtils
.
printTwoData
(
"退款笔数"
,
""
+
statisticBean
.
refundCount
)
)
}
if
(
statisticBean
.
refundTotalAmount
>
0
)
{
printer
.
printText
(
Page58MmPrintUtils
.
printTwoData
(
"退款金额"
,
""
+
StringPriceFormat
.
transStringPriceToDecimalString
(
statisticBean
.
refundTotalAmount
.
toString
())
)
)
}
}
}
printer
.
printText
(
"\n\n"
)
}
...
...
@@ -477,7 +494,7 @@ object PrintService {
* //todo 定期删除机制
*/
private
fun
getSerialNoByOrderNo
(
orderNo
:
String
):
String
{
return
MMKV
.
defaultMMKV
().
getString
(
orderNo
,
"00000"
).
toString
()
;
return
MMKV
.
defaultMMKV
().
getString
(
orderNo
,
"00000"
).
toString
()
}
private
fun
setSerialNoByOrderNo
(
orderNo
:
String
,
serialNo
:
String
)
{
...
...
app/src/main/java/com/miya/fastcashier/ui/MainActivity.kt
View file @
1a5458da
...
...
@@ -74,12 +74,31 @@ class MainActivity : BaseActivity() {
binding
.
llStatistic
.
clickWithTrigger
{
if
(
dateSelectHelper
==
null
)
{
dateSelectHelper
=
DateSelectHelper
(
this
@MainActivity
)
{
viewModel
.
orderStatistics
(
it
,
Date
()
)
viewModel
.
orderStatistics
(
it
,
Date
(),
false
)
}
}
dateSelectHelper
!!
.
showDatePicker
()
}
binding
.
llBalance
.
clickWithTrigger
{
//上次记录的时间,或者当天0点
val
timeMillis
=
MMKV
.
defaultMMKV
().
getLong
(
"balanceDate"
,
0L
)
if
(
timeMillis
>
0L
&&
timeMillis
<=
System
.
currentTimeMillis
())
{
viewModel
.
orderStatistics
(
Date
(
timeMillis
),
Date
(),
true
)
}
else
{
val
startDate
=
Calendar
.
getInstance
()
startDate
.
set
(
startDate
.
get
(
Calendar
.
YEAR
),
startDate
.
get
(
Calendar
.
MONTH
),
startDate
.
get
(
Calendar
.
DAY_OF_MONTH
),
0
,
0
,
0
)
viewModel
.
orderStatistics
(
startDate
.
time
,
Date
(),
true
)
}
}
initData
()
}
...
...
@@ -93,6 +112,15 @@ class MainActivity : BaseActivity() {
CenterToasty
.
error
(
this
@MainActivity
,
e
.
message
?:
""
).
show
()
}
})
viewModel
.
balanceLiveData
.
observe
(
this
,
{
result
->
result
.
onSuccess
{
MMKV
.
defaultMMKV
().
putLong
(
"balanceDate"
,
it
)
}
result
.
onFailure
{
e
->
CenterToasty
.
error
(
this
@MainActivity
,
e
.
message
?:
""
).
show
()
}
})
}
...
...
app/src/main/java/com/miya/fastcashier/ui/SearchOrderActivity.kt
View file @
1a5458da
...
...
@@ -208,6 +208,7 @@ class SearchOrderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
binding
.
tvRefundTag
.
visibility
=
View
.
GONE
binding
.
tvPrice
.
text
=
"¥"
+
StringPriceFormat
.
transStringPriceToDecimalString
(
data
.
tradPrice
)
binding
.
tvOrderNo
.
text
=
data
.
orderNo
}
}
...
...
app/src/main/java/com/miya/fastcashier/utils/BaseFunction.kt
View file @
1a5458da
package
com.miya.fastcashier.utils
import
android.content.Context
import
android.text.TextUtils
fun
isEmpty
(
s
:
String
?):
Boolean
{
...
...
@@ -7,5 +8,10 @@ fun isEmpty(s: String?): Boolean {
}
fun
isEmpty
(
list
:
List
<
Any
>?):
Boolean
{
return
list
!=
null
&&
list
.
isNotEmpty
()
return
list
==
null
||
list
.
isEmpty
()
}
fun
sp2px
(
context
:
Context
,
spValue
:
Float
):
Int
{
val
fontScale
:
Float
=
context
.
resources
.
displayMetrics
.
scaledDensity
return
(
spValue
*
fontScale
+
0.5f
).
toInt
()
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/utils/DateSelectHelper.kt
View file @
1a5458da
...
...
@@ -40,6 +40,7 @@ class DateSelectHelper(val context: Context, val callback: (Date) -> Unit) {
calendar
.
get
(
Calendar
.
MONTH
),
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
),
0
,
0
,
0
)
endDate
.
set
(
...
...
@@ -55,6 +56,9 @@ class DateSelectHelper(val context: Context, val callback: (Date) -> Unit) {
.
setTitleText
(
"请选择开始时间"
)
.
setType
(
booleanArrayOf
(
false
,
false
,
false
,
true
,
true
,
false
))
.
setDate
(
startDate
)
.
setContentTextSize
(
30
)
.
setTitleSize
(
30
)
.
setSubCalSize
(
30
)
.
setRangDate
(
startDate
,
endDate
)
.
build
()
}
...
...
app/src/main/java/com/miya/fastcashier/viewmodel/LoginViewModel.kt
View file @
1a5458da
...
...
@@ -11,6 +11,8 @@ import com.miya.fastcashier.beans.SelfCashierAccountInfo
import
com.miya.fastcashier.net.BaseResult
import
com.miya.fastcashier.service.LoginService
import
com.miya.fastcashier.beans.LoginFormState
import
com.tencent.mmkv.MMKV
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
java.lang.RuntimeException
...
...
@@ -21,21 +23,30 @@ class LoginViewModel : ViewModel() {
val
loginFormState
:
LiveData
<
LoginFormState
>
=
_loginForm
fun
login
(
userName
:
String
,
passWord
:
String
)
{
viewModelScope
.
launch
{
val
result
=
try
{
Result
.
success
(
errorHandle
(
LoginService
.
getApi
().
login
(
LoginRequest
(
userName
,
passWord
,
""
))))
fun
login
(
userName
:
String
,
passWord
:
String
)
{
viewModelScope
.
launch
(
Dispatchers
.
IO
)
{
try
{
val
result
=
Result
.
success
(
errorHandle
(
LoginService
.
getApi
().
login
(
LoginRequest
(
userName
,
passWord
,
""
)))
)
//MMKV记录结算时间
val
balanceDate
=
MMKV
.
defaultMMKV
().
getLong
(
"balanceDate"
,
0L
)
if
(
balanceDate
<=
0L
)
{
//todo 改成服务器时间
MMKV
.
defaultMMKV
().
putLong
(
"balanceDate"
,
System
.
currentTimeMillis
())
}
loginLiveData
.
postValue
(
result
)
}
catch
(
e
:
Exception
)
{
Result
.
failure
(
e
)
loginLiveData
.
postValue
(
Result
.
failure
(
e
)
)
}
// 注意这里是主线程,直接用setValue()即可
loginLiveData
.
value
=
result
}
}
//TODO 待优化
private
fun
<
T
>
errorHandle
(
result
:
BaseResult
<
T
>):
T
{
if
(
result
.
code
!=
"200"
)
{
if
(
result
.
code
!=
"200"
)
{
throw
RuntimeException
(
result
.
msg
)
}
return
result
.
data
;
...
...
app/src/main/java/com/miya/fastcashier/viewmodel/MainViewModel.kt
View file @
1a5458da
...
...
@@ -23,7 +23,8 @@ class MainViewModel : ViewModel() {
val
refundLiveData
:
MutableLiveData
<
Result
<
PayRepository
>>
=
MutableLiveData
()
val
statisticsLiveData
:
MutableLiveData
<
Result
<
Boolean
>>
=
MutableLiveData
()
val
statisticsLiveData
:
MutableLiveData
<
Result
<
Long
>>
=
MutableLiveData
()
val
balanceLiveData
:
MutableLiveData
<
Result
<
Long
>>
=
MutableLiveData
()
/**
* oriOrderNo 原订单号
...
...
@@ -55,10 +56,12 @@ class MainViewModel : ViewModel() {
/**
* 订单统计
*/
fun
orderStatistics
(
beginDate
:
Date
,
endDate
:
Date
)
{
fun
orderStatistics
(
beginDate
:
Date
,
endDate
:
Date
,
isBalance
:
Boolean
)
{
val
accountInfo
=
AccountService
.
getAccountInfo
()
val
liveData
:
MutableLiveData
<
Result
<
Long
>>
=
if
(
isBalance
)
balanceLiveData
else
statisticsLiveData
if
(
accountInfo
==
null
)
{
statisticsL
iveData
.
value
=
Result
.
failure
(
RuntimeException
(
"账户数据为空"
))
l
iveData
.
value
=
Result
.
failure
(
RuntimeException
(
"账户数据为空"
))
return
}
val
accountInfoFinal
=
accountInfo
!!
...
...
@@ -71,11 +74,11 @@ class MainViewModel : ViewModel() {
DateUtils
.
format18
(
beginDate
),
DateUtils
.
format18
(
endDate
)
)
PrintService
.
printStatisticInfo
(
info
,
accountInfoFinal
)
statisticsLiveData
.
postValue
(
Result
.
success
(
tru
e
))
PrintService
.
printStatisticInfo
(
info
,
accountInfoFinal
,
isBalance
)
liveData
.
postValue
(
Result
.
success
(
endDate
.
tim
e
))
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
statisticsL
iveData
.
postValue
(
Result
.
failure
(
e
))
l
iveData
.
postValue
(
Result
.
failure
(
e
))
}
}
}
...
...
app/src/main/java/com/miya/fastcashier/viewmodel/PayViewModel.kt
View file @
1a5458da
...
...
@@ -48,7 +48,7 @@ class PayViewModel : ViewModel() {
refundPayServiceResponse
=
PayRepository
.
refundByOrderNo
(
refundParams
)
XLog
.
d
(
"退款成功:${JSON.toJSONString(refundPayServiceResponse)}"
)
//保存到数据库
ViewPayOrderData
.
insert
(
p
ayServiceResponse
)
ViewPayOrderData
.
insert
(
refundP
ayServiceResponse
)
refundLiveData
.
postValue
(
Result
.
success
(
refundPayServiceResponse
))
}
catch
(
e
:
Exception
)
{
...
...
app/src/main/res/layout/item_search_order_list.xml
View file @
1a5458da
...
...
@@ -50,6 +50,7 @@
android:visibility=
"gone"
app:layout_constraintEnd_toEndOf=
"@id/tvPrice"
app:layout_constraintTop_toBottomOf=
"@id/tvPrice"
tools:text=
"退款金额"
/>
android:text=
"退款金额"
tools:visibility=
"visible"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ 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