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 @@
namespace Order;
use Our\ApiConst;
use Our\RedisHelper;
use Our\WechatCommon;
/**
......@@ -704,8 +705,11 @@ class OrderConfirmUtil {
\Error\ErrorModel::throwException(\Error\CodeConfigModel::failedUpdateFavoritesStoreForOrder);
}
$orderModel->db->doCommit();
$wechatCommon = WechatCommon::getInstance();
$access_token = $wechatCommon->getAccessToken();
//订单通过小程序表单提交过来
if($formId && ($access_token = $this->getLitAccesstoken())) {
if($formId && $access_token) {
$settingDAO = \DAO\SettingModel::getInstance();
$msg_tpl = $settingDAO->getListCache(array('wxapp_order_create_tpl'))['wxapp_order_create_tpl'];
$goods_str = '';
......@@ -719,98 +723,24 @@ class OrderConfirmUtil {
$openid = $authInfo['openid'];
$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(
'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),
'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');
$json = $wechatCommon->sendTemplateMessage($access_token, $req_data);
// \Our\Log::getInstance()->write($json, '/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();
......@@ -1333,11 +1263,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;
......@@ -1373,6 +1305,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
*
......
......@@ -72,6 +72,21 @@ class WechatCommon
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)
{
......
......@@ -2,6 +2,7 @@
namespace Business\Order;
use Business\Store\StoreServiceModel;
use DAO\Order\OrderCommonModel;
use Error\CodeConfigModel;
use Error\ErrorModel;
......@@ -17,6 +18,7 @@ use Our\NameConst;
use Our\PageConst;
use Our\Push;
use Our\RedisHelper;
use Our\WechatCommon;
/**
* 店铺service
......@@ -75,7 +77,7 @@ class OrderServiceModel extends \Business\AbstractModel
$update_data = array();
$update_data['lit_accesstoken'] = $access_info['access_token'];
$update_data['lit_expirestime'] = time() + $access_info['expires_in'] - 1800;
$update_data['lit_expirestime'] = TIMESTAMP + $access_info['expires_in'] - 1800;
$where = array('id' => $weixin['id']);
$result = $model_wx->update($update_data, $where);
......@@ -87,107 +89,216 @@ class OrderServiceModel extends \Business\AbstractModel
}
/**
* curl请求
* @param $url
* @param $access_token
* @param $data
* @param $method
* 发送付款消息
* @param $order
* @param $msg_tpl
* User: King <358887571@qq.com>
* Date: 2019/1/3 0003
* Time: 上午 11:01
*/
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);
public function sendPaymentMessage($order, $msg_tpl) {
$model = \DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
$model_member = \DAO\MemberModel::getInstance(DbNameConst::salveDBConnectName);
$model_order_goods = \DAO\Order\OrderGoodsModel::getInstance(DbNameConst::salveDBConnectName);
$wechatCommon = WechatCommon::getInstance();
$access_token = $wechatCommon->getAccessToken();
if($access_token && ($member = $model_member->getOneByMemberId($order['buyer_id'], array('member_id', 'member_wxappopenid')
))) {
$where = array('order_id'=>$order['order_id']);
$goods_datas = $model_order_goods->getOrderGoods($where, 'order_id, goods_name');
$goods_str = '';
if(count($goods_datas)>1) {
$goods_str .= $goods_datas[0]['goods_name'].'等' .count($goods_datas).'件商品';
} else {
$curl = curl_init($url.$access_token);
$goods_str .= $goods_datas[0]['goods_name'];
}
$req_data = array('touser'=>$member['member_wxappopenid'], 'template_id'=> $msg_tpl,
'form_id'=> $order['prepay_id'],
'page'=> 'pages/orders/detail/index?id='.$order['order_id'],
'data'=>array(
'keyword1'=>array('value'=>$order['order_sn']),
'keyword2'=>array('value'=>$order['store_name']),
'keyword3'=>array('value'=>$goods_str),
'keyword4'=>array('value'=>number_format($order['order_amount']/100, 2).'元'),
'keyword5'=>array('value'=>date('Y-m-d H:i',$order['payment_time'])),
'keyword6'=>array('value'=>'已付款'),
));
$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;
}
if($header){
//设置头部信息
curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
public function sendShippingMessage($order, $msg_tpl) {
$model = \DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
$model_member = \DAO\MemberModel::getInstance(DbNameConst::salveDBConnectName);
$model_order_goods = \DAO\Order\OrderGoodsModel::getInstance(DbNameConst::salveDBConnectName);
$wechatCommon = WechatCommon::getInstance();
$access_token = $wechatCommon->getAccessToken();
$common_model = \DAO\Order\OrderCommonModel::getInstance();
if($access_token && ($member = $model_member->getOneByMemberId($order['buyer_id'], array('member_id', 'member_wxappopenid')
))) {
$sub_data = $common_model->findByOrderId($order['order_id'], 'reciver_name, reciver_info');
$address = '';
if($sub_data['reciver_info']) {
$reciver_info = unserialize($sub_data['reciver_info']);
$address = $reciver_info['address'].$reciver_info['subaddress'];
}
//$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);
$where = array('order_id'=>$order['order_id']);
$goods_datas = $model_order_goods->getOrderGoods($where, 'order_id, goods_name');
$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'=>$member['member_wxappopenid'], 'template_id'=> $msg_tpl,
'form_id'=> $order['prepay_id'],
'page'=> 'pages/orders/detail/index?id='.$order['order_id'],
'data'=>array(
'keyword1'=>array('value'=>date('Y-m-d H:i', $order['add_time'])),
'keyword2'=>array('value'=>date('Y-m-d H:i', $order['send_time'])),
'keyword3'=>array('value'=>$order['order_sn']),
'keyword4'=>array('value'=>$address),
'keyword5'=>array('value'=>$order['store_name']),
'keyword6'=>array('value'=>$goods_str),
'keyword7'=>array('value'=>number_format($order['order_amount']/100, 2).'元'),
));
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
$json = $wechatCommon->sendTemplateMessage($access_token, $req_data);
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;
//开始事务
$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()
{
public function sendReceiveMessage($order, $msg_tpl) {
$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'=>array('elt', 1), 'payment_type'=>5, 'order_state'=>array('gt',10), 'prepay_id'=>
array('neq',
''), 'payment_time'=>array('gt', TIMESTAMP-7*24*60*60));
$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'))) {
echo 'order num: '.count($list)."\n";
foreach ($list as $order) {
if($access_token && ($member = $model_member->getOneByMemberId($order['buyer_id'], 'member_id,member_wxappopenid'))){
$wechatCommon = WechatCommon::getInstance();
$access_token = $wechatCommon->getAccessToken();
$store_model = \DAO\StoreModel::getInstance();
if($access_token && ($member = $model_member->getOneByMemberId($order['buyer_id'], array('member_id', 'member_wxappopenid')
))) {
$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).'个商品';
$goods_str .= $goods_datas[0]['goods_name'].'等' .count($goods_datas).'件商品';
} else {
$goods_str .= $goods_datas[0]['goods_name'];
}
$store_data = $store_model->getFieldsInfo(array('store_id'=>$order['store_id']), 'store_phone');
$shipping_type = '';
switch ($order['shipping_type']) {
case 1:
$shipping_type .= '商家配送';
break;
case 2:
$shipping_type .= '快递配送';
break;
default:
$shipping_type .= '到店自提';
break;
}
$req_data = array('touser'=>$member['member_wxappopenid'], 'template_id'=> $msg_tpl,
'form_id'=> $order['prepay_id'],
'page'=> 'pages/orders/detail/index?id='.$order['order_id'],
'data'=>array(
'keyword1'=>array('value'=>$order['order_sn']),
'keyword2'=>array('value'=>$order['store_name']),
'keyword3'=>array('value'=>$goods_str),
'keyword4'=>array('value'=>number_format($order['order_amount']/100, 2).'元'),
'keyword5'=>array('value'=>date('Y-m-d H:i',$order['payment_time'])),
'keyword6'=>array('value'=>'已付款'),
'keyword2'=>array('value'=>date('Y-m-d H:i', $order['send_time'])),
'keyword3'=>array('value'=>date('Y-m-d H:i', $order['finnshed_time'])),
'keyword4'=>array('value'=>$order['store_name']),
'keyword5'=>array('value'=>$store_data['store_phone']),
'keyword6'=>array('value'=>$goods_str),
'keyword7'=>array('value'=>number_format($order['order_amount']/100, 2).'元'),
'keyword8'=>array('value'=>$shipping_type),
'keyword9'=>array('value'=>'您购买的商品已被签收,如不是您本人签收,请尽快联系商家'),
));
\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=';
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
if($result = $this->sendurl($url, $access_token, json_encode($req_data), 'post')) {
$json = json_decode($result, true);
$json = $wechatCommon->sendTemplateMessage($access_token, $req_data);
if($json['errmsg']=='ok') {
$model->updateByOrderId(array('msg_status'=>1), $order['order_id']);
echo 'order[' . $order['order_id'] .'] send payment succ'."\n";
$model->updateByOrderId(array('msg_status'=>4), $order['order_id']);
// echo 'order[' . $order['order_id'] .'] send reciver succ'."\n";
return true;
}
}
return false;
}
/**
* 发送模板消息
*
* User: King <358887571@qq.com>
* Date: 2018/12/28 0028
* Time: 上午 11:31
*/
public function sendTemplateMessage()
{
$model = \DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
$settingDAO = \DAO\SettingModel::getInstance();
$wxapp_templates = $settingDAO->getListCache(array('wxapp_order_paysucc_tpl', 'wxapp_order_shipping_tpl', 'wxapp_order_receive_tpl'));
//付款7天内付款消息通知
$where = array('msg_status'=>array('elt', 1), 'payment_type'=>5, 'order_state'=>array('egt',20), 'prepay_id'=>
array('neq',
''), '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'];
foreach ($list['list'] as $order) {
// \Our\Log::getInstance()->write('order:'.json_encode($order), '/data/log/apptest');
$this->sendPaymentMessage($order, $msg_tpl);
}
}
echo "do payment\n";
//付款7天内订单发货通知
$where = array('msg_status'=>2, 'payment_type'=>5, 'shipping_type'=> array('in', array(1, 2)), 'order_state'=>
array('egt', 30), 'prepay_id'=>
array('neq',
''), 'payment_time'=>array('gt', TIMESTAMP-7*24*60*60), 'send_time'=>array('lt',
TIMESTAMP-10));
if($list = $model->getList($where, 'order_id,order_sn,store_id,store_name,buyer_id,order_amount,add_time, send_time, order_state, prepay_id', 0, 10, array('send_time'=>'asc'))) {
echo ' order num: '.count($list['list'])."\n";
$msg_tpl = $wxapp_templates['wxapp_order_shipping_tpl'];
foreach ($list['list'] as $order) {
// \Our\Log::getInstance()->write('order:'.json_encode($order), '/data/log/apptest');
$this->sendShippingMessage($order, $msg_tpl);
}
}
echo "do shipping\n";
//付款7天内订单确认收货通知
$where = array('msg_status'=>3, 'payment_type'=>5, 'order_state'=>
array('egt', 40), 'prepay_id'=>
array('neq',
''), 'payment_time'=>array('gt', TIMESTAMP-7*24*60*60), 'finnshed_time' => array('lt', TIMESTAMP-15));
if($list = $model->getList($where, 'order_id,order_sn,store_id,store_name,buyer_id, shipping_type,order_amount,add_time, send_time, finnshed_time, order_state, prepay_id', 0, 10, array('finnshed_time'=>'asc'))) {
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);
}
}
echo "do reciver\n";
}
......@@ -481,12 +592,13 @@ class OrderServiceModel extends \Business\AbstractModel
//$orderGoodsUpdateData['refund_state_name']='退款成功';
$orderGoodsUpdateData['is_refund']=ApiConst::refundSuccess;
$orderGoodsDao->update($where,$orderGoodsUpdateData);
$orderDao->db->doCommit();
}else{
$orderDao->db->doRollback();
ErrorModel::throwException(CodeConfigModel::cancelRefundMoneyError);
}
}
$orderDao->db->doCommit();
$push=\Our\Push::getInstance();
$pushData=array('storeId'=>$order['storeId'],
'type'=>ApiConst::messageWaitReceive,
......@@ -562,6 +674,18 @@ 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'];
$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);
$storeDao->deleteStoreCache($order['storeId'],$order['orderId']);
......@@ -576,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';
}
......@@ -887,12 +1010,12 @@ class OrderServiceModel extends \Business\AbstractModel
$orderDao->db->doRollback();
continue;
}
}
array_push($orderIds,$order['orderId']);
$this->updateOrderGoodsStoregeByOrderIds($orderIds);
array_push($newOrders,$order);
$orderIds=array();
$orderDao->db->doCommit();
}
$orderDao->deleteOrderCache($order['buyerId'],(string)$order['orderId'],$order['storeId'],true);
$storeDao->deleteStoreCache($order['storeId'],$order['orderId']);
$push=\Our\Push::getInstance();
......@@ -965,12 +1088,12 @@ class OrderServiceModel extends \Business\AbstractModel
$orderDao->db->doRollback();
continue;
}
}
array_push($orderIds,$order['orderId']);
$this->updateOrderGoodsStoregeByOrderIds($orderIds);
array_push($newOrders,$order);
$orderIds=array();
$orderDao->db->doCommit();
}
$orderDao->deleteOrderCache($order['buyerId'],(string)$order['orderId'],$order['storeId'],true);
$storeDao->deleteStoreCache($order['storeId'],$order['orderId']);
$push=\Our\Push::getInstance();
......@@ -1168,7 +1291,7 @@ class OrderServiceModel extends \Business\AbstractModel
$orderCommonDao = \DAO\Order\OrderCommonModel::getInstance(DbNameConst::salveDBConnectName);
$refundReturnDao=\DAO\Order\RefundReturnModel::getInstance(DbNameConst::salveDBConnectName);
$memberDao = \DAO\MemberModel::getInstance(DbNameConst::salveDBConnectName);
$qmMans=$qmDeliveryMan->getListByMemberId($memberId);
$qmMans=$qmDeliveryMan->getListByMemberId($memberId,true);
$diliverymanIds=array_column($qmMans,'id');
$diliverymanId = $memberDao->getInfo($memberId, 'diliveryman_id');
if (empty($diliverymanIds)) {
......@@ -1256,7 +1379,7 @@ class OrderServiceModel extends \Business\AbstractModel
$returnData['totalCount'] = $orders['totalCount'];
return $returnData;
} else {
return new \stdClass();
return array('orders'=>array(),'totalCount'=>ApiConst::zero);
}
}
......@@ -1635,7 +1758,10 @@ class OrderServiceModel extends \Business\AbstractModel
}
return $order;
}
public function testPush($msg){
echo $msg.'abcde';
return true;
}
/**
* 类实例
*
......
......@@ -49,12 +49,15 @@ class DiliverymanModel extends \DAO\AbstractModel
$data = $this->db->from($this->_tableName)->select($this->detailField)->where($where)->fetchOne();
return $data;
}
//任务脚本方法
public function getListByMemberId($memberId)
public function getListByMemberId($memberId,$isClient=false)
{
$this->setDb($this->dbName);
$where['member_id']=$memberId;
if(!$isClient){
$where['is_del']=ApiConst::zero;
}
$where = $this->db->getSqlWhereByArray($where);
$list = $this->db->select($this->detailField)->from($this->_tableName)->where($where)->fetchAll();
return $list;
......
......@@ -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"
......
......@@ -3,4 +3,4 @@
$redis = new Redis();
$redis->connect('192.168.1.201', 6379);
$message='happy New Year';
$ret=$redis->publish('pushcenter',$message);
$ret=$redis->publish('redisPublish',$message);
......@@ -57,7 +57,7 @@ class cliOrderSendTemplateMessage extends basecli
echo "*** Debug mode ***\n";
}
// Step: 02 检查是否已有相同CLI在运行中
$lockDir=$this->_getBaseFileName('orderSendTemplateMessage');
$lockDir=$this->_getBaseFileName('order');
if(!$this->mkdirs($lockDir)){
echo '****create dir fail ****';
exit;
......
......@@ -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'));
......@@ -24,5 +24,9 @@ function printTest($meg){
echo $meg.'213';
}
function callback($instance,$channelName,$message){
if($message=='outPid'){
$instance->unsubscribe(array($channelName));
return;
}
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