GoodsSku.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\common\model\sharing;
  10. use app\common\library\helper;
  11. use app\common\model\BaseModel;
  12. /**
  13. * 拼团商品SKU模型
  14. * Class GoodsSku
  15. * @package app\common\model\sharing
  16. */
  17. class GoodsSku extends BaseModel
  18. {
  19. protected $name = 'sharing_goods_sku';
  20. protected $append = ['diff_price'];
  21. /**
  22. * 规格图片
  23. * @return \think\model\relation\HasOne
  24. */
  25. public function image()
  26. {
  27. $module = self::getCalledModule() ?: 'common';
  28. return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'image_id');
  29. }
  30. /**
  31. * 获取器:拼团价与划线价差额
  32. * @param $value
  33. * @param $data
  34. * @return mixed
  35. */
  36. public function getDiffPriceAttr($value, $data)
  37. {
  38. return max(0, helper::bcsub($data['line_price'], $data['sharing_price']));
  39. }
  40. /**
  41. * 获取sku信息详情
  42. * @param $goodsId
  43. * @param $specSkuId
  44. * @return GoodsSku|null
  45. * @throws \think\exception\DbException
  46. */
  47. public static function detail($goodsId, $specSkuId)
  48. {
  49. return static::get(['goods_id' => $goodsId, 'spec_sku_id' => $specSkuId]);
  50. }
  51. }