提交 010391e9 编写于 作者: T Terry

产品部分调整

上级 ab6ab252
......@@ -45,6 +45,22 @@ return [
],
*/
],
'mysqlSearch' => [
'class' => 'fecshop\services\search\MysqlSearch',
'enableService' => true,
/*
'searchLang' => [
'en' => 'english',
'fr' => 'french',
'de' => 'german',
'es' => 'spanish',
'ru' => 'russian',
'pt' => 'portuguese',
'it' => 'italian',
'zh' => 'chinese',
],
*/
],
],
],
];
......@@ -79,6 +79,38 @@ class m190716_024608_fecshop_tables extends Migration
KEY `category_id` (`category_id`,`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=233 ;
",
"
ALTER TABLE `url_rewrite` ADD `created_at` INT( 12 ) NULL ,
ADD `updated_at` INT( 12 ) NULL
",
"
CREATE TABLE IF NOT EXISTS `full_search_product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`lang` varchar(20) DEFAULT NULL COMMENT '语言简码',
`product_id` varchar(50) DEFAULT NULL COMMENT '产品id',
`name` varchar(255) DEFAULT NULL COMMENT '产品name',
`spu` varchar(100) DEFAULT NULL COMMENT 'spu',
`sku` varchar(100) DEFAULT NULL COMMENT 'sku',
`score` int(11) DEFAULT NULL COMMENT '产品分值',
`status` int(5) DEFAULT NULL COMMENT '产品状态',
`is_in_stock` int(5) DEFAULT NULL COMMENT '产品库存状态',
`url_key` varchar(255) DEFAULT NULL COMMENT '产品url key',
`price` decimal(12,2) DEFAULT NULL COMMENT '产品价格',
`cost_price` decimal(12,2) DEFAULT NULL COMMENT '产品成本价',
`special_price` decimal(12,2) DEFAULT NULL COMMENT '产品特价',
`special_from` int(12) DEFAULT NULL COMMENT '产品特价开始时间',
`special_to` int(12) DEFAULT NULL COMMENT '产品特价结束时间',
`final_price` decimal(12,2) DEFAULT NULL COMMENT '产品最终时间',
`image` text COMMENT '产品图片',
`short_description` text COMMENT '产品简短描述',
`description` text COMMENT '产品描述',
`created_at` int(12) DEFAULT NULL COMMENT '产品创建时间',
`sync_updated_at` int(12) DEFAULT NULL COMMENT '产品同步时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
",
];
foreach ($arr as $sql) {
......
......@@ -74,6 +74,21 @@ class Product extends Service
$currentService = $this->getStorageService($this);
$this->_product = new $currentService();
}
// 动态更改为mongodb model
public function changeToMongoStorage()
{
$this->storage = 'ProductMongodb';
$currentService = $this->getStorageService($this);
$this->_product = new $currentService();
}
// 动态更改为mongodb model
public function changeToMysqlStorage()
{
$this->storage = 'ProductMysqldb';
$currentService = $this->getStorageService($this);
$this->_product = new $currentService();
}
protected function actionGetEnableStatus()
{
......@@ -395,9 +410,9 @@ class Product extends Service
* 保存产品(插入和更新),以及保存产品的自定义url
* 如果提交的数据中定义了自定义url,则按照自定义url保存到urlkey中,如果没有自定义urlkey,则会使用name进行生成。
*/
protected function actionSave($one, $originUrlKey = 'catalog/product/index')
protected function actionSave($one, $originUrlKey = 'catalog/product/index', $isLoginUser=true)
{
return $this->_product->save($one, $originUrlKey);
return $this->_product->save($one, $originUrlKey, $isLoginUser);
}
/**
......@@ -453,6 +468,11 @@ class Product extends Service
{
return $this->_product->getFrontCategoryProducts($filter);
}
public function actionSync($arr)
{
return $this->_product->sync($arr);
}
/**
* @param $filter_attr | String 需要进行统计的字段名称
......
......@@ -283,6 +283,10 @@ class Price extends Service
*/
protected function actionGetCurrentCurrencyProductPriceInfo($price, $special_price, $special_from, $special_to)
{
$price = (float)$price;
$special_price = (float)$special_price;
$special_from = (int)$special_from;
$special_to = (int)$special_to;
$this->currentOff = 0;
$price_info = $this->formatPrice($price);
$return['price'] = [
......
......@@ -365,7 +365,8 @@ class ProductMysqldb extends Service implements ProductInterface
$model = new $this->_productModelName();
$model->created_at = time();
$model->created_user_id = \fec\helpers\CUser::getCurrentUserId();
$created_user_id = Yii::$app->user->identity->id;
$model->created_user_id = $created_user_id ;
//$primaryVal = new \MongoDB\BSON\ObjectId();
//$model->{$this->getPrimaryKey()} = $primaryVal;
//验证sku 是否重复
......@@ -432,6 +433,73 @@ class ProductMysqldb extends Service implements ProductInterface
return $model;
}
/**
* @param $one|array , 产品数据数组
* 用于将mongodb的数据,同步到mysql中
*/
public function sync($one)
{
if (!$this->initSave($one)) {
return false;
}
$defaultLangTitle = Yii::$service->fecshoplang->getDefaultLangAttrVal($one['name'], 'name');
$product_one = $this->_productModel->find()->where([
'sku' => $one['sku'],
])->one();
if ($product_one['sku']) {
$model = $product_one;
} else {
$model = new $this->_productModelName();
$model->created_at = time();
}
$model->updated_at = time();
// 计算出来产品的最终价格。
$one['final_price'] = Yii::$service->product->price->getFinalPrice($one['price'], $one['special_price'], $one['special_from'], $one['special_to']);
$one['score'] = (int) $one['score'];
unset($one['_id']);
/**
* 如果 $one['custom_option'] 不为空,则计算出来库存总数,填写到qty
*/
if (is_array($one['custom_option']) && !empty($one['custom_option'])) {
$custom_option_qty = 0;
foreach ($one['custom_option'] as $co_one) {
$custom_option_qty += $co_one['qty'];
}
$one['qty'] = $custom_option_qty;
}
/**
* 保存产品
*/
$one = $this->serializeSaveData($one);
$saveStatus = Yii::$service->helper->ar->save($model, $one);
$product_id = $model->{$this->getPrimaryKey()};
// 保存分类
$this->updateProductCategory($one['category'], $product_id);
// 自定义url部分
$originUrlKey = 'catalog/product/index';
$originUrl = $originUrlKey.'?'.$this->getPrimaryKey() .'='. $product_id;
$originUrlKey = isset($one['url_key']) ? $one['url_key'] : '';
//var_dump([$defaultLangTitle, $originUrl, $originUrlKey]);
//echo $defaultLangTitle;
$urlKey = Yii::$service->url->saveRewriteUrlKeyByStr($defaultLangTitle, $originUrl, $originUrlKey);
$model->url_key = $urlKey;
$model->save();
/**
* 更新产品库存。
*/
Yii::$service->product->stock->saveProductStock($product_id, $one);
/**
* 更新产品信息到搜索表。
*/
Yii::$service->search->syncProductInfo([$product_id]);
return $model;
}
// 保存的数据进行serialize序列化
protected function serializeSaveData($one)
{
......@@ -439,6 +507,9 @@ class ProductMysqldb extends Service implements ProductInterface
$attr_group = $one['attr_group'];
$groupAttrs = Yii::$service->product->getGroupAttr($attr_group);
$groupArr = [];
if (is_array($one['attr_group_info']) && !empty($one['attr_group_info'])) {
$groupArr = $one['attr_group_info'];
}
foreach ($one as $k => $v) {
if (in_array($k, $this->serializeAttrs)) {
$one[$k] = serialize($v);
......@@ -684,7 +755,13 @@ class ProductMysqldb extends Service implements ProductInterface
$query->select($select);
}
return $query->all();
$coll = $query->all();
$arr = [];
foreach ($coll as $one) {
$arr[] = $this->unserializeData($one) ;
}
return $arr;
}
/**
* 得到分类页面的产品列表
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册