'未支付', self::NOTACCEPT=>'待支付', self::ISING=>'进行中', self::FINISHED=>'已完成', self::CANCELED=>'已取消', ]; //获取订单状态 public static function getStatus() { return self::$_order_status; } public function docter() { return $this->belongsTo(Docter::class); } public function patients(){ return $this->belongsTo(Patient::class); } public function orderPatient() { return $this->hasOne(OrderPatient::class); } public function orderPack() { return $this->hasOne(OrderPack::class); } public function orderNurse() { return $this->hasMany(OrderNurse::class); } public function orderVaccine() { return $this->hasOne(OrderVaccine::class); } public function orderUser() { return $this->hasOne(User::class,'id','user_id'); } public function organization() { return $this->belongsTo(Organization::class); } public function user() { return $this->belongsTo(User::class); } public function evaluate() { return $this->hasOne(Evaluate::class); } //支付完成的处理方法 public static function payCompletedHandle($order_id) { $order = Order::select(['user_id', 'docter_id', 'product_type', 'total_amount', 'payment_type', 'payment_amount', 'order_sn', 'pay_order_pack_id', 'organization_id'])->where('id', $order_id)->first(); //发送下单消息 if ($order['product_type'] < 6) { $product_type_text = config('config.product_type_map')[$order['product_type']]; UserMessage::saveMessage($order['user_id'], 4, $order_id, [$product_type_text]); } elseif ($order['product_type'] == 6) { $orderPack = OrderPack::select(['pack_name', 'end_time'])->where('order_id', $order_id)->first(); UserMessage::saveMessage($order['user_id'], 5, $order_id, [$orderPack['pack_name'], date('Y-m-d', $orderPack['end_time'])]); //更新用户为服务包用户 User::where('id', $order['user_id'])->update(['is_pack' => 1]); } elseif ($order['product_type'] == 7) { $user = User::select(['balance'])->where('id', $order['user_id'])->first(); UserMessage::saveMessage($order['user_id'], 7, $order_id, [round($order['total_amount']/100, 2), round($user['balance']/100, 2)]); } //发送余额付款成功消息 if ($order['payment_type'] == 2) { $user = User::select(['balance'])->where('id', $order['user_id'])->first(); UserMessage::saveMessage($order['user_id'], 8, $order_id, [round($order['payment_amount']/100, 2), round($user['balance']/100, 2)]); } //发送医生端消息 DocterMessage::saveMessage($order['docter_id'], $order['user_id'], 1, $order_id, [$order['order_sn']]); //如果是服务包支付的,就扣服务包的次数 if ($order['payment_type'] == 3) { OrderPack::deductPackData($order['pay_order_pack_id'], $order['payment_type'], $order['payment_amount']); } if (!empty($order['docter_id'])) { //更新医生的服务人数 Docter::where('id', $order['docter_id'])->increment('service_persons'); } //如果是门诊预约,预约时间段的订单数要加1 if ($order['product_type'] == 3) { $orderPatient = OrderPatient::select(['time_period_id', 'appoint_start_time'])->where('order_id', $order_id)->first(); $schedule_date = date('Y-m-d', $orderPatient['appoint_start_time']); SchedulePeriod::where('docter_id', $order['docter_id'])->where('organization_id', $order['organization_id'])->where('time_period_id', $orderPatient['time_period_id'])->where('schedule_date', $schedule_date)->increment('order_num'); } return true; } public function suggest() { return $this->hasOne(Suggest::class)->select(['id', 'order_id']); } public function getIsEvaluateAttribute() { $is_evaluate = 0; $user = User::getUserByToken(false); if (!empty($user)) { if (Evaluate::where('order_id', $this->id)->where('user_id', $user['id'])->exists()) { $is_evaluate = 1; } } return $is_evaluate; } public function getOrderDurationAttribute() { if (!empty($this->outtime) && !empty($this->receiving_time)) { $diff = $this->outtime - $this->receiving_time; $hour = round($diff/3600); if ($hour == 0) { return round($diff/60).'分钟'; } return $hour.'小时'; } return ''; } }