Commit 7cda383a authored by zhz's avatar zhz

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

parents 114b81d5 7922084f
......@@ -1202,11 +1202,13 @@ class OrderConfirmUtil {
}
$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){
$errorCode = \Error\CodeConfigModel::noOrderListForPay;
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'];
$updateOrder = array();
$updateOrder['order_state'] = \Our\ApiConst::orderStateWaitConfirm;
......@@ -1242,6 +1244,12 @@ class OrderConfirmUtil {
}*/
$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->pushMessage();
return array('flag'=>\Our\ApiConst::one,'errorCode'=>$errorCode);
......
......@@ -94,7 +94,22 @@ class Common
}
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
*
......
......@@ -123,14 +123,16 @@ class OrderServiceModel extends \Business\AbstractModel
'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);
\Our\Log::getInstance()->write($order['order_id'].'payment'.json_encode($json), '/data/log/apptest');
if($json['errmsg']=='ok') {
$model->updateByOrderId(array('msg_status'=>2), $order['order_id']);
// echo 'order[' . $order['order_id'] .'] send payment succ'."\n";
return true;
}
}
return false;
}
public function sendShippingMessage($order, $msg_tpl) {
......@@ -174,9 +176,11 @@ class OrderServiceModel extends \Business\AbstractModel
if($json['errmsg']=='ok') {
$model->updateByOrderId(array('msg_status'=>3), $order['order_id']);
// echo 'order[' . $order['order_id'] .'] send shipping succ'."\n";
return true;
}
}
return false;
}
......@@ -230,9 +234,11 @@ class OrderServiceModel extends \Business\AbstractModel
if($json['errmsg']=='ok') {
$model->updateByOrderId(array('msg_status'=>4), $order['order_id']);
// echo 'order[' . $order['order_id'] .'] send reciver succ'."\n";
return true;
}
}
return false;
}
/**
......@@ -251,7 +257,7 @@ class OrderServiceModel extends \Business\AbstractModel
//付款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));
''), 'payment_time'=>array('between', TIMESTAMP-7*24*60*60, TIMESTAMP-10));
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'];
......@@ -286,6 +292,9 @@ class OrderServiceModel extends \Business\AbstractModel
echo ' order num: '.count($list['list'])."\n";
$msg_tpl = $wxapp_templates['wxapp_order_receive_tpl'];
foreach ($list['list'] as $order) {
if($order['shipping_type']==0) {
$order['send_time'] = $order['finnshed_time'];
}
$this->sendReceiveMessage($order, $msg_tpl);
}
}
......@@ -665,13 +674,17 @@ class OrderServiceModel extends \Business\AbstractModel
'orderId'=>$order['order_id']));
$push->addOneToClient($pushData);
$push->sendTcpMessage();
if($order['prepay_id'] != '') {
$order['finnshed_time'] =TIMESTAMP;
if($order['shipping_type']==0) {
$order['send_time'] =TIMESTAMP;
}
$settingDAO = \DAO\SettingModel::getInstance();
$wxapp_templates = $settingDAO->getListCache(array('wxapp_order_receive_tpl'));
$msg_tpl = $wxapp_templates['wxapp_order_receive_tpl'];
$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); //发送收货小程序模板消息
$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);
......@@ -687,7 +700,6 @@ class OrderServiceModel extends \Business\AbstractModel
public function getOrderExpressField()
{
return $this->orderField . ',shipping_html as shippingHtml,shipping_code as shippingCode,send_time as sendTime,shipping_sign as shippingSign,shipping_status as shippingStatus,shipping_arrival_time as shippingArrivalTime';
}
......@@ -1746,7 +1758,10 @@ class OrderServiceModel extends \Business\AbstractModel
}
return $order;
}
public function testPush($msg){
echo $msg.'abcde';
return true;
}
/**
* 类实例
*
......
......@@ -145,4 +145,4 @@ class PaymentServiceModel extends \Business\AbstractModel{
return self::$_instance;
}
}
\ No newline at end of file
}
......@@ -12,6 +12,8 @@ application.dispatcher.catchException = true
; Admin模块用于后台管理
application.modules = Index,Api,Admin,Client
redis.redisPublishName='redisPublish';
[productone : common]
; 数据库配置
resources.database.params.driver = "pdo_mysql"
......
......@@ -8,8 +8,6 @@
define("APPLICATION_PATH", realpath(dirname(__FILE__) . '/../../../')); //指向public的上一级
require_once APPLICATION_PATH . '/scripts/crontab/common.php';
$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{
......
<?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'));
......@@ -42,11 +42,43 @@ class runRedisPush
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'])){
......@@ -54,14 +86,20 @@ class runRedisPush
}
//ini_set('default_socket_timeout', -1);(所有长连接不超时)
$redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
$result=$redis->subscribe(array('redisPublish'), 'callback');
function printTest($meg){
echo $meg.'213';
}
function callback($instance,$channelName,$message){
printTest($message);
$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()
{
......@@ -75,11 +113,12 @@ class runRedisPush
private function help($proc)
{
printf("%s start | stop | help \n", $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();
......@@ -89,7 +128,14 @@ class runRedisPush
$this->stop();
} else if ($argv[1] === 'start') {
$this->start();
} else {
} 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]);
}
}
......
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