PresellGoods.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\common\model;
  3. use think\model\concern\SoftDelete;
  4. class PresellGoods extends BaseModel
  5. {
  6. use SoftDelete;
  7. protected $autoWriteTimestamp = true;
  8. protected $defaultSoftDelete = 0;
  9. function getContentAttr($fieldValue, $data)
  10. {
  11. return (array) json_decode($fieldValue, true);
  12. }
  13. function setContentAttr($fieldValue, $data)
  14. {
  15. return json_encode($fieldValue, JSON_UNESCAPED_UNICODE);
  16. }
  17. function getShowGoodsAttr($fieldValue, $data)
  18. {
  19. if ($data['min_price'] == $data['max_price']) {
  20. $presell_price = "{$data['min_price']}";
  21. } else {
  22. $presell_price = "{$data['min_price']}~{$data['max_price']}";
  23. }
  24. if ($this->content['min_price'] == $this->content['max_price']) {
  25. $sell_price = "{$this->content['min_price']}";
  26. } else {
  27. $sell_price = "{$this->content['min_price']}~{$this->content['max_price']}";
  28. }
  29. return [
  30. 'presell_price' => $presell_price,
  31. 'presell_min_price' => "{$data['min_price']}",
  32. 'presell_max_price' => "{$data['max_price']}",
  33. 'sell_price' => $sell_price,
  34. 'sell_min_price' => "{$this->content['min_price']}",
  35. 'sell_max_price' => "{$this->content['max_price']}",
  36. 'name' => $this->content['name'] ?? '',
  37. 'image' => $this->content['image'] ?? '',
  38. ];
  39. }
  40. /**
  41. * @notes 预售商品规格列表
  42. * @return \think\model\relation\HasMany
  43. * @author lbzy
  44. * @datetime 2024-04-24 14:19:51
  45. */
  46. function items()
  47. {
  48. return $this->hasMany(PresellGoodsItem::class, 'presell_goods_id', 'id');
  49. }
  50. function item()
  51. {
  52. return $this->hasMany(PresellGoodsItem::class, 'presell_goods_id', 'id');
  53. }
  54. /**
  55. * @notes 商品详情
  56. * @return \think\model\relation\HasOne
  57. * @author lbzy
  58. * @datetime 2024-04-24 14:19:39
  59. */
  60. function detail()
  61. {
  62. return $this->hasOne(Goods::class, 'id', 'goods_id');
  63. }
  64. }