Goods.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\common\model\goods;
  15. use app\common\model\BaseModel;
  16. use app\common\model\goods_category\GoodsCategory;
  17. use app\common\model\performance\PerformanceRules;
  18. /**
  19. * Goods模型
  20. * Class GoodsEnum
  21. * @package app\common\model\goods
  22. */
  23. class Goods extends BaseModel
  24. {
  25. protected $name = 'goods';
  26. protected $type = [
  27. 'goods_category_ids' => 'array',
  28. 'goods_banners' => 'array'
  29. ];
  30. public function goodsCategory()
  31. {
  32. return $this->hasOne(GoodsCategory::class, 'id', 'goods_category_id')
  33. ->field('id,name,picture');
  34. }
  35. public function performanceRules()
  36. {
  37. return $this->hasOne(PerformanceRules::class, 'goods_id', 'id')
  38. ->field('goods_id,type,rate');
  39. }
  40. public function getIsTypeAttr($value,$data)
  41. {
  42. if ($data['is_agent'] == 1 && $data['is_activity'] == 1) {
  43. return -1;
  44. } else if ($data['is_agent'] == 1 && $data['is_activity'] == 0) {
  45. return 1;
  46. } else if ($data['is_agent'] == 0 && $data['is_activity'] == 1) {
  47. return 2;
  48. } else {
  49. return 0;
  50. }
  51. }
  52. public function getLabelsAttr($value)
  53. {
  54. return $value?array_map(function($item){ return (int)$item; },explode(',',$value)):[];
  55. }
  56. }