Commit 2190bc54 authored by wwccw0591's avatar wwccw0591

upd

parent 07f654ca
...@@ -712,19 +712,19 @@ class OrderConfirmUtil { ...@@ -712,19 +712,19 @@ class OrderConfirmUtil {
//订单通过小程序表单提交过来 //订单通过小程序表单提交过来
if($formId && ($access_token = $this->getLitAccesstoken())) { if($formId && ($access_token = $this->getLitAccesstoken())) {
$settingDAO = \DAO\SettingModel::getInstance(); $settingDAO = \DAO\SettingModel::getInstance();
$wxapp_order_create_tpl = $settingDAO->getListCache(array('wxapp_order_create_tpl'))['wxapp_order_create_tpl']; $msg_tpl = $settingDAO->getListCache(array('wxapp_order_create_tpl'))['wxapp_order_create_tpl'];
$goods_str = ''; $goods_str = '';
if(count($goods_datas)>2) { if(count($goods_datas)>1) {
$goods_str .= $goods_datas[0].','.$goods_datas[1] . '等' .count($goods_datas).'个商品'; $goods_str .= $goods_datas[0].'等' .count($goods_datas).'个商品';
} else { } else {
$goods_str .= implode(',', $goods_datas); $goods_str .= $goods_datas[0];
} }
$req_data = array('touser'=>$this->member['member_wxopenid'], 'template_id'=> $wxapp_order_create_tpl, 'form_id'=>$formId, $req_data = array('touser'=>$this->member['member_wxopenid'], 'template_id'=> $msg_tpl, 'form_id'=>$formId,
'data'=>array( 'data'=>array(
array('keyword1'=>array('value'=>'下单成功')), array('keyword1'=>array('value'=>'下单成功')),
array('keyword2'=>array('value'=>$order['order_sn'])), array('keyword2'=>array('value'=>$order['order_sn'])),
array('keyword3'=>array('value'=>number_format($order['goods_amount']/100, 2)).'元'), array('keyword3'=>array('value'=>number_format($order['order_amount']/100, 2)).'元'),
array('keyword4'=>array('value'=>$storeCarts['storeName'])), array('keyword4'=>array('value'=>$order['store_name'])),
array('keyword5'=>array('value'=>$goods_str)), array('keyword5'=>array('value'=>$goods_str)),
)); ));
$url = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='; $url = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=';
......
...@@ -58,11 +58,133 @@ class OrderServiceModel extends \Business\AbstractModel ...@@ -58,11 +58,133 @@ class OrderServiceModel extends \Business\AbstractModel
return $this->orderGoodsField . ',goods_commonid as goodsCommonId,goods_commonid as goodsCommonid,goods_group as goodsGroup'; return $this->orderGoodsField . ',goods_commonid as goodsCommonId,goods_commonid as goodsCommonid,goods_group as goodsGroup';
} }
/**
* 获取小程序表单
* 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;
}
/**
* 发送模板消息
*
* User: King <358887571@qq.com>
* Date: 2018/12/28 0028
* Time: 上午 11:31
*/
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();
$where = array('msg_status'=>1, 'payment_type'=>1, 'order_state'=>array('gt',10), 'prepay_id'=> array('neq',
''));
$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'))) {
foreach ($list as $order) {
if($access_token && ($member = $model_member->getInfo(array('member_id'=>$order['buyer_id']), 'member_id,member_wxopenid'))){
$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'=>$this->member['member_wxopenid'], 'template_id'=> $msg_tpl,
'form_id'=> $order['prepay_id'],
'data'=>array(
array('keyword1'=>array('value'=>$order['order_sn'])),
array('keyword2'=>array('value'=>$order['store_name'])),
array('keyword3'=>array('value'=>$goods_str)),
array('keyword4'=>array('value'=>number_format($order['order_amount']/100, 2)).'元'),
array('keyword5'=>array('value'=>date('Y-m-d H:i',$order['payment_time']))),
array('keyword6'=>array('value'=>'已付款')),
));
$url = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=';
$result = $this->sendurl($url, $access_token, $req_data, 'post');
}
}
}
}
public function getOrderIndexWhere($memberId, $keyword, $pageIndex, $pageSize) public function getOrderIndexWhere($memberId, $keyword, $pageIndex, $pageSize)
{ {
// $query1= array('match' => array('buyerId' => $memberId)); // $query1= array('match' => array('buyerId' => $memberId));
// $res1['must']=$query1; // $res1['must']=$query1;
// // $query2[]= array('match' => array('orderSn' => $keyword")); // $query2[]= array('match' => array('orderSn' => $keyword"));
// $query2[]= array('match' => array('storeName' => $keyword)); // $query2[]= array('match' => array('storeName' => $keyword));
// $query2[]= array('match' => array('goodsName' => $keyword)); // $query2[]= array('match' => array('goodsName' => $keyword));
// $res1['should']=$query2; // $res1['should']=$query2;
......
...@@ -717,7 +717,7 @@ class OrderModel extends \DAO\AbstractModel ...@@ -717,7 +717,7 @@ class OrderModel extends \DAO\AbstractModel
} }
} }
return $refundStateName; return $refundStateName;
} }
......
<?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;
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment