UserOrderRelationsService.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace common\services\mall\order;
  3. use common\enums\StatusEnum;
  4. use common\models\order\UserOrderRelations;
  5. use common\models\user\UserPartitionRelationship;
  6. use common\services\mall\BaseService;
  7. class UserOrderRelationsService extends BaseService
  8. {
  9. /**
  10. * 记录订单下单时关联关系
  11. *
  12. * @param int $userId
  13. * @param int $orderId
  14. *
  15. * @return void
  16. */
  17. public function createUserOrderRelations(int $userId, int $orderId)
  18. {
  19. $parentUserIds = UserPartitionRelationship::getParentIdArr($userId);
  20. UserOrderRelations::setData([
  21. 'mall_id' => $this->mall_id,
  22. 'order_id' => $orderId,
  23. 'user_id' => $userId,
  24. 'parents' => $parentUserIds,
  25. 'status' => StatusEnum::ENABLED
  26. ]);
  27. }
  28. /**
  29. * 获取下单时的关系链
  30. *
  31. * @param int $orderId
  32. *
  33. * @return array
  34. */
  35. public function getUserOrderRelations(int $orderId): array
  36. {
  37. $data = UserOrderRelations::getOne(
  38. [['mall_id' => $this->mall_id, 'order_id' => $orderId, 'status' => StatusEnum::ENABLED]],
  39. false,
  40. [],
  41. false,
  42. 'parents'
  43. );
  44. if (!$data) {
  45. return ['is_find' => false];
  46. }
  47. return ['is_find' => true, 'user_ids' => $data->parents];
  48. }
  49. }