MallGoods.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use think\model\concern\SoftDelete;
  5. class MallGoods extends Model
  6. {
  7. // 设置字段信息
  8. protected $schema = [
  9. 'id' => 'int',
  10. 'cateid' => 'int',
  11. 'title' => 'string',
  12. 'tilpic' => 'string',
  13. 'picall' => 'string',
  14. 'stock' => 'int',
  15. 'sales' => 'int',
  16. 'integral' => 'int',
  17. 'paymoney' => 'float',
  18. 'summary' => 'string',
  19. 'oremark' => 'string',
  20. 'details' => 'string',
  21. 'priority' => 'int',
  22. 'createtime' => 'int',
  23. 'status' => 'tinyint',
  24. 'deletetime' => 'int'
  25. ];
  26. use SoftDelete;
  27. protected $deleteTime = 'deletetime';
  28. protected $defaultSoftDelete = 0;
  29. // 设置字段自动转换类型
  30. protected $type = [
  31. 'picall' => 'json',
  32. 'createtime' => 'timestamp:Y-m-d H:i:s',
  33. 'deletetime' => 'timestamp:Y-m-d H:i:s'
  34. ];
  35. // 设置JSON数据返回数组
  36. protected $jsonAssoc = true;
  37. public function getStatusTextAttr($value,$data)
  38. {
  39. $status = [1=>'待修改', 2=>'已上架', 3=>'已下架'];
  40. return $status[$data['status']];
  41. }
  42. // 关联MallCate
  43. public function mallCate()
  44. {
  45. return $this->hasOne(MallCate::class, "id", "cateid");
  46. }
  47. // 关联MallOrder
  48. public function mallOrder()
  49. {
  50. return $this->hasMany(MallOrder::class, "goodsid", "id");
  51. }
  52. }