使用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. 关于ruby -gem无法切换淘宝源

    ruby官网提供的 淘宝的gem源 不起作用 https://ruby.taobao.org/ taobao Gems 源已停止维护,现由 ruby-china 提供镜像服务 http://gems. ...

  2. Shiro笔记--shiroFilter权限过滤

    1.shiro中shiroFilter中的一些配置页面的过滤权限 <!--名字必须和web.xml里面的filter-name一样--> <bean id="shiroFi ...

  3. 高并发关于微博、秒杀抢单等应用场景在PHP环境下结合Redis队列延迟入库

    第一步:创建模拟数据表. CREATE TABLE `test_table` ( `id` int(11) NOT NULL AUTO_INCREMENT, `uid` int(11) NOT NUL ...

  4. Samba服务器的安装与配置

    Samba服务器主要的功能是实现本地windows系统下方便读写局域网内虚拟机下的文件: Samba与window连接需要使用NetBIOS协议,请确认你的Windows系统已经安装了NetBIOS协 ...

  5. HDU - 3391 C - Mahjong

    题意:如果摸到的14张麻将,可以组成4副三张麻将连续或者相同的,以及两个一样的就能获胜. 思路:直接暴力枚举每种可以摸到的牌型,用dfs判断当前拿到的14张牌型能否获胜. 如果搜索时不优化会超时,如果 ...

  6. POJ - 2251 bfs [kuangbin带你飞]专题一

    立体bfs,共有六个方向: const int dx[] = {0,0,1,-1,0,0}; const int dy[] = {1,-1,0,0,0,0}; const int dz[] = {0, ...

  7. mysql命令汇总

    1.mysql新增.删除用户和权限分配 查看用户及权限 mysql>use mysql mysql>select * from user\G; 新增用户 mysql>insert i ...

  8. R-CNN算法概要

    参考论文:Rich feature hierarchies for accurate object detection and semantic segmentation 下载地址:https://a ...

  9. 通用的Android控件抖动效果实现

    这个小程序的功能在实际的开发中会用到,比如:设置Button左右晃动,或者上下的晃动效果,下面就给出示例代码. 首先:要定义一个xml文件,命名为Shake [html] view plain cop ...

  10. mxnet:结合R与GPU加速深度学习

    转载于统计之都,http://cos.name/tag/dmlc/,作者陈天奇 ------------------------------------------------------------ ...