Exemplo n.º 1
0
 /**
  * @param $name
  * @param $type
  * @param $code
  * @return addressCityModel
  */
 public function createCity($name, $type, $code)
 {
     $city = new addressCityModel();
     $city->code = $code;
     $city->type_service = $type;
     $city->name = $name;
     $city->save();
     return $city;
 }
Exemplo n.º 2
0
 /**
  * @param CartRequest $request
  */
 public function processCart(CartRequest $request)
 {
     $re = array();
     if (Request::isMethod('post') && $request->all()) {
         //save user
         $user = new User();
         $uid = 0;
         $username = "";
         $email = "";
         $existUser = $user->getUserByEmail($request->get('email'));
         if (!empty($existUser)) {
             $uid = $existUser->id;
             $username = $existUser->name;
             $email = $existUser->email;
         } else {
             $item = array('name' => $request->get('name'), 'email' => $request->get('email'), 'phone' => $request->get('phone'), 'role' => BUYER);
             $createdUser = $user->createItem($item);
             $uid = $createdUser->id;
             $username = $createdUser->name;
             $email = $createdUser->email;
         }
         //save address receive
         $userReceive = new addressReceiveModel();
         $item2 = array('name' => $request->get('name_2'), 'phone' => $request->get('phone_2'), 'street' => $request->get('street'), 'city_id' => $request->get('city_id'), 'ward_id' => $request->get('ward_id'));
         $address = $userReceive->createItem($item2);
         if ($uid != 0 && $address) {
             //create user address
             $userAddress = new UserAddress();
             $option = array('user_id' => $uid, 'address_id' => $address->id);
             $userAddress->createItem($option);
             //create order and order detail
             $order = new Order();
             $orderAtt = array('user_id' => $uid, 'address_id' => $address->id, 'total' => Cart::total(), 'ship' => 0, 'address' => $address->street . ", " . addressWardModel::showName($address->ward_id) . ", " . addressCityModel::showName($address->city_id));
             $createdOrder = $order->createItem($orderAtt);
             $orderDetail = new OrderDetail();
             if ($orderDetail->createItems($createdOrder->id, Cart::content())) {
                 //send email
                 $data = array('username' => $username, 'linkWebsite' => SITE_LINK, 'receiveName' => $address->name, 'receiveAddress' => $createdOrder->address, 'receivePhone' => $address->phone, 'carts' => Cart::content(), 'total' => Cart::total());
                 Cart::destroy();
                 if ($this->sendEmailOrder($email, $username, $data)) {
                     $re = array('status' => 'ok', 'id' => $createdOrder->id);
                 } else {
                     $re = array('status' => 'error', 'message' => 'Bị lỗi trong quá trình gửi mail');
                 }
             }
         }
         echo json_encode($re);
     }
 }
Exemplo n.º 3
0
 public function showFormEditUserAddress($domain, $id)
 {
     $address = addressReceiveModel::find($id);
     $cities = addressCityModel::lists('name', 'id');
     $ward = new addressWardModel();
     if (empty($address->city_id)) {
         $city_id = CITY_ID_DEFAULT;
     } else {
         $city_id = $address->city_id;
     }
     $wards = $ward->getItemsByCityId($city_id)->lists('name', 'id');
     return view("admin.user.form-edit-address", array('item' => $address, 'cities' => $cities, 'wards' => $wards));
 }
Exemplo n.º 4
0
 public function getCityByCode($code, $typeService)
 {
     return $this->_cityModel->getCityByCode($code, $typeService);
 }