示例#1
0
 /**
  *
  * create new order
  *
  * @param $userId
  * @param $addressId
  * @param $total
  * @param $discount
  * @param $originTotal
  * @param $quantity
  * @param int $status
  * @return orderModel
  */
 public function createOrder($userId, $addressId, $total = 0, $quantity = 0, $originTotal = 0, $discount = 0, $status = KACANA_ORDER_STATUS_NEW)
 {
     $address = $this->_addressService->getAddressReceiveById($addressId);
     $addressStr = $address->street;
     $orderData = new \stdClass();
     $orderData->user_id = $userId;
     $orderData->address_id = $addressId;
     $orderData->total = $total;
     $orderData->quantity = $quantity;
     $orderData->discount = $discount;
     $orderData->origin_total = $originTotal;
     $orderData->status = $status;
     $orderData->address = $addressStr . ', ' . $address->district->name . ', ' . $address->city->name;
     $order = $this->_orderModel->createItem($orderData);
     $this->_orderModel->updateItem($order->id, ['order_code' => crc32($order->id)]);
     $order->order_code = crc32($order->id);
     return $order;
 }
示例#2
0
 public function edit($domain, Request $request, $addressId)
 {
     $addressService = new addressService();
     try {
         $address = $addressService->getAddressReceiveById($addressId);
         $cities = $addressService->getListCity()->lists('name', 'id');
         $wards = $addressService->getListWardByDistrictId($address->district_id);
         $districts = $addressService->getListDistrict();
         if ($address->user_id != $this->_user->id) {
             throw new \Exception('Address is inValid!');
         }
         if ($request->isMethod('PUT')) {
             $addressService->updateAddressReceive($request->all());
         }
         return view('partner.customer.edit', ['user_address' => $address, 'cities' => $cities, 'districts' => $districts, 'wards' => $wards]);
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $return['error'] = $e->getMessage();
         $return['errorMsg'] = $e->getMessage();
         // @codeCoverageIgnoreEnd
     }
 }
示例#3
0
 public function deleteMyAddress($domain, $id, Request $request)
 {
     $userService = new userService();
     $addressService = new addressService();
     try {
         $user = $userService->getUserByEmail($this->_user->email);
         $address = $addressService->getAddressReceiveById($id);
         if (!$address || $address->user_id != $user->id || $address->default) {
             return redirect('/khach-hang/so-dia-chi');
         }
         $addressService->deleteMyAddress($user->id, $id);
         return redirect('/khach-hang/so-dia-chi');
     } catch (\Exception $e) {
         return view('errors.404', ['error_message' => $e->getMessage()]);
     }
 }