1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/6
- * Time: 14:08
- */
- namespace App\Transformers\Circle;
- use App\Models\InterestCircle;
- use App\Models\InterestCircleUser;
- use Illuminate\Support\Facades\Redis;
- use League\Fractal\TransformerAbstract;
- class DetailTransformer extends TransformerAbstract
- {
- public function __construct($uid)
- {
- $this->uid = $uid;
- }
- public function transform(InterestCircle $interestCircle)
- {
- return [
- 'id' => $interestCircle['id'],
- 'name' => $interestCircle['name'],
- 'notice' => $interestCircle['notice'],
- 'image' => $interestCircle['image'],
- 'functions' => $this->getFunction($interestCircle),
- 'join_limit' => $interestCircle['join_limit'],
- //'limit_condition' => $interestCircle['limit_condition'],
- //'join_question' => (json_decode($interestCircle['join_question'], true)) ?? [],
- 'is_join' => $this->isJoin($this->uid, $interestCircle['id']),
- //'answer_error_count' => intval(Redis::get('circle_error_count_'.$this->uid))
- ];
- }
- //判读当前用户是否加入圈子
- public function isJoin($uid, $circleId)
- {
- $info = InterestCircleUser::where([['circle_id', $circleId], ['uid', $uid]])->first();
- return $info ? 1 : 0;
- }
- /**
- * 查询圈子开放功能
- * @param InterestCircle $interestCircle
- * @return array
- */
- private function getFunction(InterestCircle $interestCircle)
- {
- $functions = json_decode($interestCircle['contains_function'], true);
- $info[] = ['name' => 'members', 'is_open' => 1, 'extra' => (string)$interestCircle['join_count']];
- foreach ($functions as &$func) {
- if ('pictures' == $func['function']) {
- if (1 == $func['is_open']) {
- $info[] = ['name' => 'pictures', 'is_open' => 1, 'extra' => (string)$interestCircle['picture_count']];
- } else {
- $info[] = ['name' => 'pictures', 'is_open' => 0, 'extra' => '0'];
- }
- }
- if ('chatroom' == $func['function']) {
- if (1 == $func['is_open']) {
- $info[] = ['name' => 'chatroom', 'is_open' => 1, 'extra' => (string)$interestCircle['relate_id']];
- } else {
- $info[] = ['name' => 'chatroom', 'is_open' => 0, 'extra' => '0'];
- }
- }
- }
- return $info;
- }
- }
|