...
|
...
|
@@ -3,11 +3,10 @@ |
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
use app\common\library\Ems;
|
|
|
use app\common\library\Sms;
|
|
|
use EasyWeChat\Factory;
|
|
|
use fast\Random;
|
|
|
use think\Validate;
|
|
|
use think\Db;
|
|
|
use think\Exception;
|
|
|
use think\exception\PDOException;
|
|
|
|
|
|
/**
|
|
|
* 会员接口
|
...
|
...
|
@@ -27,7 +26,7 @@ class User extends Api |
|
|
* @ApiTitle (个人中心)
|
|
|
* @ApiSummary (个人中心)
|
|
|
* @ApiMethod (GET)
|
|
|
* @ApiHeaders (name="token", type="string", required=true, description="token ")
|
|
|
* @ApiHeaders (name="token", type="string", required=true, description="token")
|
|
|
* @ApiReturn ({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
...
|
...
|
@@ -166,4 +165,272 @@ class User extends Api |
|
|
}
|
|
|
$this->error($this->auth->getError());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiWeigh (89)
|
|
|
* @ApiTitle (医生入驻)
|
|
|
* @ApiSummary (医生入驻)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiHeaders (name="token", type="string", required=true, description="token")
|
|
|
* @ApiParams (name=nickname, type=string, required=true, description="姓名")
|
|
|
* @ApiParams (name=mobile, type=string, required=true, description="联系电话")
|
|
|
* @ApiParams (name=city, type=string, required=true, description="所在城市")
|
|
|
* @ApiParams (name=idcard_front, type=string, required=true, description="身份证正面")
|
|
|
* @ApiParams (name=idcard_back, type=string, required=true, description="身份证反面")
|
|
|
* @ApiParams (name=certificates, type=string, required=true, description="从医资格证")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1622016289",
|
|
|
"data": null
|
|
|
})
|
|
|
*/
|
|
|
public function ruzhu(){
|
|
|
$post = $this->request->post();
|
|
|
empty($post['nickname']) && $this->error('请填写姓名');
|
|
|
empty($post['mobile']) && $this->error('请填写联系电话');
|
|
|
empty($post['city']) && $this->error('请选择所在城市');
|
|
|
empty($post['idcard_front']) && $this->error('请上传身份证正面');
|
|
|
empty($post['idcard_back']) && $this->error('请上传身份证反面');
|
|
|
empty($post['certificates']) && $this->error('请上传从医资格证');
|
|
|
$has = db('doctor')->where('user_id',$this->auth->id)->find();
|
|
|
!empty($has) && $this->error('您已申请,请勿重复操作');
|
|
|
db('doctor')->insert(array_merge([
|
|
|
'user_id' => $this->auth->id
|
|
|
],$post));
|
|
|
$this->success('成功');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiWeigh (87)
|
|
|
* @ApiTitle (订单列表)
|
|
|
* @ApiSummary (订单列表)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiHeaders (name="token", type="string", required=true, description="token")
|
|
|
* @ApiParams (name=status, type=integer, required=true, description="状态:1=未开始,2=诊断中,3=已完成,4=待评价")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1622016289",
|
|
|
"data": null
|
|
|
})
|
|
|
*/
|
|
|
public function orderList(){
|
|
|
$status = $this->request->get('status');
|
|
|
empty($status) && $this->error('缺少必需参数');
|
|
|
$where['user_id'] = $this->auth->id;
|
|
|
if($status != 4){
|
|
|
$where['status'] = $status;
|
|
|
}else{
|
|
|
$where['status'] = 3;
|
|
|
$where['is_appraise'] = '0';
|
|
|
}
|
|
|
$list = db('order')
|
|
|
->where($where)
|
|
|
->field('category_id,yuyueshiian,doctor_id')
|
|
|
->paginate(10);
|
|
|
$this->success('成功',$list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiWeigh (85)
|
|
|
* @ApiTitle (订单-确认完成)
|
|
|
* @ApiSummary (订单-确认完成)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiHeaders (name="token", type="string", required=true, description="token")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1622016289",
|
|
|
"data": null
|
|
|
})
|
|
|
*/
|
|
|
public function orderConfirm(){
|
|
|
$order_id = $this->request->get('order_id');
|
|
|
empty($order_id) && $this->error('缺少必需参数');
|
|
|
$order = db('order')->where('id',$order_id)->find();
|
|
|
empty($order) && $this->error('订单不存在');
|
|
|
$order['status'] == '1' && $this->error('预约未开始');
|
|
|
$order['status'] == '3' && $this->error('已确认完成,请勿重复操作');
|
|
|
$doctor = db('doctor')->where('id',$order['doctor_id'])->find();
|
|
|
empty($doctor) && $this->error('医生不存在');
|
|
|
Db::startTrans();
|
|
|
try{
|
|
|
db('order')->where('id',$order_id)->update(['status'=>'3']);
|
|
|
// 统计月接单量
|
|
|
$receive_num_where = [
|
|
|
'doctor_id' => $order['doctor_id'],
|
|
|
'month' => date('Y-m'),
|
|
|
];
|
|
|
$receive_num = db('doctor_receive_num')
|
|
|
->where($receive_num_where)
|
|
|
->find();
|
|
|
if(empty($receive_num)){
|
|
|
db('doctor_receive_num')->insert($receive_num_where);
|
|
|
}else{
|
|
|
db('doctor_receive_num')->where('id',$receive_num['id'])->setInc('receive_num');
|
|
|
}
|
|
|
$month_receive_num = db('doctor_receive_num')->where($receive_num_where)->value('receive_num');
|
|
|
db('doctor')->where('id',$order['doctor_id'])->update([
|
|
|
'month_receive_num' => $month_receive_num
|
|
|
]);
|
|
|
// 统计总接单量
|
|
|
db('doctor')->where('id',$order['doctor_id'])->setInc('total_receive_num');
|
|
|
Db::commit();
|
|
|
}catch (PDOException $e){
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}catch (Exception $e){
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
$this->success('成功');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiWeigh (83)
|
|
|
* @ApiTitle (订单-评论)
|
|
|
* @ApiSummary (订单-评论)
|
|
|
* @ApiMethod (GET)
|
|
|
* @ApiHeaders (name="token", type="string", required=true, description="token")
|
|
|
* @ApiParams (name=is_solve, type=string, required=true, description="问题是否解决:0=否,1=是")
|
|
|
* @ApiParams (name=star, type=string, required=true, description="满意度")
|
|
|
* @ApiParams (name=content, type=string, required=true, description="服务评价")
|
|
|
* @ApiParams (name=video, type=string, required=true, description="评价视频")
|
|
|
* @ApiParams (name=images, type=string, required=true, description="评价图片")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1622016289",
|
|
|
"data": null
|
|
|
})
|
|
|
*/
|
|
|
public function orderAppraise(){
|
|
|
$post = $this->request->post();
|
|
|
!isset($post['is_solve']) && $this->error('请确定问题是否解决');
|
|
|
!in_array($post['is_solve'],['0','1']) && $this->error('问题是否解决参数不合法');
|
|
|
empty($post['star']) && $this->error('请选择满意度');
|
|
|
empty($post['content']) && $this->error('请输入服务评价');
|
|
|
$order = Order::get($post['order_id']);
|
|
|
empty($order) && $this->error('订单不存在');
|
|
|
$order['status'] != '3' && $this->error('订单未完成,无法评价');
|
|
|
$order['is_appraise'] == '1' && $this->error('已评价,请勿重复操作');
|
|
|
$doctor = Doctor::get($order['doctor_id']);
|
|
|
empty($doctor) && $this->error('医生信息不存在');
|
|
|
// 视频封面
|
|
|
if(!empty($post['video'])){
|
|
|
// 获取七牛云视频信息
|
|
|
$video = cdnurl($post['video'],true);
|
|
|
$video_info = json_decode(file_get_contents($video.'?avinfo'),true);
|
|
|
if(empty($video_info['streams'][0]['width'])) {
|
|
|
$width = $video_info['streams'][1]['width'];
|
|
|
$height = $video_info['streams'][1]['height'];
|
|
|
} else {
|
|
|
$width = $video_info['streams'][0]['width'];
|
|
|
$height = $video_info['streams'][0]['height'];
|
|
|
}
|
|
|
$post['video_cover'] = $video.'?vframe/jpg/offset/1/w/'.$width.'/h/'.$height;
|
|
|
}
|
|
|
Db::startTrans();
|
|
|
try{
|
|
|
// 评价
|
|
|
OrderAppraise::create(array_merge([
|
|
|
'user_id' => $this->auth->id,
|
|
|
'doctor_id' => $order['doctor_id']
|
|
|
],$post));
|
|
|
// 更新订单状态
|
|
|
$order->save(['is_appraise'=>'1']);
|
|
|
// 平均星级
|
|
|
$star = OrderAppraise::where('doctor_id',$order['doctor_id'])->avg('star');
|
|
|
$doctor->setInc('star',round($star,2));
|
|
|
Db::commit();
|
|
|
}catch (PDOException $e){
|
|
|
Db::rollback();
|
|
|
$e->getMessage();
|
|
|
}catch (Exception $e){
|
|
|
Db::rollback();
|
|
|
$e->getMessage();
|
|
|
}
|
|
|
$this->success('成功');
|
|
|
}
|
|
|
|
|
|
public function gift(){
|
|
|
$list = db('gift')->select();
|
|
|
$this->success('成功',$list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiWeigh (99)
|
|
|
* @ApiTitle (购买礼物)
|
|
|
* @ApiSummary (购买礼物)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="is_custom", type="string", required=true, description="是否自定义:0=否,1=是")
|
|
|
* @ApiParams (name="gift_id", type="inter", required=false, description="礼物ID")
|
|
|
* @ApiParams (name="pay_price", type="float", required=false, description="自定义金额")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1, //返回码:0=错误普通提示,1=成功,2=普通弹窗提示,3=跳转弹窗提示
|
|
|
"msg": "成功",
|
|
|
"time": "1604282876",
|
|
|
"data": {
|
|
|
"payment": [], //支付数据
|
|
|
"order_id": 15, //订单ID
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function payGift(){
|
|
|
$is_custom = $this->request->get('is_custom');
|
|
|
$gift_id = $this->request->get('gift_id');
|
|
|
$pay_price = $this->request->get('pay_price');
|
|
|
!isset($is_custom) && $this->error('缺少必需参数');
|
|
|
switch ($is_custom){
|
|
|
case '0':
|
|
|
empty($gift_id) && $this->error('请选择礼物');
|
|
|
$gift = db('gift')->where('id',$gift_id)->find();
|
|
|
empty($gift) && $this->error('礼物不存在');
|
|
|
$pay_price = $gift['price'];
|
|
|
break;
|
|
|
case '1':
|
|
|
empty($pay_price) && $this->error('请填写自定义金额');
|
|
|
break;
|
|
|
default:
|
|
|
$this->error('参数不合法');
|
|
|
}
|
|
|
$order = GiftOrder::create([
|
|
|
'user_id' => $this->auth->id,
|
|
|
'order_sn' => get_order_sn(),
|
|
|
'gift_id' => $is_custom == '0' ? $gift_id : 0,
|
|
|
'pay_price' => $pay_price,
|
|
|
]);
|
|
|
$payment = [];
|
|
|
if($pay_price <= 0){
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
// 处理订单
|
|
|
(new Notify())->handleOrder([
|
|
|
'out_trade_no' => $order['order_sn'],
|
|
|
'transaction_id' => ''
|
|
|
]);
|
|
|
Db::commit();
|
|
|
} catch (\think\exception\PDOException $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
} catch (\think\Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
}else{
|
|
|
// 发起微信支付
|
|
|
$Wechat = new Wechat;
|
|
|
$openid = Db::name('third')->where('user_id',$this->auth->id)->value('openid');
|
|
|
if(!$payment = $Wechat->wxPay($this->model['order_sn'], $openid, $pay_price)){
|
|
|
$this->error($Wechat->getError());
|
|
|
}
|
|
|
}
|
|
|
$this->success('成功',[
|
|
|
'payment' => $payment,
|
|
|
'order_id' => $order['id']
|
|
|
]);
|
|
|
}
|
|
|
} |
...
|
...
|
|