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
cd2e0fb2
Commit
cd2e0fb2
authored
Jan 03, 2019
by
testshenbd
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'linqing' of git.shenbd.com:qm-develop/shenbd into master_dev
parents
1977320f
0d21c503
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
216 additions
and
161 deletions
+216
-161
OrderConfirmUtil.php
application/library/Order/OrderConfirmUtil.php
+13
-83
WechatCommon.php
application/library/Our/WechatCommon.php
+16
-1
OrderService.php
application/models/Business/Order/OrderService.php
+186
-76
sendTemplateMessage.php
scripts/crontab/order/sendTemplateMessage.php
+1
-1
No files found.
application/library/Order/OrderConfirmUtil.php
View file @
cd2e0fb2
...
...
@@ -3,6 +3,7 @@
namespace
Order
;
use
Our\ApiConst
;
use
Our\RedisHelper
;
use
Our\WechatCommon
;
/**
...
...
@@ -709,8 +710,11 @@ class OrderConfirmUtil {
\Error\ErrorModel
::
throwException
(
\Error\CodeConfigModel
::
failedUpdateFavoritesStoreForOrder
);
}
$orderModel
->
db
->
doCommit
();
$wechatCommon
=
WechatCommon
::
getInstance
();
$access_token
=
$wechatCommon
->
getAccessToken
();
//订单通过小程序表单提交过来
if
(
$formId
&&
(
$access_token
=
$this
->
getLitAccesstoken
())
)
{
if
(
$formId
&&
$access_token
)
{
$settingDAO
=
\DAO\SettingModel
::
getInstance
();
$msg_tpl
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_create_tpl'
))[
'wxapp_order_create_tpl'
];
$goods_str
=
''
;
...
...
@@ -724,98 +728,24 @@ class OrderConfirmUtil {
$openid
=
$authInfo
[
'openid'
];
$req_data
=
array
(
'touser'
=>
$openid
,
'template_id'
=>
$msg_tpl
,
'form_id'
=>
$formId
,
'page'
=>
'pages/orders/
list/index'
,
'page'
=>
'pages/orders/
detail/index?id='
.
$orderId
,
'data'
=>
array
(
'keyword1'
=>
array
(
'value'
=>
'下单成功'
),
'keyword2'
=>
array
(
'value'
=>
$order
[
'order_sn'
]),
'keyword3'
=>
array
(
'value'
=>
number_format
(
$order
[
'order_amount'
]
/
100
,
2
)
.
'元'
),
'keyword4'
=>
array
(
'value'
=>
$order
[
'store_name'
]),
'keyword5'
=>
array
(
'value'
=>
$goods_str
),
'keyword2'
=>
array
(
'value'
=>
$order
[
'order_sn'
]),
'keyword3'
=>
array
(
'value'
=>
number_format
(
$order
[
'order_amount'
]
/
100
,
2
)
.
'元'
),
'keyword4'
=>
array
(
'value'
=>
$order
[
'store_name'
]),
'keyword5'
=>
array
(
'value'
=>
$goods_str
),
));
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
$url
=
'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='
;
$result
=
$this
->
sendurl
(
$url
,
$access_token
,
json_encode
(
$req_data
),
'post'
);
\Our\Log
::
getInstance
()
->
write
(
var_export
(
$result
,
true
),
'/data/log/apptest'
);
$json
=
$wechatCommon
->
sendTemplateMessage
(
$access_token
,
$req_data
);
// \Our\Log::getInstance()->write($json, '/data/log/apptest');
}
$this
->
opCacheInfo
();
$this
->
pushMessage
();
return
array
(
'needPayFlag'
=>
$needPayFlag
,
'paySn'
=>
$paySn
);
}
/**
* 获取小程序表单
* User: King <358887571@qq.com>
* Date: 2018/12/27 0027
* Time: 下午 3:15
*/
private
function
getLitAccesstoken
(){
$model_wx
=
\DAO\MbWxModel
::
getInstance
();
$weixin
=
$model_wx
->
getOne
(
'id,lit_appid,lit_appsecret,lit_accesstoken,lit_expirestime'
,
'id=1'
);
$access_token
=
''
;
if
(
!
$weixin
[
'lit_expirestime'
]
||
$weixin
[
'lit_expirestime'
]
<
time
())
{
$access_info
=
json_decode
(
file_get_contents
(
'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='
.
$weixin
[
'lit_appid'
]
.
'&secret='
.
$weixin
[
'lit_appsecret'
]),
true
);
if
(
isset
(
$access_info
[
'access_token'
]))
{
$access_token
=
$access_info
[
'access_token'
];
$update_data
=
array
();
$update_data
[
'lit_accesstoken'
]
=
$access_info
[
'access_token'
];
$update_data
[
'lit_expirestime'
]
=
TIMESTAMP
+
$access_info
[
'expires_in'
]
-
1800
;
$where
=
array
(
'id'
=>
$weixin
[
'id'
]);
$result
=
$model_wx
->
update
(
$update_data
,
$where
);
}
}
else
{
$access_token
=
$weixin
[
'lit_accesstoken'
];
}
return
$access_token
;
}
/**
* curl请求
* @param $url
* @param $access_token
* @param $data
* @param $method
*/
private
function
sendurl
(
$url
,
$access_token
=
''
,
$data
=
''
,
$method
=
'get'
,
$header
=
''
)
{
//
if
(
strtolower
(
$method
)
==
'post'
)
{
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
.
$access_token
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
FALSE
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
FALSE
);
}
else
{
$curl
=
curl_init
(
$url
.
$access_token
);
}
if
(
$header
){
//设置头部信息
curl_setopt
(
$curl
,
CURLOPT_HTTPHEADER
,
$header
);
}
//$curl = curl_init($url.$access_token);
curl_setopt
(
$curl
,
CURLOPT_FAILONERROR
,
1
);
//设置允许页面重定向
curl_setopt
(
$curl
,
CURLOPT_FOLLOWLOCATION
,
1
);
//设置返回值赋给变量
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
//设置操作时间
curl_setopt
(
$curl
,
CURLOPT_TIMEOUT
,
5
);
if
(
$method
==
'post'
){
if
(
!
$data
)
$data
=
''
;
// 使用post 请求
curl_setopt
(
$curl
,
CURLOPT_POST
,
1
);
// 设置请求参数
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
$data
);
}
//开始事务
$r
=
curl_exec
(
$curl
);
curl_close
(
$curl
);
return
$r
;
}
public
function
pushMessage
(){
if
(
$this
->
pushMessageOrders
){
$orderService
=
\Business\Order\OrderServiceModel
::
getInstance
();
...
...
application/library/Our/WechatCommon.php
100755 → 100644
View file @
cd2e0fb2
...
...
@@ -72,6 +72,21 @@ class WechatCommon
return
$jsonstr
;
}
/**
* 发送模板消息
*
* @param $access_token token
* @param $req_data 请求数据数组
* User: King <358887571@qq.com>
* Date: 2019/1/2 0002
* Time: 下午 4:41
*/
public
function
sendTemplateMessage
(
$access_token
,
$req_data
)
{
$url
=
'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='
.
$access_token
;
$result
=
$this
->
httpsPostJson
(
$url
,
$req_data
,
true
);
return
$result
;
}
public
function
httpsPostJson
(
$url
,
$data
=
''
,
$array
=
false
)
{
...
...
@@ -127,4 +142,4 @@ class WechatCommon
return
self
::
$_instance
;
}
}
\ No newline at end of file
}
application/models/Business/Order/OrderService.php
View file @
cd2e0fb2
...
...
@@ -2,6 +2,7 @@
namespace
Business\Order
;
use
Business\Store\StoreServiceModel
;
use
DAO\Order\OrderCommonModel
;
use
Error\CodeConfigModel
;
use
Error\ErrorModel
;
...
...
@@ -17,6 +18,7 @@ use Our\NameConst;
use
Our\PageConst
;
use
Our\Push
;
use
Our\RedisHelper
;
use
Our\WechatCommon
;
/**
* 店铺service
...
...
@@ -75,7 +77,7 @@ class OrderServiceModel extends \Business\AbstractModel
$update_data
=
array
();
$update_data
[
'lit_accesstoken'
]
=
$access_info
[
'access_token'
];
$update_data
[
'lit_expirestime'
]
=
time
()
+
$access_info
[
'expires_in'
]
-
1800
;
$update_data
[
'lit_expirestime'
]
=
TIMESTAMP
+
$access_info
[
'expires_in'
]
-
1800
;
$where
=
array
(
'id'
=>
$weixin
[
'id'
]);
$result
=
$model_wx
->
update
(
$update_data
,
$where
);
...
...
@@ -87,49 +89,150 @@ class OrderServiceModel extends \Business\AbstractModel
}
/**
* curl请求
* @param $url
* @param $access_token
* @param $data
* @param $method
* 发送付款消息
* @param $order
* @param $msg_tpl
* User: King <358887571@qq.com>
* Date: 2019/1/3 0003
* Time: 上午 11:01
*/
private
function
sendurl
(
$url
,
$access_token
=
''
,
$data
=
''
,
$method
=
'get'
,
$header
=
''
)
{
//
if
(
strtolower
(
$method
)
==
'post'
)
{
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
.
$access_token
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
FALSE
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
FALSE
);
}
else
{
$curl
=
curl_init
(
$url
.
$access_token
);
}
public
function
sendPaymentMessage
(
$order
,
$msg_tpl
)
{
$model
=
\DAO\Order\OrderModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$model_member
=
\DAO\MemberModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$model_order_goods
=
\DAO\Order\OrderGoodsModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$wechatCommon
=
WechatCommon
::
getInstance
();
$access_token
=
$wechatCommon
->
getAccessToken
();
if
(
$access_token
&&
(
$member
=
$model_member
->
getOneByMemberId
(
$order
[
'buyer_id'
],
array
(
'member_id'
,
'member_wxappopenid'
)
)))
{
$where
=
array
(
'order_id'
=>
$order
[
'order_id'
]);
$goods_datas
=
$model_order_goods
->
getOrderGoods
(
$where
,
'order_id, goods_name'
);
$goods_str
=
''
;
if
(
count
(
$goods_datas
)
>
1
)
{
$goods_str
.=
$goods_datas
[
0
][
'goods_name'
]
.
'等'
.
count
(
$goods_datas
)
.
'件商品'
;
}
else
{
$goods_str
.=
$goods_datas
[
0
][
'goods_name'
];
}
$req_data
=
array
(
'touser'
=>
$member
[
'member_wxappopenid'
],
'template_id'
=>
$msg_tpl
,
'form_id'
=>
$order
[
'prepay_id'
],
'page'
=>
'pages/orders/detail/index?id='
.
$order
[
'order_id'
],
'data'
=>
array
(
'keyword1'
=>
array
(
'value'
=>
$order
[
'order_sn'
]),
'keyword2'
=>
array
(
'value'
=>
$order
[
'store_name'
]),
'keyword3'
=>
array
(
'value'
=>
$goods_str
),
'keyword4'
=>
array
(
'value'
=>
number_format
(
$order
[
'order_amount'
]
/
100
,
2
)
.
'元'
),
'keyword5'
=>
array
(
'value'
=>
date
(
'Y-m-d H:i'
,
$order
[
'payment_time'
])),
'keyword6'
=>
array
(
'value'
=>
'已付款'
),
));
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
$json
=
$wechatCommon
->
sendTemplateMessage
(
$access_token
,
$req_data
);
if
(
$json
[
'errmsg'
]
==
'ok'
)
{
$model
->
updateByOrderId
(
array
(
'msg_status'
=>
2
),
$order
[
'order_id'
]);
// echo 'order[' . $order['order_id'] .'] send payment succ'."\n";
}
if
(
$header
){
//设置头部信息
curl_setopt
(
$curl
,
CURLOPT_HTTPHEADER
,
$header
);
}
//$curl = curl_init($url.$access_token);
curl_setopt
(
$curl
,
CURLOPT_FAILONERROR
,
1
);
//设置允许页面重定向
curl_setopt
(
$curl
,
CURLOPT_FOLLOWLOCATION
,
1
);
//设置返回值赋给变量
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
//设置操作时间
curl_setopt
(
$curl
,
CURLOPT_TIMEOUT
,
5
);
if
(
$method
==
'post'
){
if
(
!
$data
)
$data
=
''
;
// 使用post 请求
curl_setopt
(
$curl
,
CURLOPT_POST
,
1
);
// 设置请求参数
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
$data
);
}
public
function
sendShippingMessage
(
$order
,
$msg_tpl
)
{
$model
=
\DAO\Order\OrderModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$model_member
=
\DAO\MemberModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$model_order_goods
=
\DAO\Order\OrderGoodsModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$wechatCommon
=
WechatCommon
::
getInstance
();
$access_token
=
$wechatCommon
->
getAccessToken
();
$common_model
=
\DAO\Order\OrderCommonModel
::
getInstance
();
if
(
$access_token
&&
(
$member
=
$model_member
->
getOneByMemberId
(
$order
[
'buyer_id'
],
array
(
'member_id'
,
'member_wxappopenid'
)
)))
{
$sub_data
=
$common_model
->
findByOrderId
(
$order
[
'order_id'
],
'reciver_name, reciver_info'
);
$address
=
''
;
if
(
$sub_data
[
'reciver_info'
])
{
$reciver_info
=
unserialize
(
$sub_data
[
'reciver_info'
]);
$address
=
$reciver_info
[
'address'
]
.
$reciver_info
[
'subaddress'
];
}
$where
=
array
(
'order_id'
=>
$order
[
'order_id'
]);
$goods_datas
=
$model_order_goods
->
getOrderGoods
(
$where
,
'order_id, goods_name'
);
$goods_str
=
''
;
if
(
count
(
$goods_datas
)
>
1
)
{
$goods_str
.=
$goods_datas
[
0
][
'goods_name'
]
.
'等'
.
count
(
$goods_datas
)
.
'件商品'
;
}
else
{
$goods_str
.=
$goods_datas
[
0
][
'goods_name'
];
}
$req_data
=
array
(
'touser'
=>
$member
[
'member_wxappopenid'
],
'template_id'
=>
$msg_tpl
,
'form_id'
=>
$order
[
'prepay_id'
],
'page'
=>
'pages/orders/detail/index?id='
.
$order
[
'order_id'
],
'data'
=>
array
(
'keyword1'
=>
array
(
'value'
=>
date
(
'Y-m-d H:i'
,
$order
[
'add_time'
])),
'keyword2'
=>
array
(
'value'
=>
date
(
'Y-m-d H:i'
,
$order
[
'send_time'
])),
'keyword3'
=>
array
(
'value'
=>
$order
[
'order_sn'
]),
'keyword4'
=>
array
(
'value'
=>
$address
),
'keyword5'
=>
array
(
'value'
=>
$order
[
'store_name'
]),
'keyword6'
=>
array
(
'value'
=>
$goods_str
),
'keyword7'
=>
array
(
'value'
=>
number_format
(
$order
[
'order_amount'
]
/
100
,
2
)
.
'元'
),
));
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
$json
=
$wechatCommon
->
sendTemplateMessage
(
$access_token
,
$req_data
);
if
(
$json
[
'errmsg'
]
==
'ok'
)
{
$model
->
updateByOrderId
(
array
(
'msg_status'
=>
3
),
$order
[
'order_id'
]);
// echo 'order[' . $order['order_id'] .'] send shipping succ'."\n";
}
}
}
public
function
sendReceiveMessage
(
$order
,
$msg_tpl
)
{
$model
=
\DAO\Order\OrderModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$model_member
=
\DAO\MemberModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$model_order_goods
=
\DAO\Order\OrderGoodsModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$wechatCommon
=
WechatCommon
::
getInstance
();
$access_token
=
$wechatCommon
->
getAccessToken
();
$store_model
=
\DAO\StoreModel
::
getInstance
();
if
(
$access_token
&&
(
$member
=
$model_member
->
getOneByMemberId
(
$order
[
'buyer_id'
],
array
(
'member_id'
,
'member_wxappopenid'
)
)))
{
$where
=
array
(
'order_id'
=>
$order
[
'order_id'
]);
$goods_datas
=
$model_order_goods
->
getOrderGoods
(
$where
,
'order_id, goods_name'
);
$goods_str
=
''
;
if
(
count
(
$goods_datas
)
>
1
)
{
$goods_str
.=
$goods_datas
[
0
][
'goods_name'
]
.
'等'
.
count
(
$goods_datas
)
.
'件商品'
;
}
else
{
$goods_str
.=
$goods_datas
[
0
][
'goods_name'
];
}
$store_data
=
$store_model
->
getFieldsInfo
(
array
(
'store_id'
=>
$order
[
'store_id'
]),
'store_phone'
);
$shipping_type
=
''
;
switch
(
$order
[
'shipping_type'
])
{
case
1
:
$shipping_type
.=
'商家配送'
;
break
;
case
2
:
$shipping_type
.=
'快递配送'
;
break
;
default
:
$shipping_type
.=
'到店自提'
;
break
;
}
$req_data
=
array
(
'touser'
=>
$member
[
'member_wxappopenid'
],
'template_id'
=>
$msg_tpl
,
'form_id'
=>
$order
[
'prepay_id'
],
'page'
=>
'pages/orders/detail/index?id='
.
$order
[
'order_id'
],
'data'
=>
array
(
'keyword1'
=>
array
(
'value'
=>
$order
[
'order_sn'
]),
'keyword2'
=>
array
(
'value'
=>
date
(
'Y-m-d H:i'
,
$order
[
'send_time'
])),
'keyword3'
=>
array
(
'value'
=>
date
(
'Y-m-d H:i'
,
$order
[
'finnshed_time'
])),
'keyword4'
=>
array
(
'value'
=>
$order
[
'store_name'
]),
'keyword5'
=>
array
(
'value'
=>
$store_data
[
'store_phone'
]),
'keyword6'
=>
array
(
'value'
=>
$goods_str
),
'keyword7'
=>
array
(
'value'
=>
number_format
(
$order
[
'order_amount'
]
/
100
,
2
)
.
'元'
),
'keyword8'
=>
array
(
'value'
=>
$shipping_type
),
'keyword9'
=>
array
(
'value'
=>
'您购买的商品已被签收,如不是您本人签收,请尽快联系商家'
),
));
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
$json
=
$wechatCommon
->
sendTemplateMessage
(
$access_token
,
$req_data
);
if
(
$json
[
'errmsg'
]
==
'ok'
)
{
$model
->
updateByOrderId
(
array
(
'msg_status'
=>
4
),
$order
[
'order_id'
]);
// echo 'order[' . $order['order_id'] .'] send reciver succ'."\n";
}
//开始事务
$r
=
curl_exec
(
$curl
);
curl_close
(
$curl
);
return
$r
;
}
}
/**
...
...
@@ -142,52 +245,51 @@ class OrderServiceModel extends \Business\AbstractModel
public
function
sendTemplateMessage
()
{
$model
=
\DAO\Order\OrderModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$model_member
=
\DAO\MemberModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$model_order_goods
=
\DAO\Order\OrderGoodsModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$settingDAO
=
\DAO\SettingModel
::
getInstance
();
$
access_token
=
$this
->
getLitAccesstoken
(
);
$
wxapp_templates
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_paysucc_tpl'
,
'wxapp_order_shipping_tpl'
,
'wxapp_order_receive_tpl'
)
);
$where
=
array
(
'msg_status'
=>
array
(
'elt'
,
1
),
'payment_type'
=>
5
,
'order_state'
=>
array
(
'gt'
,
10
),
'prepay_id'
=>
//付款7天内付款消息通知
$where
=
array
(
'msg_status'
=>
array
(
'elt'
,
1
),
'payment_type'
=>
5
,
'order_state'
=>
array
(
'egt'
,
20
),
'prepay_id'
=>
array
(
'neq'
,
''
),
'payment_time'
=>
array
(
'gt'
,
TIMESTAMP
-
7
*
24
*
60
*
60
));
$wxapp_templates
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_paysucc_tpl'
,
'wxapp_order_shipping_tpl'
,
'wxapp_order_receive_tpl'
));
if
(
$list
=
$model
->
getList
(
$where
,
'order_id,order_sn,store_name,buyer_id,order_amount,payment_time, order_state, prepay_id'
,
0
,
10
,
array
(
'payment_time'
=>
'asc'
)))
{
echo
'order num: '
.
count
(
$list
)
.
"
\n
"
;
foreach
(
$list
as
$order
)
{
if
(
$access_token
&&
(
$member
=
$model_member
->
getOneByMemberId
(
$order
[
'buyer_id'
],
'member_id,member_wxappopenid'
))){
$where
=
array
(
'order_id'
=>
$order
[
'order_id'
]);
$goods_datas
=
$model_order_goods
->
getOrderGoods
(
$where
,
'order_id, goods_name'
);
$msg_tpl
=
$wxapp_templates
[
'wxapp_order_paysucc_tpl'
];
$goods_str
=
''
;
if
(
count
(
$goods_datas
)
>
1
)
{
$goods_str
.=
$goods_datas
[
0
][
'goods_name'
]
.
'等'
.
count
(
$goods_datas
)
.
'个商品'
;
}
else
{
$goods_str
.=
$goods_datas
[
0
][
'goods_name'
];
}
$req_data
=
array
(
'touser'
=>
$member
[
'member_wxappopenid'
],
'template_id'
=>
$msg_tpl
,
'form_id'
=>
$order
[
'prepay_id'
],
'data'
=>
array
(
'keyword1'
=>
array
(
'value'
=>
$order
[
'order_sn'
]),
'keyword2'
=>
array
(
'value'
=>
$order
[
'store_name'
]),
'keyword3'
=>
array
(
'value'
=>
$goods_str
),
'keyword4'
=>
array
(
'value'
=>
number_format
(
$order
[
'order_amount'
]
/
100
,
2
)
.
'元'
),
'keyword5'
=>
array
(
'value'
=>
date
(
'Y-m-d H:i'
,
$order
[
'payment_time'
])),
'keyword6'
=>
array
(
'value'
=>
'已付款'
),
));
\Our\Log
::
getInstance
()
->
write
(
json_encode
(
$req_data
),
'/data/log/apptest'
);
$url
=
'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='
;
if
(
$result
=
$this
->
sendurl
(
$url
,
$access_token
,
json_encode
(
$req_data
),
'post'
))
{
$json
=
json_decode
(
$result
,
true
);
if
(
$json
[
'errmsg'
]
==
'ok'
)
{
$model
->
updateByOrderId
(
array
(
'msg_status'
=>
1
),
$order
[
'order_id'
]);
echo
'order['
.
$order
[
'order_id'
]
.
'] send payment succ'
.
"
\n
"
;
}
}
if
(
$list
=
$model
->
getList
(
$where
,
'order_id,order_sn, store_name, buyer_id, order_amount, payment_time, order_state, prepay_id'
,
0
,
10
,
array
(
'payment_time'
=>
'asc'
)))
{
echo
'order count: '
.
count
(
$list
[
'list'
])
.
"
\n
"
;
$msg_tpl
=
$wxapp_templates
[
'wxapp_order_paysucc_tpl'
];
foreach
(
$list
[
'list'
]
as
$order
)
{
// \Our\Log::getInstance()->write('order:'.json_encode($order), '/data/log/apptest');
$this
->
sendPaymentMessage
(
$order
,
$msg_tpl
);
}
}
echo
"do payment
\n
"
;
//付款7天内订单发货通知
$where
=
array
(
'msg_status'
=>
2
,
'payment_type'
=>
5
,
'shipping_type'
=>
array
(
'in'
,
array
(
1
,
2
)),
'order_state'
=>
array
(
'egt'
,
30
),
'prepay_id'
=>
array
(
'neq'
,
''
),
'payment_time'
=>
array
(
'gt'
,
TIMESTAMP
-
7
*
24
*
60
*
60
),
'send_time'
=>
array
(
'lt'
,
TIMESTAMP
-
10
));
if
(
$list
=
$model
->
getList
(
$where
,
'order_id,order_sn,store_id,store_name,buyer_id,order_amount,add_time, send_time, order_state, prepay_id'
,
0
,
10
,
array
(
'send_time'
=>
'asc'
)))
{
echo
' order num: '
.
count
(
$list
[
'list'
])
.
"
\n
"
;
$msg_tpl
=
$wxapp_templates
[
'wxapp_order_shipping_tpl'
];
foreach
(
$list
[
'list'
]
as
$order
)
{
// \Our\Log::getInstance()->write('order:'.json_encode($order), '/data/log/apptest');
$this
->
sendShippingMessage
(
$order
,
$msg_tpl
);
}
}
echo
"do shipping
\n
"
;
}
//付款7天内订单确认收货通知
$where
=
array
(
'msg_status'
=>
3
,
'payment_type'
=>
5
,
'order_state'
=>
array
(
'egt'
,
40
),
'prepay_id'
=>
array
(
'neq'
,
''
),
'payment_time'
=>
array
(
'gt'
,
TIMESTAMP
-
7
*
24
*
60
*
60
),
'finnshed_time'
=>
array
(
'lt'
,
TIMESTAMP
-
15
));
if
(
$list
=
$model
->
getList
(
$where
,
'order_id,order_sn,store_id,store_name,buyer_id, shipping_type,order_amount,add_time, send_time, finnshed_time, order_state, prepay_id'
,
0
,
10
,
array
(
'finnshed_time'
=>
'asc'
)))
{
echo
' order num: '
.
count
(
$list
[
'list'
])
.
"
\n
"
;
$msg_tpl
=
$wxapp_templates
[
'wxapp_order_receive_tpl'
];
foreach
(
$list
[
'list'
]
as
$order
)
{
$this
->
sendReceiveMessage
(
$order
,
$msg_tpl
);
}
}
echo
"do reciver
\n
"
;
}
...
...
@@ -563,6 +665,14 @@ class OrderServiceModel extends \Business\AbstractModel
'orderId'
=>
$order
[
'order_id'
]));
$push
->
addOneToClient
(
$pushData
);
$push
->
sendTcpMessage
();
$order
[
'finnshed_time'
]
=
TIMESTAMP
;
$settingDAO
=
\DAO\SettingModel
::
getInstance
();
$wxapp_templates
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_receive_tpl'
));
$msg_tpl
=
$wxapp_templates
[
'wxapp_order_receive_tpl'
];
$this
->
sendReceiveMessage
(
$order
,
$msg_tpl
);
//发送收货小程序模板消息
// \Our\RedisHelper::rpush('client_push',array('storeId'=>$order['storeId'],'type'=>$type,'op'=>NameConst::reduce,'num'=>ApiConst::one,'params'=>array('c'=>'shopkeeper','m'=>'orderDetail','orderId'=>$order['orderId'])));
$orderDao
->
deleteOrderCache
(
$memberId
,
$orderId
,
$order
[
'store_id'
],
true
,
true
);
$storeDao
->
deleteStoreCache
(
$order
[
'storeId'
],
$order
[
'orderId'
]);
...
...
scripts/crontab/order/sendTemplateMessage.php
View file @
cd2e0fb2
...
...
@@ -57,7 +57,7 @@ class cliOrderSendTemplateMessage extends basecli
echo
"*** Debug mode ***
\n
"
;
}
// Step: 02 检查是否已有相同CLI在运行中
$lockDir
=
$this
->
_getBaseFileName
(
'order
SendTemplateMessage
'
);
$lockDir
=
$this
->
_getBaseFileName
(
'order'
);
if
(
!
$this
->
mkdirs
(
$lockDir
)){
echo
'****create dir fail ****'
;
exit
;
...
...
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