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.

48 lines
1.4 KiB

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 $user_id
  16. * @param $order_main_id
  17. * @return mixed|void
  18. */
  19. public function isPlatformNewUser($user_id, $order_main_id): bool
  20. {
  21. return !OrderMain::query()
  22. ->where(['user_id' => $user_id])
  23. ->where('id', '!=', $order_main_id)
  24. ->where(function ($query){
  25. $query->whereIn('state', OrderState::FINISH);
  26. })
  27. ->exists();
  28. }
  29. /**
  30. * @inheritDoc
  31. */
  32. public function isStoreFirstOrderToday($user_id, $store_id, $current_order_id, $limit_amount = 3)
  33. {
  34. return !Order::query()
  35. ->where(['user_id' => $user_id, 'store_id' => $store_id, 'type' => OrderType::OFFLINE])
  36. ->whereIn('state', OrderState::FINISH)
  37. ->where('time_add', '>=', date('Y-m-d 00:00:00'))
  38. ->where('time_add', '<=', date('Y-m-d 23:59:59'))
  39. ->where('money', '>=', $limit_amount)
  40. ->where('id', '!=', $current_order_id)
  41. ->exists();
  42. }
  43. }