| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace common\components\rabbitmq;
- use bizHd\birthday\classes\BirthdayGiftClass;
- use common\components\noticeUtil;
- use mikemadisonweb\rabbitmq\components\ConsumerInterface;
- use PhpAmqpLib\Message\AMQPMessage;
- class birthdayGiftConsumer extends baseConsumer
- {
- public function execute(AMQPMessage $msg)
- {
- try {
- $this->ensureDbConnection();
- $data = unserialize($msg->body);
- if (!is_array($data)) {
- noticeUtil::push("生日赠礼消费者报错:Invalid message format");
- return ConsumerInterface::MSG_REJECT;
- }
- $type = $data['type'] ?? null;
- $result = false;
- if ($type == 'birthday_gift_expire') {
- $giftId = intval($data['giftId'] ?? 0);
- $result = $this->runWithDbReconnect(function () use ($giftId) {
- return BirthdayGiftClass::expireById($giftId);
- });
- } else {
- noticeUtil::push("生日赠礼消费者未知 type: {$type}");
- $result = true;
- }
- return $result ? ConsumerInterface::MSG_ACK : ConsumerInterface::MSG_ACK;
- } catch (\Exception $e) {
- noticeUtil::push("生日赠礼消费者报错:" . $e->getMessage());
- return ConsumerInterface::MSG_ACK;
- }
- }
- }
|