QappAddDeskTopService.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Modules\User\Services;
  3. use App\Consts\QuickConst;
  4. use App\Modules\SendOrder\Models\SendOrder;
  5. use App\Modules\User\Models\QappUserAddDesktopRealStats;
  6. use App\Modules\User\Models\User;
  7. class QappAddDeskTopService
  8. {
  9. /**
  10. * @param int $uid
  11. * @param string $field
  12. * @param int $num
  13. * @return bool
  14. */
  15. public static function incrAddDeskTop(int $uid, string $field, $num = 1): bool
  16. {
  17. myLog('incrAddDeskTop')->info('start', compact('uid', 'field'));
  18. // 参数判断
  19. if ($uid < 1 || $num < 1 ||
  20. !in_array($field, [QuickConst::FIELD_ADD_DESKTOP, QuickConst::FIELD_REGISTER], true)) {
  21. return false;
  22. }
  23. // 获取用户信息
  24. $user = User::getUser($uid);
  25. $sendOrderId = (int)getProp($user, 'send_order_id');
  26. $channelId = (int)getProp($user, 'distribution_channel_id');
  27. myLog('incrAddDeskTop')->info('user_data', compact('uid', 'sendOrderId', 'channelId'));
  28. if (empty($sendOrderId) || empty($channelId)) {
  29. return false;
  30. }
  31. // 获取渠道id
  32. $date = date('Y-m-d', SERVER_TIME);
  33. $realStat = QappUserAddDesktopRealStats::getDesktopRealStat($date, $sendOrderId);
  34. if (!$realStat) {
  35. // 初始化统计数据
  36. QappUserAddDesktopRealStats::insertDesktopRealStat([
  37. 'send_order_id' => $sendOrderId,
  38. 'distribution_channel_id' => $channelId,
  39. 'date' => $date,
  40. 'created_at' => date('Y-m-d H:i:s', SERVER_TIME),
  41. 'updated_at' => date('Y-m-d H:i:s', SERVER_TIME),
  42. ]);
  43. }
  44. // 增加计数
  45. myLog('incrAddDeskTop')->info('end', compact('date', 'sendOrderId', 'field', 'num'));
  46. return QappUserAddDesktopRealStats::incrDesktopRealStat($date, $sendOrderId, $field, $num);
  47. }
  48. }