LiveGift.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\merchant\model\live;
  12. /**
  13. * 直播间礼物
  14. */
  15. use basic\ModelBasic;
  16. use traits\ModelTrait;
  17. class LiveGift extends ModelBasic
  18. {
  19. use ModelTrait;
  20. /**礼物列表
  21. * @return array
  22. * @throws \think\Exception
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. * @throws \think\exception\DbException
  26. */
  27. public static function liveGiftList()
  28. {
  29. $data = self::order('sort DESC,id DESC')->select();
  30. $data = count($data) ? $data->toArray() : [];
  31. foreach ($data as &$item) {
  32. $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  33. $item['live_gift_num'] = implode(',', json_decode($item['live_gift_num']));
  34. }
  35. $count = self::count();
  36. return compact('data', 'count');
  37. }
  38. /**
  39. * 单个礼物信息
  40. */
  41. public static function liveGiftOne($id)
  42. {
  43. $gift = self::where('id', $id)->find();
  44. if ($gift) return $gift;
  45. else return [];
  46. }
  47. }