截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LiveGoods.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\common\model\live;
  20. use app\common\basics\Models;
  21. use app\common\enum\LiveGoodsEnum;
  22. use app\common\model\goods\Goods;
  23. use app\common\model\shop\Shop;
  24. /**
  25. * 直播商品
  26. * Class LiveGoods
  27. * @package app\common\model\live
  28. */
  29. class LiveGoods extends Models
  30. {
  31. /**
  32. * @notes 关联商家
  33. * @return \think\model\relation\HasOne
  34. * @author 段誉
  35. * @date 2023/2/16 12:10
  36. */
  37. public function shop()
  38. {
  39. return $this->hasOne(Shop::class, 'id', 'shop_id')
  40. ->field(['id','logo','type','name'])->append(['type_desc']);
  41. }
  42. /**
  43. * @notes 审核状态描述
  44. * @param $value
  45. * @param $data
  46. * @return string|string[]
  47. * @author 段誉
  48. * @date 2023/2/16 9:45
  49. */
  50. public function getAuditStatusTextAttr($value, $data)
  51. {
  52. return LiveGoodsEnum::getAuditStatusDesc($data['sys_audit_status']);
  53. }
  54. /**
  55. * @notes 价格描述
  56. * @param $value
  57. * @param $data
  58. * @return string
  59. * @author 段誉
  60. * @date 2023/2/16 20:45
  61. */
  62. public function getPriceTextAttr($value, $data)
  63. {
  64. if ($data['price_type'] == LiveGoodsEnum::PRICE_ONE) {
  65. return '¥' . $data['price'];
  66. } else {
  67. return '¥' . $data['price'] . '~ ¥' .$data['price2'];
  68. }
  69. }
  70. /**
  71. * @notes 价格形式
  72. * @param $value
  73. * @param $data
  74. * @return string|string[]
  75. * @author 段誉
  76. * @date 2023/2/16 21:55
  77. */
  78. public function getPriceTypeTextAttr($value, $data)
  79. {
  80. return LiveGoodsEnum::getPriceTypeDesc($data['price_type']);
  81. }
  82. /**
  83. * @notes 价格描述
  84. * @param $value
  85. * @param $data
  86. * @return string|void
  87. * @author 段誉
  88. * @date 2023/2/16 21:59
  89. */
  90. public function getPriceTipsAttr($value, $data)
  91. {
  92. if ($data['price_type'] == LiveGoodsEnum::PRICE_ONE) {
  93. return '价格 ' . $data['price'] . '元';
  94. }
  95. if ($data['price_type'] == LiveGoodsEnum::PRICE_RANGE) {
  96. return '价格 ' . $data['price'] . '元 ~ ' .$data['price2'] . '元';
  97. }
  98. if ($data['price_type'] == LiveGoodsEnum::PRICE_DISCOUNT) {
  99. return '价格 ' . $data['price'] . '元 现价 ' .$data['price2'] . '元';
  100. }
  101. }
  102. /**
  103. * @notes 来源类型
  104. * @param $value
  105. * @param $data
  106. * @return string|string[]
  107. * @author 段誉
  108. * @date 2023/2/17 9:36
  109. */
  110. public function getSourceTypeTextAttr($value, $data)
  111. {
  112. return LiveGoodsEnum::getSourceTypeDesc($data['source_type']);
  113. }
  114. /**
  115. * @notes 商品库存
  116. * @param $value
  117. * @param $data
  118. * @return int|mixed
  119. * @author 段誉
  120. * @date 2023/2/17 12:12
  121. */
  122. public function getGoodsStockAttr($value, $data)
  123. {
  124. $stock = 0;
  125. if ($data['source_type'] == LiveGoodsEnum::SOURCE_TYPE_GOODS) {
  126. $stock = Goods::where('id', $data['source_id'])->value('stock');
  127. $stock = empty($stock) ? 0 : $stock;
  128. }
  129. return $stock;
  130. }
  131. }