123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace App\Http\Controllers\Api\V1\Mentality;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Api\V1\BaseController;
- use App\Facades\DiaryLetterFacade;
- use Carbon\Carbon;
- class LetterController extends BaseController
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- $conditions = [
- 'uid' => $this->auth(),
- 'send_time' => Carbon::now()
- ];
- $fields = ['*'];
- $sort = '`send_time` desc';
- $page = request('page', 1);
- $limit = request('limit', 20);
-
- return DiaryLetterFacade::getList($conditions, $fields, $sort, $page, $limit);
- }
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- $data['uid'] = $this->auth();
- $data['content'] = $request->content;
-
- $now = Carbon::now();
- switch ($request->type){
- case 1: //半年
- $sendTime = $now->addMonths(6);
- break;
- case 2: //1年
- $sendTime = $now->addYears(1);
- break;
- case 3: //2年
- $sendTime = $now->addYears(2);
- break;
- case 4: //3年
- $sendTime = $now->addYears(3);
- break;
- case 5: //10年
- $sendTime = $now->addYears(10);
- break;
- }
- $data['send_time'] = $sendTime;
- return DiaryLetterFacade::create($data);
- }
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function show($id)
- {
- $conditions = [
- 'id' => $id,
- 'uid' => $this->auth(),
- 'send_time' => Carbon::now()
- ];
- $fields = ['*'];
- return DiaryLetterFacade::findBy($conditions, $fields);
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, $id)
- {
- //
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function destroy($id)
- {
- //
- }
- }
|