You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Constants\v3\OrderState;
  4. use App\Constants\v3\OrderType;
  5. use App\Model\v3\Order;
  6. use App\Model\v3\OrderMain;
  7. use App\Service\v3\Interfaces\UserServiceInterface;
  8. class UserService implements UserServiceInterface
  9. {
  10. /**
  11. * 是否平台新用户
  12. * 在很多奖励的地方会需要用到这个查询
  13. * 判定条件:
  14. * 没有在平台下过单(包括线上和线下)
  15. * @param $userId
  16. * @param $globalOrderId
  17. * @return mixed|void
  18. */
  19. public function isPlatformNewUser($userId, $globalOrderId): bool
  20. {
  21. return !OrderMain::query()
  22. ->where(['user_id' => $userId])
  23. ->where('global_order_id', '!=', $globalOrderId)
  24. ->whereIn('state', OrderState::FINISH)
  25. ->exists();
  26. }
  27. /**
  28. * @inheritDoc
  29. */
  30. public function isStoreFirstOrderToday($userId, $storeId, $currentOrderId, $limitAmount = 3)
  31. {
  32. return !Order::query()
  33. ->join('lanzu_order_main as main', 'main.global_order_id', '=', 'lanzu_order.order_main_id')
  34. ->where(['main.user_id' => $userId, 'lanzu_order.store_id' => $storeId, 'main.type' => OrderType::OFFLINE])
  35. ->whereIn('main.state', OrderState::FINISH)
  36. ->where('lanzu_order.created_at', '>=', strtotime(date('Y-m-d 00:00:00')))
  37. ->where('lanzu_order.created_at', '<=', strtotime(date('Y-m-d 23:59:59')))
  38. ->where('main.money', '>=', $limitAmount)
  39. ->where('lanzu_order.id', '!=', $currentOrderId)
  40. ->exists();
  41. }
  42. }