FlashProduct.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zhengmingwei
  5. * Date: 2020/2/9
  6. * Time: 6:29 PM
  7. */
  8. namespace addons\unishop\model;
  9. use addons\unishop\extend\Hashids;
  10. use think\Model;
  11. class FlashProduct extends Model
  12. {
  13. // 表名
  14. protected $name = 'unishop_flash_product';
  15. // 开启自动写入时间戳字段
  16. protected $autoWriteTimestamp = 'int';
  17. // 定义时间戳字段名
  18. protected $createTime = 'createtime';
  19. protected $updateTime = 'updatetime';
  20. // 已上架
  21. const SWITCH_ON = 1; // 是
  22. const SWITCH_OFF = 0; // 否
  23. // 隐藏属性
  24. protected $hidden = [
  25. 'flash_id',
  26. 'product_id',
  27. 'id'
  28. ];
  29. // 追加属性
  30. protected $append = [
  31. 'flash_product_id'
  32. ];
  33. public function getFlashProductIdAttr($value, $data) {
  34. return Hashids::encodeHex($data['product_id']);
  35. }
  36. /**
  37. * 关联到商品表
  38. */
  39. public function product()
  40. {
  41. return $this->belongsTo('product', 'product_id', 'id')->field('id,title,sales_price,market_price,image');
  42. }
  43. }