Rank.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的多应用管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace addon\mall\app\model\goods;
  12. use addon\mall\app\dict\goods\RankDict;
  13. use core\base\BaseModel;
  14. /**
  15. * 商品排行版模型
  16. * Class Brand
  17. * @package addon\shop\app\model\goods
  18. */
  19. class Rank extends BaseModel
  20. {
  21. /**
  22. * 数据表主键
  23. * @var string
  24. */
  25. protected $pk = 'rank_id';
  26. /**
  27. * 模型名称
  28. * @var string
  29. */
  30. protected $name = 'mall_goods_rank';
  31. protected $json = [ 'goods_json', 'category_ids', 'brand_ids', 'label_ids'];
  32. protected $jsonAssoc = true;
  33. /**
  34. * 搜索器:排行榜名称
  35. * @param $value
  36. * @param $data
  37. */
  38. public function searchNameAttr($query, $value, $data)
  39. {
  40. if ($value != '') {
  41. $query->where("name", "like", "%" . $this->handelSpecialCharacter($value) . "%");
  42. }
  43. }
  44. /**
  45. * 搜索器:排行榜名称
  46. * @param $value
  47. * @param $data
  48. */
  49. public function searchRankTypeAttr($query, $value, $data)
  50. {
  51. if ($value) {
  52. $query->where("rank_type", '=', $value);
  53. }
  54. }
  55. /**
  56. * 排行周期
  57. * @param $value
  58. * @param $data
  59. * @return mixed|string
  60. */
  61. public function getRankTypeNameAttr($value, $data)
  62. {
  63. if (empty($data['rank_type']))
  64. {
  65. return '';
  66. }
  67. return RankDict::getRankType()[$data['rank_type']] ?? '';
  68. }
  69. /**
  70. * 来源类型
  71. * @param $value
  72. * @param $data
  73. * @return mixed|string
  74. */
  75. public function getGoodsSourceNameAttr($value, $data)
  76. {
  77. if (empty($data['goods_source']))
  78. {
  79. return '';
  80. }
  81. return RankDict::getGoodsSource()[$data['goods_source']] ?? '';
  82. }
  83. /**
  84. * 排序规则
  85. * @param $value
  86. * @param $data
  87. * @return mixed|string
  88. */
  89. public function getRuleTypeNameAttr($value, $data)
  90. {
  91. if (empty($data['rule_type']))
  92. {
  93. return '';
  94. }
  95. return RankDict::getRuleType()[$data['rule_type']] ?? '';
  96. }
  97. }