ProductShangpin.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\api\model;
  3. use think\Model;
  4. class ProductShangpin extends Model
  5. {
  6. // 表名
  7. protected $name = 'product_shangpin';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. ];
  17. public function shopuser()
  18. {
  19. return $this->belongsTo('app\admin\model\ShopUser','suser_id','id')->field('id,shopname,phone,phone_axn,axn_id');
  20. }
  21. public function storeseckill()
  22. {
  23. return $this->hasOne('StoreSeckill','store_id','id');
  24. }
  25. public function attribute()
  26. {
  27. return $this->hasMany('app\admin\model\store\StoreProductAttribute','pro_id','id')->order('id asc');
  28. }
  29. public function getImageAttr($value)
  30. {
  31. if (empty($value)){
  32. return '';
  33. }
  34. // $status = [-1=>'删除',0=>'禁用',1=>'正常',2=>'待审核'];
  35. return config('site.siteUrl').$value;
  36. }
  37. public function getMp4Attr($value)
  38. {
  39. if (empty($value)){
  40. return '';
  41. }
  42. // $status = [-1=>'删除',0=>'禁用',1=>'正常',2=>'待审核'];
  43. return config('site.siteUrl').$value;
  44. }
  45. public function getSliderImageAttr($value)
  46. {
  47. $images=explode(',',$value);
  48. foreach ($images as $k=>$v){
  49. if (!empty($v)){
  50. $images[$k]=config('site.siteUrl').$v;
  51. }else{
  52. $images[$k]='';
  53. }
  54. }
  55. // $status = [-1=>'删除',0=>'禁用',1=>'正常',2=>'待审核'];
  56. return $images;
  57. }
  58. }