Files

108 lines
3.4 KiB
PHP
Raw Permalink Normal View History

2025-11-07 09:56:20 +08:00
<?php
namespace app\model;
use app\model\Base;
/**
* @property integer $id 主键(ID) - 无注释
* @property string $title 标题
* @property string $image 封面
* @property string $amounts 面额列表
* @property integer $stock 库存
* @property integer $sales 銷售量
* @property integer $user_quantity 用户累计限购
* @property string $memo 备注
* @property integer $weight 权重
* @property integer $created_at 创建时间
* @property integer $updated_at 更新时间
* @property integer $status 状态
*/
/**
--
-- 表的结构 `wa_gift`
--
CREATE TABLE `wa_gift` (
`id` int NOT NULL,
`title` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '标题',
`image` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '封面',
`amounts` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '面额列表',
`stock` int DEFAULT '0' COMMENT '库存',
`sales` int DEFAULT '0' COMMENT '銷售量',
`user_quantity` int NOT NULL DEFAULT '0' COMMENT '用户累计限购',
`memo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注',
`weight` int DEFAULT NULL COMMENT '权重',
`created_at` int DEFAULT NULL COMMENT '创建时间',
`updated_at` int DEFAULT NULL COMMENT '更新时间',
`status` tinyint DEFAULT NULL COMMENT '状态'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
--
-- 转存表中的数据 `wa_gift`
--
INSERT INTO `wa_gift` (`id`, `title`, `image`, `amounts`, `stock`, `sales`, `user_quantity`, `memo`, `weight`, `created_at`, `updated_at`, `status`) VALUES
(12, '京东礼品卡', '/upload/files/20250922/911fabdb0719edcbba3f0f7b84f59f85_68d09e2a8447e.png', '[\"1000\"]', 999, 405, 10, '', NULL, 1749809778, 1758502443, 1),
(13, '亚马逊电子礼品卡', '', '[1350.0]', 0, 530, 0, '', NULL, 1749809924, 1757263525, 1),
(14, '永辉电子礼品卡', '', '[3.5]', 0, 300, 0, '', NULL, 1749875587, 1757263532, 1),
(15, '盒马电子礼品卡', '', '[3.5]', 0, 300, 0, '', NULL, 1749953784, 1757263539, 1),
(42, '沃尔玛电子礼品卡', '', '[\"10\",\"22\"]', 99, 2, 0, '', NULL, 1757263545, 1759943587, 1);
--
-- 转储表的索引
--
--
-- 表的索引 `wa_gift`
--
ALTER TABLE `wa_gift`
ADD PRIMARY KEY (`id`) USING BTREE;
--
-- 在导出的表使用AUTO_INCREMENT
--
--
-- 使用表AUTO_INCREMENT `wa_gift`
--
ALTER TABLE `wa_gift`
MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=44;
COMMIT;
*/
class Gift extends Base
{
protected $autoWriteTimestamp = true;
protected function getOptions(): array{
return array_merge(parent::getOptions(),[
'insert' => [
'status' => 1,
'amounts' => '[]'
]
]);
}
function setAmountsAttr($v='',$row=[]){
if(is_array($v) || is_object($v)){
return json_encode($v,JSON_UNESCAPED_UNICODE);
}
if(is_string($v) && substr($v,0,1)!='['){
$v = explode(',',$v);
return json_encode($v,JSON_UNESCAPED_UNICODE);
}
return '[]';
}
function getAmountsAttr($v='',$row=[]){
if(!$v){return [];}
if(is_array($v) || is_object($v)){
return $v;
}
return json_decode($v,true);
}
function getStatusList(){
return [
'0' => '禁用',
'1' => '启用',
];
}
}