Beispiel #1
0
function testGetTodayMeals()
{
    $date = TimeUtils::getCurrentDate();
    $getTodayMealsFlag = MealAction::getTodayMeals($date);
    if ($getTodayMealsFlag === MealAction::$GET_MEALS_FAIL) {
        $result = new Response(false, "get today meals failed");
        return $result;
    } elseif (isset($getTodayMealsFlag)) {
        $result = new mealsRes(true, "", $getTodayMealsFlag, sizeof($getTodayMealsFlag));
        return $result;
    }
    return new Response(false, "服务器故障");
}
Beispiel #2
0
function testCancelFavor()
{
    $date = TimeUtils::getCurrentDate();
    $userId = $_SESSION['user']->userId;
    $meal = MealAction::getTodayMeal($date);
    $favorite = MealAction::cancelFavor($userId, $meal->mealId);
    if ($favorite === MealAction::$CANCEL_FAVOR_FAIL) {
        $result = new Response(false, "cancel favor failed");
        return $result;
    } elseif ($favorite === MealAction::$CANCEL_FAVOR_NOT_ORDER_MEAL) {
        $result = new Response(false, "you haven't ordered yet");
        return $result;
    } elseif ($favorite === MealAction::$CANCEL_FAVOR_NOT_FAVOR_BEFORE) {
        $result = new Response(false, "you haven't liked it ");
        return $result;
    } elseif ($favorite === true) {
        $result = new Response(true);
        return $result;
    }
    return new Response(false, "服务器错误");
}
Beispiel #3
0
 /**
  * @param $date String
  * @return array|Integer get orders success or error code
  */
 public static function getOrders($date = "")
 {
     if ($date == "") {
         $date = TimeUtils::getCurrentDate();
     }
     $connection = Database::getInstance()->getConnection();
     static $query = "select * from `order` natural join user where date = ? order by createTime desc";
     $result = $connection->prepare($query);
     $result->bind_param("s", $date);
     $execute = $result->execute();
     if (!$execute) {
         return self::$GET_ORDERS_FAIL;
     }
     $result->bind_result($userId, $orderId, $date, $createTime, $email, $password, $username, $nickname, $department, $location, $description);
     $orders = [];
     while ($result->fetch()) {
         $orders[] = new Order($orderId, new User($userId, $email, $username, $nickname, $department, $location, $description), $date, $createTime);
     }
     $result->close();
     return $orders;
 }
Beispiel #4
0
function testFavor($arr)
{
    $date = TimeUtils::getCurrentDate();
    $userId = $_SESSION['user']->userId;
    $meal = MealAction::getTodayMeal($date);
    $favorite = MealAction::favor($userId, $meal->mealId);
    if ($favorite === MealAction::$FAVOR_FAIL) {
        $result = new Response(false, "favor failed");
        return $result;
    } elseif ($favorite === MealAction::$FAVOR_NOT_FOUND_MEAL_ID) {
        $result = new Response(false, "can't find this meal");
        return $result;
    } elseif ($favorite === MealAction::$FAVOR_NOT_ORDER_MEAL) {
        $result = new Response(false, "can't find this order");
        return $result;
    } elseif ($favorite === MealAction::$FAVOR_DUPLICATE) {
        $result = new Response(false, "you have favorited this meal");
        return $result;
    } elseif ($favorite === true) {
        $result = new Response(true);
        return $result;
    }
    return new Response(false, "服务器故障");
}
Beispiel #5
0
 /**
  * @param $userId String
  * @param $mealId String
  * @return bool|Integer success or error code
  */
 public static function cancelFavor($userId, $mealId)
 {
     $connection = Database::getInstance()->getConnection();
     static $queryTodayOrder = "select orderId from `order` where userId = ? and `date` = ?";
     $result = $connection->prepare($queryTodayOrder);
     $date = TimeUtils::getCurrentDate();
     $result->bind_param("ss", $userId, $date);
     $execute = $result->execute();
     if (!$execute) {
         return self::$CANCEL_FAVOR_FAIL;
     }
     $result->bind_result($orderId);
     if (!$result->fetch()) {
         return self::$CANCEL_FAVOR_NOT_ORDER_MEAL;
     }
     $result->close();
     static $query = "delete from mealfavor where orderId = ? and mealId = ?";
     $result = $connection->prepare($query);
     $result->bind_param("ss", $orderId, $mealId);
     $execute = $result->execute();
     if (!$execute) {
         return self::$CANCEL_FAVOR_NOT_FAVOR_BEFOR;
     }
     $result->close();
     return true;
 }
Beispiel #6
0
 /**
  * @param $userId Integer
  * @param string $date
  * @return bool|int is ordered or error code
  */
 public static function isOrdered($userId, $date = "")
 {
     $connection = Database::getInstance()->getConnection();
     static $query = "select * from `order` where userId=? and date=?";
     $result = $connection->prepare($query);
     if ($date == "") {
         $date = TimeUtils::getCurrentDate();
     }
     $result->bind_param("ss", $userId, $date);
     $execute = $result->execute();
     if (!$execute) {
         return self::$IS_ORDERED_FAIL;
     }
     while ($result->fetch()) {
         return true;
     }
     $result->close();
     return false;
 }
Beispiel #7
0
 /**
  * @param string $userId
  * @param string $date
  * @return bool|int ,mealId fail or error code
  */
 public static function isFavored($userId, $date = "")
 {
     $connection = Database::getInstance()->getConnection();
     if ($date == "") {
         $date = TimeUtils::getCurrentDate();
     }
     static $queryTodayOrder = "select orderId from `order` where userId = ? and `date` = ?";
     $result = $connection->prepare($queryTodayOrder);
     $result->bind_param("ss", $userId, $date);
     $execute = $result->execute();
     if (!$execute) {
         return self::$IS_FAVORED_FAIL;
     }
     $result->bind_result($orderId);
     if (!$result->fetch()) {
         return self::$IS_FAVORED_NOT_ORDER_MEAL;
     }
     $result->close();
     static $query = "select mealId from mealfavor where orderId = ?";
     $result = $connection->prepare($query);
     $result->bind_param("s", $orderId);
     $execute = $result->execute();
     if (!$execute) {
         return self::$IS_FAVORED_FAIL;
     }
     $result->bind_result($mealId);
     if (!$result->fetch()) {
         return false;
     }
     $result->close();
     return $mealId;
 }