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
07f654ca
Commit
07f654ca
authored
Dec 28, 2018
by
wwccw0591
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
??
parent
91e1e913
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
179 additions
and
0 deletions
+179
-0
OrderConfirmUtil.php
application/library/Order/OrderConfirmUtil.php
+97
-0
MbWx.php
application/models/DAO/MbWx.php
+82
-0
No files found.
application/library/Order/OrderConfirmUtil.php
View file @
07f654ca
...
...
@@ -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
[]
=
$orderGoodsDao
[
'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,106 @@ class OrderConfirmUtil {
\Error\ErrorModel
::
throwException
(
\Error\CodeConfigModel
::
failedUpdateFavoritesStoreForOrder
);
}
$orderModel
->
db
->
doCommit
();
//订单通过小程序表单提交过来
if
(
$formId
&&
(
$access_token
=
$this
->
getLitAccesstoken
()))
{
$settingDAO
=
\DAO\SettingModel
::
getInstance
();
$wxapp_order_create_tpl
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_create_tpl'
))[
'wxapp_order_create_tpl'
];
$goods_str
=
''
;
if
(
count
(
$goods_datas
)
>
2
)
{
$goods_str
.=
$goods_datas
[
0
]
.
','
.
$goods_datas
[
1
]
.
'等'
.
count
(
$goods_datas
)
.
'个商品'
;
}
else
{
$goods_str
.=
implode
(
','
,
$goods_datas
);
}
$req_data
=
array
(
'touser'
=>
$this
->
member
[
'member_wxopenid'
],
'template_id'
=>
$wxapp_order_create_tpl
,
'form_id'
=>
$formId
,
'data'
=>
array
(
array
(
'keyword1'
=>
array
(
'value'
=>
'下单成功'
)),
array
(
'keyword2'
=>
array
(
'value'
=>
$order
[
'order_sn'
])),
array
(
'keyword3'
=>
array
(
'value'
=>
number_format
(
$order
[
'goods_amount'
]
/
100
,
2
))
.
'元'
),
array
(
'keyword4'
=>
array
(
'value'
=>
$storeCarts
[
'storeName'
])),
array
(
'keyword5'
=>
array
(
'value'
=>
$goods_str
)),
));
$url
=
'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='
;
$result
=
$this
->
sendurl
(
$url
,
$access_token
,
$req_data
,
'post'
);
}
$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'
]
=
time
()
+
$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/models/DAO/MbWx.php
0 → 100644
View file @
07f654ca
<?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
;
}
}
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