|
|
@@ -8,6 +8,7 @@
|
|
|
namespace app\models\store;
|
|
|
|
|
|
|
|
|
+use app\admin\model\system\SystemStoreProductStock;
|
|
|
use crmeb\basic\BaseModel;
|
|
|
use think\facade\Db;
|
|
|
use crmeb\traits\ModelTrait;
|
|
|
@@ -29,7 +30,7 @@ class StoreProductAttr extends BaseModel
|
|
|
|
|
|
protected function getAttrValuesAttr($value)
|
|
|
{
|
|
|
- return explode(',',$value);
|
|
|
+ return explode(',', $value);
|
|
|
}
|
|
|
|
|
|
public static function storeProductAttrValueDb()
|
|
|
@@ -43,49 +44,53 @@ class StoreProductAttr extends BaseModel
|
|
|
* @param $productId
|
|
|
* @return array
|
|
|
*/
|
|
|
- public static function getProductAttrDetail($productId,$uid=0,$type = 0,$type_id=0)
|
|
|
+ public static function getProductAttrDetail($productId, $uid = 0, $type = 0, $type_id = 0, $store_id = 0)
|
|
|
{
|
|
|
- $attrDetail = self::where('product_id',$productId)->where('type',$type_id)->order('id asc')->select()->toArray()?:[];
|
|
|
- $_values = self::storeProductAttrValueDb()->where('product_id',$productId)->where('type',$type_id)->select();
|
|
|
+ $attrDetail = self::where('product_id', $productId)->where('type', $type_id)->order('id asc')->select()->toArray() ?: [];
|
|
|
+ $_values = self::storeProductAttrValueDb()->where('product_id', $productId)->where('type', $type_id)->select();
|
|
|
$values = [];
|
|
|
- foreach ($_values as $value){
|
|
|
- if($type){
|
|
|
+ foreach ($_values as $value) {
|
|
|
+ if ($type) {
|
|
|
if ($uid)
|
|
|
- $value['cart_num'] = StoreCart::where('product_attr_unique',$value['unique'])->where('is_pay', 0)->where('is_del', 0)->where('is_new', 0)->where('type', 'product')->where('product_id', $productId)->where('uid', $uid)->value('cart_num');
|
|
|
+ $value['cart_num'] = StoreCart::where('product_attr_unique', $value['unique'])->where('is_pay', 0)->where('is_del', 0)->where('is_new', 0)->where('type', 'product')->where('product_id', $productId)->where('uid', $uid)->value('cart_num');
|
|
|
else
|
|
|
$value['cart_num'] = 0;
|
|
|
if (is_null($value['cart_num'])) $value['cart_num'] = 0;
|
|
|
}
|
|
|
+ if ($store_id && $type_id == 0) {
|
|
|
+ $stockinfo = SystemStoreProductStock::where('unique', $value['unique'])->find();
|
|
|
+ $value['price'] = $stockinfo ? $stockinfo['price'] : $value['price'];
|
|
|
+ }
|
|
|
$values[$value['suk']] = $value;
|
|
|
}
|
|
|
- foreach ($attrDetail as $k=>$v){
|
|
|
+ foreach ($attrDetail as $k => $v) {
|
|
|
$attr = $v['attr_values'];
|
|
|
// unset($productAttr[$k]['attr_values']);
|
|
|
- foreach ($attr as $kk=>$vv){
|
|
|
- $attrDetail[$k]['attr_value'][$kk]['attr'] = $vv;
|
|
|
- $attrDetail[$k]['attr_value'][$kk]['check'] = false;
|
|
|
+ foreach ($attr as $kk => $vv) {
|
|
|
+ $attrDetail[$k]['attr_value'][$kk]['attr'] = $vv;
|
|
|
+ $attrDetail[$k]['attr_value'][$kk]['check'] = false;
|
|
|
}
|
|
|
}
|
|
|
- return [$attrDetail,$values];
|
|
|
+ return [$attrDetail, $values];
|
|
|
}
|
|
|
|
|
|
public static function uniqueByStock($unique)
|
|
|
{
|
|
|
- return self::storeProductAttrValueDb()->where('unique',$unique)->value('stock')?:0;
|
|
|
+ return self::storeProductAttrValueDb()->where('unique', $unique)->value('stock') ?: 0;
|
|
|
}
|
|
|
|
|
|
public static function uniqueByAttrInfo($unique, $field = '*')
|
|
|
{
|
|
|
- return self::storeProductAttrValueDb()->field($field)->where('unique',$unique)->find();
|
|
|
+ return self::storeProductAttrValueDb()->field($field)->where('unique', $unique)->find();
|
|
|
}
|
|
|
|
|
|
- public static function issetProductUnique($productId,$unique)
|
|
|
+ public static function issetProductUnique($productId, $unique)
|
|
|
{
|
|
|
// $res = self::be(['product_id'=>$productId]);
|
|
|
- $res = self::where('product_id',$productId)->where('type',0)->find();
|
|
|
- if($unique){
|
|
|
- return $res && self::storeProductAttrValueDb()->where('product_id',$productId)->where('unique',$unique)->where('type',0)->count() > 0;
|
|
|
- }else{
|
|
|
+ $res = self::where('product_id', $productId)->where('type', 0)->find();
|
|
|
+ if ($unique) {
|
|
|
+ return $res && self::storeProductAttrValueDb()->where('product_id', $productId)->where('unique', $unique)->where('type', 0)->count() > 0;
|
|
|
+ } else {
|
|
|
return !$res;
|
|
|
}
|
|
|
}
|