<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use JiGuang\JSMS as JSMS;
use Illuminate\Support\Facades\Redis;
use Dingo\Api\Http\Response;
use Validator;
use DB;
use App\Models\User;
use App\Services\SystemService;
use App\Models\UserAddress;
use App\Models\Doctors;
use App\Models\Article;

/**
 *
 * Copyright: Copyright (c) 2019
 *
 * @Description:
 * @version: v1.0.0
 * @author: fengyichao
 * @date: 2019年9月29日 下午4:43:44
 *
 * Modification History:
 * Date         Author          Version            Description
 *---------------------------------------------------------*
 * 2019年9月29日     fengyichao           v1.0.0               修改原因
 */
class DoctorController extends ApiController {
	// 利用 Laravel 的自动解析功能注入 CartService 类
	public function __construct(SystemService $systemService) {
		$this->systemService = $systemService;
	}
	/**
	 *
	 * @api {post} doctor/list 医生-医生列表
	 * @apiName doctor/list
	 * @apiGroup doctor
	 * @apiParam {int} page 页码 default:1
	 * @apiParam {string} keywords 关键字 非必传【搜索时传入】
	 * @apiParam {string} category_id 分类id 非必传 【需要根据分类id获取商品列表时传入】
	 * @apiSuccess {int}  current_page 当前页
	 * @apiSuccess {List[Map]}  data 医生列表
	 * @apiSuccess (data) {int}  id 商品id
	 * @apiSuccess (data) {string}  name 医生姓名
	 * @apiSuccess (data) {string}  title 职务
	 * @apiSuccess (data) {string}  room 科室
	 * @apiSuccess (data) {string}  image 头像 图片地址 需要前端自行拼接阿里云前缀
	 * @apiSuccess (data) {string}  good_at 擅长领域
	 * @apiSuccess {int}  current_page 当前页
	 * @apiSuccess {int}  total 总页数
	 * @apiParamExample {curl} Example usage:
	 * http://www.zhufuwuyou.net/api/doctor/list
	 */
	public function list(Request $request) {
		$page = $request->input ( 'page', 1 );
		$queryBuild = Doctors::select ( [ 
				'name',
				'room',
				'id',
				'title',
				'image',
				'good_at'
		] );
		$products = $queryBuild->orderBy ( 'id', 'desc' )->paginate ( 15, [ 
				'id',
				'title',
				'image',
				'good_at'
		], 'page', $page );
		$resultData = $products;
		return $this->success ( $resultData );
	}
	/**
	 *
	 * @api {post} doctor/detail 医生-医生详情
	 * @apiName doctor/detail
	 * @apiGroup doctor
	 * @apiParam {int} doctor_id 医生id
	 * @apiSuccess {Object}  doctor 医生信息
	 * @apiSuccess (doctor) {int}  id id
	 * @apiSuccess (doctor) {string}  name 姓名 *
	 * @apiSuccess (doctor) {string}  title 职务
	 * @apiSuccess (doctor) {string}  room 科室
	 * @apiSuccess (doctor) {string}  image 头像 图片地址 需要前端自行拼接阿里云前缀
	 * @apiSuccess (doctor) {string}  good_at 擅长领域
	 * @apiSuccess (doctor) {string}  length_of_time 咨询时长 *
	 * @apiSuccess (doctor) {int}  price 咨询费
	 * @apiSuccess {List[Map]} articles 精选文章
	 * @apiSuccess (articles) {int} id 文章id
	 * @apiSuccess (articles) {string} head_img 文章主图
	 * @apiSuccess (articles) {string} title 标题
	 * @apiSuccess (articles) {string} author 作者【同医生姓名，此处展示的是本医生发的文章】
	 * @apiSuccess {List[Map]}  answers 经典问答
	 * @apiSuccess (answers) {string} head_img 用户头像
	 * @apiSuccess (answers) {string} name 用户昵称
	 * @apiSuccess (answers) {string} question 用户提问
	 * @apiSuccess (answers) {string} answer 医生回答
	 * @apiSuccess {List[Map]}  pay_type_list 支付方式列表 *
	 * @apiSuccess {int}  current_pay_type 当前支付方式 *
	 * @apiParamExample {curl} Example usage:
	 * http://www.zhufuwuyou.net/api/doctor/detail?doctor_id=1
	 */
	public function detail(Request $request) {
		$doctor = Doctors::find ( $request->doctor_id );
		$resultData ['doctor'] = $doctor;
		$resultData ['articles'] = Article::select ( [ 
				'id',
				'head_img',
				'title'
		] )->where ( 'author_doctor_id', $request->doctor_id )->limit ( 2 )->get ();

		$item = [ 
				'head_img' => 'xxx',
				'name' => '患者1',
				'question' => '如何才能变有钱',
				'answer' => '多喝酒多睡觉'
		];
		$resultData ['answers'] = [ 
				$item,
				$item
		];
		$resultData ['pay_type'] = [
				1 => '微信支付'
		];
		$resultData['current_pay_type'] = 1;
		return $this->success ( $resultData );
	}
}
