|
@@ -197,7 +197,44 @@ class Application extends Base
|
|
|
return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ public function cancel(){
|
|
|
+ try{
|
|
|
+ log::record($_REQUEST);
|
|
|
+ $sessionid = $_REQUEST['sessionid'];
|
|
|
+ $doctor = Cache::get($sessionid);
|
|
|
+ // 远程申请权限 6
|
|
|
+ $return = Verify::check_role($sessionid,6);
|
|
|
+ if($return != 1){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'1029','msg'=>'没有操作权限']);
|
|
|
+ }
|
|
|
+ $param = $_REQUEST['param'];
|
|
|
+ $order_id = $param['order_id'];
|
|
|
+ $remote_order = DB::table('remote_order')->where('id', $order_id)->field('application_id, hospital_id, doctor_id, status, pay_type, order_money')->find();
|
|
|
+ if(!$remote_order) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2101','msg'=> '没有找到该订单']);
|
|
|
+ }
|
|
|
+ if(!($remote_order['status'] === self::ORDER_STATUS['CREATE'] || $remote_order['status'] === self::ORDER_STATUS['PAYCOMPLTET'])) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2102','msg'=> '订单状态不可取消']);
|
|
|
+ }
|
|
|
+ $application = DB::table('remote_application')->where('id', $remote_order['application_id'])->field('report_status')->find();
|
|
|
+ if(!$application) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2103','msg'=> '没有找到远程诊断申请单']);
|
|
|
+ }
|
|
|
+ if(!($application['report_status'] === '5' || $application['report_status'] === '12')) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2103','msg'=> '进行中的远程诊断订单不可取消']);
|
|
|
+ }
|
|
|
+ if($remote_order['pay_type'] === self::PAY_TYPE['HOSPITAL']) {
|
|
|
+ return $this->cancelHospitalOrder($order_id, $remote_order['hospital_id'], $remote_order['order_money']);
|
|
|
+ }
|
|
|
+ if($remote_order['pay_type'] === self::PAY_TYPE['WECHAT']) {
|
|
|
+ return $this->cancelPatientsOrder($order_id, $remote_order['application_id']);
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','sessionid'=>$sessionid]);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 提交申请
|
|
|
*
|
|
@@ -512,7 +549,6 @@ class Application extends Base
|
|
|
}
|
|
|
return json_encode(['status'=>'fail','code'=>'2018','远程诊断发起失败']);
|
|
|
}
|
|
|
-
|
|
|
private function createPatientsOrder($hospital_id, $super_hospital_id, $doctor_id, $super_doctor_id, $exam_class, $application_id, $order_money) {
|
|
|
$pay_type = self::PAY_TYPE['PATIENT'];
|
|
|
$pay_way = self::PAY_WAY['WECHAT'];
|
|
@@ -554,6 +590,48 @@ class Application extends Base
|
|
|
return json_encode(['status'=>'fail','code'=>'2020','远程诊断发起失败']);
|
|
|
}
|
|
|
|
|
|
+ private function cancelHospitalOrder($order_id, $hospital_id, $order_money) {
|
|
|
+ DB::startTrans();
|
|
|
+ $water_type = self::WATER_TYPE['ADD'];
|
|
|
+ $water_why = self::WATER_WHY['REFUNDINCOME'];
|
|
|
+ try{
|
|
|
+ DB::table('remote_order')->where('order_id', $order_id)->update(["status" => self::ORDER_STATUS["CANCEL"]]);
|
|
|
+ $hospital = DB::table('institution')
|
|
|
+ ->where('id', $hospital_id)
|
|
|
+ ->field('current_money')
|
|
|
+ ->find();
|
|
|
+ $current_money = $hospital['current_money'];
|
|
|
+ DB::table('institution')->where('id',$hospital_id)->update(['current_money'=> $current_money + $order_money]);
|
|
|
+ DB::table('remote_water')->insert([
|
|
|
+ 'id' => UUIDs::uuid16(),
|
|
|
+ 'hospital_id' => $hospital_id,
|
|
|
+ 'order_id' => $order_id,
|
|
|
+ 'money' => $order_money,
|
|
|
+ 'type' => $water_type,
|
|
|
+ 'why' => $water_why,
|
|
|
+ 'timestamp' => time(),
|
|
|
+ ]);
|
|
|
+ // 提交事务
|
|
|
+ DB::commit();
|
|
|
+ // todo 消息推送
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000']);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ DB::rollback();
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2018','取消订单失败']);
|
|
|
+ }
|
|
|
+ private function cancelPatientsOrder($order_id) {
|
|
|
+ try{
|
|
|
+ DB::table('remote_order')->where('order_id', $order_id)->update(["status" => self::ORDER_STATUS["CANCEL"]]);
|
|
|
+ // todo 消息推送
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000']);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ var_dump($e);
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2109','订单取消失败']);
|
|
|
+ }
|
|
|
+
|
|
|
/**订单状态 创建 支付完成 订单完成 取消 */
|
|
|
private const ORDER_STATUS = [
|
|
|
'CREATE' => 1,
|