9 changed files with 96 additions and 46 deletions
-
10app/Controller/CommunityController.php
-
6app/Model/UserRelationBind.php
-
1app/Request/CommunityBindRequest.php
-
30app/Service/CommunityService.php
-
9app/Service/CommunityServiceInterface.php
-
35app/Service/UserCommunityBindService.php
-
48app/Service/UserRelationBindServiceInterface.php
-
2config/autoload/dependencies.php
-
1config/routes.php
@ -1,30 +0,0 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace App\Service; |
|||
|
|||
|
|||
use App\Model\UserRelationBind; |
|||
|
|||
class CommunityService implements CommunityServiceInterface |
|||
{ |
|||
|
|||
public function bind($data) |
|||
{ |
|||
if ($res = $this->isBinded($data['bind_type'], $data['source_id'], $data['user_id'])) { |
|||
return $res; |
|||
} |
|||
return UserRelationBind::query()->updateOrCreate( |
|||
['bind_type' => $data['bind_type'], 'source_id' => $data['source_id'], 'user_id' => $data['user_id']], |
|||
['json_data' => $data['json_data']] |
|||
); |
|||
} |
|||
|
|||
public function isBinded($bind_type, $source_id, $user_id) |
|||
{ |
|||
return UserRelationBind::query() |
|||
->select('id') |
|||
->where(['bind_type' => $bind_type, 'source_id' => $source_id, 'user_id' => $user_id]) |
|||
->first(); |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
interface CommunityServiceInterface |
|||
{ |
|||
public function isBinded($bind_type, $source_id, $user_id); |
|||
public function bind($data); |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
use App\Model\UserRelationBind; |
|||
|
|||
class UserCommunityBindService implements UserRelationBindServiceInterface |
|||
{ |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
public function bindLimitByUser($bind_type, $source_id, $user_id, $extra_data) |
|||
{ |
|||
return UserRelationBind::query()->updateOrCreate( |
|||
['bind_type' => $bind_type, 'user_id' => $user_id], |
|||
['source_id' => $source_id, 'json_data' => $extra_data] |
|||
); |
|||
} |
|||
|
|||
public function bindLimitBySource($bind_type, $source_id, $user_id, $extra_data) |
|||
{ |
|||
// TODO: Implement bindLimitBySource() method.
|
|||
} |
|||
|
|||
public function bind($bind_type, $source_id, $user_id, $extra_data) |
|||
{ |
|||
// TODO: Implement bind() method.
|
|||
} |
|||
|
|||
public function isBinded($bind_type, $source_id, $user_id) |
|||
{ |
|||
// TODO: Implement isBinded() method.
|
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
interface UserRelationBindServiceInterface |
|||
{ |
|||
/** |
|||
* 绑定 |
|||
* 依据用户绑定一个关系,即每次都是新的绑定关系,原来的绑定关系解除(user_id不变,更新其他) |
|||
* @param $bind_type |
|||
* @param $source_id |
|||
* @param $user_id |
|||
* @param $extra_data |
|||
* @return mixed |
|||
*/ |
|||
public function bindLimitByUser($bind_type, $source_id, $user_id, $extra_data); |
|||
|
|||
/** |
|||
* 绑定 |
|||
* 依据绑定人(根据bind_type确定)绑定一个关系,即每次都是新的绑定关系,原来的绑定关系解除(source_id不变,更新其他) |
|||
* @param $bind_type |
|||
* @param $source_id |
|||
* @param $user_id |
|||
* @param $extra_data |
|||
* @return mixed |
|||
*/ |
|||
public function bindLimitBySource($bind_type, $source_id, $user_id, $extra_data); |
|||
|
|||
/** |
|||
* 绑定 |
|||
* 始终绑定一个新的关系,如果这个关系(source_id=》user_id)存在则更新其他数据 |
|||
* @param $bind_type |
|||
* @param $source_id |
|||
* @param $user_id |
|||
* @param $extra_data |
|||
* @return mixed |
|||
*/ |
|||
public function bind($bind_type, $source_id, $user_id, $extra_data); |
|||
|
|||
/** |
|||
* 是否已经存在绑定关系 |
|||
* @param $bind_type |
|||
* @param $source_id |
|||
* @param $user_id |
|||
* @return mixed |
|||
*/ |
|||
public function isBinded($bind_type, $source_id, $user_id); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue