/**
 * count
 * @param Db $db
 * @return array
 */
function getCountRecFood(&$db)
{
    $sql = "select favor,cometrue from recommendedfood,users \n\t\t\twhere recommendedfood.user_id=users.user_id\n\t\t\tand users.school_id={$_POST['school_id']};";
    $res = $db->query($sql);
    if ($res !== false) {
        $return = array();
        $return['count'] = 0;
        $return['wish_satisfied_rate'] = 0.0;
        $return['lineover_rate'] = 0.0;
        $return['line'] = 500;
        //心愿线数量
        $return['count'] = sizeof($res);
        if ($return['count'] === 0) {
            return $return;
        }
        $linecount = 0;
        $truecount = 0;
        foreach ($res as $value) {
            if ($value['cometrue']) {
                $truecount++;
            }
            if ($value['favor'] >= 500) {
                $linecount++;
            }
        }
        $return['lineover_rate'] = $linecount / $return['count'];
        $return['wish_satisfied_rate'] = $truecount / $return['count'];
        return $return;
    } else {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        //错误日志
        exit;
    }
}
function countComments(&$db, &$value)
{
    $res = $db->query("select count(*) from food_comments where canteen_id={$value['canteen_id']} and food_id={$value['food_id']};");
    if ($res === false) {
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        $db->close();
        exit;
    }
    $value['commentscount'] = $res[0]['count(*)'];
}
function getReply(&$db, &$value)
{
    $sql = "select content,time from complaint_replies\n\twhere complaint_id={$value['complaint_id']};";
    $res = $db->query($sql);
    if ($res === false) {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        exit;
    } else {
        $value['reply'] = false;
        if (!empty($res)) {
            $value['reply'] = true;
            $value['reply_content'] = $res[0]['content'];
            $value['reply_time'] = $res[0]['time'];
        }
    }
}
function getMethod(&$db, &$value)
{
    $sql = "select content,imageurl from foodmethod where recommend_id={$value['recommend_id']} order by sequence;";
    $res = $db->query($sql);
    if ($res !== false) {
        $value['content'] = array();
        $value['imagefile'] = array();
        if (empty($res)) {
            $value['content'] = null;
        }
        foreach ($res as $val) {
            $value['content'][] = $val['content'];
            $value['imagefile'][] = $val['imageurl'];
        }
    } else {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        exit;
    }
}
                            echo getJsonResponse(1, $db->error, null);
                            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
                            $db->rollback();
                            $db->close();
                            exit;
                        }
                    } else {
                        //上传图片失败
                        echo getJsonResponse(4, $uf->errorMsg, null);
                        $db->rollback();
                        //回滚
                        $db->close();
                        exit;
                    }
                }
            }
        }
        $db->commit();
        echo getJsonResponse(0, "success", array("complaint_id" => $complaint_id));
    } else {
        //插入失败
        echo getJsonResponse(1, $mysqli->error, null);
        $db->rollback();
        //回滚
        Log::error_log('database error:' . $mysqli->error . ' in ' . basename(__FILE__));
    }
    $db->close();
} else {
    echo getJsonResponse(2, "参数没有设置", null);
    exit;
}
        $sql = "select * from upgrade where device_id={$_POST['device_id']};";
        $res = $db->query($sql);
        if ($res === false) {
            echo getJsonResponse(1, $db->error, null);
            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        } else {
            if (empty($res)) {
                echo getJsonResponse(2, "id错", null);
            } else {
                if ($res[0]['major_version_number'] > $major || $res[0]['major_version_number'] == $major && $res[0]['minor_version_number'] > $max || $res[0]['major_version_number'] == $major && $res[0]['minor_version_number'] == $max && $res[0]['revision_number'] > $min) {
                    //需要更新
                    $return = array();
                    $return['newversion'] = $res[0]['major_version_number'] . '.' . $res[0]['minor_version_number'] . '.' . $res[0]['revision_number'];
                    $return['apkurl'] = $res[0]['apkurl'];
                    $return['upgrade_content'] = $res[0]['upgrade_content'];
                    echo getJsonResponse(0, "success", $return);
                } else {
                    echo getJsonResponse(3, "版本已为最新", null);
                }
            }
        }
        $db->close();
    } catch (Exception $e) {
        echo getJsonResponse(1, '数据库连接错误', null);
        Log::error_log("数据库连接错误");
        exit;
    }
} else {
    echo getJsonResponse(2, "参数错误", null);
    exit;
}
function getAcceptRate(&$db)
{
    $sql = "select count(*) from canteen_complaints where canteen_id={$_POST['canteen_id']};";
    $res = $db->query($sql);
    //食堂投诉数量
    if ($res === false) {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        //错误日志
        exit;
    } else {
        if ($res[0]['count(*)'] == 0) {
            return 100;
        }
        $sql2 = "select count(*) from canteen_complaints,complaint_replies where \n\t\t canteen_id={$_POST['canteen_id']} and canteen_complaints.complaint_id=complaint_replies.complaint_id;";
        $res2 = $db->query($sql2);
        //食堂回复数
        if ($res2 === false) {
            echo getJsonResponse(1, $db->error, null);
            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
            //错误日志
            exit;
        } else {
            if ($res2[0]['count(*)'] == 0) {
                return 0;
            }
            return $res2[0]['count(*)'] / $res[0]['count(*)'];
        }
    }
}
Exemple #8
0
function checkExist(&$db, $which)
{
    $sql = '';
    if ($which == 'canteen') {
        $sql = "select count(*) from canteen_grade where user_id={$_POST['user_id']} and canteen_id={$_POST['canteen_id']};";
    } else {
        $sql = "select count(*) from food_grade where user_id={$_POST['user_id']} and canteen_id={$_POST['canteen_id']} and food_id={$_POST['food_id']};";
    }
    $res = $db->query($sql);
    if ($res === false) {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        //错误日志
        exit;
    } else {
        if ($res[0]['count(*)'] == 1) {
            return true;
        } else {
            return false;
        }
    }
}
Exemple #9
0
function getNew(&$db, &$value)
{
    $sql = "select time>curdate()-3 from canteen_food where canteen_id={$_POST['canteen_id']} \n\t\t\tand food_id={$value['food_id']};";
    $res = $db->query($sql);
    if ($res === false) {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        //错误日志
        exit;
    } else {
        $value['new'] = $res[0]['time>curdate()-3'];
    }
}
Exemple #10
0
function checkUserName(&$db, $username)
{
    $res = $db->query("select user_id from users where username='******';");
    if ($res === false) {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        $db->close();
        exit;
    }
    if (empty($res)) {
        return false;
    } else {
        return true;
    }
}
function getFavor(&$db, $userid, &$value)
{
    $sql = "select user_id from food_comments_favor where comment_id={$value['comment_id']} and user_id={$userid};";
    $res = $db->query($sql);
    if ($res !== false) {
        if (empty($res)) {
            $value['is_favor'] = false;
        } else {
            $value['is_favor'] = true;
        }
    } else {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        exit;
    }
}
/**
 * 食物做法步骤
 * @param unknown $db
 * @param unknown $foodid
 * @param unknown $content
 */
function setContent(&$db, $recid, $content, $imagefile)
{
    if ($content == null) {
        return;
    }
    //$method=explode("||", $content);
    $method = json_decode($content, true);
    for ($i = 1; $i <= sizeof($method); $i++) {
        if (empty($imagefile[$i - 1])) {
            $imagefile[$i - 1] = 'http://' . getServerIp() . '/uploads/recommendedfood/default.jpg';
        }
        $sql = "insert into foodmethod values({$recid},{$i},'" . stringToDb($method[$i - 1]) . "','{$imagefile[$i - 1]}');";
        $res = $db->execute($sql);
        if (!$res) {
            echo getJsonResponse(1, $db->error, null);
            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
            $db->rollback();
            $db->close();
            exit;
        }
    }
}