NoticeLogic.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\logic;
  20. use app\common\enum\DistributionConfigEnum;
  21. use app\common\enum\NoticeEnum;
  22. use app\common\logic\BaseLogic;
  23. use app\common\model\Config;
  24. use app\common\model\DistributionConfig;
  25. use app\common\model\Notice;
  26. use app\common\service\ConfigService;
  27. use app\common\service\FileService;
  28. /**
  29. * 通知逻辑
  30. * Class NoticeLogic
  31. * @package app\shopapi\logic
  32. */
  33. class NoticeLogic extends BaseLogic
  34. {
  35. /**
  36. * @notes 消息通知
  37. * @param $userId
  38. * @return array
  39. * @author Tab
  40. * @date 2021/8/25 10:26
  41. */
  42. public static function index($userId)
  43. {
  44. // 最新系统消息
  45. $system = Notice::where('scene_id', '<>', NoticeEnum::EARNINGS_NOTICE)
  46. ->where(['user_id' => $userId, 'send_type' => NoticeEnum::SYSTEM])
  47. ->order('id desc')
  48. ->findOrEmpty()->toArray();
  49. $system_notice_icon = ConfigService::get('default_image', 'system_notice_icon');
  50. $system_notice_icon = FileService::getFileUrl($system_notice_icon);
  51. $data['system'] = [
  52. 'title' => '系统通知',
  53. 'content' => $system['content'] ?? '暂无系统消息',
  54. 'img' => $system_notice_icon,
  55. 'type' => 'system',
  56. ];
  57. // 最新收益通知
  58. $dbConfig = DistributionConfig::column('value', 'key');
  59. $switch = $dbConfig['switch'] ?? DistributionConfigEnum::DEFAULT_SWITCH;
  60. if ($switch == 1) {
  61. $earnings = Notice::where('scene_id', '=',NoticeEnum::EARNINGS_NOTICE)
  62. ->where(['user_id' => $userId, 'send_type' => NoticeEnum::SYSTEM])
  63. ->order('id desc')
  64. ->findOrEmpty()->toArray();
  65. }
  66. if ($switch == 1) {
  67. $earnings_notice_icon = ConfigService::get('default_image', 'earnings_notice_icon');
  68. $earnings_notice_icon = FileService::getFileUrl($earnings_notice_icon);
  69. $data['earnings'] = [
  70. 'title' => '收益通知',
  71. 'content' => $earnings['content'] ?? '暂无收益消息',
  72. 'img' => $earnings_notice_icon,
  73. 'type' => 'earnings',
  74. ];
  75. }
  76. return array_values($data);
  77. }
  78. }