🎈 perf(wpfw模块,小程序订单提交): 添加推送job,使用queue来推送信息
添加推送的job,优化queue。部署需开启php-cil来运行插件目录下的queue.php
This commit is contained in:
parent
7c7b977ab7
commit
a9f43c4546
@ -12,7 +12,7 @@ class Receiver extends WeModuleReceiver {
|
||||
//redis 防止并发
|
||||
$open_redis = function_exists('redis') && !is_error(redis());
|
||||
$redis_key = "receive_".$this->message['from'];
|
||||
// $file_key = __DIR__."/{$this->message['from']}.json";
|
||||
//$file_key = __DIR__."/{$this->message['from']}.json";
|
||||
if($open_redis){
|
||||
$redis = redis();
|
||||
if($redis->get($redis_key)){
|
||||
|
115
core/job/posttoe.php
Normal file
115
core/job/posttoe.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
namespace core\job;
|
||||
|
||||
class posttoe
|
||||
{
|
||||
|
||||
public $order_id;
|
||||
public $_W;
|
||||
public $order_sn;
|
||||
public $order_info;
|
||||
public $timestamp;
|
||||
|
||||
public function __construct($config = array())
|
||||
{
|
||||
if (!empty($config)){
|
||||
foreach ($config as $name => $value) {
|
||||
$this->$name = $value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送测试
|
||||
public function test_post_e()
|
||||
{
|
||||
global $_W;
|
||||
if (is_file(EWEI_SHOPV2_CORE . 'queue.pid')) {
|
||||
require __DIR__ . '/../../core/job/posttoe.php';
|
||||
queue_push(
|
||||
new core\job\posttoe(
|
||||
array(
|
||||
'_W' => array(
|
||||
'uniacid' => $_W['uniacid'],
|
||||
'acid' => $_W['acid'],
|
||||
'siteroot' => $_W['siteroot'],
|
||||
'sitescheme' => $_W['sitescheme'],
|
||||
'siteurl' => $_W['siteurl'],
|
||||
'attachurl' => $_W['attachurl'],
|
||||
'ispost' => $_W['ispost'],
|
||||
'isajax' => $_W['isajax'],
|
||||
'setting' => $_W['setting'],
|
||||
'config' => $_W['config']
|
||||
),
|
||||
'order_id' => $order_id,
|
||||
'order_sn' => $order_sn,
|
||||
'order_info'=>$order_info,
|
||||
'timestamp' => TIMESTAMP
|
||||
)
|
||||
)
|
||||
);
|
||||
}else{
|
||||
$res = m('wpfw')->order_post($order_id,$order_sn);
|
||||
die(json_encode($res));
|
||||
}
|
||||
}
|
||||
*/
|
||||
public function execute($queue)
|
||||
{
|
||||
global $_W;
|
||||
$_W = $this->_W;
|
||||
$order_id = $this->order_id;
|
||||
$order_sn = $this->order_sn;
|
||||
$order_info = $this->order_info;
|
||||
|
||||
$logfile = IA_ROOT . "/data/log/poste.log";
|
||||
echo date('Y-m-d H:i:s').' 开始推送任务,订单:'.$order_id.' 派发:'.date('Y-m-d H:i:s',$this->timestamp).PHP_EOL;
|
||||
file_put_contents($logfile, date('Y-m-d H:i:s').'开始推送任务'.PHP_EOL,FILE_APPEND);
|
||||
file_put_contents($logfile, json_encode($this,JSON_UNESCAPED_UNICODE).PHP_EOL,FILE_APPEND);
|
||||
|
||||
if($order_info['error'] != 0){
|
||||
file_put_contents($logfile, '参数错误,未找到订单!'.PHP_EOL,FILE_APPEND);
|
||||
return array('msg' => "参数错误,未找到订单!", 'error' => 552001, 'status' => 552001);
|
||||
}
|
||||
//保存推送结果
|
||||
$data = array();
|
||||
//todo:订单的商品
|
||||
$goods = $order_info['order']['goods'];
|
||||
if(empty($goods)){
|
||||
file_put_contents($logfile, '参数错误,未找到订单下的商品!'.PHP_EOL,FILE_APPEND);
|
||||
return array('msg' => "参数错误,未找到订单下的商品!", 'error' => 552001, 'status' => 552001);
|
||||
}
|
||||
$set = [];
|
||||
foreach($goods as $item){
|
||||
$gset = m('wpfw')->good_get_wpset($item['id']);
|
||||
if(empty($set['wpfw_url']) && $gset['open_wpfw'] > 0 && empty($set['wpfw_url'])){
|
||||
$set = $gset;
|
||||
}
|
||||
}
|
||||
if(empty($set['wpfw_url']) || $set['open_wpfw'] == 0){
|
||||
file_put_contents($logfile, '订单的推送url为空或不支持推送!'.PHP_EOL,FILE_APPEND);
|
||||
return array('msg' => "订单的推送url为空或不支持推送!", 'error' => 552001, 'status' => 552001);
|
||||
}
|
||||
$info = json_encode($order_info['order']);
|
||||
$to_data = m('wpfw')->generateSign(array('order'=>$info),$set['wpfw_api_key']);
|
||||
$request = ihttp_post($set['wpfw_url'],$to_data);
|
||||
|
||||
|
||||
if(!empty($request['errno'])){
|
||||
file_put_contents($logfile, '推送失败 (errno:'.$request['errno'].' message: ' . $request['message'] . ')'.PHP_EOL,FILE_APPEND);
|
||||
return array('status' => $request['errno'], 'message' => '推送失败 (errno:'.$request['errno'].' message: ' . $request['message'] . ')');
|
||||
}
|
||||
$result = json_decode($request['content'], true);
|
||||
if ($request['code'] != 200) {
|
||||
$result['message'] = $request['headers']['X-Ca-Error-Message'];
|
||||
$result['message'] = $request['message'];
|
||||
file_put_contents($logfile, '推送失败(错误信息: ' . $result['message'] . ')'.PHP_EOL,FILE_APPEND);
|
||||
return array('status' => 0, 'message' => '推送失败(错误信息: ' . $result['message'] . ')');
|
||||
}else{
|
||||
file_put_contents($logfile, '推送成功'.PHP_EOL,FILE_APPEND);
|
||||
return array('status' => 1, 'message' => '推送成功');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ class sendPoster
|
||||
$_W = $this->_W;
|
||||
$openid = $this->openid;
|
||||
$content = $this->content;
|
||||
//用户
|
||||
//用户
|
||||
if(empty($openid)){
|
||||
return;
|
||||
}
|
||||
@ -78,13 +78,13 @@ class sendPoster
|
||||
$waittext = str_replace('"','\"',$waittext);
|
||||
m('message')->sendCustomNotice($openid, $waittext);
|
||||
|
||||
//获取二维码图片
|
||||
//获取二维码图片
|
||||
$qr = p('poster')->getQR($poster, $member, $goodsid);
|
||||
if (is_error($qr)) {
|
||||
m('message')->sendCustomNotice($openid, '生成二维码出错: ' . $qr['message']);
|
||||
return;
|
||||
}
|
||||
//生成海报
|
||||
//生成海报
|
||||
$img = p('poster')->createPoster($poster, $member, $qr);
|
||||
|
||||
$mediaid = $img['mediaid'];
|
||||
|
@ -143,10 +143,12 @@ class Wpfw_EweiShopV2Model {
|
||||
/**
|
||||
* 获取商品详情
|
||||
*/
|
||||
public function get_order_info($order_id = null, $order_sn = null)
|
||||
public function get_order_info($order_id = null, $order_sn = null,$uniacid=0)
|
||||
{
|
||||
global $_W, $_GPC;
|
||||
$uniacid = $_W['uniacid'];
|
||||
if(intval($uniacid) == 0){
|
||||
$uniacid = $_W['uniacid'];
|
||||
}
|
||||
if (empty($order_id) && empty($order_sn)) {
|
||||
return array('msg' => "参数错误,订单号或ID为空!", 'error' => 552000);
|
||||
}
|
||||
@ -182,7 +184,7 @@ class Wpfw_EweiShopV2Model {
|
||||
$diyformfields = ",og.diyformfields,og.diyformdata";
|
||||
}
|
||||
$param = array();
|
||||
$param[':uniacid'] = $_W['uniacid'];
|
||||
$param[':uniacid'] = $uniacid;
|
||||
if ($order['isparent'] == 1) {
|
||||
$scondition = " og.parentorderid=:parentorderid";
|
||||
$param[':parentorderid'] = $orderid;
|
||||
|
1
core/queue.pid
Normal file
1
core/queue.pid
Normal file
@ -0,0 +1 @@
|
||||
19472
|
@ -8,7 +8,7 @@
|
||||
* TEL: 4000097827/18661772381/15865546761
|
||||
*/
|
||||
|
||||
use function Qiniu\json_decode;
|
||||
|
||||
|
||||
if (!defined('IN_IA')) {
|
||||
exit('Access Denied');
|
||||
@ -926,11 +926,36 @@ class Op_EweiShopV2Page extends WebPage {
|
||||
$opdata = $this->opData();
|
||||
extract($opdata);
|
||||
|
||||
$res = m('wpfw')->order_post($id);
|
||||
//var_dump($res);
|
||||
//show_json(1);
|
||||
die(json_encode($res));
|
||||
//die(json_decode($ret));
|
||||
if (is_file(EWEI_SHOPV2_CORE . 'queue.pid')) {
|
||||
require dirname(__DIR__) . "/../../defines.php";
|
||||
require dirname(__DIR__) . '/../../core/job/posttoe.php';
|
||||
$order_info = m('wpfw')->get_order_info($id);
|
||||
queue_push(
|
||||
new core\job\posttoe(
|
||||
array(
|
||||
'_W' => array(
|
||||
'uniacid' => $_W['uniacid'],
|
||||
'acid' => $_W['acid'],
|
||||
'siteroot' => $_W['siteroot'],
|
||||
'sitescheme' => $_W['sitescheme'],
|
||||
'siteurl' => $_W['siteurl'],
|
||||
'attachurl' => $_W['attachurl'],
|
||||
'ispost' => $_W['ispost'],
|
||||
'isajax' => $_W['isajax'],
|
||||
'setting' => $_W['setting'],
|
||||
'config' => $_W['config']
|
||||
),
|
||||
'order_id' => $id,
|
||||
'order_sn' => '',
|
||||
'order_info'=>$order_info,
|
||||
'timestamp' => TIMESTAMP
|
||||
)
|
||||
)
|
||||
);
|
||||
}else{
|
||||
$res = m('wpfw')->order_post($id);
|
||||
die(json_encode($res));
|
||||
}
|
||||
}
|
||||
function diyformdata() {
|
||||
global $_W, $_GPC;
|
||||
|
@ -1054,6 +1054,7 @@ class Index_EweiShopV2Page extends WebPage {
|
||||
|
||||
function notice_redis(){
|
||||
global $_W,$_GPC;
|
||||
//phpinfo();die;
|
||||
m('common') -> updateSysset(array('notice_redis' => array('notice_redis_click'=>1)));
|
||||
if($_W['ispost']){
|
||||
ca('sysset.note_redis.edit');
|
||||
|
@ -2523,10 +2523,7 @@ class Create_EweiShopV2Page extends AppMobilePage {
|
||||
global $_W, $_GPC;
|
||||
$openid = $_W['openid'];
|
||||
$uniacid = $_W['uniacid'];
|
||||
// if (empty($_SESSION['order_token'])) {
|
||||
// show_json(-1,'不要短时间重复下订单!');
|
||||
// }
|
||||
// unset($_SESSION['order_token']);
|
||||
|
||||
//会员
|
||||
$member = m('member')->getMember($openid);
|
||||
//是黑名单
|
||||
@ -2536,10 +2533,6 @@ class Create_EweiShopV2Page extends AppMobilePage {
|
||||
if (p('quick') && !empty($_GPC['fromquick'])) {
|
||||
$_GPC['fromcart'] = 0;
|
||||
}
|
||||
// 验证是否必须绑定手机
|
||||
// if(!empty($_W['shopset']['wap']['open']) && !empty($_W['shopset']['wap']['mustbind']) && empty($member['mobileverify'])){
|
||||
// show_json(0, array('message'=>"请先绑定手机", 'url'=>mobileUrl('member/bind', null, true)));
|
||||
// }
|
||||
|
||||
//允许参加优惠
|
||||
$allow_sale = true;
|
||||
@ -4031,6 +4024,36 @@ class Create_EweiShopV2Page extends AppMobilePage {
|
||||
}
|
||||
}
|
||||
unset($_SESSION[$openid."_order_create"]);
|
||||
//todo:小程序订单提交后推送到e
|
||||
if (is_file(EWEI_SHOPV2_CORE . 'queue.pid')) {
|
||||
require EWEI_SHOPV2_CORE . "/../defines.php";
|
||||
require EWEI_SHOPV2_CORE . '/job/posttoe.php';
|
||||
$order_info = m('wpfw')->get_order_info($orderid);
|
||||
queue_push(
|
||||
new core\job\posttoe(
|
||||
array(
|
||||
'_W' => array(
|
||||
'uniacid' => $_W['uniacid'],
|
||||
'acid' => $_W['acid'],
|
||||
'siteroot' => $_W['siteroot'],
|
||||
'sitescheme' => $_W['sitescheme'],
|
||||
'siteurl' => $_W['siteurl'],
|
||||
'attachurl' => $_W['attachurl'],
|
||||
'ispost' => $_W['ispost'],
|
||||
'isajax' => $_W['isajax'],
|
||||
'setting' => $_W['setting'],
|
||||
'config' => $_W['config']
|
||||
),
|
||||
'order_id' => $orderid,
|
||||
'order_sn' => '',
|
||||
'order_info'=>$order_info,
|
||||
'timestamp' => TIMESTAMP
|
||||
)
|
||||
)
|
||||
);
|
||||
}else{
|
||||
$res = m('wpfw')->order_post($id);
|
||||
}
|
||||
return app_json(array("orderid" => $orderid, "has_sub_account" => $hasSubAccount, "is_merch" => $ismerch, "order_count" => count($merch_array)));
|
||||
}
|
||||
|
||||
|
12
we.cnp5.cn_T5a2BF.code-workspace
Normal file
12
we.cnp5.cn_T5a2BF.code-workspace
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "../.."
|
||||
},
|
||||
{
|
||||
"name": "ewei_shopv2 @ eebdf69",
|
||||
"uri": "gitlens://7b22726566223a2265656264663639616237353464336461666563396161663732346466663632323331653739303731222c227265706f50617468223a22643a2f77652e636e70352e636e5f5435613242462f6164646f6e732f657765695f73686f707632227d/d:/we.cnp5.cn_T5a2BF/addons/ewei_shopv2?{\"ref\":\"eebdf69\"}"
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user