WorkGroupChatStatisticServices.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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\services\work;
  12. use app\dao\work\WorkGroupChatStatisticDao;
  13. use app\services\BaseServices;
  14. /**
  15. * 群聊统计
  16. * Class WorkGroupChatStatisticServices
  17. * @package app\services\work
  18. * @mixin WorkGroupChatStatisticDao
  19. */
  20. class WorkGroupChatStatisticServices extends BaseServices
  21. {
  22. /**
  23. * WorkGroupChatServicesServices constructor.
  24. * @param WorkGroupChatStatisticDao $dao
  25. */
  26. public function __construct(WorkGroupChatStatisticDao $dao)
  27. {
  28. $this->dao = $dao;
  29. }
  30. /**
  31. * 保存或者修改
  32. * @param int $chatId
  33. * @param bool $todaySum
  34. * @param bool $todayReturnSum
  35. * @param int $chatSum
  36. * @param int $chatReturnSum
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function saveOrUpdate(int $chatId, bool $todaySum, bool $todayReturnSum, int $chatSum, int $chatReturnSum)
  42. {
  43. $info = $this->dao->getToDayInfo($chatId);
  44. if ($info) {
  45. if ($todaySum) {
  46. $info->today_sum++;
  47. }
  48. if ($todayReturnSum) {
  49. $info->today_return_sum++;
  50. }
  51. $info->chat_sum = $chatSum;
  52. $info->chat_return_sum = $chatReturnSum;
  53. $info->save();
  54. } else {
  55. $this->dao->save([
  56. 'group_id' => $chatId,
  57. 'today_sum' => $todaySum ? 1 : 0,
  58. 'today_return_sum' => $todayReturnSum ? 1 : 0,
  59. 'chat_sum' => $chatSum,
  60. 'chat_return_sum' => $chatReturnSum,
  61. ]);
  62. }
  63. }
  64. /**
  65. * 群统计列表
  66. * @param int $id
  67. * @param string $time
  68. * @return array
  69. */
  70. public function getChatStatisticsList(int $id, string $time)
  71. {
  72. [$page, $limit] = $this->getPageValue();
  73. $list = $this->dao->getDataList(['time' => $time, 'group_id' => $id], ['*'], $page, $limit);
  74. $count = $this->dao->count(['time' => $time, 'group_id' => $id]);
  75. return compact('list', 'count');
  76. }
  77. }