使用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. LCA—倍增法求解

    LCA(Least Common Ancestors) 即最近公共祖先,是指在有根树中,找出某两个结点u和v最近的公共祖先. 常见解法一般有三种 这里讲解一种在线算法-倍增 首先我们定义fa[u][j ...

  2. 深入分析Java ClassLoader的原理(转)

    一.什么是ClassLoader? 大家都知道,当我们写好一个Java程序之后,不是管是CS还是BS应用,都是由若干个.class文件组织而成的一个完整的Java应用程序,当程序在运行时,即会调用该程 ...

  3. SpringMvc笔记-对RESTFUL风格的配置

    1.@RequestMapping注解可以使用如下参数: 1,params:例如params={'username',"age!=100"}表示需要usernmame并且age 属 ...

  4. mac下使用mysql控制台命令行

    命令行中输入 open .bash_profile 然后将 alias mysql=/usr/local/mysql/bin/mysqlalias mysqladmin=/usr/local/mysq ...

  5. sphinx初识

    sphinx(SQL Phrase Index),查询词组索引. 定义:Sphinx是一个全文检索引擎. 特性: 1.高速索引 (在新款CPU上,近10 MB/秒); 2.高速搜索 (2-4G的文本量 ...

  6. Mybatis认识

    MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis .iB ...

  7. DataCleaner第一章

    Part1. Introduction to DataCleaner 介绍DataCleaner |--What is data quality(DQ) 数据质量? |--What is data p ...

  8. Hi3531 SDK 安装以及升级使用说明

    Hi3531 SDK 安装以及升级使用说明 第一章 Hi3531_SDK_Vx.x.x.x版本升级操作说明    如果您是首次安装本SDK,请直接参看第2章.     第二章 首次安装SDK 1.Hi ...

  9. 获取NVIDIA显卡的温度

    NVIDIA显卡在硬件上有温度传感器,可以感知显卡的运行环境.温度数据的获取,一般是通过调用NVIDIA的SDK的相关函数即可.SDK的下载的网址(https://developer.nvidia.c ...

  10. HighCharts之2D柱状图、折线图的组合双轴图

    HighCharts之2D柱状图.折线图的组合双轴图 1.实例源码 DoubleAxis.html: <!DOCTYPE html> <html> <head> & ...