Attribute.php 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace mall\basic;
  10. use think\facade\Db;
  11. class Attribute {
  12. public static function get($goods_id,$spec,$json=false){
  13. $array = explode(",",$spec);
  14. $data = [];
  15. foreach($array as $key=>$val){
  16. $a = explode(":",$val);
  17. $attr = Db::name("goods_attribute")
  18. ->where("goods_id",$goods_id)
  19. ->where("attr_id",$a[0])
  20. ->where("attr_data_id",$a[1])
  21. ->find();
  22. $data[$key] = ["name"=>$attr["name"],"value"=>$attr["value"]];
  23. }
  24. return $json ? json_encode($data,JSON_UNESCAPED_UNICODE) : $data;
  25. }
  26. }