Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
joshine
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
joshine
Commits
1ae54516
Commit
1ae54516
authored
Apr 07, 2023
by
halweg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix : 未订阅用户设置10min 推送一次订阅优惠
parent
d5c864d2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
25 deletions
+95
-25
app/code/Joshine/CouponPusher/Controller/Ajax/Subscribe.php
+11
-0
app/code/Joshine/CouponPusher/Helper/Constant.php
+13
-2
app/code/Joshine/CouponPusher/Helper/CustomerChecker.php
+41
-16
app/code/Joshine/CouponPusher/Model/PushStrategyManager.php
+12
-4
app/code/Joshine/CouponPusher/Model/Strategy/StopPushStrategy.php
+1
-1
app/code/Joshine/CouponPusher/Model/Strategy/SubscribePushStrategy.php
+17
-2
No files found.
app/code/Joshine/CouponPusher/Controller/Ajax/Subscribe.php
View file @
1ae54516
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
*/
*/
namespace
Joshine\CouponPusher\Controller\Ajax
;
namespace
Joshine\CouponPusher\Controller\Ajax
;
use
Joshine\CouponPusher\Helper\CustomerChecker
;
use
Magento\Customer\Api\AccountManagementInterface
as
CustomerAccountManagement
;
use
Magento\Customer\Api\AccountManagementInterface
as
CustomerAccountManagement
;
use
Magento\Customer\Model\Session
;
use
Magento\Customer\Model\Session
;
use
Magento\Customer\Model\Url
as
CustomerUrl
;
use
Magento\Customer\Model\Url
as
CustomerUrl
;
...
@@ -50,6 +51,8 @@ class Subscribe extends SubscriberController implements HttpPostActionInterface
...
@@ -50,6 +51,8 @@ class Subscribe extends SubscriberController implements HttpPostActionInterface
private
$resultJsonFactory
;
private
$resultJsonFactory
;
private
$customerChecker
;
/**
/**
* Initialize dependencies.
* Initialize dependencies.
*
*
...
@@ -71,12 +74,14 @@ class Subscribe extends SubscriberController implements HttpPostActionInterface
...
@@ -71,12 +74,14 @@ class Subscribe extends SubscriberController implements HttpPostActionInterface
CustomerAccountManagement
$customerAccountManagement
,
CustomerAccountManagement
$customerAccountManagement
,
SubscriptionManagerInterface
$subscriptionManager
,
SubscriptionManagerInterface
$subscriptionManager
,
EmailValidator
$emailValidator
=
null
,
EmailValidator
$emailValidator
=
null
,
CustomerChecker
$customerChecker
,
JsonFactory
$jsonFactory
JsonFactory
$jsonFactory
)
{
)
{
$this
->
customerAccountManagement
=
$customerAccountManagement
;
$this
->
customerAccountManagement
=
$customerAccountManagement
;
$this
->
subscriptionManager
=
$subscriptionManager
;
$this
->
subscriptionManager
=
$subscriptionManager
;
$this
->
emailValidator
=
$emailValidator
?:
ObjectManager
::
getInstance
()
->
get
(
EmailValidator
::
class
);
$this
->
emailValidator
=
$emailValidator
?:
ObjectManager
::
getInstance
()
->
get
(
EmailValidator
::
class
);
$this
->
resultJsonFactory
=
$jsonFactory
;
$this
->
resultJsonFactory
=
$jsonFactory
;
$this
->
customerChecker
=
$customerChecker
;
parent
::
__construct
(
parent
::
__construct
(
$context
,
$context
,
$subscriberFactory
,
$subscriberFactory
,
...
@@ -184,6 +189,7 @@ class Subscribe extends SubscriberController implements HttpPostActionInterface
...
@@ -184,6 +189,7 @@ class Subscribe extends SubscriberController implements HttpPostActionInterface
'data'
=>
$message
,
'data'
=>
$message
,
'coupon_code'
=>
$this
->
getCouponCode
()
'coupon_code'
=>
$this
->
getCouponCode
()
];
];
$this
->
setSubscribeCookie
();
}
catch
(
LocalizedException
$e
)
{
}
catch
(
LocalizedException
$e
)
{
$message
=
[
'error'
=>
$e
->
getMessage
()];
$message
=
[
'error'
=>
$e
->
getMessage
()];
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
...
@@ -240,4 +246,9 @@ class Subscribe extends SubscriberController implements HttpPostActionInterface
...
@@ -240,4 +246,9 @@ class Subscribe extends SubscriberController implements HttpPostActionInterface
ScopeInterface
::
SCOPE_STORE
ScopeInterface
::
SCOPE_STORE
);
);
}
}
private
function
setSubscribeCookie
()
{
$this
->
customerChecker
->
setSubscribeCookie
();
}
}
}
app/code/Joshine/CouponPusher/Helper/Constant.php
View file @
1ae54516
...
@@ -2,6 +2,17 @@
...
@@ -2,6 +2,17 @@
namespace
Joshine\CouponPusher\Helper
;
namespace
Joshine\CouponPusher\Helper
;
class
Constant
{
class
Constant
{
const
FIRST_VISITOR
=
'first_visitor'
;
const
FIRST_VISITOR
=
'first_visitor'
;
const
OTHER
=
'other'
;
const
HAS_SUBSCRIBE
=
'has_subscribe'
;
const
STOP_COUPON_PUSH
=
'coupon_push_stop'
;
const
NOT_SUBSCRIBE
=
'not_subscribe'
;
const
HAS_SUBSCRIBE_COOKIE_DURATION
=
86400
*
365
;
const
HAS_VISITED_COOKIE_KEY
=
'has_visited'
;
const
HAS_VISITED_COOKIE_DURATION
=
86400
*
365
;
const
OTHER
=
'other'
;
}
}
app/code/Joshine/CouponPusher/Helper/CustomerChecker.php
View file @
1ae54516
<?php
<?php
namespace
Joshine\CouponPusher\Helper
;
namespace
Joshine\CouponPusher\Helper
;
class
CustomerChecker
implements
\Magento\Framework\Data\CollectionDataSourceInterface
class
CustomerChecker
implements
\Magento\Framework\Data\CollectionDataSourceInterface
{
{
const
HAS_VISITED_COOKIE_KEY
=
'has_visited'
;
const
HAS_VISITED_COOKIE_DURATION
=
86400
*
30
;
protected
$_cookieManager
;
protected
$_cookieManager
;
...
@@ -29,28 +28,54 @@ class CustomerChecker implements \Magento\Framework\Data\CollectionDataSourceInt
...
@@ -29,28 +28,54 @@ class CustomerChecker implements \Magento\Framework\Data\CollectionDataSourceInt
public
function
checkFirstVisit
()
:
bool
public
function
checkFirstVisit
()
:
bool
{
{
$previousTimestamp
=
$this
->
_cookieManager
->
getCookie
(
self
::
HAS_VISITED_COOKIE_KEY
);
return
is_null
(
$this
->
_cookieManager
->
getCookie
(
Constant
::
HAS_VISITED_COOKIE_KEY
));
if
(
!
$previousTimestamp
)
{
}
$metadata
=
$this
->
_cookieMetadataFactory
->
createPublicCookieMetadata
()
public
function
setFirstVisitCookie
()
->
setPath
(
'/'
)
{
->
setDuration
(
self
::
HAS_VISITED_COOKIE_DURATION
);
$this
->
setCookie
(
Constant
::
HAS_VISITED_COOKIE_KEY
,
'true'
,
Constant
::
HAS_VISITED_COOKIE_DURATION
);
$this
->
_cookieManager
->
setPublicCookie
(
}
self
::
HAS_VISITED_COOKIE_KEY
,
'true'
,
$metadata
public
function
checkSubscribed
()
:
bool
);
{
return
true
;
return
!
is_null
(
$this
->
_cookieManager
->
getCookie
(
Constant
::
HAS_SUBSCRIBE
));
}
}
return
false
;
public
function
setSubscribeCookie
()
{
$this
->
setCookie
(
Constant
::
HAS_SUBSCRIBE
,
'true'
,
Constant
::
HAS_SUBSCRIBE_COOKIE_DURATION
);
}
public
function
setCookie
(
$key
,
$data
,
$time
)
{
$metadata
=
$this
->
_cookieMetadataFactory
->
createPublicCookieMetadata
()
->
setPath
(
'/'
)
->
setDuration
(
$time
);
$this
->
_cookieManager
->
setPublicCookie
(
$key
,
$data
,
$metadata
);
}
}
//访客细分
//访客细分
public
function
getCustomerSegments
()
:
string
public
function
getCustomerSegments
()
:
string
{
{
if
(
$this
->
checkFirstVisit
())
{
if
(
$this
->
checkFirstVisit
())
{
$this
->
setFirstVisitCookie
();
return
Constant
::
FIRST_VISITOR
;
return
Constant
::
FIRST_VISITOR
;
}
}
if
(
!
$this
->
checkSubscribed
())
{
return
Constant
::
NOT_SUBSCRIBE
;
}
if
(
$this
->
checkSubscribed
())
{
return
Constant
::
HAS_SUBSCRIBE
;
}
return
Constant
::
OTHER
;
return
Constant
::
OTHER
;
}
}
}
}
app/code/Joshine/CouponPusher/Model/PushStrategyManager.php
View file @
1ae54516
...
@@ -5,8 +5,8 @@ namespace Joshine\CouponPusher\Model;
...
@@ -5,8 +5,8 @@ namespace Joshine\CouponPusher\Model;
use
Joshine\CouponPusher\Helper\Constant
;
use
Joshine\CouponPusher\Helper\Constant
;
use
Joshine\CouponPusher\Helper\CustomerChecker
;
use
Joshine\CouponPusher\Helper\CustomerChecker
;
use
Joshine\CouponPusher\Model\Strategy\ContractPushStrategy
;
use
Joshine\CouponPusher\Model\Strategy\ContractPushStrategy
;
use
Joshine\CouponPusher\Model\Strategy\
FirstVisitor
PushStrategy
;
use
Joshine\CouponPusher\Model\Strategy\
Subscribe
PushStrategy
;
use
Joshine\CouponPusher\Model\Strategy\
Nope
PushStrategy
;
use
Joshine\CouponPusher\Model\Strategy\
Stop
PushStrategy
;
use
Magento\Framework\ObjectManagerInterface
;
use
Magento\Framework\ObjectManagerInterface
;
class
PushStrategyManager
class
PushStrategyManager
...
@@ -26,10 +26,18 @@ class PushStrategyManager
...
@@ -26,10 +26,18 @@ class PushStrategyManager
public
function
tagToStrategy
(
$tag
)
:
string
public
function
tagToStrategy
(
$tag
)
:
string
{
{
$map
=
[
$map
=
[
Constant
::
FIRST_VISITOR
=>
FirstVisitorPushStrategy
::
class
,
//第一次访问推送订阅券
Constant
::
FIRST_VISITOR
=>
SubscribePushStrategy
::
class
,
//未订阅,持续推送订阅券
Constant
::
NOT_SUBSCRIBE
=>
SubscribePushStrategy
::
class
,
//已订阅停止推送
Constant
::
HAS_SUBSCRIBE
=>
StopPushStrategy
::
class
,
];
];
if
(
!
isset
(
$map
[
$tag
]))
{
if
(
!
isset
(
$map
[
$tag
]))
{
return
Nope
PushStrategy
::
class
;
return
Stop
PushStrategy
::
class
;
}
}
return
$map
[
$tag
];
return
$map
[
$tag
];
}
}
...
...
app/code/Joshine/CouponPusher/Model/Strategy/
Nope
PushStrategy.php
→
app/code/Joshine/CouponPusher/Model/Strategy/
Stop
PushStrategy.php
View file @
1ae54516
...
@@ -4,7 +4,7 @@ namespace Joshine\CouponPusher\Model\Strategy;
...
@@ -4,7 +4,7 @@ namespace Joshine\CouponPusher\Model\Strategy;
use
Joshine\CouponPusher\Block\CouponNopeAlert
;
use
Joshine\CouponPusher\Block\CouponNopeAlert
;
class
Nope
PushStrategy
implements
ContractPushStrategy
class
Stop
PushStrategy
implements
ContractPushStrategy
{
{
/**
/**
...
...
app/code/Joshine/CouponPusher/Model/Strategy/
FirstVisitor
PushStrategy.php
→
app/code/Joshine/CouponPusher/Model/Strategy/
Subscribe
PushStrategy.php
View file @
1ae54516
...
@@ -3,23 +3,37 @@
...
@@ -3,23 +3,37 @@
namespace
Joshine\CouponPusher\Model\Strategy
;
namespace
Joshine\CouponPusher\Model\Strategy
;
use
Joshine\CouponPusher\Block\CouponSubscribeAlert
;
use
Joshine\CouponPusher\Block\CouponSubscribeAlert
;
use
Joshine\CouponPusher\Helper\Constant
;
use
Joshine\CouponPusher\Helper\CustomerChecker
;
class
FirstVisitor
PushStrategy
implements
ContractPushStrategy
class
Subscribe
PushStrategy
implements
ContractPushStrategy
{
{
/**
/**
* @var \Magento\Framework\View\Element\BlockFactory
* @var \Magento\Framework\View\Element\BlockFactory
*/
*/
private
$blockFactory
;
private
$blockFactory
;
private
$customerChecker
;
public
function
__construct
(
public
function
__construct
(
\Magento\Framework\View\Element\BlockFactory
$blockFactory
\Magento\Framework\View\Element\BlockFactory
$blockFactory
,
CustomerChecker
$customerChecker
)
)
{
{
$this
->
blockFactory
=
$blockFactory
;
$this
->
blockFactory
=
$blockFactory
;
$this
->
customerChecker
=
$customerChecker
;
}
}
public
function
push
()
public
function
push
()
{
{
//停推10分钟
$this
->
stopPushTerm
();
return
$this
->
blockFactory
->
createBlock
(
CouponSubscribeAlert
::
class
)
->
toHtml
();
return
$this
->
blockFactory
->
createBlock
(
CouponSubscribeAlert
::
class
)
->
toHtml
();
}
}
public
function
stopPushTerm
()
{
$this
->
customerChecker
->
setCookie
(
Constant
::
STOP_COUPON_PUSH
,
'true'
,
60
*
10
);
}
}
}
\ 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