Commit 406b4311 authored by liuyuzhen's avatar liuyuzhen

Merge branch 'master_dev' of git.shenbd.com:qm-develop/shenbd into lyz_version1

parents d384db68 7922084f
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Order; namespace Order;
use Our\ApiConst; use Our\ApiConst;
use Our\RedisHelper; use Our\RedisHelper;
use Our\WechatCommon;
/** /**
...@@ -704,8 +705,11 @@ class OrderConfirmUtil { ...@@ -704,8 +705,11 @@ class OrderConfirmUtil {
\Error\ErrorModel::throwException(\Error\CodeConfigModel::failedUpdateFavoritesStoreForOrder); \Error\ErrorModel::throwException(\Error\CodeConfigModel::failedUpdateFavoritesStoreForOrder);
} }
$orderModel->db->doCommit(); $orderModel->db->doCommit();
$wechatCommon = WechatCommon::getInstance();
$access_token = $wechatCommon->getAccessToken();
//订单通过小程序表单提交过来 //订单通过小程序表单提交过来
if($formId && ($access_token = $this->getLitAccesstoken())) { if($formId && $access_token) {
$settingDAO = \DAO\SettingModel::getInstance(); $settingDAO = \DAO\SettingModel::getInstance();
$msg_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 = '';
...@@ -719,98 +723,24 @@ class OrderConfirmUtil { ...@@ -719,98 +723,24 @@ class OrderConfirmUtil {
$openid = $authInfo['openid']; $openid = $authInfo['openid'];
$req_data = array('touser'=>$openid, 'template_id'=> $msg_tpl, 'form_id'=>$formId, $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( 'data'=>array(
'keyword1'=>array('value'=>'下单成功'), 'keyword1'=>array('value'=>'下单成功'),
'keyword2'=>array('value'=>$order['order_sn']), 'keyword2'=>array('value'=> $order['order_sn']),
'keyword3'=>array('value'=>number_format($order['order_amount']/100, 2).'元'), 'keyword3'=>array('value'=> number_format($order['order_amount']/100, 2).'元'),
'keyword4'=>array('value'=>$order['store_name']), 'keyword4'=>array('value'=> $order['store_name']),
'keyword5'=>array('value'=>$goods_str), 'keyword5'=>array('value'=> $goods_str),
)); ));
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest'); // \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='; $json = $wechatCommon->sendTemplateMessage($access_token, $req_data);
$result = $this->sendurl($url, $access_token, json_encode($req_data), 'post'); // \Our\Log::getInstance()->write($json, '/data/log/apptest');
\Our\Log::getInstance()->write(var_export($result, true), '/data/log/apptest');
} }
$this->opCacheInfo(); $this->opCacheInfo();
$this->pushMessage(); $this->pushMessage();
return array('needPayFlag'=>$needPayFlag,'paySn'=>$paySn); 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(){ public function pushMessage(){
if($this->pushMessageOrders){ if($this->pushMessageOrders){
$orderService=\Business\Order\OrderServiceModel::getInstance(); $orderService=\Business\Order\OrderServiceModel::getInstance();
...@@ -1333,11 +1263,13 @@ class OrderConfirmUtil { ...@@ -1333,11 +1263,13 @@ class OrderConfirmUtil {
} }
$orderCon = array('pay_sn'=>$paySn,'order_state'=>array('in',array(\Our\ApiConst::orderStateWaitPay,ApiConst::orderStateCancel))); $orderCon = array('pay_sn'=>$paySn,'order_state'=>array('in',array(\Our\ApiConst::orderStateWaitPay,ApiConst::orderStateCancel)));
$orderList = $orderModel->getListByCon($orderCon,'order_id,coupon_id,buyer_id,store_id,order_sn'); $orderList = $orderModel->getListByCon($orderCon,'order_id,order_sn, store_name, buyer_id, order_amount, payment_time, order_state, prepay_id,coupon_id');
if(!$orderList){ if(!$orderList){
$errorCode = \Error\CodeConfigModel::noOrderListForPay; $errorCode = \Error\CodeConfigModel::noOrderListForPay;
return array('flag'=>\Our\ApiConst::zero,'errorCode'=>$errorCode,'data'=>$data); return array('flag'=>\Our\ApiConst::zero,'errorCode'=>$errorCode,'data'=>$data);
} }
$order = $orderList[0];
$order['payment_time'] = (isset($data['payment_time'])? strtotime($data['payment_time']) : TIMESTAMP);//更新付款时间
$memberId = $orderList[0]['buyer_id']; $memberId = $orderList[0]['buyer_id'];
$updateOrder = array(); $updateOrder = array();
$updateOrder['order_state'] = \Our\ApiConst::orderStateWaitConfirm; $updateOrder['order_state'] = \Our\ApiConst::orderStateWaitConfirm;
...@@ -1373,6 +1305,12 @@ class OrderConfirmUtil { ...@@ -1373,6 +1305,12 @@ class OrderConfirmUtil {
}*/ }*/
$orderModel->db->doCommit(); $orderModel->db->doCommit();
//支付支付成功微信小程序模板消息
$settingDAO = \DAO\SettingModel::getInstance();
$msg_tpl = $settingDAO->getListCache(array('wxapp_order_paysucc_tpl'))['wxapp_order_paysucc_tpl'];
\Business\Order\OrderServiceModel::getInstance()->sendPaymentMessage($order, $msg_tpl);
//发送订单消息
$this->deleteCacheInfo($memberId); $this->deleteCacheInfo($memberId);
$this->pushMessage(); $this->pushMessage();
return array('flag'=>\Our\ApiConst::one,'errorCode'=>$errorCode); return array('flag'=>\Our\ApiConst::one,'errorCode'=>$errorCode);
......
...@@ -94,7 +94,22 @@ class Common ...@@ -94,7 +94,22 @@ class Common
} }
return false; return false;
} }
public static function redisPublish($control,$method,$params){
//发布application.redis.redisPublishName
$conf = \Yaf\Registry::get('config')->get('redis.database.params');
$redisPublishName=\Yaf\Registry::get('config')->get('redis.redisPublishName');
$redis=new \Redis();
$redis->connect($conf['host'], $conf['port']);
if(!empty($conf['password'])){
$redis->auth($conf['password']);
}
$message['className']=$control;
$message['method']=$method;
$message['params']=$params;
$message=json_encode($message);
$ret=$redis->publish($redisPublishName,$message);
return $ret;
}
/** /**
* 获取客户端IP * 获取客户端IP
* *
......
...@@ -72,6 +72,21 @@ class WechatCommon ...@@ -72,6 +72,21 @@ class WechatCommon
return $jsonstr; 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) public function httpsPostJson($url, $data = '', $array = false)
{ {
...@@ -127,4 +142,4 @@ class WechatCommon ...@@ -127,4 +142,4 @@ class WechatCommon
return self::$_instance; return self::$_instance;
} }
} }
\ No newline at end of file
...@@ -145,4 +145,4 @@ class PaymentServiceModel extends \Business\AbstractModel{ ...@@ -145,4 +145,4 @@ class PaymentServiceModel extends \Business\AbstractModel{
return self::$_instance; return self::$_instance;
} }
} }
\ No newline at end of file
...@@ -49,12 +49,15 @@ class DiliverymanModel extends \DAO\AbstractModel ...@@ -49,12 +49,15 @@ class DiliverymanModel extends \DAO\AbstractModel
$data = $this->db->from($this->_tableName)->select($this->detailField)->where($where)->fetchOne(); $data = $this->db->from($this->_tableName)->select($this->detailField)->where($where)->fetchOne();
return $data; return $data;
} }
//任务脚本方法 //任务脚本方法
public function getListByMemberId($memberId) public function getListByMemberId($memberId,$isClient=false)
{ {
$this->setDb($this->dbName); $this->setDb($this->dbName);
$where['member_id']=$memberId; $where['member_id']=$memberId;
$where['is_del']=ApiConst::zero; if(!$isClient){
$where['is_del']=ApiConst::zero;
}
$where = $this->db->getSqlWhereByArray($where); $where = $this->db->getSqlWhereByArray($where);
$list = $this->db->select($this->detailField)->from($this->_tableName)->where($where)->fetchAll(); $list = $this->db->select($this->detailField)->from($this->_tableName)->where($where)->fetchAll();
return $list; return $list;
......
...@@ -12,6 +12,8 @@ application.dispatcher.catchException = true ...@@ -12,6 +12,8 @@ application.dispatcher.catchException = true
; Admin模块用于后台管理 ; Admin模块用于后台管理
application.modules = Index,Api,Admin,Client application.modules = Index,Api,Admin,Client
redis.redisPublishName='redisPublish';
[productone : common] [productone : common]
; 数据库配置 ; 数据库配置
resources.database.params.driver = "pdo_mysql" resources.database.params.driver = "pdo_mysql"
......
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
$redis = new Redis(); $redis = new Redis();
$redis->connect('192.168.1.201', 6379); $redis->connect('192.168.1.201', 6379);
$message='happy New Year'; $message='happy New Year';
$ret=$redis->publish('pushcenter',$message); $ret=$redis->publish('redisPublish',$message);
...@@ -57,7 +57,7 @@ class cliOrderSendTemplateMessage extends basecli ...@@ -57,7 +57,7 @@ class cliOrderSendTemplateMessage extends basecli
echo "*** Debug mode ***\n"; echo "*** Debug mode ***\n";
} }
// Step: 02 检查是否已有相同CLI在运行中 // Step: 02 检查是否已有相同CLI在运行中
$lockDir=$this->_getBaseFileName('orderSendTemplateMessage'); $lockDir=$this->_getBaseFileName('order');
if(!$this->mkdirs($lockDir)){ if(!$this->mkdirs($lockDir)){
echo '****create dir fail ****'; echo '****create dir fail ****';
exit; exit;
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
define("APPLICATION_PATH", realpath(dirname(__FILE__) . '/../../../')); //指向public的上一级 define("APPLICATION_PATH", realpath(dirname(__FILE__) . '/../../../')); //指向public的上一级
require_once APPLICATION_PATH . '/scripts/crontab/common.php'; require_once APPLICATION_PATH . '/scripts/crontab/common.php';
$conf = \Yaf\Registry::get('config')->get('redis.database.params'); $conf = \Yaf\Registry::get('config')->get('redis.database.params');
$http = new swoole_http_server("0.0.0.0", 9501); $http = new swoole_http_server("0.0.0.0", 9501);
$http->on('request', function ($request, $response) { $http->on('request', function ($request, $response) {
try{ try{
......
<?php
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 bridgeStart
{
/* config */
const LISTEN = "tcp://192.168.2.15:5555";
const MAXCONN = 100;
const pidfile = __CLASS__;
const uid = 81;
const gid = 81;
/**/
protected $pool = NULL;
protected $zmq = NULL;
public function __construct()
{
$this->pidfile = '/var/run/' . self::pidfile . '.pid';
}
private function daemon()
{
if (file_exists($this->pidfile)) {
echo "The file $this->pidfile exists.\n";
exit();
}
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// we are the parent
//pcntl_wait($status); //Protect against Zombie children
exit($pid);
} else {
// we are the child
file_put_contents($this->pidfile, getmypid());
posix_setuid(self::uid);
posix_setgid(self::gid);
return (getmypid());
}
}
public function callback($instance,$channelName,$message){
$orderService=\Business\Order\OrderServiceModel::getInstance();
$orderService->testPush($message);
}
protected function status(){
if (file_exists($this->pidfile)) {
$pid = file_get_contents($this->pidfile);
printf("%s already running, pid = %s\n", $this->argv[0], $pid);
}else{
printf("%s haven't running\n", $this->argv[0]);
}
}
private function start()
{
$pid = $this->daemon();
$conf = \Yaf\Registry::get('config')->get('redis.database.params');
$http = new swoole_http_server("0.0.0.0", 9501);
$http->on('request', function ($request, $response) {
try{
$respData=$request->post;
// echo json_encode($respData);
if(isset($respData['type'])&&$respData['type']==1){
$info=$respData['content'];
$memberDao=$info['className']::getInstance(\Our\DbNameConst::masterDBConnectName);
echo json_encode($info);
if(empty($info['params'])){
$res=call_user_func_array(array($memberDao,$info['method']),array());
}else{
$res=call_user_func_array(array($memberDao,$info['method']),$info['params']);
}
$res=(isset($res)&&!empty($res))?$res:false;
unset($memberDao);
\Mysql\LinkMySQLModel::unsetDbConecet();
if($res!==false){
echo 'success';
$response->end(json_encode(array('status'=>1,'message'=>'执行成功','data'=>$res)));
}else{
echo 'fail1';
$response->end(json_encode(array('status'=>0,'message'=>'执行失败')));
}
}else{
echo 'fail2';
$response->end(json_encode(array('status'=>0,'message'=>'执行失败')));
}
}catch(Exception $ex){
throw new Exception($ex->getMessage(),$ex->getCode());
}
});
$http->start();
}
private function reload(){
if (file_exists($this->pidfile)) {
$pid = file_get_contents($this->pidfile);
//posix_kill(posix_getpid(), SIGHUP);
posix_kill($pid, SIGHUP);
}
}
protected function restart(){
$this->stop();
sleep(1);
$this->start();
}
private function stop()
{
if (file_exists($this->pidfile)) {
$pid = file_get_contents($this->pidfile);
posix_kill($pid, 9);
unlink($this->pidfile);
}
}
private function help($proc)
{
printf("%s start | stop | help | restart | reload \n", $proc);
}
private $argv;
public function main($argv)
{
$this->argv=$argv;
if (count($argv) < 2) {
printf("please input help parameter\n");
exit();
}
if ($argv[1] === 'stop') {
$this->stop();
} else if ($argv[1] === 'start') {
$this->start();
} else if($argv[1] === 'restart'){
$this->restart();
}else if($argv[1] === 'status'){
$this->status();
}else if($argv[1]==='reload'){
$this->reload();
}
else{
$this->help($argv[0]);
}
}
}
$cgse = new bridgeStart();
$cgse->main($argv);
\ No newline at end of file
<?php
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);
//发布
//$conf = \Yaf\Registry::get('config')->get('redis.database.params');
//$redis=new Redis();
//$redis->connect($conf['host'], $conf['port']);
//if(!empty($conf['password'])){
// $redis->auth($conf['password']);
//}
//$message=array('abd','happy New Year');
//$message=json_encode($message);
//$ret=$redis->publish('redisPublish',$message);
\Our\Common::redisPublish('\Business\Order\OrderServiceModel','testPush',array('happy New Year'));
...@@ -24,5 +24,9 @@ function printTest($meg){ ...@@ -24,5 +24,9 @@ function printTest($meg){
echo $meg.'213'; echo $meg.'213';
} }
function callback($instance,$channelName,$message){ function callback($instance,$channelName,$message){
if($message=='outPid'){
$instance->unsubscribe(array($channelName));
return;
}
printTest($message); printTest($message);
} }
<?php
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 runRedisPush
{
/* config */
const LISTEN = "tcp://192.168.2.15:5555";
const MAXCONN = 100;
const pidfile = __CLASS__;
const uid = 80;
const gid = 80;
/**/
protected $pool = NULL;
protected $zmq = NULL;
public function __construct()
{
$this->pidfile = '/var/run/' . self::pidfile . '.pid';
}
private function daemon()
{
if (file_exists($this->pidfile)) {
echo "The file $this->pidfile exists.\n";
exit();
}
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// we are the parent
//pcntl_wait($status); //Protect against Zombie children
exit($pid);
} else {
// we are the child
file_put_contents($this->pidfile, getmypid());
posix_setuid(self::uid);
posix_setgid(self::gid);
return (getmypid());
}
}
public function callback($instance,$channelName,$message){
try{
$message=json_decode($message,true);
$callInstance=$message['className']::getInstance(\Our\DbNameConst::masterDBConnectName);
echo json_encode($message)."\r\n";
if(empty($message['params'])){
$res=call_user_func_array(array($callInstance,$message['method']),array());
}else{
$res=call_user_func_array(array($callInstance,$message['method']),$message['params']);
}
$res=(isset($res)&&!empty($res))?$res:false;
if($res!==false){
echo 'success'."\r\n";
}else{
echo 'fail1'."\r\n";
}
unset($callInstance);
\Mysql\LinkMySQLModel::unsetDbConecet();
}catch(Exception $ex){
echo $ex->getMessage();
}
// $orderService=\Business\Order\OrderServiceModel::getInstance();
// $orderService->testPush($message);
}
protected function status(){
if (file_exists($this->pidfile)) {
$pid = file_get_contents($this->pidfile);
printf("%s already running, pid = %s\n", $this->argv[0], $pid);
}else{
printf("%s haven't running\n", $this->argv[0]);
}
}
private function start()
{
$pid = $this->daemon();
$conf = \Yaf\Registry::get('config')->get('redis.database.params');
$redisPublishName=\Yaf\Registry::get('config')->get('redis.redisPublishName');
$redis=new Redis();
$redis->connect($conf['host'], $conf['port']);
if(!empty($conf['password'])){
$redis->auth($conf['password']);
}
//ini_set('default_socket_timeout', -1);(所有长连接不超时)
$redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
$result=$redis->subscribe(array($redisPublishName), array($this,'callback'));
}
private function reload(){
if (file_exists($this->pidfile)) {
$pid = file_get_contents($this->pidfile);
//posix_kill(posix_getpid(), SIGHUP);
posix_kill($pid, SIGHUP);
}
}
protected function restart(){
$this->stop();
$this->start();
}
private function stop()
{
if (file_exists($this->pidfile)) {
$pid = file_get_contents($this->pidfile);
posix_kill($pid, 9);
unlink($this->pidfile);
}
}
private function help($proc)
{
printf("%s start | stop | help | restart | reload \n", $proc);
}
private $argv;
public function main($argv)
{
$this->argv=$argv;
if (count($argv) < 2) {
printf("please input help parameter\n");
exit();
}
if ($argv[1] === 'stop') {
$this->stop();
} else if ($argv[1] === 'start') {
$this->start();
} else if($argv[1] === 'restart'){
$this->restart();
}else if($argv[1] === 'status'){
$this->status();
}else if($argv[1]==='reload'){
$this->reload();
}
else{
$this->help($argv[0]);
}
}
}
$cgse = new runRedisPush();
$cgse->main($argv);
\ No newline at end of file
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