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
57ee6f45
Commit
57ee6f45
authored
Dec 29, 2018
by
testshenbd
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'lyz' of git.shenbd.com:qm-develop/shenbd into master_dev
parents
d41c9158
a31db60a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
597 additions
and
16 deletions
+597
-16
OrderConfirmUtil.php
application/library/Order/OrderConfirmUtil.php
+104
-0
ArrayConst.php
application/library/Our/ArrayConst.php
+3
-2
GoodsClassService.php
application/models/Business/Goods/GoodsClassService.php
+2
-5
OrderService.php
application/models/Business/Order/OrderService.php
+224
-8
MbWx.php
application/models/DAO/MbWx.php
+80
-0
Order.php
application/models/DAO/Order/Order.php
+1
-1
ShortMessage.php
application/models/DAO/ShortMessage.php
+2
-0
closeSecond.php
scripts/crontab/order/closeSecond.php
+91
-0
sendTemplateMessage.php
scripts/crontab/order/sendTemplateMessage.php
+90
-0
No files found.
application/library/Order/OrderConfirmUtil.php
View file @
57ee6f45
...
...
@@ -517,6 +517,7 @@ class OrderConfirmUtil {
$giftCoupons
=
array
();
$this
->
pushMessageOrders
=
array
();
$storeDao
=
\DAO\StoreModel
::
getInstance
(
\Our\DbNameConst
::
masterDBConnectName
);
$goods_datas
=
array
();
//商品列表
foreach
(
$storeCartData
[
'cartList'
]
as
$storeId
=>
$storeCarts
){
$order
=
array
();
$order
[
'order_sn'
]
=
$this
->
makeOrderSn
(
$orderPayResult
);
...
...
@@ -629,6 +630,7 @@ class OrderConfirmUtil {
$orderGoods
[
'order_id'
]
=
$orderId
;
$orderGoods
[
'goods_id'
]
=
$storeCart
[
'goodsId'
];
$orderGoods
[
'goods_name'
]
=
$storeCart
[
'goodsName'
];
$goods_datas
[]
=
$orderGoods
[
'goods_name'
];
$orderGoods
[
'goods_num'
]
=
$storeCart
[
'goodsNum'
];
$orderGoods
[
'goods_image'
]
=
$storeCart
[
'goodsImagePath'
];
$orderGoods
[
'snapshot_id'
]
=
(
isset
(
$storeCarts
[
'snapshot_id'
])
&&
$storeCarts
[
'snapshot_id'
])
?
$storeCarts
[
'snapshot_id'
]
:
\our\ApiConst
::
zero
;
...
...
@@ -707,11 +709,113 @@ class OrderConfirmUtil {
\Error\ErrorModel
::
throwException
(
\Error\CodeConfigModel
::
failedUpdateFavoritesStoreForOrder
);
}
$orderModel
->
db
->
doCommit
();
//订单通过小程序表单提交过来
if
(
$formId
&&
(
$access_token
=
$this
->
getLitAccesstoken
()))
{
$settingDAO
=
\DAO\SettingModel
::
getInstance
();
$msg_tpl
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_create_tpl'
))[
'wxapp_order_create_tpl'
];
$goods_str
=
''
;
if
(
count
(
$goods_datas
)
>
1
)
{
$goods_str
.=
$goods_datas
[
0
]
.
'等'
.
count
(
$goods_datas
)
.
'个商品'
;
}
else
{
$goods_str
.=
$goods_datas
[
0
];
}
$sess
=
\Yaf\Session
::
getInstance
();
$authInfo
=
$sess
->
get
(
'wxAuthInfo'
);
$openid
=
$authInfo
[
'openid'
];
$req_data
=
array
(
'touser'
=>
$openid
,
'template_id'
=>
$msg_tpl
,
'form_id'
=>
$formId
,
'page'
=>
'pages/orders/list/index'
,
'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
),
));
// \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'
);
}
$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/ArrayConst.php
View file @
57ee6f45
...
...
@@ -82,10 +82,11 @@ class ArrayConst
//小程序账号
const
wechatInfo
=
array
(
'appid'
=>
'wxab22edc34913554b'
,
'secret'
=>
'
938b33cfa0bb756a7cbb1e2b454c99f
0'
,
'secret'
=>
'
63df6bf0bb37862893bde46e7db218d
0'
,
'grant_type'
=>
'authorization_code'
,
);
//卖家处理状态
const
sellerState
=
array
(
1
=>
'处理中'
,
...
...
@@ -169,4 +170,4 @@ class ArrayConst
\Our\ApiConst
::
plus
=>
'+'
,
\Our\ApiConst
::
set
=>
'='
);
}
\ No newline at end of file
}
application/models/Business/Goods/GoodsClassService.php
View file @
57ee6f45
...
...
@@ -82,7 +82,6 @@ class GoodsClassServiceModel extends \Business\AbstractModel{
if
(
$serviceStoreIds
&&
$signStoreIds
){
$serviceStoreIds
=
array_diff
(
$serviceStoreIds
,
$signStoreIds
);
}
$serviceParentClassIds
=
$this
->
getServiceStoreClasses
(
$serviceStoreIds
);
if
(
$serviceParentClassIds
){
$classIds
=
array_merge
(
$serviceParentClassIds
,
$classIds
);
...
...
@@ -202,9 +201,9 @@ class GoodsClassServiceModel extends \Business\AbstractModel{
$newStoreIds
=
array
();
foreach
(
$signStoreClasses
as
$signClass
){
$inAreaFlag
=
\Our\CommonExtension
::
locationInArea
(
$lat
,
$lng
,
$signClass
[
'sign_scope'
]);
$store
=
$storeList
[
$signClass
[
'store_id'
]];
//判断签约分类是否可以为当前用户提供服务,并且记录这些店铺对应的store_id
if
(
$inAreaFlag
){
$store
=
$storeList
[
$signClass
[
'store_id'
]];
if
(
$inAreaFlag
&&
$store
){
$class_distance
=
\Our\CommonExtension
::
getDistance
(
$lat
,
$lng
,
$store
[
'store_latitude'
],
$store
[
'store_latitude'
],
1
);
$class
=
$signClass
;
$class
[
'class_distance'
]
=
$class_distance
;
...
...
@@ -215,14 +214,12 @@ class GoodsClassServiceModel extends \Business\AbstractModel{
}
}
foreach
(
$returnClass
as
$key
=>
$class
){
$classDistance
[
$key
]
=
$class
[
'class_distance'
];
}
array_multisort
(
$classDistance
,
SORT_DESC
,
$returnClass
);
$signParentClassIds
=
array_unique
(
array_column
(
$returnClass
,
'gc_parent_id'
));
//$signStoreIds = array_unique(array_column($returnClass,'store_id'));
$signStoreIds
=
$newStoreIds
;
//将当前位置对应签约店铺存入缓存
...
...
application/models/Business/Order/OrderService.php
View file @
57ee6f45
This diff is collapsed.
Click to expand it.
application/models/DAO/MbWx.php
0 → 100644
View file @
57ee6f45
<?php
namespace
DAO
;
/**
* 微信公众号配置实体
* Class MbWxModel
* @package DAO
* User: King <358887571@qq.com>
* Date: 2018/12/27 0027
* Time: 下午 3:35
*
*/
class
MbWxModel
extends
\DAO\AbstractModel
{
/**
* 表名
*
* @var string
*/
protected
$_tableName
=
'han_mb_wx'
;
/**
* 主键
*
* @var string
*/
protected
$_primaryKey
=
'id'
;
public
function
init
(){
}
/**
* 获取记录
* @param $field 查询字段
* @param $where 查询条件
* @return mixed 记录数组
* User: King <358887571@qq.com>
* Date: 2018/12/27 0027
* Time: 下午 3:41
*/
public
function
getOne
(
$field
,
$where
){
$this
->
setDb
(
$this
->
dbName
);
return
$this
->
db
->
select
(
$field
)
->
from
(
$this
->
_tableName
)
->
where
(
$where
)
->
fetchOne
();
}
/**
* 更新记录
* @param $param 更新数据
* @param $where 更新条件
* @return mixed 操作结果
* User: King <358887571@qq.com>
* Date: 2018/12/27 0027
* Time: 下午 3:43
*/
public
function
update
(
$param
,
$where
){
$this
->
setDb
(
\Our\DbNameConst
::
masterDBConnectName
);
return
$this
->
db
->
update
(
$this
->
_tableName
)
->
rows
(
$param
)
->
where
(
$where
)
->
execute
();
}
/**
* 类实例
*
* @var \DAO\UserModel
*/
private
static
$_instance
=
null
;
/**
* 获取类实例
*
* @return \DAO\UserModel
*/
public
static
function
getInstance
(
$dbName
=
\Our\DbNameConst
::
salveDBConnectName
)
{
if
(
!
(
self
::
$_instance
instanceof
self
))
{
self
::
$_instance
=
new
self
(
$dbName
);
}
return
self
::
$_instance
;
}
}
application/models/DAO/Order/Order.php
View file @
57ee6f45
...
...
@@ -717,7 +717,7 @@ class OrderModel extends \DAO\AbstractModel
}
}
return
$refundStateName
;
}
...
...
application/models/DAO/ShortMessage.php
View file @
57ee6f45
...
...
@@ -99,9 +99,11 @@ class ShortMessageModel {
$templateId
=
$template
[
'templateId'
];
// $param = $template['parameters'];
$result
=
\AliyunSms\Sms
::
sendSms
(
$mobile
,
$templateId
,
$params
);
if
(
$result
[
'status'
]){
return
true
;
}
\Our\Log
::
getInstance
()
->
write
(
$result
[
'msg'
]);
}
return
false
;
}
...
...
scripts/crontab/order/closeSecond.php
0 → 100644
View file @
57ee6f45
<?php
/**
* 关闭订单
* 执行时间:每分钟执行一次
*
* @author chenjiebin <sjlinyu@qq.com>
*/
define
(
"APPLICATION_PATH"
,
realpath
(
dirname
(
__FILE__
)
.
'/../../../'
));
//指向public的上一级
require
APPLICATION_PATH
.
'/scripts/crontab/baseCli.php'
;
require
APPLICATION_PATH
.
'/scripts/crontab/common.php'
;
error_reporting
(
E_ALL
^
E_NOTICE
);
class
cliOrderClose
extends
basecli
{
const
CLI_ADMIN_ID
=
255
;
private
$bDoUnLock
=
FALSE
;
// 是否允许释放 LOCK 文件
private
$_debug
=
0
;
private
$lockFileName
;
private
$fromState
;
private
function
mkdirs
(
$dir
,
$mode
=
0777
)
{
if
(
is_dir
(
$dir
)
||
@
mkdir
(
$dir
,
$mode
)){
return
TRUE
;
}
if
(
!
$this
->
mkdirs
(
dirname
(
$dir
),
$mode
)){
return
FALSE
;
}
return
@
mkdir
(
$dir
,
$mode
);
}
/**
* 析构
*/
public
function
__destruct
()
{
parent
::
__destruct
();
if
(
$this
->
bDoUnLock
)
{
@
unlink
(
$this
->
lockFileName
);
}
}
protected
function
autoCloseOrder
(){
$orderService
=
\Business\Order\OrderServiceModel
::
getInstance
(
\Our\DbNameConst
::
masterDBConnectName
);
$orderService
->
baseDir
=
\Our\Common
::
getConfig
(
'out.config'
);
$orderService
->
changeOrderStatusSecond
();
$messageService
=
\Business\Message\MessageServiceModel
::
getInstance
(
\Our\DbNameConst
::
masterDBConnectName
);
$messageService
->
addMessageCenterToDb
();
}
protected
function
_runCli
()
{
$this
->
_debug
=
isset
(
$this
->
aArgv
[
1
])
?
intval
(
$this
->
aArgv
[
1
])
:
0
;
if
(
$this
->
_debug
)
{
echo
"*** Debug mode ***
\n
"
;
}
// Step: 02 检查是否已有相同CLI在运行中
$lockDir
=
$this
->
_getBaseFileName
(
'order'
);
if
(
!
$this
->
mkdirs
(
$lockDir
)){
echo
'****create dir fail ****'
;
exit
;
}
$this
->
lockFileName
=
$lockDir
.
DS
.
'close.locks'
;
if
(
file_exists
(
$this
->
lockFileName
)
)
{
$stat
=
stat
(
$this
->
lockFileName
);
if
(
(
TIMESTAMP
-
$stat
[
'mtime'
])
>
1800
)
{
echo
"文件被锁超过1800秒,被强制删除"
;
@
unlink
(
$this
->
lockFileName
);
}
else
{
$this
->
halt
(
'['
.
date
(
'Y-m-d H:i:s'
)
.
'] The CLI is running'
.
"
\n
"
);
}
}
$this
->
bDoUnLock
=
true
;
if
(
APP_ENV
==
'pre'
||
APP_ENV
==
'product'
){
file_put_contents
(
$this
->
lockFileName
,
"running"
);
// CLI 独占锁
}
$this
->
autoCloseOrder
();
echo
date
(
'Y-m-d H:i:s'
,
TIMESTAMP
)
.
'定单关闭消息成功'
.
"
\r\n
"
;
}
}
$oCli
=
new
cliOrderClose
(
TRUE
);
EXIT
;
?>
scripts/crontab/order/sendTemplateMessage.php
0 → 100644
View file @
57ee6f45
<?php
/**
* 自动确认收货
* 执行时间:每小时执行一次
*
* @author chenjiebin <sjlinyu@qq.com>
*/
define
(
"APPLICATION_PATH"
,
realpath
(
dirname
(
__FILE__
)
.
'/../../../'
));
//指向public的上一级
require
APPLICATION_PATH
.
'/scripts/crontab/baseCli.php'
;
require
APPLICATION_PATH
.
'/scripts/crontab/common.php'
;
error_reporting
(
E_ALL
^
E_NOTICE
);
class
cliOrderSendTemplateMessage
extends
basecli
{
const
CLI_ADMIN_ID
=
255
;
private
$bDoUnLock
=
FALSE
;
// 是否允许释放 LOCK 文件
private
$_debug
=
0
;
private
$lockFileName
;
private
$fromState
;
private
function
mkdirs
(
$dir
,
$mode
=
0777
)
{
if
(
is_dir
(
$dir
)
||
@
mkdir
(
$dir
,
$mode
)){
return
TRUE
;
}
if
(
!
$this
->
mkdirs
(
dirname
(
$dir
),
$mode
)){
return
FALSE
;
}
return
@
mkdir
(
$dir
,
$mode
);
}
/**
* 析构
*/
public
function
__destruct
()
{
parent
::
__destruct
();
if
(
$this
->
bDoUnLock
)
{
@
unlink
(
$this
->
lockFileName
);
}
}
private
function
autoSendMessage
(){
$service
=
\Business\Order\OrderServiceModel
::
getInstance
(
\Our\DbNameConst
::
masterDBConnectName
);
$service
->
baseDir
=
\Our\Common
::
getConfig
(
'out.config'
);
}
protected
function
_runCli
()
{
$this
->
fromState
=
$this
->
aArgv
[
1
];
$this
->
_debug
=
isset
(
$this
->
aArgv
[
1
])
?
intval
(
$this
->
aArgv
[
1
])
:
0
;
if
(
$this
->
_debug
)
{
echo
"*** Debug mode ***
\n
"
;
}
// Step: 02 检查是否已有相同CLI在运行中
$lockDir
=
$this
->
_getBaseFileName
(
'orderSendTemplateMessage'
);
if
(
!
$this
->
mkdirs
(
$lockDir
)){
echo
'****create dir fail ****'
;
exit
;
}
$this
->
lockFileName
=
$lockDir
.
'/orderSendTemplateMessage.locks'
;
if
(
file_exists
(
$this
->
lockFileName
)
)
{
$stat
=
stat
(
$this
->
lockFileName
);
if
(
(
TIMESTAMP
-
$stat
[
'mtime'
])
>
1800
)
{
echo
"文件被锁超过1800秒,被强制删除"
;
@
unlink
(
$this
->
lockFileName
);
}
else
{
$this
->
halt
(
'['
.
date
(
'Y-m-d H:i:s'
)
.
'] The CLI is running'
.
"
\n
"
);
}
}
$this
->
bDoUnLock
=
true
;
file_put_contents
(
$this
->
lockFileName
,
'running'
);
// CLI 独占锁
if
(
APP_ENV
==
'pre'
||
APP_ENV
==
'product'
){
file_put_contents
(
$this
->
lockFileName
,
"running"
);
// CLI 独占锁
}
$this
->
autoSendMessage
();
echo
date
(
'Y-m-d H:i:s'
,
TIMESTAMP
)
.
"订单消息通知成功
\r\n
"
;
}
}
$oCli
=
new
cliOrderConfirm
(
TRUE
);
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