使用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. 关于ssh登录出现异常警告:WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

    提示警告信息如下: arnold@WSN:~$ ssh 10.18.46.111 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ...

  2. 阿里云maven仓库配置

    1.在maven的setting.xml配置文件中<mirrors>标签下添加以下配置 <mirror> <id>nexus-aliyun</id> & ...

  3. vim+makefile入门编辑,编译,差错实例

    vim+makefile入门编辑,编译,差错实例 vim makefile 编译 编写代码,一般在vim中编辑完后,输入:wq,在命令行下输入g++ hello.cc -o hello ,出现问题,打 ...

  4. Linux CentOs集群LVS+Keepalived负载均衡的实现

    准备工作 环境:Win10下Centos6.4虚拟机. 负载均衡:两台(一主一备)  LVS + Keepalived. HTTP服务器:3台. 给每台服务器配置IP 1.VIP(virtual ip ...

  5. UVA - 12333 字典树+大数

    思路:用字典树将前40个数字记录下来,模拟大数加法即可. AC代码 #include <cstdio> #include <cmath> #include <algori ...

  6. java网络编程(7)——利用tcp实现文件上传

    其实客户端与服务端通讯的道理都是一样的,都是通过输入与输出这两个流,那么实现文件上传也就是同样的,客户端把文件读到文件流,服务端用文件流来接受,然后写到一个文件中,这样子就实现了文件上传,文件拷贝也是 ...

  7. UVA - 12186 Another Crisis (树形DP)

    思路:dp[i]表示让上司i签字至少需要多少工人签字.       转移方程:将i的所有节点根据所需工人数量升序排序,设i需要k个下属签字,dp[i] = sum{dp[v]| 0 <= v & ...

  8. SIFT解析(三)生成特征描述子

    以上两篇文章中检测在DOG空间中稳定的特征点,lowe已经提到这些特征点是比Harris角点等特征还要稳定的特征.下一步骤我们要考虑的就是如何去很好地描述这些DOG特征点. 下面好好说说如何来描述这些 ...

  9. Luogu P1757 通天之分组背包

    题目背景 直达通天路·小A历险记第二篇 题目描述 自01背包问世之后,小A对此深感兴趣.一天,小A去远游,却发现他的背包不同于01背包,他的物品大致可分为k组,每组中的物品相互冲突,现在,他想知道最大 ...

  10. HTML入门标签汇总

    HTML入门标签汇总 1.<div></div>用于定义文档的区块,用来划分出独立不同的部分. 2.<h1></h1>数字1-6定义从大到小的标题. 3 ...