那個Timer::add里面的延遲時間能不能設(shè)置發(fā)貨后7天自動收貨的,會不會延時時間太長?而且要很多個用戶很多個物流訂單會不會堵塞?或者變成線程太多程序掛起不能運行?能不能做個demo給我?該怎么優(yōu)化和使用???
不用Redis吧,查詢7天前的數(shù)據(jù)訂單數(shù)據(jù)就可以了
Db::table('orders')->whereDate('CreateTime', date("Y-m-d",strtotime("-7 day")))->get();
這樣就可以查詢到7天前的數(shù)據(jù)列表了,然后再進(jìn)行邏輯處理就行了
如果是大數(shù)據(jù)的話,可以采用分塊處理
http://www.wtbis.cn/doc/webman/db/queries.html#%E5%88%86%E5%9D%97%E7%BB%93%E6%9E%9C
Db::table('orders')->whereDate('CreateTime', date("Y-m-d",strtotime("-7 day")))->chunkById(100, function ($orders) {
// Process the records...
return false;
});
<?php
namespace process;
use Workerman\Timer;
use app\model\Billing;
class AutoSign
{
public function onWorkerStart()
{
$timer = config('iot.time');
$Billing = new Billing;
Timer::add($timer, function() use ($Billing){
$time = time() - 3600 24 7;
$billingData = $Billing->where('createtime', '<', $time)->where('status', '未簽收')->select();
if(count($billingData) > 0) {
$billingData = $Billing->changeStatus($billingData);
}
});
}
}
用redis-queue插件 那個延遲投遞不就行了,發(fā)貨以后投遞數(shù)據(jù)
Redis::send($queue, $data, 延遲秒數(shù));