/**
  * @param $name
  * @param $cityId
  * @param $districtId
  * @param $code
  * @param $type
  * @return addressDistrictModel
  */
 public function createWard($name, $cityId, $districtId, $code, $type)
 {
     $ward = new addressWardModel();
     $ward->code = $code;
     $ward->type_service = $type;
     $ward->name = $name;
     $ward->city_id = $cityId;
     $ward->district_id = $districtId;
     $ward->save();
     return $ward;
 }
Exemple #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);
     }
 }
Exemple #3
0
 public function showListWards($domain, $id)
 {
     $ward = new addressWardModel();
     $lists = $ward->getItemsByCityId($id)->lists('name', 'id');
     echo Form::select('ward_id', $lists, null, array('class' => 'form-control'));
 }
Exemple #4
0
 /**
  * @param $name
  * @param $cityId
  * @param $districtId
  * @param $code
  * @param $type
  * @return addressDistrictModel
  */
 public function createWard($name, $cityId, $districtId, $code, $type)
 {
     return $this->_wardModel->createWard($name, $cityId, $districtId, $code, $type);
 }