123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace app\common\model;
- use think\Model;
- use think\model\concern\SoftDelete;
- class MallGoods extends Model
- {
- // 设置字段信息
- protected $schema = [
- 'id' => 'int',
- 'cateid' => 'int',
- 'title' => 'string',
- 'tilpic' => 'string',
- 'picall' => 'string',
- 'stock' => 'int',
- 'sales' => 'int',
- 'integral' => 'int',
- 'paymoney' => 'float',
- 'summary' => 'string',
- 'oremark' => 'string',
- 'details' => 'string',
- 'priority' => 'int',
- 'createtime' => 'int',
- 'status' => 'tinyint',
- 'deletetime' => 'int'
- ];
- use SoftDelete;
- protected $deleteTime = 'deletetime';
- protected $defaultSoftDelete = 0;
- // 设置字段自动转换类型
- protected $type = [
- 'picall' => 'json',
- 'createtime' => 'timestamp:Y-m-d H:i:s',
- 'deletetime' => 'timestamp:Y-m-d H:i:s'
- ];
- // 设置JSON数据返回数组
- protected $jsonAssoc = true;
-
- public function getStatusTextAttr($value,$data)
- {
- $status = [1=>'待修改', 2=>'已上架', 3=>'已下架'];
- return $status[$data['status']];
- }
- // 关联MallCate
- public function mallCate()
- {
- return $this->hasOne(MallCate::class, "id", "cateid");
- }
-
- // 关联MallOrder
- public function mallOrder()
- {
- return $this->hasMany(MallOrder::class, "goodsid", "id");
- }
-
-
- }
|