HomeController.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Http\Controllers\Api\V1\Controller;
  4. use App\Models\BaseSettingsModel;
  5. use App\Models\DreamImages;
  6. use App\Models\DreamInfoModel;
  7. use App\Models\SystemInfoModel;
  8. use App\Models\UserCareUser;
  9. use App\Models\UserDream;
  10. use App\Models\UserInfoModel;
  11. use Illuminate\Http\Request;
  12. use App\Services\Base\ErrorCode;
  13. class HomeController extends Controller
  14. {
  15. /**
  16. * @api {get} /api/user/index/ 用户信息
  17. * @apiDescription 用户信息
  18. * @apiGroup Auth
  19. * @apiPermission Passport
  20. * @apiVersion 0.1.0
  21. * @apiParam {int} user_id 用户ID
  22. * @apiSuccessExample {json} Success-Response:
  23. * HTTP/1.1 200 OK
  24. * {
  25. * "nickname": "", 名字
  26. * "pic": "", 头像
  27. *"tall": "", 身高
  28. *"job": "", 职业
  29. *"emotion": "1", 情感
  30. * "address": "",地址
  31. * "score": 1000, 支持分
  32. * "care": 4, 关注
  33. * "fens": 3, 粉丝
  34. * "user_dream": [
  35. *{
  36. * "id": 2,
  37. * "dream": "去旅游去旅游2",
  38. * "about": "欧冠胡234",
  39. * "money": 200,
  40. * "time": 0,
  41. * "get_money": 0,
  42. * "dream_imgs": [
  43. * {
  44. * {
  45. * "id": 3,
  46. *"dream": "3去旅游",
  47. *"about": "",
  48. * "money": 0,
  49. *"time": 0,
  50. * "get_money": 0,
  51. * "mark": 0,
  52. * "status": 0,
  53. * "created_at": null,
  54. * "updated_at": null,
  55. * "deleted_at": null,
  56. * "pic": [],
  57. * "pivot": {
  58. *"user_id": 1,
  59. * "dream_id": 3
  60. * },
  61. * "dream_imgs": []
  62. * },
  63. * "near_dream_pic": [
  64. * {
  65. * "pic": "234"
  66. * },
  67. * ]
  68. * }
  69. * }
  70. * @apiErrorExample {json} Error-Response:
  71. *HTTP/1.1 400 Bad Request
  72. *{
  73. *"status": false,
  74. *"status_code": 1105,
  75. * "message": "用户不存在",
  76. *"data": null
  77. * }
  78. */
  79. public function index(Request $request)
  80. {
  81. $user_id = $request->user_id;
  82. $care = UserCareUser::where('user_id',$user_id)->get();
  83. $fens = UserCareUser::where('other_user_id',$user_id)->get();
  84. $user = UserInfoModel::find($user_id);
  85. if (count($user == 0)) return $this->error(ErrorCode::USER_DOES_NOT_EXIST);
  86. $job = BaseSettingsModel::where(['category' => 'job'])->where(['key' => $user->job])->first();
  87. $job = count($job) > 0 ? $job->value : '';
  88. $emotion = BaseSettingsModel::where(['category' => 'emotion'])->where(['key' => $user->emotion])->first();
  89. $emotion = count($emotion) > 0 ? $emotion->value : '';
  90. // 当前梦想
  91. $near_dream_id = UserDream::where('user_id',$user_id)->orderBy('id','desc')->first()->dream_id;
  92. $near_dream =DreamInfoModel::find($near_dream_id);
  93. // 封面图片
  94. $near_dream_pic = DreamImages::where('dream_id',$near_dream_id)->select('pic')->get();
  95. // 曾经的梦想
  96. $dreams = $user->UserDream;
  97. foreach ($dreams as $dream){
  98. $dream->pic = $dream->dreamImgs;
  99. }
  100. $user->score = 1000;//自定义 算法
  101. $user->care = count($care);
  102. $user->fens = count($fens);
  103. $user->job = $job;
  104. $user->emotion = $emotion;
  105. // 支持的梦想
  106. $sup_dreams = $user->supDream;
  107. foreach ($sup_dreams as $sup_dream){
  108. $sup_dream->pic = $sup_dream->dreamImgs;
  109. }
  110. return $this->api(compact('user','near_dream','sup_dreams','near_dream_pic'));
  111. }
  112. /**
  113. * @api {post} /api/user/support 支持梦想
  114. * @apiDescription 支持梦想
  115. * @apiGroup Auth
  116. * @apiPermission Passport
  117. * @apiVersion 0.1.0
  118. * @apiParam {int} coin 支持梦想币数量
  119. * @apiParam {int} dream_id 梦想ID
  120. * @apiSuccessExample {json} Success-Response:
  121. * HTTP/1.1 200 OK
  122. *{
  123. * "status": true,
  124. * "status_code": 0,
  125. *"message": "",
  126. *"data": ""
  127. *}
  128. * @apiErrorExample {json} Error-Response:
  129. *HTTP/1.1 400 Bad Request
  130. * {
  131. * "state": false,
  132. * "code": 1000,
  133. * "message": "传入参数不正确",
  134. * "data": null or []
  135. * }
  136. * 可能出现的代码
  137. * {
  138. *"status": false,
  139. *"status_code": 1303,
  140. *"message": "商户余额不足",
  141. * "data": null
  142. * }
  143. *
  144. */
  145. public function support(Request $request)
  146. {
  147. $user = $this->getUser();
  148. $dream_id = $request->dream_id;
  149. $dream_info = DreamInfoModel::find($dream_id);
  150. $validator = \Validator::make($request->all(),
  151. [
  152. 'coin' => 'required',
  153. 'dream_id' => 'required',
  154. ],
  155. [
  156. 'coin.required' => '梦想币不能为空',
  157. 'dream_id.required' => '支持对象不能为空',
  158. ]
  159. );
  160. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  161. $coin = $request->coin;
  162. if ($user->money < $coin) {
  163. return $this->error(ErrorCode::MERCHANT_BALANCE_NOT_ENOUGH);
  164. }else{
  165. $user->money = $user->money - $coin;
  166. $user->save();
  167. $dream_info->get_money += $coin;
  168. $dream_info->save();
  169. $data = [
  170. 'user_id'=>$user->id,
  171. 'other_id'=>$dream_id,
  172. 'coin'=>$coin,
  173. ];
  174. $ok = SystemInfoModel::create($data);
  175. if (!$ok) {
  176. return $this->error(ErrorCode::MERCHANT_SERVICE_STATUS_INVALID);
  177. }
  178. return $this->api('');
  179. }
  180. }
  181. /**
  182. * @api {post} /api/auth/bank_card/update 更新银行卡
  183. * @apiDescription 更新银行卡
  184. * @apiGroup Auth
  185. * @apiPermission Passport
  186. * @apiVersion 0.1.0
  187. * @apiParam {int} user_id 用户ID
  188. * @apiSuccessExample {json} Success-Response:
  189. * HTTP/1.1 200 OK
  190. * {
  191. * "state": true,
  192. * "code": 0,
  193. * "message": "success",
  194. * "data": {
  195. * ....
  196. * }
  197. * }
  198. * @apiErrorExample {json} Error-Response:
  199. *HTTP/1.1 400 Bad Request
  200. * {
  201. * "state": false,
  202. * "code": 1000,
  203. * "message": "传入参数不正确",
  204. * "data": null or []
  205. * }
  206. */
  207. public function interaction(Request $request)
  208. {
  209. }
  210. /**
  211. * @api {post} /api/auth/bank_card/update 更新银行卡
  212. * @apiDescription 更新银行卡
  213. * @apiGroup Auth
  214. * @apiPermission Passport
  215. * @apiVersion 0.1.0
  216. * @apiParam {int} user_id 用户ID
  217. * @apiSuccessExample {json} Success-Response:
  218. * HTTP/1.1 200 OK
  219. * {
  220. * "state": true,
  221. * "code": 0,
  222. * "message": "success",
  223. * "data": {
  224. * ....
  225. * }
  226. * }
  227. * @apiErrorExample {json} Error-Response:
  228. *HTTP/1.1 400 Bad Request
  229. * {
  230. * "state": false,
  231. * "code": 1000,
  232. * "message": "传入参数不正确",
  233. * "data": null or []
  234. * }
  235. */
  236. public function paihang(Request $request)
  237. {
  238. }
  239. }