作者 何书鹏
1 个管道 的构建 通过 耗费 0 秒

购物车尺寸信息

... ... @@ -199,7 +199,7 @@ class Cart extends Model
if(!$cart->user_size){
$cart->user_size = [];
}else{
$cart->user_size->visible(['id','name']);
$cart->user_size->visible(['id','name','size_text']);
}
$cart_list[] = $cart->visible([
'id',
... ... @@ -237,7 +237,7 @@ class Cart extends Model
$coupon = [
'list' => $this->orderCouponList($user,$cart_list),
'user_coupon_id' => 0,
'coupon_name' => '',
'coupon_name' => '暂无可用',
'coupon_price' => 0,
];
if(!empty($data['user_coupon_id'])){
... ...
... ... @@ -14,6 +14,11 @@ class UserSize extends Model
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'size_text'
];
/**
* 隐藏字段
* @var array
... ... @@ -105,4 +110,36 @@ class UserSize extends Model
{
return self::get(compact('user_id', 'id'));
}
/**
* 尺寸详情
*/
public function getSizeTextAttr($value,$data){
$size_text = [];
if(!empty($data['body_info'])){
$size = json_decode(str_replace('\'','"',$data['body_info']),true);
foreach($size as $k => $v){
$style = Style::where('id',$k)->field('style_name,style_type')->find()->toArray();
$style['style_value'] = '';
switch ($style['style_type']) {
case '1':
$style['style_value'] = StyleValue::where('id',$v)->value('style_value_name');
break;
case '2':
$style['style_value'] = $v;
break;
case '3':
$style['style_value'] = cdnurl($v,true);
break;
}
$size_text[] = $style;
}
}
$size_text = array_merge([
['style_name'=>'身高','style_type'=>'1','style_value_name'=>$data['height'].'CM'],
['style_name'=>'体重','style_type'=>'1','style_value_name'=>$data['weight'].'KG'],
['style_name'=>'腰围','style_type'=>'1','style_value_name'=>$data['waistline']],
],$size_text);
return $size_text;
}
}
... ...