LetterController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Http\Controllers\Api\V1\Mentality;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Api\V1\BaseController;
  5. use App\Facades\DiaryLetterFacade;
  6. use Carbon\Carbon;
  7. class LetterController extends BaseController
  8. {
  9. /**
  10. * Display a listing of the resource.
  11. *
  12. * @return \Illuminate\Http\Response
  13. */
  14. public function index()
  15. {
  16. $conditions = [
  17. 'uid' => $this->auth(),
  18. 'send_time' => Carbon::now()
  19. ];
  20. $fields = ['*'];
  21. $sort = '`send_time` desc';
  22. $page = request('page', 1);
  23. $limit = request('limit', 20);
  24. return DiaryLetterFacade::getList($conditions, $fields, $sort, $page, $limit);
  25. }
  26. /**
  27. * Store a newly created resource in storage.
  28. *
  29. * @param \Illuminate\Http\Request $request
  30. * @return \Illuminate\Http\Response
  31. */
  32. public function store(Request $request)
  33. {
  34. $data['uid'] = $this->auth();
  35. $data['content'] = $request->content;
  36. $now = Carbon::now();
  37. switch ($request->type){
  38. case 1: //半年
  39. $sendTime = $now->addMonths(6);
  40. break;
  41. case 2: //1年
  42. $sendTime = $now->addYears(1);
  43. break;
  44. case 3: //2年
  45. $sendTime = $now->addYears(2);
  46. break;
  47. case 4: //3年
  48. $sendTime = $now->addYears(3);
  49. break;
  50. case 5: //10年
  51. $sendTime = $now->addYears(10);
  52. break;
  53. }
  54. $data['send_time'] = $sendTime;
  55. return DiaryLetterFacade::create($data);
  56. }
  57. /**
  58. * Display the specified resource.
  59. *
  60. * @param int $id
  61. * @return \Illuminate\Http\Response
  62. */
  63. public function show($id)
  64. {
  65. $conditions = [
  66. 'id' => $id,
  67. 'uid' => $this->auth(),
  68. 'send_time' => Carbon::now()
  69. ];
  70. $fields = ['*'];
  71. return DiaryLetterFacade::findBy($conditions, $fields);
  72. }
  73. /**
  74. * Update the specified resource in storage.
  75. *
  76. * @param \Illuminate\Http\Request $request
  77. * @param int $id
  78. * @return \Illuminate\Http\Response
  79. */
  80. public function update(Request $request, $id)
  81. {
  82. //
  83. }
  84. /**
  85. * Remove the specified resource from storage.
  86. *
  87. * @param int $id
  88. * @return \Illuminate\Http\Response
  89. */
  90. public function destroy($id)
  91. {
  92. //
  93. }
  94. }