コード例 #1
0
 /**
  * Referral feature
  */
 public function referral()
 {
     $userRepo = app('UserRepo');
     if (Auth::user()->ref_code == null || Auth::user()->ref_code == '') {
         $userRepo->saveRefCodeCustomer();
         return Redirect::route('user.referral');
     }
     return View::make('user.referral')->with(['space_credit' => $userRepo->getCustomerSpaceCredit(), 'customer_join' => $userRepo->getCustomerJoinReferral(), 'space' => Space::where('user_id', Auth::user()->id)->orderBy('created_at', 'desc')->get()]);
 }
コード例 #2
0
ファイル: OrderRepo.php プロジェクト: rizalafani/thankspace
 /**
  * Get Storage Query, for get available storage in whare house
  * and create new invoice for almost expired storage period,
  * send mail and return stuff. this function processed with cron job
  *
  * @return array $data
  */
 public function GetInvoiceAlmostExpired()
 {
     $interval_info = [-7, -3, 0, 1];
     $interval_returned = 3;
     $orderPayments = $this->_GetStorages()->where('order.is_returned', 0)->where('payment_1.status', 2)->where('order_schedule.status', 1)->whereNull('order_stuff.return_schedule_id')->having('expired_on', '>=', $interval_info[0])->get();
     $data = $this->_getInvoiceInfo($orderPayments);
     foreach ($data as $d) {
         $temp = $d;
         if (in_array($temp['expired_on'], $interval_info)) {
             $lunas = false;
             // langsung lunas
             // cek, apakah sudah punya invoice baru apa tidak. jika tidak, buatkan !
             if ($temp['next_invoice'] == null) {
                 // ambil space credit user_id
                 $space_credit = app('UserRepo')->getCustomerSpaceCredit($temp['user_id']);
                 // ambil total biaya
                 $totalBiaya = getTotalFromCountStuff($temp['stuff']);
                 // ambil input new_invoice_input ( order_payment )
                 $newPayment = $temp['new_invoice_input'];
                 if ($space_credit != 0) {
                     if ($space_credit >= $totalBiaya) {
                         $newPayment += ['space_credit_used' => $totalBiaya, 'status' => '2'];
                         $lunas = true;
                     } else {
                         $newPayment += ['space_credit_used' => $space_credit];
                     }
                 }
                 // buat order baru
                 $newInvoice = $this->_save_orderPayment($temp['order_id'], $newPayment);
                 $temp['next_invoice'] = $newInvoice->code;
                 $temp['new_invoice'] = $newInvoice;
                 // insert space debet jika $space_credit_used != 0
                 if ($newInvoice->space_credit_used != 0) {
                     \Space::create(['user_id' => $temp['user_id'], 'type' => 'debet', 'nominal' => $newInvoice->space_credit_used, 'keterangan' => 'Credit used for purchases invoice #' . $newInvoice->code]);
                 }
             }
             if ($lunas) {
                 // kirim email langsung lunas
                 $this->_sendRecurringInvoiceLunasMail($temp);
             } else {
                 // kirim email invoice expired & invoice baru
                 $this->_sendRecurringInvoiceMail($temp);
             }
         } elseif ($temp['expired_on'] == $interval_returned) {
             // lakukan pengembalian barang
             $returnScheduleInput = ['user_id' => $temp['user_id'], 'order_id' => $temp['order_id'], 'return_date' => \Carbon\Carbon::parse($temp['expired_date'])->addDays(4)->format('Y-m-d'), 'return_time' => '08:00am - 10:00am', 'stuffs' => explode(',', implode(',', array_column($temp['stuff'], 'ids'))), 'city_id' => '', 'other_address' => '', 'status' => 0];
             $this->createReturnSchedule($returnScheduleInput);
             $_newInvoice = $temp['new_invoice'];
             //hapus invoice baru yang dibuat
             \OrderPayment::where('code', $_newInvoice->code)->delete();
             // cek apakah invoice baru menggunakan space credit, jika iya, hapus space debet nya untuk invoice ini.
             if ($_newInvoice->space_credit_used != 0) {
                 \Space::where('keterangan', 'like', '%#' . $_newInvoice->code . '%')->delete();
             }
             // kirim email pengembalian barang
             $this->_sendRecurringInvoiceKirimBarangMail($temp);
         }
     }
     return $data;
 }