Browse Source
Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix
master
Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix
master
6 changed files with 161 additions and 0 deletions
-
30app/Controller/v3/CommunityController.php
-
45app/Request/v3/CommunityBindRequest.php
-
36app/Service/v3/Implementations/UserCommunityBindService.php
-
48app/Service/v3/Interfaces/UserRelationBindServiceInterface.php
-
1config/autoload/dependencies.php
-
1config/routes.php
@ -0,0 +1,30 @@ |
|||||
|
<?php |
||||
|
|
||||
|
declare(strict_types=1); |
||||
|
|
||||
|
namespace App\Controller\v3; |
||||
|
|
||||
|
use App\Controller\BaseController; |
||||
|
use App\Model\v3\UserRelationBind; |
||||
|
use App\Request\v3\CommunityBindRequest; |
||||
|
use App\Service\v3\Interfaces\UserRelationBindServiceInterface; |
||||
|
use Hyperf\Di\Annotation\Inject; |
||||
|
|
||||
|
class CommunityController extends BaseController |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @Inject |
||||
|
* @var UserRelationBindServiceInterface |
||||
|
*/ |
||||
|
protected $userCommunityService; |
||||
|
|
||||
|
public function bind(CommunityBindRequest $request) |
||||
|
{ |
||||
|
$data = $request->validated(); |
||||
|
$jsonData = $data['json_data'] ?? json_encode([]); |
||||
|
$res = $this->userCommunityService->bindLimitByUser(UserRelationBind::BIND_TYPE_COMMUNITY, $data['source_id'], $data['user_id'], $jsonData); |
||||
|
return $this->success(['id' => $res->id]); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
<?php |
||||
|
|
||||
|
declare(strict_types=1); |
||||
|
|
||||
|
namespace App\Request\v3; |
||||
|
|
||||
|
use App\Request\BaseFormRequest; |
||||
|
|
||||
|
class CommunityBindRequest extends BaseFormRequest |
||||
|
{ |
||||
|
/** |
||||
|
* Determine if the user is authorized to make this request. |
||||
|
*/ |
||||
|
public function authorize(): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the validation rules that apply to the request. |
||||
|
*/ |
||||
|
public function rules(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'source_id' => 'required|nonempty', |
||||
|
'user_id' => 'required|nonempty|exists_enable:ims_cjdc_user,id', |
||||
|
'json_data' => 'json', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function messages(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'*.nonempty' => ':attribute参数异常', |
||||
|
'user_id.exists_enable' => '用户不存在', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function attributes(): array |
||||
|
{ |
||||
|
return [ |
||||
|
|
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Service\v3\Implementations; |
||||
|
|
||||
|
use App\Model\v3\UserRelationBind; |
||||
|
use App\Service\v3\Interfaces\UserRelationBindServiceInterface; |
||||
|
|
||||
|
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\v3\Interfaces; |
||||
|
|
||||
|
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