123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- namespace App\Http\Controllers\Api\V1\Mentality;
- use App\Models\MentalityDrillsSubject;
- use Illuminate\Http\Request;
- use App\Facades\MentalityDrillFacade;
- use App\Http\Controllers\Api\V1\BaseController;
- use App\Facades\BrowseRecordFacade;
- use App\Models\BrowseRecord;
- class DrillController extends BaseController
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- $commentTag = request('comment_tag');
- if ($commentTag){
- $commentTag = json_decode($commentTag);
- }
- $conditions = [
- 'category_id' => request('category_id'),
- 'search' => request('search'),
- 'comment_tag' => $commentTag
- ];
- $fields = ['*'];
- switch (request('sort')) {
- case 1: // 最新上架
- $sort = '`id` desc';
- break;
- case 2: // 最受欢迎
- $sort = '`number_of_studies` desc';
- break;
- default:
- $sort = '`rank` desc, `id` desc';
- }
- $page = request('page', 1);
- $limit = request('limit', 20);
- return MentalityDrillFacade::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)
- {
- //
- }
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function show($id)
- {
- $conditions = [
- 'id' => $id
- ];
- $record = [
- 'uid' => $this->auth(),
- 'column' => BrowseRecord::COLUMN_2,
- 'object_id' => $id,
- 'repeat' => 'uid:'.$this->auth().' column:'.BrowseRecord::COLUMN_2.' object_id:'.$id
- ];
- //加入浏览记录
- try {
- BrowseRecordFacade::create($record);
- } catch (\Exception $e) {
- }
- return MentalityDrillFacade::findBy($conditions, ['*']);
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, $id)
- {
- //
- }
- /**
- * 播放训练科目
- * @param int $id
- * @return mixed
- */
- public function playSubject(int $id)
- {
- $record = [
- 'uid' => $this->auth(),
- 'column' => BrowseRecord::COLUMN_4,
- 'object_id' => $id,
- 'repeat' => 'uid:'.$this->auth().' column:'.BrowseRecord::COLUMN_4.' object_id:'.$id
- ];
- //加入浏览记录
- try {
- BrowseRecordFacade::create($record);
- } catch (\Exception $e) {
- }
- return response()->horesp(1000, MentalityDrillsSubject::query()->find($id), "成功");
- }
- /**
- * 点赞
- * @param $id
- * @return array
- */
- public function thumbsUpNum($id)
- {
- return MentalityDrillFacade::thumbsUpNum($id,$this->auth());
- }
- /**
- * 喜欢
- * @param $id
- * @return array
- */
- public function loveNum($id)
- {
- return MentalityDrillFacade::loveNum($id,$this->auth());
- }
- /**
- * 留言
- * @param Request $request
- * @return array
- */
- public function leaveMessage(Request $request)
- {
- $id = $request->get("id",0);
- $message = $request->get("message",0);
- return MentalityDrillFacade::leaveMessage($id,$this->auth(),$message);
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function destroy($id)
- {
- //
- }
- }
|