AutoUpdateLive.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\listener\acitivty;
  12. use app\services\activity\live\LiveGoodsServices;
  13. use app\services\activity\live\LiveRoomServices;
  14. use crmeb\utils\Cron;
  15. use crmeb\interfaces\ListenerInterface;
  16. use think\facade\Log;
  17. /**
  18. * 自动更新直播间状态和直播间产品状态
  19. * Class AutoUpdateLive
  20. * @package app\listener\order
  21. */
  22. class AutoUpdateLive extends Cron implements ListenerInterface
  23. {
  24. /**
  25. * @param $event
  26. */
  27. public function handle($event): void
  28. {
  29. //自动更新直播间状态和直播间产品状态
  30. $this->tick(1000 * 60, function () {
  31. //更新直播商品状态
  32. try {
  33. /** @var LiveGoodsServices $liveGoods */
  34. $liveGoods = app()->make(LiveGoodsServices::class);
  35. $liveGoods->syncGoodStatus();
  36. } catch (\Throwable $e) {
  37. Log::error('更新直播商品状态失败,失败原因:[' . class_basename($this) . ']' . $e->getMessage());
  38. }
  39. //更新直播间状态
  40. try {
  41. /** @var LiveRoomServices $liveRoom */
  42. $liveRoom = app()->make(LiveRoomServices::class);
  43. $liveRoom->syncRoomStatus();
  44. } catch (\Throwable $e) {
  45. Log::error('更新直播间状态失败,失败原因:[' . class_basename($this) . ']' . $e->getMessage());
  46. }
  47. return true;
  48. });
  49. }
  50. }