Exemplo n.º 1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     if (session('user')) {
         //$customers = Customer::orderBy('id', 'desc')->paginate(10);
         $customers = Merchant::find(session('user'))->customers()->orderBy('id', 'desc')->paginate(10);
         return view('customers.index', compact('customers'));
     } else {
         return back();
     }
 }
Exemplo n.º 2
0
 public function sendToMerchant($you, $msg, $who)
 {
     $apikey = $this->apikey;
     //block phone and emails
     $msg = preg_replace('/\\+?[0-9][0-9()-\\s+]{4,20}[0-9]/', '[blocked]', $msg);
     $msg = preg_replace("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,})\$/", '[blocked]', $msg);
     //get merchant id
     if ($merchant_id = Product::find($who)->merchant_id) {
         if ($merchant = Merchant::find($merchant_id)) {
             $chat_id = $merchant->chat_id;
             //create telegram instance
             $telegram = new \Matriphe\Telegrambot\Telegrambot($apikey);
             if ($chat_id == $this->support_channel) {
                 $msg = "*unhandled interaction*                    " . $you . "                                                              " . $msg . "                                           *merchant responsible: " . $merchant->phonenumber;
                 $message = $telegram->sendMessage(['chat_id' => $chat_id, 'text' => $msg]);
                 $this->customerLog($you, $chat_id, $msg, $message, $who);
             } else {
                 $message = $telegram->sendMessage(['chat_id' => $chat_id, 'text' => $msg]);
                 $this->customerLog($you, $chat_id, $msg, $message, $who);
             }
         } else {
             $message = $telegram->sendMessage(['chat_id' => $chat_id, 'text' => $msg]);
             //$this->customerLog($you,$chat_id,$msg,$message,$who);
         }
     }
     // Get bot info
     //$getme = $telegram->getMe();
     //var_dump($getme);
     // Get bot messages received by bot. See user_id from here.
     //$updates = $telegram->getUpdates();
     //var_dump($updates[2]);
     //echo sizeof($updates);
     //// Send message to user.
     //$message = $telegram->sendMessage([
     //    'chat_id' => $chat_id,
     //    'text' => $msg
     //]);
     //var_dump($message);
     //// Upload file, use fopen function.
     //$filepath = '/home/matriphe/photo.jpg';
     //$photo = $telegram->sendPhoto([
     //    'chat_id' => $chat_id,
     //    'photo' => fopen($filepath, 'rb'),
     //    'caption' => 'The caption goes here!'
     //]);
     //var_dump($photo);
 }
 public function addBusStop(Request $request, $id)
 {
     $input = $request->all();
     $agent = Merchant::find($id);
     if (isset($input['type']) && $input['type'] == 'genticket') {
         $validator = Validator::make($request->all(), ["terminal_id" => "required", "ticket_type" => "required"]);
         if ($validator->fails()) {
             if ($request->ajax()) {
                 return response()->json($validator->messages());
             } else {
                 return \Redirect::back()->withErrors($validator)->withInput();
             }
         }
         //$input = $request->all();
         $stack = new Ticketstack();
         $stack->batch_code = Ticket::stackCode();
         $stack->created_at = date("Y-m-d H:i:s");
         $stack->save();
         $ticket = new Ticket();
         $terminal = Busstop::where("id", "=", trim($input['terminal_id']))->first();
         $count = $input['qty'];
         $account = Account::where("app_id", "=", $input['app_id'])->first();
         for ($k = 1; $k <= $count; $k++) {
             $time = time();
             DB::table('ticketseed')->insert(['code' => $time]);
             $mid = DB::table("ticketseed")->max("id");
             //$amount   =  ($input['ticket_type'] == 1) ? $terminal->one_way_to_fare : $terminal->one_way_from_fare ;
             $amount = 1000;
             Ticket::insert(array("code" => $ticket->ticketCode($mid), "account_id" => $account->id, "app_id" => $input['app_id'], "agent_id" => $id, "serial_no" => $ticket->uniqueID($mid), "terminal_id" => $terminal->id, "stack_id" => $stack->id, "route_id" => $input['route_id'], "amount" => $amount, "ticket_type" => $input['ticket_type']));
         }
         $account->balance += $amount * $input['qty'];
         $agent->balance += $amount * $input['qty'];
         $account->update();
         $agent->update();
     } else {
         $account = new Account();
         $mid = Account::uniqueID() + 1;
         $terminal_id = DB::table("busstops")->where("short_name", "=", $input['short_name'])->pluck("id");
         $account->merchant_id = $input['merchant_id'];
         $account->busstop_id = $terminal_id;
         $m = $account->merchant_id + $mid;
         $realid = uniqid($m);
         $realid = substr($realid, -1, 5);
         $realid = $realid . str_pad($mid, 5, 0, STR_PAD_LEFT);
         $account->account_id = uniqid($m);
         if ($account->save()) {
             return response()->json("record saved successfully");
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update($id)
 {
     $merchant = Merchant::find($id);
     $merchant->name = Input::get('name');
     $merchant->tac = Input::get('tac');
     $merchant->desc = Input::get('desc');
     if (Input::file('banner') != null) {
         $banner = Input::file('banner');
         $destinationPath = 'C:/xampp/htdocs/tagin/public/assets/img';
         $filename = $banner->getClientOriginalName();
         $banner->move($destinationPath, $filename);
         $merchant['banner'] = $filename;
     }
     if (Input::file('logo') != null) {
         $logo = Input::file('logo');
         $logoDestinationPath = 'C:/xampp/htdocs/tagin/public/assets/img';
         $logoFilename = $logo->getClientOriginalName();
         $logo->move($logoDestinationPath, $logoFilename);
         $merchant['logo'] = $logoFilename;
     }
     $merchant->save();
     return Redirect::route('admin.merchant.index', $merchant->id)->with('message', $merchant->title . ' updated.');
 }
Exemplo n.º 5
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $product = Merchant::find(session('user'))->products->find($id);
     if (!is_null($product)) {
         $product = Product::findOrFail($id);
         return view('products.edit', compact('product'));
     } else {
         return back();
     }
 }