| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace common\services\mall\order;
- use common\enums\StatusEnum;
- use common\models\order\UserOrderRelations;
- use common\models\user\UserPartitionRelationship;
- use common\services\mall\BaseService;
- class UserOrderRelationsService extends BaseService
- {
- /**
- * 记录订单下单时关联关系
- *
- * @param int $userId
- * @param int $orderId
- *
- * @return void
- */
- public function createUserOrderRelations(int $userId, int $orderId)
- {
- $parentUserIds = UserPartitionRelationship::getParentIdArr($userId);
- UserOrderRelations::setData([
- 'mall_id' => $this->mall_id,
- 'order_id' => $orderId,
- 'user_id' => $userId,
- 'parents' => $parentUserIds,
- 'status' => StatusEnum::ENABLED
- ]);
- }
- /**
- * 获取下单时的关系链
- *
- * @param int $orderId
- *
- * @return array
- */
- public function getUserOrderRelations(int $orderId): array
- {
- $data = UserOrderRelations::getOne(
- [['mall_id' => $this->mall_id, 'order_id' => $orderId, 'status' => StatusEnum::ENABLED]],
- false,
- [],
- false,
- 'parents'
- );
- if (!$data) {
- return ['is_find' => false];
- }
- return ['is_find' => true, 'user_ids' => $data->parents];
- }
- }
|