RiceCardGoods.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\common\model\card;
  3. use app\common\library\helper;
  4. use app\common\model\BaseModel;
  5. /**
  6. * 米卡商品模型
  7. * @package app\common\model
  8. */
  9. class RiceCardGoods extends BaseModel
  10. {
  11. // 是否除外
  12. const EXCEPT_YES = 1; // 除外商品
  13. const EXCEPT_NO = 0; // 可兑换商品
  14. protected $name = 'rice_card_goods';
  15. /**
  16. * 关联 米卡表
  17. */
  18. public function riceCard()
  19. {
  20. return $this->belongsTo('RiceCard', 'card_id');
  21. }
  22. public function image()
  23. {
  24. $model = "app\\common\\model\\UploadFile";
  25. return $this->belongsTo($model, 'image_id', 'file_id');
  26. }
  27. /**
  28. * 获取器:规格属性
  29. * @param $value
  30. * @return array
  31. */
  32. public function getGoodsPropsAttr($value)
  33. {
  34. return helper::jsonDecode($value);
  35. }
  36. /**
  37. * 设置器:规格属性
  38. * @param $value
  39. * @return string
  40. */
  41. public function setGoodsPropsAttr($value)
  42. {
  43. return !empty($value) ? helper::jsonEncode($value) : '';
  44. }
  45. /**
  46. * 获取记录
  47. * @param int $id
  48. * @param array $with
  49. * @return static
  50. */
  51. public static function detail(int $id, array $with = [])
  52. {
  53. return static::get($id, $with);
  54. }
  55. }