Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
my-yaf-project
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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenchuanwen
my-yaf-project
Commits
894646fe
Commit
894646fe
authored
Jan 24, 2019
by
liuyuzhengrace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
计算免费月份数据
parent
f73df66e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
175 additions
and
129 deletions
+175
-129
StoreUtil.php
application/library/Store/StoreUtil.php
+101
-93
StoreClassChargeLog.php
application/models/DAO/GoodsClass/StoreClassChargeLog.php
+26
-24
QmStoreClass.php
application/models/DAO/QmStoreClass.php
+14
-12
StoreClassPayLog.php
application/models/DAO/Store/StoreClassPayLog.php
+34
-0
No files found.
application/library/Store/StoreUtil.php
View file @
894646fe
...
...
@@ -70,108 +70,116 @@ class StoreUtil {
return
self
::
checkAddressInServiceArea
(
array
(
'lat'
=>
$lat
,
'lng'
=>
$lng
),
$storeId
);
}
public
function
calcChargeMoney
(
$param
){
/*$storeIds = array_keys($param);
$qmStoreClassModel = \DAO\QmStoreClassModel::getInstance();
$list = $qmStoreClassModel->getList(array('store_id'=>array('in',$storeIds),'class_style'=>2,'is_charged'=>1,'qm_store_class.deadline'=>array('lt',$store['contract_time'])),'');//当前店铺正在经营的二级签约分类
/*if(count($list)!=count($gcIds)){
showMessage('存在不能续费的分类');
}*/
/*$gcParentIds = array_unique(array_column($list,'gc_parent_id'));
$tempGoodsClassList = Model('goods_class')->getGoodsClassList(array('gc_id'=>array('in',$gcParentIds)),'gc_id,gc_name');
$goodsClassList = array();
foreach($tempGoodsClassList as $tempClass){
$goodsClassList[$tempClass['gc_id']] = $tempClass;
}
foreach($list as &$temp){
$temp['gc_parent_name'] = $goodsClassList[$temp['gc_parent_id']]['gc_name'];
}
$maxDeadline = max(array_column($list,'deadline'));
$storeEndTime = $store['store_end_time'];
$currExpTime = max(array($storeEndTime,$maxDeadline));
$currentMonthEnd = mktime(0,0,0,(date('m')+1),1,date('Y'))-1;
if($currExpTime<$currentMonthEnd){
$startEndTime = mktime(0,0,0,(date('m')+1),1,date('Y'))-1;
}else if($currExpTime==$currentMonthEnd){
$startEndTime = mktime(0,0,0,(date('m')+2),1,date('Y'))-1;
}else{
$futureEndTime = mktime(0,0,0,(date('m',$currExpTime)+1),1,date('Y',$currExpTime))-1;
if($futureEndTime>$currExpTime){
$startEndTime = mktime(0,0,0,(date('m',$currExpTime)+1),1,date('Y',$currExpTime))-1;
}else{
$startEndTime = mktime(0,0,0,(date('m',$currExpTime)+2),1,date('Y',$currExpTime))-1;
}
}
$startFee = 0;
foreach($list as $class){
$tempCurrExpTime = max(array($storeEndTime,$class['deadline']));
$startFee += $this->getChargedMoney($class,$tempCurrExpTime,$startEndTime);
/**
* 计算分类对应
* @param $class
* @param $storeEndTime
* @param int $month
* @return array|bool
*/
public
function
getFreeChargeMoney
(
$class
,
$storeEndTime
,
$month
=
1
){
if
(
$month
<=
0
){
return
false
;
}
if(chksubmit()){
try{
$endDate = $_POST['endDate']
;
if(!$endDat
e){
throw new Exception('缴费至期限不能为空')
;
$currentTime
=
mktime
(
23
,
59
,
59
,
date
(
'm'
),
date
(
'd'
),
date
(
'Y'
));
$tempOldTime
=
max
(
array
(
$storeEndTime
,
$class
[
'deadline'
]));
$oldTime
=
mktime
(
23
,
59
,
59
,
date
(
'm'
,
$tempOldTime
),
date
(
'd'
,
$tempOldTime
),
date
(
'Y'
,
$tempOldTime
));
$currExpTime
=
$oldTime
;
if
(
$currentTime
>
$oldTim
e
){
$currExpTime
=
$currentTime
;
}
$dateArr = explode('-',$endDate);
if(count($dateArr)!=2){
throw new Exception('截止时间格式错误');
$currentMonthEnd
=
mktime
(
0
,
0
,
0
,(
date
(
'm'
,
$currExpTime
)
+
1
),
1
,
date
(
'Y'
,
$currExpTime
))
-
1
;
$endTime
=
mktime
(
0
,
0
,
0
,(
date
(
'm'
,
$currExpTime
)
+
1
+
$month
),
1
,
date
(
'Y'
,
$currExpTime
))
-
1
;
if
(
$currentMonthEnd
>
$currExpTime
){
$endTime
=
$currentMonthEnd
;
if
(
$month
>
1
){
$endTime
=
mktime
(
0
,
0
,
0
,(
date
(
'm'
,
$currExpTime
)
+
$month
),
1
,
date
(
'Y'
,
$currExpTime
))
-
1
;
}
$endTime = mktime(0,0,0,($dateArr[1]+1),1,$dateArr[0])-1;
}
return
array
(
'service_fee'
=>
0
,
'old_end_time'
=>
$tempOldTime
,
'new_start_time'
=>
$currExpTime
+
1
,
'new_end_time'
=>
$endTime
,
'curr_month_fee'
=>
0
,
'pre_month_fee'
=>
0
);
}
if($endTime<$startEndTime){
throw new Exception('截止时间不能小于'.date('Y-m',$startEndTime));
/**
* 生成随机数
* @param $len 随机数
*/
private
function
createncode
(
$len
=
10
)
{
$strs
=
'0123456789'
;
$strlen
=
strlen
(
$strs
)
-
1
;
$rt
=
''
;
for
(
$i
=
0
;
$i
<
$len
;
$i
++
)
{
$rt
.=
$strs
[
rand
(
0
,
$strlen
)];
}
return
$rt
;
}
/**
* 计算试用期即将到期的店铺续费
* @param $param array(11=>array('month'=>1,'store_end_time'=>1548950399,'contract_time'=>'1577807999'))
* @return bool
*/
public
function
calcChargeMoney
(
$param
){
$storeIds
=
array_keys
(
$param
);
$dbName
=
\Our\DbNameConst
::
masterDBConnectName
;
var_dump
(
$dbName
);
$qmStoreClassModel
=
\DAO\QmStoreClassModel
::
getInstance
(
$dbName
);
var_dump
(
$dbName
.
'1test'
);
$qmStoreClassModel
->
setDb
(
$dbName
);
$list
=
$qmStoreClassModel
->
selectByWhere
(
array
(
'store_id'
=>
array
(
'in'
,
$storeIds
),
'class_style'
=>
2
,
'is_charged'
=>
1
));
//当前店铺正在经营的二级签约分类
//,'qm_store_class.deadline'=>array('lt',$store['contract_time'])
$currentTime
=
TIMESTAMP
;
$qmStoreClassModel
->
db
->
doTransaction
();
$addKey
=
\Our\Common
::
getConfig
(
'password.key'
);
$payLogList
=
array
();
$newChargeList
=
array
();
foreach
(
$list
as
$class
){
$paySn
=
date
(
'YmdHis'
)
.
$this
->
createncode
(
18
);
$storeId
=
$class
[
'store_id'
];
$payLog
=
array
();
$payLog['store_id'] = $store_i
d;
$payLog['pay_state'] = 0
;
$payLog
[
'store_id'
]
=
$storeI
d
;
$payLog
[
'pay_state'
]
=
1
;
$payLog
[
'pay_sn'
]
=
$paySn
;
$payLog
[
'gmt_create'
]
=
$currentTime
;
$payLog['pay_type'] = $_POST['pay_type'];
$payLog
[
'gmt_update'
]
=
$currentTime
;
$payLog
[
'pay_time'
]
=
$currentTime
;
$payLog
[
'pay_type'
]
=
3
;
$payContent
=
array
();
$pay_amount = 0;
foreach($list as $class){
$chargeLog
=
array
();
$feeArr = $this->getChargedMoney($class,$storeEndTime,$endTime,false);
$feeArr
=
$this
->
getFreeChargeMoney
(
$class
,
$param
[
$storeId
][
'store_end_time'
],
$param
[
$storeId
][
'month'
]);
if
(
$feeArr
[
'new_end_time'
]
>
$param
[
$storeId
][
'contract_time'
]){
\Our\Log
::
getInstance
()
->
write
(
json_encode
(
$class
)
.
'分类超过有效期'
,
'/data/log/feeMonth'
);
continue
;
}
$chargeLog
[
'gc_id'
]
=
$class
[
'gc_id'
];
$chargeLog['store_id'] = $store_i
d;
$chargeLog
[
'store_id'
]
=
$storeI
d
;
$chargeLog
[
'pay_sn'
]
=
$paySn
;
$chargeLog
=
array_merge
(
$feeArr
,
$chargeLog
);
$payContent
[]
=
$chargeLog
;
$pay_amount += $feeArr['service_fee'];
}
$payLog['pay_amount'] =$pay_amount;
$payLog
[
'pay_content'
]
=
serialize
(
$payContent
);
$result = BaseModel('store_class_pay_log')->add($payLog);
if(!$result){
throw new Exception('支付记录写入失败');
}
if(intval($payLog['pay_type'])==1){
$param['body']='我的身边店-订单编号'.$paySn;
$param['attach']='c|'.$paySn;
$param['pay_sn'] =$paySn;
$param['pay_amount']=$pay_amount;
$param['store_name']=$store['store_name'];
$result1=Model('store_class_pay_log')->generatePayQrcode($param);
if(!$result1){
showMessage('二维码生成失败','','html','error');
}
import('function.redisHelper');
excuteYafMethod('\DAO\QmStoreClassModel','delStoreSignClassesCache',array($store['store_citycode']));
$this->ajaxReturn(array('payType'=>1,'qrcodeUrl'=>UPLOAD_SITE_URL.DS.ATTACH_SIGNCLASS.DS.$result1,'paySn'=>$paySn),'二维码生成成功','1');
}else{
import('function.redisHelper');
excuteYafMethod('\DAO\QmStoreClassModel','delStoreSignClassesCache',array($store['store_citycode']));
$this->ajaxReturn(array('payType'=>2,'paySn'=>$paySn),'待支付数据生成成功','1');
}
}catch(Exception $e){
$this->ajaxReturn('',$e->getMessage(),'0');
}
}*/
$payLog
[
'pay_amount'
]
=
0
;
$chargeLog
[
'gmt_create'
]
=
$currentTime
;
$chargeLog
[
'gmt_update'
]
=
$currentTime
;
$chargeLog
[
'service_fee_sign'
]
=
md5
(
$currentTime
,
$chargeLog
[
'service_fee'
],
$addKey
);
$newChargeList
[]
=
$chargeLog
;
$resultClass
=
$qmStoreClassModel
->
update
(
array
(
'deadline'
=>
$chargeLog
[
'new_end_time'
],
'deadline_sign'
=>
md5
(
$class
[
'gmt_create'
],
$chargeLog
[
'new_end_time'
],
$addKey
),
'gmt_update'
=>
$currentTime
),
array
(
'gc_id'
=>
$chargeLog
[
'gc_id'
],
'store_id'
=>
$chargeLog
[
'store_id'
]));
if
(
$resultClass
===
false
){
$qmStoreClassModel
->
db
->
doRollback
();
}
$payLogList
[]
=
$payLog
;
}
$resultPayLog
=
\DAO\Store\StoreClassPayLogModel
::
getInstance
(
$dbName
)
->
insertBatch
(
$payLogList
);
if
(
!
$resultPayLog
){
$qmStoreClassModel
->
db
->
doRollback
();
}
$resultChargeLog
=
\DAO\GoodsClass\StoreClassChargeLogModel
::
getInstance
(
$dbName
)
->
insertBatch
(
$newChargeList
);
if
(
!
$resultChargeLog
){
$qmStoreClassModel
->
db
->
doRollback
();
}
$qmStoreClassModel
->
db
->
doCommit
();
return
true
;
}
/**
...
...
application/models/DAO/GoodsClass/StoreClassChargeLog.php
View file @
894646fe
...
...
@@ -29,33 +29,35 @@ class StoreClassChargeLogModel extends \DAO\AbstractModel{
return
$this
->
db
->
select
(
$field
)
->
from
(
$this
->
_tableName
)
->
where
(
$where
)
->
fetchAll
();
}
/**
* 计算分类对应
* @param $class
* @param $storeEndTime
* @param int $month
* @return array|bool
*/
public
function
getFreeChargeMoney
(
$class
,
$storeEndTime
,
$month
=
1
){
if
(
$month
<=
0
){
return
false
;
public
function
insertBatch
(
$datas
){
$this
->
setDb
(
\Our\DbNameConst
::
masterDBConnectName
);
$error
=
0
;
$baseSql
=
"insert IGNORE into
{
$this
->
_tableName
}
(gc_id,store_id,old_end_time,new_start_time,new_end_time,service_fee,gmt_create,gmt_update,pay_sn,curr_month_fee,pre_month_fee,service_fee_sign) values"
;
$insertAllSql
=
$baseSql
;
for
(
$i
=
0
;
$i
<
count
(
$datas
);
$i
++
)
{
$addSql
=
\Our\Common
::
format
(
"('
{
0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11
}
'),"
,
$datas
[
$i
][
'gc_id'
],
$datas
[
$i
][
'store_id'
],
$datas
[
$i
][
'old_end_time'
],
$datas
[
$i
][
'new_start_time'
],
$datas
[
$i
][
'new_end_time'
],
$datas
[
$i
][
'service_fee'
],
$datas
[
$i
][
'gmt_create'
],
$datas
[
$i
][
'gmt_update'
],
$datas
[
$i
][
'pay_sn'
],
$datas
[
$i
][
'curr_month_fee'
],
$datas
[
$i
][
'pre_month_fee'
],
$datas
[
$i
][
'service_fee_sign'
]);
$insertAllSql
.=
$addSql
;
if
(
$i
%
1000
==
0
&&
$i
!=
0
)
{
$insertAllSql
=
rtrim
(
$insertAllSql
,
','
);
$one
=
$this
->
db
->
insert
(
$this
->
_tableName
)
->
query
(
$insertAllSql
);
if
(
!
$one
)
{
$error
++
;
}
$currentTime
=
mktime
(
23
,
59
,
59
,
date
(
'm'
),
date
(
'd'
),
date
(
'Y'
));
$tempOldTime
=
max
(
array
(
$storeEndTime
,
$class
[
'deadline'
]));
$oldTime
=
mktime
(
23
,
59
,
59
,
date
(
'm'
,
$tempOldTime
),
date
(
'd'
,
$tempOldTime
),
date
(
'Y'
,
$tempOldTime
));
$currExpTime
=
$oldTime
;
if
(
$currentTime
>
$oldTime
){
$currExpTime
=
$currentTime
;
$insertAllSql
=
$baseSql
;
}
$currentMonthEnd
=
mktime
(
0
,
0
,
0
,(
date
(
'm'
,
$currExpTime
)
+
1
),
1
,
date
(
'Y'
,
$currExpTime
))
-
1
;
$endTime
=
mktime
(
0
,
0
,
0
,(
date
(
'm'
,
$currExpTime
)
+
1
+
$month
),
1
,
date
(
'Y'
,
$currExpTime
))
-
1
;
if
(
$currentMonthEnd
>
$currExpTime
){
$endTime
=
$currentMonthEnd
;
if
(
$month
>
1
){
$endTime
=
mktime
(
0
,
0
,
0
,(
date
(
'm'
,
$currExpTime
)
+
$month
),
1
,
date
(
'Y'
,
$currExpTime
))
-
1
;
}
if
(
$insertAllSql
!=
$baseSql
)
{
$insertAllSql
=
rtrim
(
$insertAllSql
,
','
);
$one
=
$this
->
db
->
insert
(
$this
->
_tableName
)
->
query
(
$insertAllSql
);
if
(
!
$one
)
{
$error
++
;
}
}
if
(
$error
>
0
)
{
return
false
;
}
return
array
(
'service_fee'
=>
0
,
'old_end_time'
=>
$tempOldTime
,
'new_start_time'
=>
$currExpTime
+
1
,
'new_end_time'
=>
$endTime
,
'curr_month_fee'
=>
0
,
'pre_month_fee'
=>
0
)
;
return
true
;
}
/**
...
...
application/models/DAO/QmStoreClass.php
View file @
894646fe
...
...
@@ -29,7 +29,7 @@ class QmStoreClassModel extends \DAO\AbstractModel{
public
function
selectByWhere
(
$where
=
null
,
$field
=
'*'
,
$limit
=
false
){
$this
->
setDb
();
$this
->
setDb
(
$this
->
dbName
);
if
(
is_array
(
$where
)){
$where
=
$this
->
db
->
getSqlWhereByArray
(
$where
);
}
...
...
@@ -41,6 +41,7 @@ class QmStoreClassModel extends \DAO\AbstractModel{
return
$result
;
}
public
function
delSignScopeCache
(
$storeId
){
$result
=
\Our\RedisHelper
::
delCachedFunction
(
\Redis\Db6\QmStoreClassRedisModel
::
getInstance
(),
array
(
&
$this
,
'selectByWhere'
),
array
(),
array
(
$storeId
));
return
$result
;
...
...
@@ -80,6 +81,14 @@ class QmStoreClassModel extends \DAO\AbstractModel{
return
$list
;
}
public
function
update
(
$data
,
$where
){
$this
->
setDb
(
\Our\DbNameConst
::
masterDBConnectName
);
$result
=
$this
->
db
->
update
(
$this
->
_tableName
)
->
rows
(
$data
)
->
where
(
$where
)
->
execute
();
return
$result
;
}
/**
* 类实例
*/
...
...
@@ -88,21 +97,21 @@ class QmStoreClassModel extends \DAO\AbstractModel{
/**
* 获取类实例
*/
public
static
function
getInstance
()
{
public
static
function
getInstance
(
$dbName
=
\Our\DbNameConst
::
salveDBConnectName
)
{
if
(
!
(
self
::
$_instance
instanceof
self
))
{
self
::
$_instance
=
new
self
();
self
::
$_instance
=
new
self
(
$dbName
);
}
return
self
::
$_instance
;
}
public
function
getStoreClasses
(
$where
,
$field
=
'*'
){
$this
->
setDb
();
$this
->
setDb
(
$this
->
dbName
);
$result
=
$this
->
db
->
select
(
$field
)
->
from
(
$this
->
_tableName
)
->
where
(
$where
)
->
fetchAll
();
return
$result
;
}
public
function
getStoreSignClasses
(
$where
,
$field
=
"*"
){
$this
->
setDb
();
$this
->
setDb
(
$this
->
dbName
);
if
(
is_array
(
$where
)){
$where
=
$this
->
db
->
getSqlWhereByArray
(
$where
);
}
...
...
@@ -137,11 +146,4 @@ class QmStoreClassModel extends \DAO\AbstractModel{
\Our\RedisHelper
::
delCachedFunction
(
\Redis\Db6\QmStoreClassRedisModel
::
getInstance
(),
array
(
&
$this
,
'getStoreClasses'
),
array
(),
array
(
$cityCode
));
}
public
function
update
(
$data
,
$where
){
$this
->
setDb
(
\Our\DbNameConst
::
masterDBConnectName
);
$result
=
$this
->
db
->
update
(
$this
->
_tableName
)
->
rows
(
$data
)
->
where
(
$where
)
->
execute
();
return
$result
;
}
}
\ No newline at end of file
application/models/DAO/Store/StoreClassPayLog.php
View file @
894646fe
...
...
@@ -31,6 +31,40 @@ class StoreClassPayLogModel extends \DAO\AbstractModel
$this
->
setDb
(
$this
->
dbName
);
return
$this
->
db
->
select
(
$field
)
->
from
(
$this
->
_tableName
)
->
where
(
$where
)
->
fetchOne
();
}
public
function
insertBatch
(
$datas
){
$this
->
setDb
(
\Our\DbNameConst
::
masterDBConnectName
);
$error
=
0
;
$baseSql
=
"insert IGNORE into
{
$this
->
_tableName
}
(store_id,pay_state,pay_sn,pay_content,gmt_create,pay_time,pay_amount,pay_type,gmt_update) values"
;
$insertAllSql
=
$baseSql
;
for
(
$i
=
0
;
$i
<
count
(
$datas
);
$i
++
)
{
$addSql
=
\Our\Common
::
format
(
"('
{
0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8
}
'),"
,
$datas
[
$i
][
'store_id'
],
$datas
[
$i
][
'pay_state'
],
$datas
[
$i
][
'pay_sn'
],
$datas
[
$i
][
'pay_content'
],
$datas
[
$i
][
'gmt_create'
],
$datas
[
$i
][
'pay_time'
],
$datas
[
$i
][
'pay_amount'
],
$datas
[
$i
][
'pay_type'
],
$datas
[
$i
][
'gmt_update'
]);
$insertAllSql
.=
$addSql
;
if
(
$i
%
1000
==
0
&&
$i
!=
0
)
{
$insertAllSql
=
rtrim
(
$insertAllSql
,
','
);
$one
=
$this
->
db
->
insert
(
$this
->
_tableName
)
->
query
(
$insertAllSql
);
if
(
!
$one
)
{
$error
++
;
}
$insertAllSql
=
$baseSql
;
}
}
if
(
$insertAllSql
!=
$baseSql
)
{
$insertAllSql
=
rtrim
(
$insertAllSql
,
','
);
$one
=
$this
->
db
->
insert
(
$this
->
_tableName
)
->
query
(
$insertAllSql
);
if
(
!
$one
)
{
$error
++
;
}
}
if
(
$error
>
0
)
{
return
false
;
}
return
true
;
}
/**
* 类实例
*
...
...
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