fastadmin 后台关联表时间筛选 报数据表不存在的问题处理

1.首先排查js文件和控制器文件的代码是否存在逻辑问题
2.如果正常则考虑是 日期时间条件解析的问题
打开文件
thinkphp/library/think/db/Builder.php第478行

/**
     * 日期时间条件解析
     * @access protected
     * @param string    $value
     * @param string    $key
     * @param array     $options
     * @param string    $bindName
     * @param integer   $bindType
     * @return string
     */
    protected function parseDateTime($value, $key, $options = [], $bindName = null, $bindType = null)
    {
        // 获取时间字段类型
        if (strpos($key, '.')) {
            list($table, $key) = explode('.', $key);
            if (isset($options['alias']) && $pos = array_search($table, $options['alias'])) {
                $table = $pos;
            } else {
                $prefix = config('database.prefix');
                if (strpos($table, $prefix) === false) {
                    $table = $prefix . $table;
                }
            }
        } else {
            $table = $options['table'];
        }

        $type = $this->query->getTableInfo($table, 'type');
        
        if (isset($type[$key])) {
            $info = $type[$key];
        }
        if (isset($info)) {
            if (is_string($value)) {
                $value = strtotime($value) ?: $value;
            }

            if (preg_match('/(datetime|timestamp)/is', $info)) {
                // 日期及时间戳类型
                $value = date('Y-m-d H:i:s', $value);
            } elseif (preg_match('/(date)/is', $info)) {
                // 日期及时间戳类型
                $value = date('Y-m-d', $value);
            }
        }
        $bindName = $bindName ?: $key;

        if ($this->query->isBind($bindName)) {
            $bindName .= '_' . str_replace('.', '_', uniqid('', true));
        }

        $this->query->bind($bindName, $value, $bindType);
        return ':' . $bindName;
    }

使用这段代码来替换之前的代码
区别在于

if (isset($options['alias']) && $pos = array_search($table, $options['alias'])) {
                $table = $pos;
} else {
                $prefix = config('database.prefix');
                if (strpos($table, $prefix) === false) {
                    $table = $prefix . $table;
                }
}

替换之后问题应该就解决了,我的项目就是这么处理的

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现优惠券管理功能需要创建两个数据表:`coupon` 和 `coupon_log`。 `coupon` 结构如下: ``` CREATE TABLE `coupon` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', `name` varchar(50) NOT NULL DEFAULT '' COMMENT '优惠券名称', `total` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '发放总量', `amount` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '优惠金额', `min_amount` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '最低消费金额', `start_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '有效期开始时间', `end_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '有效期结束时间', `status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态:1=正常;2=禁用', `create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', `update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='优惠券'; ``` `coupon_log` 结构如下: ``` CREATE TABLE `coupon_log` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', `user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID', `coupon_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '优惠券ID', `status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态:1=未使用;2=已使用;3=已过期', `create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', `update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='优惠券领取记录'; ``` 在 FastAdmin TP6 后台中,可以通过 `CouponController` 控制器来实现优惠券的管理,包括优惠券的添加、编辑、删除、发放、作废等操作。同时,还需要创建 `CouponLogController` 控制器,来实现优惠券领取记录的管理,包括查看、导出等操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值