票务系统微信小程序后端(二)

接上文展开后端接口开发
1.composer安装下需要的几个库,直接放到根目录composer.json文件下:
passport(OAuth2登录用)excel(导出excel表用)laravel-filesystem-cos(腾讯云存储)、laravel-filesystem-qiniu(七牛云存储)、laravel-wechat(安神的easywechart)、yansongda/laravel-pay(微信支付宝支付)

 "require": {
        "php": "^8.0.2",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^9.11",
        "laravel/sanctum": "^2.14.1",
        "laravel/passport": "^10.3",
        "maatwebsite/excel": "^3.1",
        "overtrue/laravel-filesystem-cos": "^3.1",
        "overtrue/laravel-filesystem-qiniu": "^2.0",
        "overtrue/laravel-wechat": "^6.0",
        "yansongda/laravel-pay": "~3.1.0",
        "psr/simple-cache": "^1.0",
        "laravel/tinker": "^2.7"
    },

执行下更新安装就好了

sudo composer update

注意:
(1)laravel-wechat执行下面名称创建配置文件,会在config目录下生成一个wechat.php

php artisan vendor:publish --provider="Overtrue\LaravelWeChat\ServiceProvider"

把wechat.php小程序部分的配置注释打开

 /*
     * 小程序
     */
     'mini_program' => [
         'default' => [
             'app_id'  => env('WECHAT_MINI_PROGRAM_APPID', ''),
             'secret'  => env('WECHAT_MINI_PROGRAM_SECRET', ''),
             'token'   => env('WECHAT_MINI_PROGRAM_TOKEN', ''),
             'aes_key' => env('WECHAT_MINI_PROGRAM_AES_KEY', ''),
         ],
     ],

在.env文件中配置好app_id和secret
WECHAT_MINI_PROGRAM_APPID=上篇小程序中存好的ID
WECHAT_MINI_PROGRAM_TOKEN=上篇小程序中存好的key
(2)yansongda/laravel-pay执行下面名称创建配置文件:/config/pay.php

php artisan vendor:publish --provider="Yansongda\LaravelPay\PayServiceProvider" --tag=laravel-pay

配置参考安神的laravel-wechat
(3)config/filesystem.php中需要在disks中加上两个存储配置

'qiniu' => [
            'driver'     => 'qiniu',
            'access_key' => env('QINIU_ACCESS_KEY', 'xxxxxxxxxxxxxxxx'),
            'secret_key' => env('QINIU_SECRET_KEY', 'xxxxxxxxxxxxxxxx'),
            'bucket'     => env('QINIU_BUCKET', 'test'),
            'domain'     => env('QINIU_DOMAIN', 'xxx.clouddn.com'), // or host: https://xxxx.clouddn.com
        ],
        'cos' => [
            'driver' => 'cos',

            'app_id'     => env('COS_APP_ID'),
            'secret_id'  => env('COS_SECRET_ID'),
            'secret_key' => env('COS_SECRET_KEY'),
            'region'     => env('COS_REGION', 'ap-guangzhou'),

            'bucket'     => env('COS_BUCKET'),  // 不带数字 app_id 后缀

            // 可选,如果 bucket 为私有访问请打开此项
            'signed_url' => false,

            // 可选,是否使用 https,默认 false
            'use_https' => true,

            // 可选,自定义域名
            'domain' => 'emample-12340000.cos.test.com',

            // 可选,使用 CDN 域名时指定生成的 URL host
            'cdn' => env('COS_CDN'),

            'prefix' => env('COS_PATH_PREFIX'), // 全局路径前缀

            'guzzle' => [
                'timeout' => env('COS_TIMEOUT', 60),
                'connect_timeout' => env('COS_CONNECT_TIMEOUT', 60),
            ],
        ],

相关秘钥也是在.env文件中配置好
(4)excel执行下面名称生成config/excel.php配置文件

php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config

2.准备创建表
票务系统用到的几个表users(用户表)、payments(支付订单)、tickets(门票)、codes(一票一码)、refunds(退票)、newtmpls(订阅消息),还有passport用到的5张表,对于票务系统基本功能就可以了。
通过命令分别创建好:模型、控制器和migration文件

php artisan make:model User -m -c
php artisan make:model Payment -m -c
php artisan make:model Ticket -m -c
php artisan make:model Code -m -c
php artisan make:model Refund -m -c
php artisan make:model Newtmpl -m -c

打开database/migrations找到相关表新增字段信息,里面都做好备注
(1)users表

 Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->nullable();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->string('real_name')->nullable()->comment('真实姓名');
            $table->string('real_avatar')->nullable()->comment('真实头像');
            $table->string('id_card')->nullable()->comment('身份证号');
            $table->string('phone')->nullable()->comment('手机');
            //微信资料
            $table->string('unionid')->nullable()->comment('微信开放id');
            $table->string('weapp_openid')->nullable()->comment('微信开放id');
            $table->string('weapp_avatar')->nullable()->comment('微信头像');
            $table->string('nick_name')->nullable()->comment('微信昵称');
            //阿里资料
            $table->string('ali_id')->nullable()->comment('阿里id');
            $table->string('alipay_id')->nullable()->comment('阿里付款id');

            $table->string('address')->nullable()->comment('详细地址');
            $table->string('house')->nullable()->comment('房子地址');
            $table->json('location')->nullable()->comment('当前地理信息');
            $table->string('level',8)->default(0);
            $table->string('is_admin',8)->default('F')->comment('是否管理员');
            $table->string('is_hidden',8)->default('F')->comment('是否隐藏');
            $table->rememberToken();
            $table->timestamps();
        });

(2)payments表

Schema::create('payments', function (Blueprint $table) {
            $table->id();
            $table->string('number_id')->nullable()->comment('交易单号');
            $table->string('out_trade_no')->nullable()->comment('商户单号');
            $table->unsignedInteger('ticket_id')->nullable()->comment('门票ID');
            $table->unsignedInteger('user_id')->nullable()->comment('用户ID');
            $table->unsignedInteger('service_id')->nullable()->comment('客服ID');
            $table->unsignedInteger('type_id')->nullable()->comment('付款类别ID');

            $table->string('title')->nullable()->comment('门票名称');
            $table->string('name')->nullable()->comment('客户姓名');
            $table->string('id_card')->nullable()->comment('客户身份证号');
            $table->string('phone')->nullable()->comment('客户联系方式');
            $table->string('address')->nullable()->comment('客户详细地址');
            $table->string('location')->nullable()->comment('客户位置');
            $table->string('code')->nullable()->comment('条码');

            $table->decimal('unit_price')->nullable()->comment('单价');
            $table->integer('quantity')->nullable()->comment('数量');
            $table->decimal('total_price')->nullable()->comment('总价');

            $table->date('day_at')->nullable()->comment('预计游玩日期');

            $table->timestamp('time_at')->nullable()->comment('付款时间');
            $table->timestamp('time_end')->nullable()->comment('成交时间');
            $table->text('remark')->nullable()->comment('备注');

            $table->string('is_hidden')->default('F')->comment('隐藏');
            $table->timestamps();
        });

(3)tickets表

 Schema::create('tickets', function (Blueprint $table) {
            $table->id();
            $table->string('title')->nullable()->comment('票名');
            $table->string('pic')->nullable()->comment('封面图片');
            $table->unsignedInteger('user_id')->nullable()->comment('客服ID');
            $table->string('tel')->nullable()->comment('客服电话');

            $table->string('time_at')->nullable()->comment('开始时间');
            $table->string('time_end')->nullable()->comment('截止时间');

            $table->decimal('unit_price')->nullable()->comment('单价');
            $table->integer('quantity')->nullable()->comment('日最大数量');
            $table->string('explain')->nullable()->comment('说明');

            $table->string('address')->nullable()->comment('详细地址');
            $table->string('location')->nullable()->comment('位置');

            $table->text('remark')->nullable()->comment('备注');
            $table->string('is_hidden')->default('F')->comment('隐藏');
            $table->timestamps();
        });

(4)codes表

Schema::create('codes', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('payment_id')->nullable()->comment('支付ID');
            $table->unsignedInteger('user_id')->nullable()->comment('用户ID');
            $table->string('title')->nullable()->comment('门票名称');
            $table->string('name')->nullable()->comment('客户姓名');
            $table->string('code')->nullable()->comment('条码');
            $table->string('pic')->nullable()->comment('条码图片');
            $table->decimal('unit_price')->nullable()->comment('单价');
            $table->timestamp('times_at')->nullable()->comment('预计游玩时间');
            $table->timestamp('times_end')->nullable()->comment('验票时间');
            $table->text('remark')->nullable()->comment('备注');
            $table->string('is_verify',8)->default('0')->comment('0未验1已验票2申请退票中3已退票');
            $table->timestamp('verify_at')->nullable()->comment('验票/退票时间');
            $table->string('is_print',8)->default('F')->comment('是否打印');
            $table->timestamp('print_at')->nullable()->comment('打印时间');
            $table->string('is_hidden',8)->default('F')->comment('是否隐藏');
            $table->timestamps();
        });

(5)refunds表

Schema::create('refunds', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('payment_id')->nullable()->comment('支付ID');
            $table->unsignedInteger('user_id')->nullable()->comment('用户ID');
            $table->unsignedInteger('code_id')->nullable()->comment('票码ID');
            $table->string('title')->nullable()->comment('门票名称');
            $table->string('name')->nullable()->comment('客户姓名');
            $table->string('code')->nullable()->comment('条码');
            $table->string('pic')->nullable()->comment('条码图片');
            $table->decimal('unit_price')->nullable()->comment('单价');
            $table->timestamp('times_at')->nullable()->comment('申请时间');
            $table->string('is_verify',8)->default('F')->comment('是否审核');
            $table->timestamp('verify_at')->nullable()->comment('审核时间');
            $table->text('remark')->nullable()->comment('备注');
            $table->string('is_hidden',8)->default('F')->comment('是否隐藏');
            $table->timestamps();
        });

(6)newtmpls表

Schema::create('newtmpls', function (Blueprint $table) {
            $table->id();
            $table->integer('user_id')->nullable()->comment('UserId');
            $table->integer('model_id')->nullable()->comment('模型ID');
            $table->string('models')->nullable()->comment('模型');
            $table->string('template_title')->nullable()->comment('标题');
            $table->string('template_keywords')->nullable()->comment('消息模板关键词');
            $table->string('template_id')->nullable()->comment('消息模板id');
            $table->string('template_type')->nullable()->comment('消息模板类型');
            $table->string('is_hidden',8)->default('F')->comment('是否隐藏');
            $table->timestamps();
        });

以上表内字段都添加完后执行下面名称在数据库中创建表:

php artisan migrate

创建好自己的表后,执行下面命令创建passport相关的表:

php artisan passport:install

以上操作,本系统用到的表就创建完成了,如图:

票务系统微信小程序后端(二)

本作品采用《CC 协议》,转载必须注明作者和本文链接
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!