예제 #1
0
파일: Order.php 프로젝트: artemsk/veer-core
 protected function prepareData($fill)
 {
     if (empty($fill['sites_id'])) {
         $fill['sites_id'] = app('veer')->siteId;
     }
     if (empty($fill['users_id']) && $this->action != 'add') {
         $fill['users_id'] = \Auth::id();
     }
     foreach (['free', 'close', 'hidden', 'archive', 'delivery_free', 'delivery_hold', 'payment_hold', 'payment_done'] as $key) {
         $fill[$key] = isset($fill[$key]) ? 1 : 0;
     }
     if ($fill['close']) {
         $fill['close_time'] = now();
     }
     $fill['progress'] = isset($fill['progress']) ? strtr($fill['progress'], ["%" => ""]) : 5;
     $fill['delivery_plan'] = !empty($fill['delivery_plan']) ? parse_form_date($fill['delivery_plan']) : null;
     $fill['delivery_real'] = !empty($fill['delivery_real']) ? parse_form_date($fill['delivery_real']) : null;
     $fill += ['cluster_oid' => null, 'cluster' => null, 'delivery_method_id' => $this->order->delivery_method_id, 'payment_method_id' => $this->order->payment_method_id, 'status_id' => $this->order->status_id, 'userbook_id' => $this->order->userbook_id];
     if ($this->order->cluster_oid != $fill['cluster_oid'] || $this->order->cluster != $fill['cluster']) {
         $existingOrders = \Veer\Models\Order::where('sites_id', '=', $fill['sites_id'])->where('cluster', '=', $fill['cluster'])->where('cluster_oid', '=', $fill['cluster_oid'])->first();
         // we cannot update cluster ids if they already exist
         if (is_object($existingOrders) || empty($fill['cluster_oid'])) {
             array_forget($fill, ['cluster_oid', 'cluster']);
         }
     }
     if ($this->order->delivery_method_id != $fill['delivery_method_id'] && empty($fill['delivery_method'])) {
         $fill['delivery_method'] = \Veer\Models\OrderShipping::where('id', '=', $fill['delivery_method_id'])->pluck('name');
     }
     if ($this->order->payment_method_id != $fill['payment_method_id'] && empty($fill['payment_method'])) {
         $fill['payment_method'] = \Veer\Models\OrderPayment::where('id', '=', $fill['payment_method_id'])->pluck('name');
     }
     return $fill;
 }
예제 #2
0
 public function update($id)
 {
     $p = \Veer\Models\OrderPayment::find($id);
     if (is_object($p)) {
         $this->entity = $p;
         event('veer.message.center', trans('veeradmin.payment.update'));
     } else {
         event('veer.message.center', trans('veeradmin.payment.error'));
     }
     return $this;
 }
예제 #3
0
 /**
  * recalculate Payment for Orders
  * @param type $order
  */
 public function recalculateOrderPayment($order, $payment = null, $pretend = false)
 {
     if (empty($payment)) {
         $payment = \Veer\Models\OrderPayment::find($order->payment_method_id);
     }
     if (!is_object($payment)) {
         return $order;
     }
     $order->payment_method = $payment->name;
     // 1
     switch ($payment->paying_time) {
         case "now":
             // @todo redirect to payment system (but if admin then change to later)
             break;
         case "later":
             // @todo create link to payment system and send it to user (save it somewhere)
             break;
     }
     // 2 calculator
     $class = starts_with($payment->func_name, "\\") ? $payment->func_name : "\\Veer\\Components\\Ecommerce\\" . $payment->func_name;
     if (!empty($payment->func_name) && class_exists($class)) {
         $paymentFunc = new $class();
         $getData = $paymentFunc->fire($order, $payment);
         $order->payment_done = isset($getData->payment_done) ? $getData->payment_done : false;
         $order->payment_hold = isset($getData->payment_hold) ? $getData->payment_hold : true;
         // @todo do we need this
         $payment->commission = isset($getData->commission) ? $getData->commission : $payment->commission;
         $payment->discount_enable = isset($getData->discount_enable) ? $getData->discount_enable : $payment->discount_enable;
         $payment->discount_price = isset($getData->discount_price) ? $getData->discount_price : $payment->discount_price;
         $payment->discount_conditions = isset($getData->discount_conditions) ? $getData->discount_conditions : $payment->discount_conditions;
     }
     // 3
     if ($payment->commission > 0) {
         $content = new \Veer\Models\OrderProduct();
         $content->orders_id = $order->id;
         $content->product = 0;
         $content->products_id = 0;
         $content->name = \Lang::get('veeradmin.order.content.payment.commission') . " (" . $payment->commission . "%)";
         $content->original_price = $order->content_price * ($payment->commission / 100);
         $content->quantity = 1;
         $content->attributes = "";
         $content->comments = \Lang::get('veeradmin.order.content.commission');
         $content->price_per_one = $content->original_price;
         $content->price = $content->original_price;
         if ($pretend == false) {
             $content->save();
         }
         $order->content_price = $order->content_price + $content->price;
     }
     // 4
     if ($payment->discount_enable == 1 && $payment->discount_price > 0) {
         $checkConditions = $this->checkDisountConditions($payment->discount_conditions, $order, "total");
         if (array_get($checkConditions, 'activate') == true || array_get($checkConditions, 'conditions') == false) {
             if (array_get($checkConditions, 'price') == "total") {
                 $content = new \Veer\Models\OrderProduct();
                 $content->orders_id = $order->id;
                 $content->product = 0;
                 $content->products_id = 0;
                 $content->name = \Lang::get('veeradmin.order.content.payment.discount') . " (-" . $payment->discount_price . "%)";
                 $content->original_price = 0 - $order->content_price * ($payment->discount_price / 100);
                 $content->quantity = 1;
                 $content->attributes = "";
                 $content->comments = \Lang::get('veeradmin.order.content.discount');
                 $content->price_per_one = $content->original_price;
                 $content->price = $content->original_price;
                 if ($pretend == false) {
                     $content->save();
                 }
                 $order->content_price = $order->content_price + $content->price;
             } else {
                 $order->delivery_price = $order->delivery_price * (1 - $payment->discount_price / 100);
             }
         }
     }
     return $order;
 }
예제 #4
0
 /**
  * Get all veer shop payments
  * @return object
  */
 function payments($siteId = null)
 {
     if (empty($siteId)) {
         $payments = \Veer\Models\OrderPayment::select();
     } else {
         $payments = \Veer\Models\OrderPayment::where('sites_id', '=', $siteId);
     }
     return \Cache::remember('listofPaymentMethods-' . $siteId, 0.5, function () use($payments) {
         return $payments->where('enable', '=', true)->orderBy('manual_order', 'asc')->get();
     });
 }
예제 #5
0
파일: Bill.php 프로젝트: artemsk/veer-core
 public function add($params, $template = null)
 {
     $order = \Veer\Models\Order::find(array_get($params, 'orders_id'));
     $status = \Veer\Models\OrderStatus::find(array_get($params, 'status_id'));
     $payment = $payment_method = array_get($params, 'payment_method');
     $sendEmail = array_pull($params, 'sendTo', null);
     if (empty($payment)) {
         $payment = \Veer\Models\OrderPayment::find(array_get($params, 'payment_method_id'));
         $payment_method = isset($payment->name) ? $payment->name : $payment_method;
     }
     $content = '';
     if (!empty($template)) {
         /* leave 'view' instead of 'viewx' because we always need (rendered) html representation of the bill */
         $content = view("components.bills." . $template, ["order" => $order, "status" => $status, "payment" => $payment, "price" => array_get($params, 'price')])->render();
     }
     $b = new \Veer\Models\OrderBill();
     $b->fill($params);
     $b->users_id = isset($order->users_id) ? $order->users_id : 0;
     $b->payment_method = $payment_method;
     $b->content = $content;
     if (!empty($sendEmail)) {
         $b->sent = true;
     }
     $b->save();
     if (!empty($sendEmail) && is_object($order)) {
         $this->sendEmailBillCreate($b, $order);
     }
     return $this;
 }