ProductAttr.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\home\model;
  14. use think\Db;
  15. use think\Model;
  16. /**
  17. * 产品参数
  18. */
  19. class ProductAttr extends Model
  20. {
  21. //初始化
  22. protected function initialize()
  23. {
  24. // 需要调用`Model`的`initialize`方法
  25. parent::initialize();
  26. }
  27. /**
  28. * 获取指定产品的所有参数
  29. * @author 小虎哥 by 2018-4-3
  30. */
  31. public function getProAttr($aids = [], $field = 'b.*, a.*')
  32. {
  33. $where = [];
  34. !empty($aids) && $where['b.aid'] = ['IN', $aids];
  35. $where['a.is_del'] = 0;
  36. $result = Db::name('ProductAttribute')->field($field)
  37. ->alias('a')
  38. ->join('__PRODUCT_ATTR__ b', 'b.attr_id = a.attr_id', 'LEFT')
  39. ->where($where)
  40. ->order('a.sort_order asc, a.attr_id asc')
  41. ->select();
  42. !empty($result) && $result = group_same_key($result, 'aid');
  43. return $result;
  44. }
  45. }