Exemplo n.º 1
0
 public function get_money(Request $request)
 {
     if ($request->register_id == null || $request->money == null || $request->code == null) {
         return $this->responseBadRequest('Not enough parameters!');
     }
     $register_id = $request->register_id;
     $money = str_replace(array('.', ','), '', $request->money);
     $code = $request->code;
     $register = Register::find($register_id);
     if ($register->status == 1) {
         return $this->responseBadRequest('Học viên này đã đóng tiền rồi');
     }
     $register->money = $money;
     $register->paid_time = format_time_to_mysql(time());
     $register->note = $request->note;
     $register->staff_id = $this->user->id;
     $regis_by_code = Register::where('code', $code)->first();
     if ($regis_by_code != null) {
         return $this->responseBadRequest('code is already existed');
     } else {
         $register->code = $code;
         $register->status = 1;
         $register->save();
         $transaction = new Transaction();
         $transaction->money = $money;
         $transaction->sender_id = $this->user->id;
         $transaction->receiver_id = $register->id;
         $transaction->sender_money = $this->user->money;
         $transaction->note = "Học viên " . $register->user->name . " - Lớp " . $register->studyClass->name;
         $transaction->status = 1;
         $transaction->type = 1;
         $transaction->save();
         DB::insert(DB::raw("\n                insert into attendances(`register_id`,`checker_id`,class_lesson_id)\n                (select registers.id,-1,class_lesson.id\n                from class_lesson\n                join registers on registers.class_id = class_lesson.class_id\n                where registers.id = {$register->id}\n                )\n                "));
         $current_money = $this->user->money;
         $this->user->money = $current_money + $money;
         $this->user->save();
         send_mail_confirm_receive_studeny_money($register, ["*****@*****.**", "*****@*****.**"]);
     }
     $return_data = array('data' => ['money' => $register->money, 'code' => $register->code, 'paid_time' => format_date_full_option($register->paid_time)], 'message' => "success");
     return $this->respond($return_data);
 }
Exemplo n.º 2
0
 public function create_transaction($domain, Request $request)
 {
     if ($this->user->status == 2) {
         return $this->responseBadRequest('Nhân viên này đang chuyển tiền.');
     } else {
         $this->user->status = 2;
         $this->user->save();
         $transaction = new Transaction();
         $transaction->status = 0;
         $transaction->sender_id = $this->user->id;
         $transaction->receiver_id = $request->receiver_id;
         $transaction->receiver_money = User::find($request->receiver_id)->money;
         $transaction->money = $this->user->money;
         $transaction->save();
         $notification = new Notification();
         $notification->product_id = $transaction->id;
         $notification->actor_id = $this->user->id;
         $notification->receiver_id = $request->receiver_id;
         $notification->type = 3;
         $notification->save();
         $data = array("message" => $notification->actor->name . " vừa chuyển tiền cho bạn và đang chờ bạn xác nhận.", "link" => "", 'transaction' => ['id' => $transaction->id, 'sender' => $transaction->sender->name, 'receiver' => $transaction->receiver->name, 'status' => transaction_status_raw($transaction->status), 'money' => $transaction->money], 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
         $publish_data = array("event" => "notification", "data" => $data);
         Redis::publish('colorme-channel', json_encode($publish_data));
         $publish_data = array("event" => "notification", "data" => ["notification" => $this->notificationTransformer->transform($notification)]);
         Redis::publish('colorme-channel', json_encode($publish_data));
         return $this->respond(['transaction' => ['sender' => $transaction->sender->name, 'receiver' => $transaction->receiver->name, 'status' => transaction_status_raw($transaction->status), 'money' => $transaction->money]]);
     }
 }
Exemplo n.º 3
0
 public function transform($shift_pick)
 {
     $shift = $shift_pick->shift;
     return ["user" => ['name' => $shift_pick->user->name], 'status' => $shift_pick->status, 'shift' => ["name" => $shift->shift_session->name, 'date' => $shift->date, 'start_time' => format_time_shift(strtotime($shift->shift_session->start_time)), 'end_time' => format_time_shift(strtotime($shift->shift_session->end_time))], 'created_at' => format_date_full_option($shift_pick->created_at)];
 }
Exemplo n.º 4
0
 public function store_comment(Request $request)
 {
     $comment_content = $request->comment_content;
     $product_id = $request->product_id;
     //send one notifcation to author
     if (Product::find($product_id)->author->id != $this->user->id) {
         $notification = new Notification();
         $notification->product_id = $request->product_id;
         $notification->actor_id = $this->user->id;
         $notification->receiver_id = Product::find($product_id)->author->id;
         $notification->type = 1;
         $notification->save();
         $data = array("message" => $notification->actor->name . " đã bình luận về bài viết của bạn", "link" => url('bai-tap-colorme?id=' . $notification->product_id), 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
         $publish_data = array("event" => "notification", "data" => $data);
         Redis::publish('colorme-channel', json_encode($publish_data));
     }
     $product = Product::find($product_id);
     $already_sent_noti = array();
     //send to all others that involve in the post
     foreach ($product->comments as $comment) {
         $commenter_id = $comment->commenter_id;
         if ($product->author->id != $commenter_id && $commenter_id != $this->user->id && !in_array($commenter_id, $already_sent_noti)) {
             $notification = new Notification();
             $notification->product_id = $request->product_id;
             $notification->actor_id = $this->user->id;
             $notification->receiver_id = $commenter_id;
             $notification->type = 2;
             $notification->save();
             $data = array("message" => $notification->actor->name . " cũng đã bình luận về bài viết mà bạn đã bình luận", "link" => url('bai-tap-colorme?id=' . $notification->product_id), 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
             $publish_data = array("event" => "notification", "data" => $data);
             Redis::publish('colorme-channel', json_encode($publish_data));
             $already_sent_noti[] = $commenter_id;
         }
     }
     $comment = new Comment();
     $comment->product_id = $product_id;
     $comment->commenter_id = $this->user->id;
     $comment->content = $comment_content;
     $comment->save();
     $view = View::make('components.comment_item', ['comment' => $comment]);
     $contents = $view->render();
     $publish_data = array("event" => "comment", "data" => $contents);
     Redis::publish('colorme-channel', json_encode($publish_data));
     return time_elapsed_string(strtotime($comment->created_at));
 }
Exemplo n.º 5
0
 public function confirm_transaction(Request $request)
 {
     $transaction_id = $request->id;
     $status = $request->status;
     $transaction = Transaction::find($transaction_id);
     if ($transaction->status != 0) {
         return json_encode(['error' => 'Giao dịch không ở trạng thái pending', 'status' => transaction_status($transaction->status), 'money' => currency_vnd_format($transaction->receiver->money)]);
     }
     $transaction->status = $status;
     $transaction->sender->status = 0;
     if ($status == 1) {
         $transaction->sender->money = $transaction->sender->money - $transaction->money;
         $transaction->receiver->money = $transaction->receiver->money + $transaction->money;
     }
     $transaction->save();
     $transaction->sender->save();
     $transaction->receiver->save();
     $notification = new Notification();
     $notification->product_id = $transaction->id;
     $notification->actor_id = $transaction->receiver->id;
     $notification->receiver_id = $transaction->sender->id;
     $notification->type = 4;
     $notification->save();
     $data = array("message" => "Bạn chuyển tiền cho " . $transaction->receiver->name . " " . transaction_status_raw($transaction->status), "link" => "", 'transaction' => ['id' => $transaction->id, 'sender' => $transaction->sender->name, 'receiver' => $transaction->receiver->name, 'status' => transaction_status_raw($transaction->status), 'money' => $transaction->money], 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
     $publish_data = array("event" => "notification", "data" => $data);
     Redis::publish('colorme-channel', json_encode($publish_data));
     $publish_data = array("event" => "notification", "data" => ["notification" => $this->notificationTransformer->transform($notification)]);
     Redis::publish('colorme-channel', json_encode($publish_data));
     $return_data = array('status' => transaction_status($transaction->status), 'money' => currency_vnd_format($transaction->receiver->money));
     return json_encode($return_data);
 }
Exemplo n.º 6
0
 public function topic(Request $request)
 {
     $topic = new Topic();
     $topic->name = $request->name;
     $topic->description = $request->description;
     $image_name = uploadFileToS3($request, 'avatar', 300, $topic->avatar_url);
     if ($image_name != null) {
         $topic->avatar_name = $image_name;
         $topic->avatar_url = $this->s3_url . $image_name;
     }
     $topic->class_id = $request->class_id;
     $topic->author_id = $this->user->id;
     $topic->deadline = $request->deadline;
     $topic->save();
     $class = StudyClass::find($request->class_id);
     foreach ($class->registers as $register) {
         $notification = new Notification();
         $notification->actor_id = $this->user->id;
         $notification->product_id = $topic->id;
         $notification->receiver_id = $register->user->id;
         $notification->type = 5;
         $notification->save();
         $data = array("message" => "Lớp " . $class->name . ": " . $this->user->name . " vừa tạo một topic mới ", "link" => url('group/class/' . $request->class_id . '#/topic/' . $topic->id), 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
         $publish_data = array("event" => "notification", "data" => $data);
         Redis::publish('colorme-channel', json_encode($publish_data));
     }
     return response()->json($topic, 200);
 }