使用cache实现一个简单粗糙的订单推送队列

Linux  定时任务

* * * * * /usr/bin/curl  http://tc.m.com/test.php

/**
* User: [一秋]
* Date: 2017/9/18
* Time: 上午8:56
* Desc: 成功来源于点滴
*/ namespace app\api\service; //订单队列
use app\api\model\Order; class OrderQueue
{
private $order_queue;
private $key;
private $expire_time = 60; public $orderid; public function __construct()
{
$this->key = 'your key value';
$this->order_queue = $this->queryNotReceiveOrder();
} //查询未接订单
private function queryNotReceiveOrder()
{
$data = cache($this->key); if (!$data) {
$lists = Order::with('receiveOrder')
->field('orderid')
->order('ctime desc')
->where('orderstatus', '=', 2)->page(1, 10)
->select(); $data = [];
foreach ($lists as $key => $val) {
if ($val->receive_order == null) {
$data[] = $val->orderid;
}
} if (!empty($data)) { cache($this->key, $data, $this->expire_time); } } return $data;
} //有新的订单 添加到队列中
public function pushToQueue()
{ if (!$this->orderid) {
return true;
} if ($this->order_queue) { array_unshift($this->order_queue, $this->orderid); } else {
$this->order_queue = ["$this->orderid"];
}
$this->order_queue = $this->array_unique(); cache($this->key, $this->order_queue, $this->expire_time); return true; } //从订单队列中拉取数据 推送
public function pullFromQueue()
{ if ($this->order_queue) {
//提取第一个数据
// $first_orderid = array_shift($this->order_queue);
// Order::placeOrderGetuiList($first_orderid);
//推送完毕 存放到数组最后
// array_push($this->order_queue, $first_orderid); foreach ($this->order_queue as $key=>$val){
Order::placeOrderGetuiList($val);//推送订单。
sleep(10);
} // cache($this->key) ? cache($this->key, null) : true; }
return true;
} //从订单队列中 移除
public function clearOneOrder(){ if($this->order_queue){
$key = array_search($this->orderid,$this->order_queue);
if(!$key && $key != 0){
return true;
}
unset($this->order_queue[$key]);
cache($this->key,$this->order_queue,$this->expire_time);
} return true; } //数组去重
private function array_unique(){
return array_unique($this->order_queue);
} public function pushToList($order_arr){ if(!is_array($order_arr)){
return true;
}
foreach ($order_arr as $key=>$val){
$this->orderid = $val;
$this->pushToQueue();
}
return true;
} }

cache 订单队列 - TP5的更多相关文章

  1. 消息队列第二篇:MessageQueue实战(课程订单)

    上一篇:消息队列介绍 本篇一开始就上代码,主要演练MessageQueue的实际应用.用户提交订单(消息发送),系统将订单发送到订单队列(Order Queue)中:订单管理系统(消息接收)端,监听消 ...

  2. MyBatis源码分析(3)—— Cache接口以及实现

    @(MyBatis)[Cache] MyBatis源码分析--Cache接口以及实现 Cache接口 MyBatis中的Cache以SPI实现,给需要集成其它Cache或者自定义Cache提供了接口. ...

  3. Azure Messaging-ServiceBus Messaging消息队列技术系列3-消息顺序保证

    上一篇:Window Azure ServiceBus Messaging消息队列技术系列2-编程SDK入门  http://www.cnblogs.com/tianqing/p/5944573.ht ...

  4. springboot~rabbitmq的队列初始化和绑定

    配置文件,在rabbit中自动建立exchange,queue和绑定它们的关系 代码里初始化exchange 代码里初始化queue 代码里绑定exchange,queue和routekey 配置文件 ...

  5. PHP 消息队列 详解

    前言:之前做过的一些项目中有时候会接触到消息队列,但是对消息队列并没有一个很清楚的认知,本篇文章将会详细分析和归纳一些笔记,以供后续学习. 一.消息对列概念 从本质上说消息对列就是一个队列结构的中间件 ...

  6. PHP消息队列实现及应用

    目前对消息队列并不了解其原理,本篇文章主要是通过慕课网学习归纳的一些笔记,为后续学习打下基础. 众所周知在对网站设计的时候,会遇到给用户“群发短信”,“订单系统有大量的日志”,“秒杀设计”等,服务器没 ...

  7. php调用Redis队列使用例子

    1.Controller顶部引入use think\Queue; 2.Controller调用Redis任务 // 1.当前任务将由哪个类来负责处理. $job = 'app\api\job\Resu ...

  8. PHP消息队列实现及应用_慕课网学习

    https://blog.csdn.net/d_g_h/article/details/79643714 https://blog.csdn.net/tTU1EvLDeLFq5btqiK/articl ...

  9. PHP消息队列学习

    在我们平常网站设计时,会遇到“给用户群发短信”,“商城订单系统大批量订单处理”,“商城秒杀活动”等需求,这些功能,都有一个共同的特点:就是在面对高迸发的同时,必须要保证系统处理数据的有效性.那么如何处 ...

随机推荐

  1. 【ZOJ2760】How Many Shortest Path

    How Many Shortest Path 标签: 网络流 描述 Given a weighted directed graph, we define the shortest path as th ...

  2. JAVA死锁

    死锁是这样一种情形:多个线程同时被阻塞,它们中的一个或者全部都在等待某个资源被释放.由于线程被无限期地阻塞,因此程序不能正常运行. 简单的说就是:线程死锁时,第一个线程等待第二个线程释放资源,而同时第 ...

  3. 二、Item Pipeline和Spider-----基于scrapy取校花网的信息

    Item Pipeline 当Item在Spider中被收集之后,它将会被传递到Item Pipeline,这些Item Pipeline组件按定义的顺序处理Item. 每个Item Pipeline ...

  4. IE兼容swiper

    swiper3能完美运用在移动端,但是运用在PC端,特别是IE浏览器上不能兼容,没有效果,要使IE兼容Swiper的话必须使用swiper2,也就是idangerous.swiper.js, 下载地址 ...

  5. Bootstrap表单验证

    主要用过两个: jqBootstrapValidation: https://github.com/ReactiveRaven/jqBootstrapValidation bootstrapValid ...

  6. 常见JedisConnectionException异常分析

    异常内容:我看了很多人的博客,千篇一律都是说redis.conf文件的配置问题,发现并不能解决我的问题,今天写这个博客讲解一下我的解决办法: 遇到这个问题第一步:查看虚拟机的防火墙是否关闭,测试方法就 ...

  7. JDBC编程流程以及详细代码

    加载驱动 打开连接 执行查询 处理结果 清理环境 import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Co ...

  8. 计蒜客 数字解码 dp

    思路:dp(i)表示前i个字符的解码方案种数.进行状态转移时需要仔细思考,分情况讨论: 设第i个字符和第i-1个字符组成的数为x. 1.如果x根本不可能出现说明不是合理的编码,直接使dp(i)为0,例 ...

  9. hdu1556 Color the ball 线段树区间染色问题

    都是老套路了,如果n=5,要把区间[1,4]染色,可以递归去染区间[1,3]和区间[4,4],如果区间相等就自加,不相等继续递归寻找对应区间. 打印结果时,把所有到达叶节点包含i的区间值相加,就是最后 ...

  10. 决策树-C4.5算法(三)

    在上述两篇的文章中主要讲述了决策树的基础,但是在实际的应用中经常用到C4.5算法,C4.5算法是以ID3算法为基础,他在ID3算法上做了如下的改进: 1) 用信息增益率来选择属性,克服了用信息增益选择 ...