41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace app\common\model\localstore;
|
|
|
|
use app\common\basics\Models;
|
|
|
|
class LocalStoreGoodsCart extends Models
|
|
{
|
|
public function goods()
|
|
{
|
|
return $this->hasOne(LocalStoreGoods::class, 'id', 'lsg_id');
|
|
}
|
|
|
|
// 商品规格为空,获取封面图
|
|
public function getPicAttr($value, $data)
|
|
{
|
|
if ($data['item_id'] == 0) {
|
|
$pic = LocalStoreGoodsPic::where('lsg_id', $data['lsg_id'])->field('url')->find();
|
|
if ($pic) {
|
|
return $pic['url'];
|
|
}
|
|
}
|
|
}
|
|
|
|
// 获取带有商品规格的属性
|
|
public function getItemAttr($value, $data)
|
|
{
|
|
if ($data['item_id'] > 0) {
|
|
return LocalStoreGoodsItem::where('id', $data['item_id'])->field('image, spec_value_str, price')->find()->toArray();
|
|
}
|
|
}
|
|
|
|
public static function getSelfCart($user_id, $cart_id = 0)
|
|
{
|
|
if ($cart_id > 0) {
|
|
return self::where(['id' => $cart_id, 'user_id' => $user_id, 'is_delete' => 0])->find();
|
|
} else {
|
|
return self::where(['user_id' => $user_id, 'is_delete' => 0])->select();
|
|
}
|
|
}
|
|
} |