今日总结 – yii2在redis增加短信

// 发送短信(加入短信队列并记录短信记录)
// todo 下方队列代码需要改进,应该增加一个专门的队列扩展,这里为了快速实现,先直接用redis的操作写在这里。
/** @var Connection $redis */
$redis = \Yii::$app->get('redis');
if($redis)
{
    $redis->executeCommand('lpush', ['order_sms', Json::encode([
        'sms_id' => $this->action->sms_id,
        'phone' => $this->order->user->phone,
        'sms_data' => $this->getSmsData()
    ])]); // 左边进,右边出。lpush rpop
    // 取出方法 $redis->executeCommand('rpop', ['order_sms']);
}

// 在短信记录表增加短信记录
$sms = new OrderSms();
$sms->order_id = $this->order_id;
$sms->flow_id = $this->flow_id;
$sms->flow_node_id = $this->node_id;
$sms->flow_action_id = $this->action_id;
$sms->content = $this->getPreviewSms();
$sms->phone = $this->order->user->phone;
$sms->clerk_id = $record->clerk_id;
$sms->clerk_name = $record->clerk_name;
$sms->created_at = $record->created_at;
$sms->save(false);

正文完