Exemplo n.º 1
0
 public function delete($id)
 {
     \Veer\Models\Order::where('delivery_method_id', '=', $id)->update(['delivery_method_id' => 0]);
     \Veer\Models\OrderShipping::destroy($id);
     event('veer.message.center', trans('veeradmin.shipping.delete') . " " . $this->restore_link('OrderShipping', $id));
     return $this;
 }
Exemplo n.º 2
0
 public function delete($id)
 {
     \Veer\Models\Order::where('payment_method_id', '=', $id)->update(['payment_method_id' => 0]);
     \Veer\Models\OrderBill::where('payment_method_id', '=', $id)->update(['payment_method_id' => 0]);
     \Veer\Models\OrderPayment::destroy($id);
     event('veer.message.center', trans('veeradmin.payment.delete') . " " . $this->restore_link('OrderPayment', $id));
     return $this;
 }
Exemplo n.º 3
0
 /**
  * delete Status
  */
 public function delete($id)
 {
     \Veer\Models\Order::where('status_id', '=', $id)->update(['status_id' => 0]);
     \Veer\Models\OrderBill::where('status_id', '=', $id)->update(['status_id' => 0]);
     \Veer\Models\OrderHistory::where('status_id', '=', $id)->update(['status_id' => 0]);
     \Veer\Models\OrderStatus::destroy($id);
     event('veer.message.center', trans('veeradmin.status.delete') . " " . $this->restore_link('OrderStatus', $id));
     return $this;
 }
Exemplo n.º 4
0
 protected function filterOrders($type, $filters)
 {
     $fields = array("userbook" => "userbook_id", "userdiscount" => "userdiscount_id", "status" => "status_id", "delivery" => "delivery_method_id", "payment" => "payment_method_id", "status_history" => "status_id", "site" => null, "user" => null);
     if (array_key_exists($type, $fields) || empty($type)) {
         return $this->buildFilterWithElementsQuery($filters, "\\Veer\\Models\\Order", $this->getPluralizeValue($type), array_get($fields, $type));
     }
     if ($type == "products") {
         return $this->filterOrderByProducts(head($filters));
     }
     return \Veer\Models\Order::where($type, '=', head($filters));
 }
Exemplo n.º 5
0
 /**
  * send emails when updating order status
  */
 protected function sendEmailOrdersStatus($orderId, $options = array())
 {
     $data = \Veer\Models\Order::where('id', '=', $orderId)->select('sites_id', 'cluster', 'cluster_oid', 'name', 'email')->first();
     $data_array = $data->toArray();
     $data_array['orders_id'] = app('veershop')->getOrderId($data->cluster, $data->cluster_oid);
     $data_array['status'] = array_get($options, 'history');
     $data_array['link'] = $data->site->url . "/order/" . $orderId;
     $subject = \Lang::get('veeradmin.emails.order.subject', array('oid' => $data_array['orders_id']));
     if (!empty($data->email)) {
         (new \Veer\Commands\SendEmailCommand('emails.order-status', $data_array, $subject, $data->email, null, $data->sites_id))->handle();
     }
 }
Exemplo n.º 6
0
 /**
  * add New Order
  * 
  * pin, close_time, type, status_id, cluster, cluster_oid,
  * users_id, user_type, userdiscount_id, userbook_id, country, city, address, hash
  * 
  * @param $order
  * @param $usersId
  * @return array
  */
 public function addNewOrder($order, $usersId, $book = array(), $pretend = false)
 {
     $order->pin = false;
     $order->close_time = null;
     $order->type = 'reg';
     $firststatus = \Veer\Models\OrderStatus::firststatus()->pluck('id');
     $order->status_id = !empty($firststatus) ? $firststatus : 0;
     $cluster = \Veer\Models\Configuration::where('sites_id', '=', $order->sites_id)->where('conf_key', '=', 'CLUSTER')->pluck('conf_val');
     if (empty($cluster)) {
         $cluster = 0;
     }
     $order->cluster = $cluster;
     $order->cluster_oid = \Veer\Models\Order::where('sites_id', '=', $order->sites_id)->where('cluster', '=', $cluster)->max('cluster_oid') + 1;
     if (empty($usersId) && !empty($order->email)) {
         $findUser = \Veer\Models\User::where('sites_id', '=', $order->sites_id)->where('email', '=', $order->email)->first();
         if (is_object($findUser)) {
             $order->users_id = $findUser->id;
             if (empty($order->phone)) {
                 $order->phone = $findUser->phone;
             }
             if (empty($order->name)) {
                 $order->name = $findUser->firstname . " " . $findUser->lastname;
             }
         } else {
             $newUser = new \Veer\Models\User();
             $newUser->sites_id = $order->sites_id;
             $newUser->email = $order->email;
             $newUser->phone = $order->phone;
             $password2Email = str_random(16);
             $newUser->password = $password2Email;
             $newUser->save();
             $order->users_id = $newUser->id;
             $order->type = 'unreg';
             $unregStatus = \Veer\Models\OrderStatus::unregstatus()->pluck('id');
             if (!empty($unregStatus)) {
                 $order->status_id = $unregStatus;
             }
         }
     }
     if (!empty($usersId) && (empty($order->email) || empty($order->phone) || empty($order->name))) {
         $findUser = \Veer\Models\User::where('id', '=', $usersId)->first();
         if (is_object($findUser)) {
             if (empty($order->email)) {
                 $order->email = $findUser->email;
             }
             if (empty($order->phone)) {
                 $order->phone = $findUser->phone;
             }
             if (empty($order->name)) {
                 $order->name = $findUser->firstname . " " . $findUser->lastname;
             }
         }
     }
     $userRole = \Veer\Models\UserRole::whereHas('users', function ($q) use($order) {
         $q->where('users.id', '=', $order->users_id);
     })->pluck('role');
     $order->user_type = !empty($userRole) ? $userRole : '';
     if (!empty($order->userdiscount_id)) {
         $checkDiscount = \Veer\Models\UserDiscount::where('id', '=', $order->userdiscount_id)->where('sites_id', '=', $order->sites_id)->whereNested(function ($q) use($order) {
             $q->where('users_id', '=', 0)->orWhere('users_id', '=', $order->users_id);
         })->whereNested(function ($q) {
             $q->where('status', '=', 'wait')->orWhere('status', '=', 'active');
         })->first();
         if (is_object($checkDiscount)) {
             $checkDiscount->users_id = $order->users_id;
             $checkDiscount->status = 'active';
             $checkDiscount->save();
         } else {
             $order->userdiscount_id = 0;
         }
     }
     if (!empty($book)) {
         $book['fill']['users_id'] = $order->users_id;
         $newBook = $this->updateOrNewBook($book, $pretend);
     }
     if (isset($newBook) && is_object($newBook)) {
         $order->userbook_id = $newBook->id;
         $order->country = !empty($newBook->country) ? $newBook->country : '';
         $order->city = !empty($newBook->city) ? $newBook->city : '';
         $order->address = trim($newBook->postcode . " " . $newBook->address);
     }
     $order->hash = bcrypt($order->cluster . $order->cluster_oid . $order->users_id . $order->sites_id . str_random(16));
     if ($pretend == false) {
         $order->save();
         $this->incrementOrdersCount($order->users_id);
         $secret = new \Veer\Models\Secret(array("secret" => str_random(64)));
         $order->secrets()->save($secret);
     }
     return array($order, isset($checkDiscount) ? $checkDiscount : null);
 }
Exemplo n.º 7
0
 public function status($history)
 {
     array_set($history, 'orders_id', $this->id);
     array_set($history, 'name', \Veer\Models\OrderStatus::where('id', '=', array_get($history, 'status_id'))->pluck('name'));
     if (empty($history['name'])) {
         $history['name'] = '[?]';
     }
     $update = ['status_id' => array_get($history, 'status_id')];
     $progress = array_pull($history, 'progress');
     if (!empty($progress)) {
         $update['progress'] = $progress;
     }
     $sendEmail = array_pull($history, 'send_to_customer');
     \Veer\Models\OrderHistory::create($history);
     \Veer\Models\Order::where('id', '=', $this->id)->update($update);
     if (!empty($sendEmail)) {
         $this->sendEmailOrdersStatus($this->id, ['history' => $history]);
     }
     return $this;
 }