Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. <<<<<<< HEAD
  2. $salonId = $this->applicationService->getCurrentSalon();
  3. $id = $request->get('id');
  4.  
  5. // $result = DB::select("SELECT u.name,phone,b.id,s.name as service,price,b.status,payment_id,to_char(start_time::date, 'DD,Mon YYYY')as date
  6. // FROM bookings b left join services s on s.id=b.service_id
  7. // left join users u on u.id=b.user_id where b.id=? and b.salon_id=?",[$id,$salonId]);
  8. //
  9. // return ['book' => $result[0]];
  10. /** @var Booking $booking */
  11. $booking = $this->bookingRepository->findWhere(['id' => $id, 'salon_id' => $salonId])->first();
  12. if (is_null($booking)) {
  13. return [
  14. 'Not authorized'
  15. ];
  16. }
  17.  
  18. $book = [
  19. 'date' => $booking->start_time->format('h:ma d, M Y'),
  20. 'id' => $booking->id,
  21. 'name' => $booking->user ? ($booking->user->name . ' ' . $booking->user->surname) : 'Not found',
  22. 'phone' => $booking->user ? $booking->user->phone : 'Not found',
  23. 'service' => $booking->service ? $booking->service->name : 'Not found',
  24. 'status' => $booking->status,
  25. 'original_price' => $booking->original_price,
  26. 'price' => $booking->total_price,
  27. 'discount' => $booking->is_discount,
  28. ];
  29. if ($booking->is_discount && $booking->promo) {
  30. $book['promo'] = [
  31. 'code' => $booking->promo->code,
  32. 'value' => $booking->promo->value,
  33. 'type' => $booking->promo->type,
  34. ];
  35. }
  36. return [
  37. 'book' => $book
  38. ];
  39. }
  40.  
  41.  
  42. public function store(BookRequest $request)
  43. {
  44. $id = $request->get('id');
  45. $status = $request->get('status');
  46.  
  47. $salonId = intval($this->applicationService->getCurrentSalon(), 10);
  48. $booking = $this->bookingRepository->find($id);
  49.  
  50. // dont trust the clients!!!
  51. if ($booking->salon_id == $salonId &&
  52. in_array($status, [Booking::SUCCESSFUL, Booking::CANCELED])) {
  53.  
  54. // always check params
  55. $booking->status = $status;
  56. $booking->save();
  57. // notify customer & vendor
  58. $this->dispatch(new BookingStatuses($id, $status, BookingStatuses::ACTION_BY_VENDOR));
  59.  
  60. return [
  61. 'success' => true
  62. ];
  63.  
  64.  
  65. }
  66. return [
  67. 'error' => 'Not authorized.'
  68. ];
  69.  
  70. =======
  71. return $this->bookingRepository->findWhere(['id' => $request->get('id')])->first();
  72. >>>>>>> stage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement