| xqd
@@ -17,12 +17,12 @@ use App\Services\Base\ErrorCode;
|
|
|
class DreamController extends Controller
|
|
|
{
|
|
|
/**
|
|
|
- * @api {get} /api/dream/index 梦想
|
|
|
+ * @api {get} /api/dream/show 梦想
|
|
|
* @apiDescription 梦想
|
|
|
* @apiGroup Dream
|
|
|
* @apiPermission Passport
|
|
|
* @apiVersion 0.1.0
|
|
|
- * @apiParam {int} type interaction paihang 默认index
|
|
|
+ * @apiParam {int} type index interaction paihang 默认all
|
|
|
* @apiParam {int} id 梦想ID
|
|
|
* @apiSuccessExample {json} Success-Response:
|
|
|
* HTTP/1.1 200 OK
|
| xqd
@@ -132,74 +132,71 @@ class DreamController extends Controller
|
|
|
* "data": null
|
|
|
* }
|
|
|
*/
|
|
|
- public function index(Request $request)
|
|
|
+ public function show(Request $request)
|
|
|
{
|
|
|
$user = $this->getUser();
|
|
|
$type = $request->type; //类型
|
|
|
$id = $request->id; //梦想ID
|
|
|
if (empty($id)) return $this->error(ErrorCode::KEY_ERROR);
|
|
|
|
|
|
- if ($type == 'paihang') {
|
|
|
- $data = [];
|
|
|
- $info = SupportDreamModel::where('dream_id',$id)->get();
|
|
|
- $arr = [] ;
|
|
|
- foreach ($info as $item) {
|
|
|
- if (!array_key_exists($item->user_id,$arr)) {
|
|
|
- $arr[$item->user_id] = $item->score;
|
|
|
- }else{
|
|
|
- $arr[$item->user_id] += $item->score;
|
|
|
- }
|
|
|
- }
|
|
|
- arsort($arr);
|
|
|
- foreach ($arr as $k => $v){
|
|
|
- $user = UserInfoModel::find($k);
|
|
|
- $user->score = $v;
|
|
|
- $data[] = $user;
|
|
|
+ $info = SupportDreamModel::where('dream_id',$id)->get();
|
|
|
+ $top = [] ;
|
|
|
+ $topuser = [];
|
|
|
+ $top3user = [];
|
|
|
+ foreach ($info as $item) {
|
|
|
+ if (!array_key_exists($item->user_id,$top)) {
|
|
|
+ $top[$item->user_id] = $item->score;
|
|
|
+ }else{
|
|
|
+ $top[$item->user_id] += $item->score;
|
|
|
}
|
|
|
- return $this->api($data);
|
|
|
+ }
|
|
|
+ arsort($top);
|
|
|
+ foreach ($top as $user_id => $score){
|
|
|
+ $user = UserInfoModel::find($user_id);
|
|
|
+ $user->score = $score;
|
|
|
+ $topuser[] = $user;
|
|
|
+ if(count($top3user)<=2)$top3user[] = $user;
|
|
|
+ }
|
|
|
+ if ($type == 'paihang') return $this->api($topuser);
|
|
|
|
|
|
- } elseif ($type == 'interaction') {
|
|
|
- $times = DreamInfoModel::find($id)->time;
|
|
|
- $data = InteractionInfo::where('dream_id',$id)->orderBy('id','desc')->get();
|
|
|
- foreach ($data as $item) {
|
|
|
- $item->comments = $item->comments;
|
|
|
- foreach ($item->comments as $comment) {
|
|
|
- $comment->pic = UserInfoModel::find($comment->user_id)->pic;
|
|
|
- $comment->replay = $comment->replay;
|
|
|
- foreach ($comment->replay as $k1 => $v1){
|
|
|
- $v1->pic = UserInfoModel::find($v1->user_id)->pic;
|
|
|
- }
|
|
|
+ $interactios = InteractionInfo::where('dream_id',$id)->orderBy('id','desc')->get();
|
|
|
+ foreach ($interactios as $item) {
|
|
|
+ $item->comments = $item->comments;
|
|
|
+ foreach ($item->comments as $comment) {
|
|
|
+ $comment->pic = UserInfoModel::find($comment->user_id)->pic;
|
|
|
+ $comment->replay = $comment->replay;
|
|
|
+ foreach ($comment->replay as $k1 => $v1){
|
|
|
+ $v1->pic = UserInfoModel::find($v1->user_id)->pic;
|
|
|
}
|
|
|
}
|
|
|
- return $this->api(compact('data','times'));
|
|
|
- }else{
|
|
|
+ }
|
|
|
+ if ($type == 'interaction') return $this->api(compact('data'));
|
|
|
// 梦想 图片 支持者前三 支持乘数参数 用户余额 梦想分数
|
|
|
- $score = 0 ;
|
|
|
- $a = SupportDreamModel::where('dream_id',$id)->get();
|
|
|
- foreach ($a as $value){
|
|
|
- $score += $value->score;
|
|
|
- }
|
|
|
- $money = $user->money;
|
|
|
- $number = BaseSettingsModel::where('category','score')->select('key','value')->first();
|
|
|
- $a = count($number) > 0 ? $number->key : '';
|
|
|
- $c = count($number) > 0 ? $number->value : '';
|
|
|
- $dream = DreamInfoModel::find($id);
|
|
|
- $imgs = DreamImages::where('dream_id',$id)->orderBy('id','desc')->get();
|
|
|
- $info = SupportDreamModel::where('dream_id',$id)->get();
|
|
|
- $arr = [] ;
|
|
|
- foreach ($info as $item) {
|
|
|
- if (!array_key_exists($item->user_id,$arr)) {
|
|
|
- $arr[$item->user_id] = $item->score;
|
|
|
- }else{
|
|
|
- $arr[$item->user_id] += $item->score;
|
|
|
- }
|
|
|
- }
|
|
|
- arsort($arr);
|
|
|
- foreach ($arr as $k => $v){
|
|
|
- $arr[$k] = UserInfoModel::find($k)->pic;
|
|
|
+
|
|
|
+// $money = $user->money;
|
|
|
+ $number = BaseSettingsModel::where('category','score')->select('key','value')->first();
|
|
|
+ $a = count($number) > 0 ? $number->key : '';
|
|
|
+ $c = count($number) > 0 ? $number->value : '';
|
|
|
+ $dream = DreamInfoModel::with(['dreamImgs','dreamUser'])->find($id);
|
|
|
+// $imgs = DreamImages::where('dream_id',$id)->orderBy('id','desc')->get();
|
|
|
+// $info = SupportDreamModel::where('dream_id',$id)->get();
|
|
|
+ $top3 = [] ;
|
|
|
+ $score = 0 ;
|
|
|
+ foreach ($info as $item) {
|
|
|
+ $score += $item->score;
|
|
|
+ if (!array_key_exists($item->user_id,$top3)) {
|
|
|
+ $top3[$item->user_id] = $item->score;
|
|
|
+ }else{
|
|
|
+ $top3[$item->user_id] += $item->score;
|
|
|
}
|
|
|
- return $this->api(compact('dream','imgs','money','arr','a','c','score'));
|
|
|
}
|
|
|
+ arsort($top3);
|
|
|
+ foreach ($top3 as $k => $v){
|
|
|
+ $user = UserInfoModel::find($k);
|
|
|
+ if($user)
|
|
|
+ $top3[$k] = $user->pic;
|
|
|
+ }
|
|
|
+ return $this->api(compact('dream','top3user','a','c','score','topuser'));
|
|
|
}
|
|
|
|
|
|
/**
|
| xqd
@@ -242,12 +239,10 @@ class DreamController extends Controller
|
|
|
[
|
|
|
'coin' => 'required',
|
|
|
'id' => 'required',
|
|
|
- 'number' => 'required',
|
|
|
],
|
|
|
[
|
|
|
'coin.required' => '梦想币不能为空',
|
|
|
'id.required' => '支持梦想不能为空',
|
|
|
- 'number.required' => '支持乘数不能为空',
|
|
|
]
|
|
|
);
|
|
|
if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
|
| xqd
@@ -255,9 +250,13 @@ class DreamController extends Controller
|
|
|
$dream_id = $request->id;
|
|
|
$dream_info = DreamInfoModel::find($dream_id);
|
|
|
$user_id = $dream_info->user_id;
|
|
|
-
|
|
|
$coin = $request->coin;
|
|
|
- $number = $request->number;
|
|
|
+
|
|
|
+ $setting = BaseSettingsModel::where('category','score')->select('key','value')->first();
|
|
|
+ $a = count($setting) > 0 ? $setting->key : '';
|
|
|
+ $c = count($setting) > 0 ? $setting->value : '';
|
|
|
+ //Todo 支持乘数目公式
|
|
|
+ $number = 2;
|
|
|
|
|
|
if ($user->money < $coin) {
|
|
|
return $this->error(ErrorCode::MERCHANT_BALANCE_NOT_ENOUGH);
|