萤火php端: 查询数据的时候报错: “message“: “Undefined index: pay_status“,

ops/2024/10/10 15:15:24/

代码:getGoodsFromHistory  

<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);namespace app\api\service;use app\api\model\Order as OrderModel;
use app\api\model\order\Delivery as DeliveryModel;
use app\api\model\OrderAddress as OrderAddressModel;
use app\api\service\User as UserService;
use app\common\service\Order as OrderService;
use app\common\service\Express as ExpressService;
use app\common\enum\order\OrderStatus as OrderStatusEnum;
use cores\exception\BaseException;/*** 订单服务类* Class Order* @package app\common\service*/
class Order extends OrderService
{/*** 获取物流信息* @param int $orderId 订单ID* @return mixed* @throws BaseException* @throws \think\db\exception\DataNotFoundException* @throws \think\db\exception\DbException* @throws \think\db\exception\ModelNotFoundException*/public function express(int $orderId){// 获取发货单列表$model = new DeliveryModel;$list = $model->getList($orderId);// 整理物流跟踪信息return $this->getExpressTraces($orderId, $list);}/*** 整理物流跟踪信息* @param int $orderId 订单ID* @param $list* @return mixed* @throws BaseException* @throws \think\db\exception\DataNotFoundException* @throws \think\db\exception\DbException* @throws \think\db\exception\ModelNotFoundException*/private function getExpressTraces(int $orderId, $list){// 订单收货地址$address = OrderAddressModel::detail(['order_id' => $orderId]);// 整理物流跟踪信息$Express = new ExpressService;foreach ($list as $item) {if (!empty($item['express'])) {$item['traces'] = $Express->traces($item['express'],$item['express_no'],$address,$this->getStoreId());}}return $list;}/*** 获取某商品的购买件数* @param int $userId 用户ID* @param int $goodsId 商品ID* @param int $orderSource* @return int*/public static function getGoodsBuyNum(int $userId, int $goodsId, int $orderSource): int{return (int) (new OrderModel)->setBaseQuery('order', [['order_goods', 'order_id']])->where('order_goods.user_id', '=', $userId)->where('order_goods.goods_id', '=', $goodsId)->where('order.order_source', '=', $orderSource)->where('order.order_status', '<>', OrderStatusEnum::CANCELLED)->where('order.is_delete', '=', 0)->sum('order_goods.total_num');}/*** 根据用户id 来判断是否是新用户* @return \app\api\model\Goods[]|array|\think\Collection* @throws \cores\exception\BaseException* @throws \think\db\exception\DataNotFoundException* @throws \think\db\exception\DbException* @throws \think\db\exception\ModelNotFoundException*/public function getGoodsList(){// 当前用户ID$userId = UserService::getCurrentLoginUserId();// 查询列表记录return (new orderModel)->where('user_id', '=', $userId)->where('is_delete', '=', 0)->select();}public function getGoodsFromHistory(){$userId = UserService::getCurrentLoginUserId();return (new OrderModel())->alias('a')->join('order_goods b', 'a.order_id = b.order_id')->where('a.user_id', '=', $userId)->where('a.is_delete', '=', 0)//->field('b.goods_id,a.order_status')->field('b.goods_id,a.order_status,a.pay_status,a.delivery_status,a.receipt_status') // 选择商品ID和购买总数->select()->toArray();}}

表结构:

CREATE TABLE `yoshop_order` (`order_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '订单ID',`order_no` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '订单号',`order_type` tinyint(3) unsigned NOT NULL DEFAULT '10' COMMENT '订单类型(10实物订单)',`total_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '商品总金额(不含优惠折扣)',`order_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '订单金额(含优惠折扣)',`coupon_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '优惠券ID',`coupon_money` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '优惠券抵扣金额',`points_money` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '积分抵扣金额',`points_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '积分抵扣数量',`pay_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '实际付款金额(包含运费)',`update_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '后台修改的订单金额(差价)',`buyer_remark` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '买家留言',`pay_method` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '支付方式(余额/微信/支付宝)',`pay_status` tinyint(3) unsigned NOT NULL DEFAULT '10' COMMENT '付款状态(10未付款 20已付款)',`pay_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '付款时间',`trade_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '第三方交易记录ID',`delivery_type` tinyint(3) unsigned NOT NULL DEFAULT '10' COMMENT '配送方式(10快递配送 20门店自提 30无需配送)',`express_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '运费金额',`delivery_status` tinyint(3) unsigned NOT NULL DEFAULT '10' COMMENT '发货状态(10未发货 20已发货 30部分发货)',`delivery_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '发货时间',`receipt_status` tinyint(3) unsigned NOT NULL DEFAULT '10' COMMENT '收货状态(10未收货 20已收货)',`receipt_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '收货时间',`order_status` tinyint(3) unsigned NOT NULL DEFAULT '10' COMMENT '订单状态(10进行中 20取消 21待取消 30已完成)',`points_bonus` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '赠送的积分数量',`merchant_remark` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '商家备注',`is_settled` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '订单是否已结算(0未结算 1已结算)',`settled_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '订单结算时间',`is_comment` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '是否已评价(0否 1是)',`order_source` tinyint(3) unsigned NOT NULL DEFAULT '10' COMMENT '订单来源(10普通订单 20砍价订单 30秒杀订单)',`order_source_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '来源记录ID',`order_source_data` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '来源记录的参数 (json格式)',`platform` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '来源客户端 (APP、H5、小程序等)',`user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',`is_delete` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除',`store_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID',`create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',`update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',PRIMARY KEY (`order_id`),UNIQUE KEY `order_no` (`order_no`),KEY `store_id` (`store_id`),KEY `user_id` (`user_id`),KEY `pay_status` (`pay_status`),KEY `delivery_status` (`delivery_status`),KEY `receipt_status` (`receipt_status`),KEY `order_status` (`order_status`),KEY `is_settled` (`is_settled`),KEY `order_source` (`order_source`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='订单记录表';CREATE TABLE `yoshop_order_goods` (`order_goods_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '订单商品ID',`goods_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商品ID',`goods_type` tinyint(3) unsigned NOT NULL DEFAULT '10' COMMENT '商品类型(10实物商品)',`goods_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '商品名称',`image_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商品封面图ID',`deduct_stock_type` tinyint(3) unsigned NOT NULL DEFAULT '20' COMMENT '库存计算方式(10下单减库存 20付款减库存)',`spec_type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '规格类型(10单规格 20多规格)',`goods_sku_id` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '商品sku唯一标识',`goods_props` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'SKU的规格属性(json格式)',`content` longtext COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品详情',`goods_no` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '商品编码',`goods_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '商品价格(单价)',`line_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '商品划线价',`goods_weight` double unsigned NOT NULL DEFAULT '0' COMMENT '商品重量(Kg)',`is_user_grade` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '是否存在会员等级折扣',`grade_ratio` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '会员折扣比例(0-10)',`grade_goods_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '会员折扣的商品单价',`grade_total_money` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '会员折扣的总额差',`coupon_money` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '优惠券折扣金额',`points_money` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '积分金额',`points_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '积分抵扣数量',`points_bonus` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '赠送的积分数量',`total_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '购买数量',`total_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '商品总价(数量×单价)',`total_pay_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '实际付款价(折扣和优惠后)',`delivery_status` tinyint(3) unsigned NOT NULL DEFAULT '10' COMMENT '发货状态(10未发货 20已发货 30部分发货)',`delivery_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '已发货数量',`is_comment` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '是否已评价(0否 1是)',`order_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '订单ID',`user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',`goods_source_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '来源记录ID',`store_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID',`create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',PRIMARY KEY (`order_goods_id`),KEY `goods_id` (`goods_id`),KEY `order_id` (`order_id`),KEY `user_id` (`user_id`),KEY `store_id` (`store_id`)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='订单商品记录表';

我只想查到用户下单的商品的id 。  然后filed 中只写了  goods_id  报错如上。 

然后发现在Order 模型中有一个将 订单的付款状态返回成  0-》 未支付 的函数 ,因为我查询出来的数据没有这个字段所以报错。  加上所需要的字段就正常了

Order 模型代码:getStateTextAttr

<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);namespace app\common\model;use app\api\model\Order as OrderModel;
use app\api\service\User as UserService;
use cores\BaseModel;
use app\common\service\Order as OrderService;
use app\common\enum\order\PayStatus as PayStatusEnum;
use app\common\enum\order\OrderStatus as OrderStatusEnum;
use app\common\enum\order\ReceiptStatus as ReceiptStatusEnum;
use app\common\enum\order\DeliveryStatus as DeliveryStatusEnum;
use app\common\library\helper;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\model\relation\HasOne;
use think\model\relation\HasMany;
use think\model\relation\BelongsTo;/*** 订单模型* Class Order* @package app\common\model*/
class Order extends BaseModel
{// 定义表名protected $name = 'order';// 定义表名(外部引用)public static string $tableName = 'order';// 定义主键protected $pk = 'order_id';// 定义别名protected string $alias = 'order';/*** 追加字段* @var array*/protected $append = ['state_text',   // 售后单状态文字描述];/*** 订单商品列表* @return HasMany*/public function goods(): HasMany{$module = self::getCalledModule();return $this->hasMany("app\\{$module}\\model\\OrderGoods")->withoutField('content');}/*** 关联订单发货单* @return hasMany*/public function delivery(): HasMany{$module = self::getCalledModule();return $this->hasMany("app\\{$module}\\model\\order\\Delivery");}/*** 关联订单收货地址表* @return HasOne*/public function address(): HasOne{$module = self::getCalledModule();return $this->hasOne("app\\{$module}\\model\\OrderAddress");}/*** 关联用户表* @return BelongsTo*/public function user(): BelongsTo{$module = self::getCalledModule();return $this->belongsTo("app\\{$module}\\model\\User");}/*** 关联物流公司表 (仅用于兼容旧物流数据)* @return BelongsTo*/public function express(): BelongsTo{$module = self::getCalledModule();return $this->belongsTo("app\\{$module}\\model\\Express");}/*** 关联模型:第三方交易记录* @return BelongsTo*/public function trade(): BelongsTo{$module = self::getCalledModule();return $this->belongsTo("app\\{$module}\\model\\PaymentTrade", 'trade_id', 'trade_id');}/*** 获取器:订单状态文字描述* @param $value* @param $data* @return string*/public function getStateTextAttr($value, $data): string{//todo  这种设置了TextAttr 的查询的时候会加上这个// 订单状态if ($data['order_status'] != OrderStatusEnum::NORMAL) {return OrderStatusEnum::data()[$data['order_status']]['name'];}// 付款状态if ($data['pay_status'] == PayStatusEnum::PENDING) {return '待支付';}// 发货状态if ($data['delivery_status'] != DeliveryStatusEnum::DELIVERED) {$enum = [DeliveryStatusEnum::NOT_DELIVERED => '待发货', DeliveryStatusEnum::PART_DELIVERED => '部分发货'];return $enum[$data['delivery_status']];}// 收货状态if ($data['receipt_status'] == ReceiptStatusEnum::NOT_RECEIVED) {return '待收货';}return $value;}/*** 获取器:订单金额(含优惠折扣)* @param $value* @param $data* @return string*/public function getOrderPriceAttr($value, $data): string{// 兼容旧数据:订单金额if ($value == 0) {return helper::bcadd(helper::bcsub($data['total_price'], $data['coupon_money']), $data['update_price']);}return $value;}/*** 获取器:改价金额(差价)* @param $value* @return array*/public function getUpdatePriceAttr($value): array{return ['symbol' => $value < 0 ? '-' : '+','value' => sprintf('%.2f', abs((float)$value))];}/*** 获取器:付款时间* @param $value* @return false|string*/public function getPayTimeAttr($value){return format_time($value);}/*** 获取器:发货时间* @param $value* @return false|string*/public function getDeliveryTimeAttr($value){return format_time($value);}/*** 获取器:收货时间* @param $value* @return false|string*/public function getReceiptTimeAttr($value){return format_time($value);}/*** 获取器:来源记录的参数* @param $json* @return array*/public function getOrderSourceDataAttr($json): array{return $json ? helper::jsonDecode($json) : [];}/*** 修改器:来源记录的参数* @param array $data* @return string*/public function setOrderSourceDataAttr(array $data): string{return helper::jsonEncode($data);}/*** 生成订单号* @return string*/public function orderNo(): string{return OrderService::createOrderNo();}/*** 订单详情* @param $where* @param array $with* @return static|array|null*/public static function detail($where, array $with = []){is_array($where) ? $filter = $where : $filter['order_id'] = (int)$where;return self::get($filter, $with);}/*** 批量获取订单列表* @param array $orderIds* @param array $with* @return array* @throws DataNotFoundException* @throws DbException* @throws ModelNotFoundException*/public function getListByIds(array $orderIds, array $with = []): array{$data = $this->getListByInArray('order_id', $orderIds, $with);return helper::arrayColumn2Key($data, 'order_id');}/*** 批量获取订单列表* @param $field* @param $data* @param array $with* @return \think\Collection* @throws \think\db\exception\DataNotFoundException* @throws \think\db\exception\DbException* @throws \think\db\exception\ModelNotFoundException*/private function getListByInArray($field, $data, array $with = []): \think\Collection{return $this->with($with)->where($field, 'in', $data)->where('is_delete', '=', 0)->select();}/*** 根据订单号批量查询* @param $orderNos* @param array $with* @return \think\Collection* @throws \think\db\exception\DataNotFoundException* @throws \think\db\exception\DbException* @throws \think\db\exception\ModelNotFoundException*/public function getListByOrderNos($orderNos, array $with = []): \think\Collection{return $this->getListByInArray('order_no', $orderNos, $with);}/*** 批量更新订单* @param $orderIds* @param $data* @return bool|false*/public function onBatchUpdate($orderIds, $data): bool{return static::updateBase($data, [['order_id', 'in', $orderIds]]);}
}


http://www.ppmy.cn/ops/123553.html

相关文章

【QT Quick】C++交互:调用QML函数

在本节中&#xff0c;我们将深入探讨如何在C中调用QML函数。这项功能非常常用&#xff0c;尤其是在需要将C逻辑与QML界面进行交互时。我们将重点关注invokeMethod函数&#xff0c;它支持多种参数形式&#xff0c;并允许我们灵活地处理不同的调用场景。 invokeMethod概述 invo…

TypeScript 中枚举类型的理解?应用场景有哪些

文章目录 一、是什么二、使用数字枚举字符串枚举异构枚举本质 三、应用场景 一、是什么 枚举是一个被命名的整型常数的集合&#xff0c;用于声明一组命名的常数,当一个变量有几种可能的取值时,可以将它定义为枚举类型 通俗来说&#xff0c;枚举就是一个对象的所有可能取值的集…

微信小程序15天

UniApp(Vue3组合式API)和微信小程序15天学习计划 第1天&#xff1a;开发环境配置和基础知识 UniApp和微信小程序概述及对比安装并配置HBuilderX(UniApp)和微信开发者工具创建第一个UniApp Vue3项目和微信小程序项目了解两个平台的项目结构差异配置外部浏览器和各种小程序模拟…

影视cms泛目录用什么程序?苹果cms二次开发泛目录插件

影视CMS泛目录一般使用的程序有很多种&#xff0c;&#xff08;maccmscn&#xff09;以下是其中几种常见的程序&#xff1a; WordPress&#xff1a;WordPress是一个非常流行的开源内容管理系统&#xff0c;可以通过安装一些插件来实现影视CMS泛目录功能。其中&#xff0c;一款常…

JDBC介绍

JDBC&#xff1a; ( Java DataBase Connectivity )&#xff0c;就是使用Java语言操作关系型数据库的一套API。 本质&#xff1a; Sun公司官方定义的一套操作所有关系型数据库的规范&#xff0c;即接口。 各个数据库厂商去实现这套接口&#xff0c;提供数据库驱动jar包。 我们…

python27_strip()去除函数

strip()去除函数 # 示例字符串 s1 "*hello*world*oh*yeah*" s2 " helloworldohyeah "# 使用 strip() 去除两端的 * def StrStrip(a):result_strip a.strip("*")return result_strip# 替换成空字符串 def StrReplaceNull(a):result_empty a.…

leetcode:反转字符串II

题目链接 string reverse(string s1) {string s2;string::reverse_iterator rit s1.rbegin();while (rit ! s1.rend()){s2 *rit;rit;}return s2; } class Solution { public:string reverseStr(string s, int k) {string s1;int i 0;//标记字符串下标int j 0;int length …

【长文梳理Webserver核心】框架篇

感谢前人的总结&#xff0c;让一个小白快速成长&#xff0c;那我也贡献一份自己的力量~ 大框架梳理从main函数开始学习 大框架梳理 先摆图&#xff1a; 目光先放到最上面的两个小框架&#xff0c;半同步/半反应堆线程池和异步日志系统&#xff0c;日志系统晓得伐&#xff1f;…