点餐小程序系统开发源代码 支持APP+微信小程序+抖音小程序

 

最近新开发了一套小程序点餐系统,用户点餐之后可以选择堂食或者是外卖到家,这套系统主要功能有,产品展示,支付系统,外卖配送,用户系统,积分系统,商家管理系统,抽奖系统,积分商城系统,购物车系统等等。

下面给大家介绍一下,开发过程中前端的功能介绍:

需求功能表(小程序)
前后端功能大类功能小类功能描述
前端首页注册获取手机号码登录
搜索可以搜索菜品
在线下单(扫码)选择菜品、选择堂食、选择桌号(后台收到订单,可以直接语音提醒)
在线点餐用户可以去筛选菜品、添加菜品、减少菜品、
加入购物车,一起结算,添加收货地址(姓名,电话,收货地址)
店铺名称、店铺火爆菜品、销量最高、人气推荐、我要分享
幸运大转盘进入抽奖,平台积分抽奖,门店消费抽奖
企业介绍企业文化,品牌故事,可以在后台上传图文
积分商城积分消费得积分,后台可指定得积分
双积分门店积分和总店都可以积分
积分商品上传图片,需要用户的积分数
积分兑换优惠劵、满减劵、代金券
积分+现金1、企业文化宣传品
2、语音播报设备
3、各种文化输出产品
4、企业周边产品
现金购买商品
个人中心登录微信绑定登录,或者手机号码登录
多门店门店在线点餐,扫码点餐,门店积分商品兑换
用户用户名称、头像模块
正常的用户头像,昵称,可修改,可更换,首次获取直接拉取用户的基本信息
抽奖订单订单状态、未发货、已发货
积分明细积分展示:用户消费多少钱,获取多少积分,单次金额不累计
地址管理模块消费记录:展示消费门店,消费时间,消费金额,所获得积分
用户自己输入地址,用于商城,外卖的地址管理

 

 点餐系统部分开发源码分享:

<?php

namespace app\admin\command\Api\library;

use Exception;

/**
 * Class imported from https://github.com/eriknyk/Annotations
 * @author  Erik Amaru Ortiz https://github.com/eriknyk‎
 *
 * @license http://opensource.org/licenses/bsd-license.php The BSD License
 * @author  Calin Rada <rada.calin@gmail.com>
 */
class Extractor
{

    /**
     * Static array to store already parsed annotations
     * @var array
     */
    private static $annotationCache;

    private static $classAnnotationCache;

    private static $classMethodAnnotationCache;

    private static $classPropertyValueCache;

    /**
     * Indicates that annotations should has strict behavior, 'false' by default
     * @var boolean
     */
    private $strict = false;

    /**
     * Stores the default namespace for Objects instance, usually used on methods like getMethodAnnotationsObjects()
     * @var string
     */
    public $defaultNamespace = '';

    /**
     * Sets strict variable to true/false
     * @param bool $value boolean value to indicate that annotations to has strict behavior
     */
    public function setStrict($value)
    {
        $this->strict = (bool)$value;
    }

    /**
     * Sets default namespace to use in object instantiation
     * @param string $namespace default namespace
     */
    public function setDefaultNamespace($namespace)
    {
        $this->defaultNamespace = $namespace;
    }

    /**
     * Gets default namespace used in object instantiation
     * @return string $namespace default namespace
     */
    public function getDefaultAnnotationNamespace()
    {
        return $this->defaultNamespace;
    }

    /**
     * Gets all anotations with pattern @SomeAnnotation() from a given class
     *
     * @param string $className class name to get annotations
     * @return array  self::$classAnnotationCache all annotated elements
     */
    public static function getClassAnnotations($className)
    {
        if (!isset(self::$classAnnotationCache[$className])) {
            $class = new \ReflectionClass($className);
            $annotationArr = self::parseAnnotations($class->getDocComment());
            $annotationArr['ApiTitle'] = !isset($annotationArr['ApiTitle'][0]) || !trim($annotationArr['ApiTitle'][0]) ? [$class->getShortName()] : $annotationArr['ApiTitle'];
            self::$classAnnotationCache[$className] = $annotationArr;
        }

        return self::$classAnnotationCache[$className];
    }

    /**
     * 获取类所有方法的属性配置
     * @param $className
     * @return mixed
     * @throws \ReflectionException
     */
    public static function getClassMethodAnnotations($className)
    {
        $class = new \ReflectionClass($className);

        foreach ($class->getMethods() as $object) {
            self::$classMethodAnnotationCache[$className][$object->name] = self::getMethodAnnotations($className, $object->name);
        }

        return self::$classMethodAnnotationCache[$className];
    }

    public static function getClassPropertyValues($className)
    {
        $class = new \ReflectionClass($className);

        foreach ($class->getProperties() as $object) {
            self::$classPropertyValueCache[$className][$object->name] = self::getClassPropertyValue($className, $object->name);
        }

        return self::$classMethodAnnotationCache[$className];
    }

    public static function getAllClassAnnotations()
    {
        return self::$classAnnotationCache;
    }

    public static function getAllClassMethodAnnotations()
    {
        return self::$classMethodAnnotationCache;
    }

    public static function getAllClassPropertyValues()
    {
        return self::$classPropertyValueCache;
    }

    public static function getClassPropertyValue($className, $property)
    {
        $_SERVER['REQUEST_METHOD'] = 'GET';
        $reflectionClass = new \ReflectionClass($className);
        $reflectionProperty = $reflectionClass->getProperty($property);
        $reflectionProperty->setAccessible(true);
        return $reflectionProperty->getValue($reflectionClass->newInstanceWithoutConstructor());
    }

    /**
     * Gets all anotations with pattern @SomeAnnotation() from a determinated method of a given class
     *
     * @param string $className  class name
     * @param string $methodName method name to get annotations
     * @return array  self::$annotationCache all annotated elements of a method given
     */
    public static function getMethodAnnotations($className, $methodName)
    {
        if (!isset(self::$annotationCache[$className . '::' . $methodName])) {
            try {
                $method = new \ReflectionMethod($className, $methodName);
                $class = new \ReflectionClass($className);
                if (!$method->isPublic() || $method->isConstructor()) {
                    $annotations = array();
                } else {
                    $annotations = self::consolidateAnnotations($method, $class);
                }
            } catch (\ReflectionException $e) {
                $annotations = array();
            }

            self::$annotationCache[$className . '::' . $methodName] = $annotations;
        }

        return self::$annotationCache[$className . '::' . $methodName];
    }

    /**
     * Gets all anotations with pattern @SomeAnnotation() from a determinated method of a given class
     * and instance its abcAnnotation class
     *
     * @param string $className  class name
     * @param string $methodName method name to get annotations
     * @return array  self::$annotationCache all annotated objects of a method given
     */
    public function getMethodAnnotationsObjects($className, $methodName)
    {
        $annotations = $this->getMethodAnnotations($className, $methodName);
        $objects = array();

        $i = 0;

        foreach ($annotations as $annotationClass => $listParams) {
            $annotationClass = ucfirst($annotationClass);
            $class = $this->defaultNamespace . $annotationClass . 'Annotation';

            // verify is the annotation class exists, depending if Annotations::strict is true
            // if not, just skip the annotation instance creation.
            if (!class_exists($class)) {
                if ($this->strict) {
                    throw new Exception(sprintf('Runtime Error: Annotation Class Not Found: %s', $class));
                } else {
                    // silent skip & continue
                    continue;
                }
            }

            if (empty($objects[$annotationClass])) {
                $objects[$annotationClass] = new $class();
            }

            foreach ($listParams as $params) {
                if (is_array($params)) {
                    foreach ($params as $key => $value) {
                        $objects[$annotationClass]->set($key, $value);
                    }
                } else {
                    $objects[$annotationClass]->set($i++, $params);
                }
            }
        }

        return $objects;
    }

    private static function consolidateAnnotations($method, $class)
    {
        $dockblockClass = $class->getDocComment();
        $docblockMethod = $method->getDocComment();
        $methodName = $method->getName();

        $methodAnnotations = self::parseAnnotations($docblockMethod);
        $methodAnnotations['ApiTitle'] = !isset($methodAnnotations['ApiTitle'][0]) || !trim($methodAnnotations['ApiTitle'][0]) ? [$method->getName()] : $methodAnnotations['ApiTitle'];

        $classAnnotations = self::parseAnnotations($dockblockClass);
        $classAnnotations['ApiTitle'] = !isset($classAnnotations['ApiTitle'][0]) || !trim($classAnnotations['ApiTitle'][0]) ? [$class->getShortName()] : $classAnnotations['ApiTitle'];

        if (isset($methodAnnotations['ApiInternal']) || $methodName == '_initialize' || $methodName == '_empty') {
            return [];
        }

        $properties = $class->getDefaultProperties();
        $noNeedLogin = isset($properties['noNeedLogin']) ? (is_array($properties['noNeedLogin']) ? $properties['noNeedLogin'] : [$properties['noNeedLogin']]) : [];
        $noNeedRight = isset($properties['noNeedRight']) ? (is_array($properties['noNeedRight']) ? $properties['noNeedRight'] : [$properties['noNeedRight']]) : [];

        preg_match_all("/\*[\s]+(.*)(\\r\\n|\\r|\\n)/U", str_replace('/**', '', $docblockMethod), $methodArr);
        preg_match_all("/\*[\s]+(.*)(\\r\\n|\\r|\\n)/U", str_replace('/**', '', $dockblockClass), $classArr);

        if (!isset($methodAnnotations['ApiMethod'])) {
            $methodAnnotations['ApiMethod'] = ['get'];
        }
        if (!isset($methodAnnotations['ApiWeigh'])) {
            $methodAnnotations['ApiWeigh'] = [0];
        }
        if (!isset($methodAnnotations['ApiSummary'])) {
            $methodAnnotations['ApiSummary'] = $methodAnnotations['ApiTitle'];
        }

        if ($methodAnnotations) {
            foreach ($classAnnotations as $name => $valueClass) {
                if (count($valueClass) !== 1) {
                    continue;
                }

                if ($name === 'ApiRoute') {
                    if (isset($methodAnnotations[$name])) {
                        $methodAnnotations[$name] = [rtrim($valueClass[0], '/') . $methodAnnotations[$name][0]];
                    } else {
                        $methodAnnotations[$name] = [rtrim($valueClass[0], '/') . '/' . $method->getName()];
                    }
                }

                if ($name === 'ApiSector') {
                    $methodAnnotations[$name] = $valueClass;
                }
            }
        }
        if (!isset($methodAnnotations['ApiRoute'])) {
            $urlArr = [];
            $className = $class->getName();

            list($prefix, $suffix) = explode('\\' . \think\Config::get('url_controller_layer') . '\\', $className);
            $prefixArr = explode('\\', $prefix);
            $suffixArr = explode('\\', $suffix);
            if ($prefixArr[0] == \think\Config::get('app_namespace')) {
                $prefixArr[0] = '';
            }
            $urlArr = array_merge($urlArr, $prefixArr);
            $urlArr[] = implode('.', array_map(function ($item) {
                return \think\Loader::parseName($item);
            }, $suffixArr));
            $urlArr[] = $method->getName();

            $methodAnnotations['ApiRoute'] = [implode('/', $urlArr)];
        }
        if (!isset($methodAnnotations['ApiSector'])) {
            $methodAnnotations['ApiSector'] = isset($classAnnotations['ApiSector']) ? $classAnnotations['ApiSector'] : $classAnnotations['ApiTitle'];
        }
        if (!isset($methodAnnotations['ApiParams'])) {
            $params = self::parseCustomAnnotations($docblockMethod, 'param');
            foreach ($params as $k => $v) {
                $arr = explode(' ', preg_replace("/[\s]+/", " ", $v));
                $methodAnnotations['ApiParams'][] = [
                    'name'        => isset($arr[1]) ? str_replace('$', '', $arr[1]) : '',
                    'nullable'    => false,
                    'type'        => isset($arr[0]) ? $arr[0] : 'string',
                    'description' => isset($arr[2]) ? $arr[2] : ''
                ];
            }
        }
        $methodAnnotations['ApiPermissionLogin'] = [!in_array('*', $noNeedLogin) && !in_array($methodName, $noNeedLogin)];
        $methodAnnotations['ApiPermissionRight'] = !$methodAnnotations['ApiPermissionLogin'][0] ? [false] : [!in_array('*', $noNeedRight) && !in_array($methodName, $noNeedRight)];
        return $methodAnnotations;
    }

    /**
     * Parse annotations
     *
     * @param string $docblock
     * @param string $name
     * @return array  parsed annotations params
     */
    private static function parseCustomAnnotations($docblock, $name = 'param')
    {
        $annotations = array();

        $docblock = substr($docblock, 3, -2);
        if (preg_match_all('/@' . $name . '(?:\s*(?:\(\s*)?(.*?)(?:\s*\))?)??\s*(?:\n|\*\/)/', $docblock, $matches)) {
            foreach ($matches[1] as $k => $v) {
                $annotations[] = $v;
            }
        }
        return $annotations;
    }

    /**
     * Parse annotations
     *
     * @param string $docblock
     * @return array  parsed annotations params
     */
    private static function parseAnnotations($docblock)
    {
        $annotations = array();

        // Strip away the docblock header and footer to ease parsing of one line annotations
        $docblock = substr($docblock, 3, -2);
        if (preg_match_all('/@(?<name>[A-Za-z_-]+)[\s\t]*\((?<args>(?:(?!\)).)*)\)\r?/s', $docblock, $matches)) {
            $numMatches = count($matches[0]);
            for ($i = 0; $i < $numMatches; ++$i) {
                $name = $matches['name'][$i];
                $value = '';
                // annotations has arguments
                if (isset($matches['args'][$i])) {
                    $argsParts = trim($matches['args'][$i]);
                    if ($name == 'ApiReturn') {
                        $value = $argsParts;
                    } elseif ($matches['args'][$i] != '') {
                        $argsParts = preg_replace("/\{(\w+)\}/", '#$1#', $argsParts);
                        $value = self::parseArgs($argsParts);
                        if (is_string($value)) {
                            $value = preg_replace("/\#(\w+)\#/", '{$1}', $argsParts);
                        }
                    }
                }

                $annotations[$name][] = $value;
            }
        }
        if (stripos($docblock, '@ApiInternal') !== false) {
            $annotations['ApiInternal'] = [true];
        }
        if (!isset($annotations['ApiTitle'])) {
            preg_match_all("/\*[\s]+(.*)(\\r\\n|\\r|\\n)/U", str_replace('/**', '', $docblock), $matchArr);
            $title = isset($matchArr[1]) && isset($matchArr[1][0]) ? $matchArr[1][0] : '';
            $annotations['ApiTitle'] = [$title];
        }

        return $annotations;
    }

    /**
     * Parse individual annotation arguments
     *
     * @param string $content arguments string
     * @return array  annotated arguments
     */
    private static function parseArgs($content)
    {
        // Replace initial stars
        $content = preg_replace('/^\s*\*/m', '', $content);

        $data = array();
        $len = strlen($content);
        $i = 0;
        $var = '';
        $val = '';
        $level = 1;

        $prevDelimiter = '';
        $nextDelimiter = '';
        $nextToken = '';
        $composing = false;
        $type = 'plain';
        $delimiter = null;
        $quoted = false;
        $tokens = array('"', '"', '{', '}', ',', '=');

        while ($i <= $len) {
            $prev_c = substr($content, $i - 1, 1);
            $c = substr($content, $i++, 1);

            if ($c === '"' && $prev_c !== "\\") {
                $delimiter = $c;
                //open delimiter
                if (!$composing && empty($prevDelimiter) && empty($nextDelimiter)) {
                    $prevDelimiter = $nextDelimiter = $delimiter;
                    $val = '';
                    $composing = true;
                    $quoted = true;
                } else {
                    // close delimiter
                    if ($c !== $nextDelimiter) {
                        throw new Exception(sprintf(
                            "Parse Error: enclosing error -> expected: [%s], given: [%s]",
                            $nextDelimiter,
                            $c
                        ));
                    }

                    // validating syntax
                    if ($i < $len) {
                        if (',' !== substr($content, $i, 1) && '\\' !== $prev_c) {
                            throw new Exception(sprintf(
                                "Parse Error: missing comma separator near: ...%s<--",
                                substr($content, ($i - 10), $i)
                            ));
                        }
                    }

                    $prevDelimiter = $nextDelimiter = '';
                    $composing = false;
                    $delimiter = null;
                }
            } elseif (!$composing && in_array($c, $tokens)) {
                switch ($c) {
                    case '=':
                        $prevDelimiter = $nextDelimiter = '';
                        $level = 2;
                        $composing = false;
                        $type = 'assoc';
                        $quoted = false;
                        break;
                    case ',':
                        $level = 3;

                        // If composing flag is true yet,
                        // it means that the string was not enclosed, so it is parsing error.
                        if ($composing === true && !empty($prevDelimiter) && !empty($nextDelimiter)) {
                            throw new Exception(sprintf(
                                "Parse Error: enclosing error -> expected: [%s], given: [%s]",
                                $nextDelimiter,
                                $c
                            ));
                        }

                        $prevDelimiter = $nextDelimiter = '';
                        break;
                    case '{':
                        $subc = '';
                        $subComposing = true;

                        while ($i <= $len) {
                            $c = substr($content, $i++, 1);

                            if (isset($delimiter) && $c === $delimiter) {
                                throw new Exception(sprintf(
                                    "Parse Error: Composite variable is not enclosed correctly."
                                ));
                            }

                            if ($c === '}') {
                                $subComposing = false;
                                break;
                            }
                            $subc .= $c;
                        }

                        // if the string is composing yet means that the structure of var. never was enclosed with '}'
                        if ($subComposing) {
                            throw new Exception(sprintf(
                                "Parse Error: Composite variable is not enclosed correctly. near: ...%s'",
                                $subc
                            ));
                        }

                        $val = self::parseArgs($subc);
                        break;
                }
            } else {
                if ($level == 1) {
                    $var .= $c;
                } elseif ($level == 2) {
                    $val .= $c;
                }
            }

            if ($level === 3 || $i === $len) {
                if ($type == 'plain' && $i === $len) {
                    $data = self::castValue($var);
                } else {
                    $data[trim($var)] = self::castValue($val, !$quoted);
                }

                $level = 1;
                $var = $val = '';
                $composing = false;
                $quoted = false;
            }
        }

        return $data;
    }

    /**
     * Try determinate the original type variable of a string
     *
     * @param string  $val  string containing possibles variables that can be cast to bool or int
     * @param boolean $trim indicate if the value passed should be trimmed after to try cast
     * @return mixed   returns the value converted to original type if was possible
     */
    private static function castValue($val, $trim = false)
    {
        if (is_array($val)) {
            foreach ($val as $key => $value) {
                $val[$key] = self::castValue($value);
            }
        } elseif (is_string($val)) {
            if ($trim) {
                $val = trim($val);
            }
            $val = stripslashes($val);
            $tmp = strtolower($val);

            if ($tmp === 'false' || $tmp === 'true') {
                $val = $tmp === 'true';
            } elseif (is_numeric($val)) {
                return $val + 0;
            }

            unset($tmp);
        }

        return $val;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值