소스 검색

custom option model 后台商品编辑添加

chengwl 5 년 전
부모
커밋
823efff482

+ 9 - 0
vendor/fancyecommerce/fecshop/config/services/Product.php

@@ -83,6 +83,15 @@ return [
                 'class' => 'fecshop\services\product\Stock',
                 'class' => 'fecshop\services\product\Stock',
                 //'zeroInventory' => 0, // 是否零库存,1代表开启零库存。
                 //'zeroInventory' => 0, // 是否零库存,1代表开启零库存。
             ],
             ],
+            'option' => [
+                'class' => 'fecshop\services\product\Option',
+            ],
+            'optionGroup' => [
+                'class' => 'fecshop\services\product\OptionGroup',
+            ],
+
+
+
             /* #暂时没用
             /* #暂时没用
 
 
             'coll' => [
             'coll' => [

+ 28 - 0
vendor/fancyecommerce/fecshop/models/mysqldb/Option.php

@@ -0,0 +1,28 @@
+<?php
+/**
+ * FecShop file.
+ *
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+
+namespace fecshop\models\mysqldb;
+
+use yii\db\ActiveRecord;
+
+/**
+ * @author Terry Zhao <2358269014@qq.com>
+ * @since 1.0
+ */
+class Option extends ActiveRecord
+{
+    const STATUS_ENABLE  = 1;
+    const STATUS_DISABLE = 2;
+    
+    public static function tableName()
+    {
+        return '{{%custom_option_item}}';
+    }
+
+}

+ 28 - 0
vendor/fancyecommerce/fecshop/models/mysqldb/OptionGroup.php

@@ -0,0 +1,28 @@
+<?php
+/**
+ * FecShop file.
+ *
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+
+namespace fecshop\models\mysqldb;
+
+use yii\db\ActiveRecord;
+
+/**
+ * @author Terry Zhao <2358269014@qq.com>
+ * @since 1.0
+ */
+class OptionGroup extends ActiveRecord
+{
+    const STATUS_ENABLE  = 1;
+    const STATUS_DISABLE = 2;
+    
+    public static function tableName()
+    {
+        return '{{%custom_option_group}}';
+    }
+
+}

+ 77 - 0
vendor/fancyecommerce/fecshop/services/Product.php

@@ -119,6 +119,8 @@ class Product extends Service
         $allGroupColl = $this->attrGroup->getActiveAllColl();
         $allGroupColl = $this->attrGroup->getActiveAllColl();
         // attr
         // attr
         $allAttrColl = $this->attr->getActiveAllColl();
         $allAttrColl = $this->attr->getActiveAllColl();
+        $customOptionGroupArr=[];
+        $customOptionGroupArr=$this->initCustomOptionGroup();
         $attrTypeColl = [];
         $attrTypeColl = [];
         if ($allAttrColl) {
         if ($allAttrColl) {
             foreach ($allAttrColl as $one) {
             foreach ($allAttrColl as $one) {
@@ -177,9 +179,84 @@ class Product extends Service
                 }
                 }
             }
             }
         }
         }
+        foreach($customAttrGroupArr as $k=>$v){
+            if(isset($customOptionGroupArr[$k])&& is_array($customOptionGroupArr[$k])){
+                $customAttrGroupArr[$k]['custom_options']=$customOptionGroupArr[$k];
+            }
+        }
+
         $this->customAttrGroup = $customAttrGroupArr;
         $this->customAttrGroup = $customAttrGroupArr;
     }
     }
     
     
+    protected function initCustomOptionGroup()
+    {
+        $attrPrimaryKey =$this->option->getPrimaryKey();
+        $attrGroupPrimaryKey = $this->optionGroup->getPrimaryKey();
+        $allGroupColl = $this->optionGroup->getActiveAllColl();
+        // attr
+        $allAttrColl = $this->option->getActiveAllColl();
+        $attrTypeColl = [];
+        if ($allAttrColl) {
+            foreach ($allAttrColl as $one) {
+                $attrTypeColl[$one[$attrPrimaryKey]] = $one;
+            }
+        }
+        $customOptionGroupArr = [];
+        if ($allGroupColl) {
+            foreach ($allGroupColl as $one) {
+                $groupName = $one['name'];
+                $attr_ids = $one['attr_ids'];
+                if (!is_array($attr_ids) || empty($attr_ids)) {
+                    continue;
+                }
+                $attr_ids = \fec\helpers\CFunc::array_sort($attr_ids, 'sort_order', 'desc');
+                //var_dump($attr_ids);exit;
+                foreach ($attr_ids as $attr_id_one) {
+                    if (!is_array($attr_id_one)) {
+                        continue;
+                    }
+                    $attr_id = $attr_id_one['attr_id'];
+                    $attr_sort_order = $attr_id_one['sort_order'];
+                    $attrOne = $attrTypeColl[$attr_id];
+                    if (!$attrOne) {
+                        continue;
+                    }
+                    $attrName = $attrOne['name'];
+                    $attrType = $attrOne['attr_type'];
+                    
+                    $attrInfo = [
+                        'dbtype'     => $attrOne['db_type'],
+                        'name'       => $attrName,
+                        'showAsImg'  => $attrOne['show_as_img'] == 1 ? true : false ,
+                        'sort_order'   => $attr_sort_order,
+                    ];
+                    $displayType = $attrOne['display_type'];
+                    $displayInfo = [];
+                    if ($displayType == 'inputString-Lang') {
+                        $displayInfo['type'] = 'inputString';
+                        $displayInfo['lang'] = true;
+                    } else {
+                        $displayInfo['type'] = $displayType;
+                    }
+                    if (is_array($attrOne['display_data'])) {
+                        $d_arr = [];
+                        foreach ($attrOne['display_data'] as $o) {
+                            if ($o['key']) {
+                                $d_arr[] = $o['key'];
+                            }
+                        }
+                        $displayInfo['data'] = $d_arr;
+                    }
+                    $attrInfo['display'] = $displayInfo;
+                    $customOptionGroupArr[$groupName][$attrName] = $attrInfo;
+                }
+            }
+        }
+        return $customOptionGroupArr;
+    }
+
+
+
     /**
     /**
      * 得到产品的所有的属性组。
      * 得到产品的所有的属性组。
      */
      */

+ 172 - 0
vendor/fancyecommerce/fecshop/services/product/Option.php

@@ -0,0 +1,172 @@
+<?php
+
+/*
+ * FecShop file.
+ *
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+
+namespace fecshop\services\product;
+
+use yii\base\InvalidCallException;
+use yii\base\InvalidConfigException;
+use fecshop\services\Service;
+use Yii;
+
+/**
+ * Product Service is the component that you can get product info from it.
+ *
+ * @property \fecshop\services\Image | \fecshop\services\Product\Image $image image service or product image sub-service
+ * @property \fecshop\services\product\Info $info product info sub-service
+ * @property \fecshop\services\product\Stock $stock stock sub-service of product service
+ *
+ * @method getByPrimaryKey($primaryKey) get product model by primary key
+ * @see \fecshop\services\Product::actionGetByPrimaryKey()
+ * @method getEnableStatus() get enable status
+ * @see \fecshop\services\Product::actionGetEnableStatus()
+ *
+ * @author Terry Zhao <2358269014@qq.com>
+ * @since 1.0
+ */
+class Option extends Service
+{
+    
+    /**
+     * $storagePrex , $storage , $storagePath 为找到当前的storage而设置的配置参数
+     * 可以在配置中更改,更改后,就会通过容器注入的方式修改相应的配置值
+     */
+    public $storage  = 'OptionMysqldb';   // AttrMysqldb | AttrMongodb 当前的storage,如果在config中配置,那么在初始化的时候会被注入修改
+
+    /**
+     * 设置storage的path路径,
+     * 如果不设置,则系统使用默认路径
+     * 如果设置了路径,则使用自定义的路径
+     */
+    public $storagePath = '';
+
+    /**
+     * @var \fecshop\services\product\ProductInterface 根据 $storage 及 $storagePath 配置的 Product 的实现
+     */
+    protected $_attr;
+
+
+    public function init()
+    {
+        parent::init();
+        // 从数据库配置中得到值, 设置成当前service存储,是Mysqldb 还是 Mongodb
+        //$config = Yii::$app->store->get('service_db', 'category_and_product');
+        //$this->storage = 'ProductMysqldb';
+        //if ($config == Yii::$app->store->serviceMongodbName) {
+        //    $this->storage = 'ProductMongodb';
+        //}
+        $currentService = $this->getStorageService($this);
+        $this->_attr = new $currentService();
+    }
+    // 动态更改为mongodb model
+    public function changeToMongoStorage()
+    {
+        $this->storage     = 'OptionMongodb';
+        $currentService = $this->getStorageService($this);
+        $this->_attr = new $currentService();
+    }
+    
+    // 动态更改为mongodb model
+    public function changeToMysqlStorage()
+    {
+        $this->storage     = 'OptionMysqldb';
+        $currentService = $this->getStorageService($this);
+        $this->_attr = new $currentService();
+    }
+
+    protected function actionGetEnableStatus()
+    {
+        return $this->_attr->getEnableStatus();
+    }
+    
+    /**
+     * get artile's primary key.
+     */
+    protected function actionGetPrimaryKey()
+    {
+        return $this->_attr->getPrimaryKey();
+    }
+
+    /**
+     * get artile model by primary key.
+     */
+    protected function actionGetByPrimaryKey($primaryKey)
+    {
+        return $this->_attr->getByPrimaryKey($primaryKey);
+    }
+    
+    protected function actionColl($filter = '')
+    {
+        return $this->_attr->coll($filter);
+    }
+
+    /**
+     * @param $one|array , save one data .
+     * @param $originUrlKey|string , article origin url key.
+     * save $data to cms model,then,add url rewrite info to system service urlrewrite.
+     */
+    protected function actionSave($one)
+    {
+        return $this->_attr->save($one);
+    }
+
+    protected function actionRemove($ids)
+    {
+        return $this->_attr->remove($ids);
+    }
+    
+    protected function actionGetActiveColl($ids)
+    {
+        return $this->_attr->remove($ids);
+    }
+    
+    public function getActiveAllColl()
+    {
+        return $this->_attr->getActiveAllColl();
+    }
+    
+    
+    public function getAttrTypes()
+    {
+        return [
+            'spu_attr' => Yii::$service->page->translate->__('Spu Attr'),
+            'general_attr' => Yii::$service->page->translate->__('General Attr'),
+        ];
+    }
+    
+    public function getDbTypes()
+    {
+        return [
+            'String' => 'String',
+        ];
+        
+    }
+    
+    
+    public function getDisplayTypes()
+    {
+        return [
+            'inputString' => 'inputString',
+            'inputString-Lang' => 'inputString-Lang',
+            'inputEmail' => 'inputEmail',
+            'inputDate' => 'inputDate',
+            'editSelect' => 'editSelect',
+            'select' => 'select',
+        ];
+        
+    }
+    
+    
+    
+    
+    
+    
+    
+    
+}

+ 133 - 0
vendor/fancyecommerce/fecshop/services/product/OptionGroup.php

@@ -0,0 +1,133 @@
+<?php
+
+/*
+ * FecShop file.
+ *
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+
+namespace fecshop\services\product;
+
+use yii\base\InvalidCallException;
+use yii\base\InvalidConfigException;
+use fecshop\services\Service;
+use Yii;
+
+/**
+ * Product Service is the component that you can get product info from it.
+ *
+ * @property \fecshop\services\Image | \fecshop\services\Product\Image $image image service or product image sub-service
+ * @property \fecshop\services\product\Info $info product info sub-service
+ * @property \fecshop\services\product\Stock $stock stock sub-service of product service
+ *
+ * @method getByPrimaryKey($primaryKey) get product model by primary key
+ * @see \fecshop\services\Product::actionGetByPrimaryKey()
+ * @method getEnableStatus() get enable status
+ * @see \fecshop\services\Product::actionGetEnableStatus()
+ *
+ * @author Terry Zhao <2358269014@qq.com>
+ * @since 1.0
+ */
+class OptionGroup extends Service
+{
+    
+    /**
+     * $storagePrex , $storage , $storagePath 为找到当前的storage而设置的配置参数
+     * 可以在配置中更改,更改后,就会通过容器注入的方式修改相应的配置值
+     */
+    public $storage  = 'OptionGroupMysqldb';   // AttrGroupMysqldb | AttrGroupMongodb 当前的storage,如果在config中配置,那么在初始化的时候会被注入修改
+
+    /**
+     * 设置storage的path路径,
+     * 如果不设置,则系统使用默认路径
+     * 如果设置了路径,则使用自定义的路径
+     */
+    public $storagePath = '';
+
+    /**
+     * @var \fecshop\services\product\ProductInterface 根据 $storage 及 $storagePath 配置的 Product 的实现
+     */
+    protected $_attrGroup;
+
+
+    public function init()
+    {
+        parent::init();
+        // 从数据库配置中得到值, 设置成当前service存储,是Mysqldb 还是 Mongodb
+        //$config = Yii::$app->store->get('service_db', 'category_and_product');
+        //$this->storage = 'ProductMysqldb';
+        //if ($config == Yii::$app->store->serviceMongodbName) {
+        //    $this->storage = 'ProductMongodb';
+        //}
+        $currentService = $this->getStorageService($this);
+        $this->_attrGroup = new $currentService();
+    }
+    // 动态更改为mongodb model
+    public function changeToMongoStorage()
+    {
+        $this->storage     = 'OptionGroupMongodb';
+        $currentService = $this->getStorageService($this);
+        $this->_attrGroup = new $currentService();
+    }
+    
+    // 动态更改为mongodb model
+    public function changeToMysqlStorage()
+    {
+        $this->storage     = 'OptionGroupMysqldb';
+        $currentService = $this->getStorageService($this);
+        $this->_attrGroup = new $currentService();
+    }
+
+    protected function actionGetEnableStatus()
+    {
+        return $this->_attrGroup->getEnableStatus();
+    }
+    
+    /**
+     * get artile's primary key.
+     */
+    protected function actionGetPrimaryKey()
+    {
+        return $this->_attrGroup->getPrimaryKey();
+    }
+
+    /**
+     * get artile model by primary key.
+     */
+    protected function actionGetByPrimaryKey($primaryKey)
+    {
+        return $this->_attrGroup->getByPrimaryKey($primaryKey);
+    }
+    
+    protected function actionColl($filter = '')
+    {
+        return $this->_attrGroup->coll($filter);
+    }
+
+    /**
+     * @param $one|array , save one data .
+     * @param $originUrlKey|string , article origin url key.
+     * save $data to cms model,then,add url rewrite info to system service urlrewrite.
+     */
+    protected function actionSave($one)
+    {
+        return $this->_attrGroup->save($one);
+    }
+
+    protected function actionRemove($ids)
+    {
+        return $this->_attrGroup->remove($ids);
+    }
+    
+    public function getActiveAllColl()
+    {
+        return $this->_attrGroup->getActiveAllColl();
+        
+    }
+    
+    
+    
+    
+}

+ 61 - 1
vendor/fancyecommerce/fecshop/services/product/ProductApi.php

@@ -266,7 +266,67 @@ class ProductApi extends Service
          *  6. 数组的key,需要和sku相等,譬如 red-l-s2-s3 要等于下面的  "sku": "red-l-s2-s3"
          *  6. 数组的key,需要和sku相等,譬如 red-l-s2-s3 要等于下面的  "sku": "red-l-s2-s3"
          *
          *
          */
          */
-       
+        /*
+        $custom_option = $post['custom_option'];
+        if (!empty($custom_option) && is_array($custom_option) && isset($customAttrGroup[$attr_group]['custom_options']) && $customAttrGroup[$attr_group]['custom_options']) {
+            $custom_option_arr = [];
+            // 1.
+            // 该属性组对应的 custom option 的数据配置结构
+            $attr_group_config = $customAttrGroup[$attr_group]['custom_options'];
+            foreach ($custom_option as $key => $info) {
+                // 1. 图片地址是否存在,不存在则报错
+                if (!isset($info['image']) || !$info['image']) {
+                    $this->_error[] = 'custom option: image can not empty';
+                }
+                // 2.sku 存在
+                if (!isset($info['sku']) || !$info['sku']) {
+                    $this->_error[] = 'custom option: sku can not empty';
+                }
+                // 4. qty 是否存在,不存在,则初始化为0
+                $info['qty'] = (int)$info['qty'];
+                if (!$info['qty']) {
+                    $info['qty'] = 0;
+                }
+                // 5. price是否存在,不存在则初始化为0,
+                $info['price'] = (float)$info['price'];
+                if (!$info['price']) {
+                    $info['price'] = 0;
+                }
+                // 3. 通过属性组 attr_group 找到相应的custom option,查看里面的值,在这里是否都存在
+                if (is_array($attr_group_config)) {
+                    // 遍历 custom option 的数据配置结构
+                    foreach ($attr_group_config as $attrKey => $custom_option_info) {
+                        // 当前行数据中,是否符合 数据配置结构
+                        $val = '';
+                        if (isset($info[$attrKey]) && $info[$attrKey]) {
+                            $val = $info[$attrKey];
+                        } else {
+                            $this->_error[] = '[custom option error]: (attr_group:'.$attr_group.') attr['.$attrKey.'] is exist in config file ,but current data is empty';
+                            // error: 缺失 $attrKey 存在数据配置结构中,但是当前的插入数据中不存在这个属性。
+                        }
+                        if (isset($custom_option_info['display']['data']) && is_array($custom_option_info['display']['data'])) {
+                            $attr_group_config_val_arr = $custom_option_info['display']['data'];
+                            if (in_array($val, $attr_group_config_val_arr)) {
+                                
+                                // success
+                            } else {
+                                $this->_error[] = '[custom option error]: (attr_group:'.$attr_group.') attr['.$attrKey.':'.$val.'] must exist in array ['.implode(',', $attr_group_config_val_arr).'] ';
+                                // error:$attrKey 这个属性在当前的插入数据中存在,但是值不合法,值必须存在于 "数据配置结构" 中对应的数据列表中
+                            }
+                        } else {
+                            $this->_error[] = '[custom option config error]: (attr_group:'.$attr_group.') attr['.$attrKey.'] config is not correct , it must exist: [\'display\'][\'data\']';
+                        }
+                    }
+                } else {
+                    $this->_error[] = '[custom option config error]: (attr_group:'.$attr_group.') , it must be array';
+                }
+                $custom_option_arr[$info['sku']] = $info;
+            }
+            if (!empty($custom_option_arr)) {
+                $this->_param['custom_option'] = $custom_option_arr;
+            }
+        }
+        */
         
         
         // 选填
         // 选填
         $remark = $post['remark'];
         $remark = $post['remark'];

+ 18 - 17
vendor/fancyecommerce/fecshop/services/product/ProductMongodb.php

@@ -364,7 +364,6 @@ class ProductMongodb extends Service implements ProductInterface
                     //var_dump([$sar => $one[$sar]]);
                     //var_dump([$sar => $one[$sar]]);
                     $product_mode->andWhere([$sar => $one[$sar]]);
                     $product_mode->andWhere([$sar => $one[$sar]]);
                 }
                 }
-                
                 $product_one = $product_mode->one();
                 $product_one = $product_mode->one();
                 if ($product_one['sku']) {
                 if ($product_one['sku']) {
                     Yii::$service->helper->errors->add('product Spu of the same22,  Spu attributes cannot be the same');
                     Yii::$service->helper->errors->add('product Spu of the same22,  Spu attributes cannot be the same');
@@ -372,6 +371,7 @@ class ProductMongodb extends Service implements ProductInterface
                     return false;
                     return false;
                 }
                 }
             }
             }
+            //TODO custom option 同等验证
         } else {
         } else {
             $model = new $this->_productModelName();
             $model = new $this->_productModelName();
             $model->created_at = time();
             $model->created_at = time();
@@ -411,7 +411,8 @@ class ProductMongodb extends Service implements ProductInterface
         $one['final_price'] = Yii::$service->product->price->getFinalPrice($one['price'], $one['special_price'], $one['special_from'], $one['special_to']);
         $one['final_price'] = Yii::$service->product->price->getFinalPrice($one['price'], $one['special_price'], $one['special_from'], $one['special_to']);
         $one['score'] = (int) $one['score'];
         $one['score'] = (int) $one['score'];
         unset($one['_id']);
         unset($one['_id']);
-        unset($one['custom_option']);
+
+        // unset($one['custom_option']);
         /**
         /**
          * 如果 $one['custom_option'] 不为空,则计算出来库存总数,填写到qty
          * 如果 $one['custom_option'] 不为空,则计算出来库存总数,填写到qty
          */
          */
@@ -490,13 +491,13 @@ class ProductMongodb extends Service implements ProductInterface
         /**
         /**
          * 如果 $one['custom_option'] 不为空,则计算出来库存总数,填写到qty
          * 如果 $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;
-        }
+        //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;
+        //}
         
         
         /**
         /**
          * 保存产品
          * 保存产品
@@ -624,14 +625,14 @@ class ProductMongodb extends Service implements ProductInterface
 
 
             return false;
             return false;
         }
         }
-        //if (is_array($one['custom_option']) && !empty($one['custom_option'])) {
-        //    $new_custom_option = [];
-        //    foreach ($one['custom_option'] as $k=>$v) {
-        //        $k = preg_replace('/[^A-Za-z0-9\-_]/', '', $k);
-        //        $new_custom_option[$k] = $v;
-        //    }
-        //    $one['custom_option'] = $new_custom_option;
-        //}
+        if (is_array($one['custom_option']) && !empty($one['custom_option'])) {
+           $new_custom_option = [];
+           foreach ($one['custom_option'] as $k=>$v) {
+               $k = preg_replace('/[^A-Za-z0-9\-_]/', '', $k);
+               $new_custom_option[$k] = $v;
+           }
+           $one['custom_option'] = $new_custom_option;
+        }
 
 
         return true;
         return true;
     }
     }

+ 27 - 0
vendor/fancyecommerce/fecshop/services/product/option/OptionInterface.php

@@ -0,0 +1,27 @@
+<?php
+
+/*
+ * FecShop file.
+ *
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+
+namespace fecshop\services\product\option;
+
+/**
+ * Product services interface.
+ * @author Terry Zhao <2358269014@qq.com>
+ * @since 1.0
+ */
+interface OptionInterface
+{
+    public function getByPrimaryKey($primaryKey);
+
+    public function coll($filter);
+
+    public function save($one);
+
+    public function remove($ids);
+}

+ 0 - 0
vendor/fancyecommerce/fecshop/services/product/option/OptionMongodb.php


+ 171 - 0
vendor/fancyecommerce/fecshop/services/product/option/OptionMysqldb.php

@@ -0,0 +1,171 @@
+<?php
+
+/*
+ * FecShop file.
+ *
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+
+namespace fecshop\services\product\option;
+
+use fecshop\services\Service;
+use yii\db\Query;
+use Yii;
+
+/**
+ * Product ProductMysqldb Service 未开发。
+ * @author Terry Zhao <2358269014@qq.com>
+ * @since 1.0
+ */
+class OptionMysqldb extends Service implements OptionInterface
+{
+    public $numPerPage = 20;
+    
+    protected $_attrModelName = '\fecshop\models\mysqldb\Option';
+
+    protected $_attrModel;
+    
+    
+    
+    public function init()
+    {
+        parent::init();
+        list($this->_attrModelName, $this->_attrModel) = \Yii::mapGet($this->_attrModelName);
+    }
+    
+    public function getPrimaryKey()
+    {
+        return 'id';
+    }
+    
+    
+
+    /**
+     * 得到分类激活状态的值
+     */
+    public function getEnableStatus()
+    {
+        $model = $this->_attrModel;
+        return $model::STATUS_ENABLE;
+    }
+    
+    
+    public function getByPrimaryKey($primaryKey = null)
+    {
+        if ($primaryKey) {
+            $one = $this->_attrModel->findOne($primaryKey);
+            
+            return $one;
+            //return $this->unserializeData($one) ;
+        } else {
+            return new $this->_attrModel();
+        }
+    }
+    
+    
+    /*
+     * example filter:
+     * [
+     * 		'numPerPage' 	=> 20,
+     * 		'pageNum'		=> 1,
+     * 		'orderBy'	=> ['_id' => SORT_DESC, 'sku' => SORT_ASC ],
+     * 		'where'			=> [
+                ['>','price',1],
+                ['<=','price',10]
+     * 			['sku' => 'uk10001'],
+     * 		],
+     * 	'asArray' => true,
+     * ]
+     */
+    public function coll($filter = '')
+    {
+        $query = $this->_attrModel->find();
+        $query = Yii::$service->helper->ar->getCollByFilter($query, $filter);
+        
+        $coll = $query->all();
+        //$arr = [];
+        //foreach ($coll as $one) {
+        //    $arr[] = $this->unserializeData($one) ;
+        //}
+        return [
+            'coll' => $coll,
+            'count'=> $query->limit(null)->offset(null)->count(),
+        ];
+    }
+    /**
+     * @param $one|array
+     * save $data to cms model,then,add url rewrite info to system service urlrewrite.
+     */
+    public function save($one)
+    {
+        $primaryVal = isset($one[$this->getPrimaryKey()]) ? $one[$this->getPrimaryKey()] : '';
+        if ($primaryVal) {
+            $model = $this->_attrModel->findOne($primaryVal);
+            if (!$model) {
+                Yii::$service->helper->errors->add('Product attr {primaryKey} is not exist', ['primaryKey' => $this->getPrimaryKey()]);
+
+                return;
+            }
+        } else {
+            $model = new $this->_attrModelName();
+            $model->created_at = time();
+        }
+        $model->updated_at = time();
+        $primaryKey = $this->getPrimaryKey();
+        $model      = Yii::$service->helper->ar->save($model, $one);
+        $primaryVal = $model[$primaryKey];
+
+        return true;
+    }
+    
+    public function remove($ids)
+    {
+        if (!$ids) {
+            Yii::$service->helper->errors->add('remove id is empty');
+
+            return false;
+        }
+        if (is_array($ids) && !empty($ids)) {
+            foreach ($ids as $id) {
+                $model = $this->_attrModel->findOne($id);
+                $model->delete();
+            }
+        } else {
+            $id = $ids;
+            $model = $this->_attrModel->findOne($id);
+            $model->delete();
+        }
+
+        return true;
+    }
+    
+    public function getActiveAllColl()
+    {
+        // attribute Group
+        $filter = [
+            'where' => [
+                ['status' => $this->getEnableStatus()]
+            ],
+            'fetchAll' => true,
+            'asArray' => true,
+        ];
+        $query = $this->_attrModel->find();
+        $query = Yii::$service->helper->ar->getCollByFilter($query, $filter);
+        
+        $coll = $query->all();
+        if (is_array($coll)) {
+            foreach ($coll as $k => $one) {
+                if ($one['display_data']) {
+                    $coll[$k]['display_data'] = unserialize($one['display_data']);
+                }
+            }
+            return $coll;
+        }
+        
+        return null;
+        
+    }
+    
+}

+ 27 - 0
vendor/fancyecommerce/fecshop/services/product/optiongroup/OptionGroupInterface.php

@@ -0,0 +1,27 @@
+<?php
+
+/*
+ * FecShop file.
+ *
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+
+namespace fecshop\services\product\optiongroup;
+
+/**
+ * Product services interface.
+ * @author Terry Zhao <2358269014@qq.com>
+ * @since 1.0
+ */
+interface OptionGroupInterface
+{
+    public function getByPrimaryKey($primaryKey);
+
+    public function coll($filter);
+
+    public function save($one);
+
+    public function remove($ids);
+}

+ 0 - 0
vendor/fancyecommerce/fecshop/services/product/optiongroup/OptionGroupMongodb.php


+ 170 - 0
vendor/fancyecommerce/fecshop/services/product/optiongroup/OptionGroupMysqldb.php

@@ -0,0 +1,170 @@
+<?php
+
+/*
+ * FecShop file.
+ *
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+
+namespace fecshop\services\product\optiongroup;
+
+use fecshop\services\Service;
+use yii\db\Query;
+use Yii;
+
+/**
+ * Product ProductMysqldb Service 未开发。
+ * @author Terry Zhao <2358269014@qq.com>
+ * @since 1.0
+ */
+class OptionGroupMysqldb extends Service implements OptionGroupInterface
+{
+    public $numPerPage = 20;
+    
+    protected $_attrGroupModelName = '\fecshop\models\mysqldb\OptionGroup';
+
+    protected $_attrGroupModel;
+    
+    
+    
+    public function init()
+    {
+        parent::init();
+        list($this->_attrGroupModelName, $this->_attrGroupModel) = \Yii::mapGet($this->_attrGroupModelName);
+    }
+    
+    public function getPrimaryKey()
+    {
+        return 'id';
+    }
+    
+    
+
+    /**
+     * 得到分类激活状态的值
+     */
+    public function getEnableStatus()
+    {
+        $model = $this->_attrGroupModel;
+        return $model::STATUS_ENABLE;
+    }
+    
+    public function getByPrimaryKey($primaryKey = null)
+    {
+        if ($primaryKey) {
+            $one = $this->_attrGroupModel->findOne($primaryKey);
+            return $one;
+        } else {
+            return new $this->_attrGroupModel();
+        }
+    }
+    
+    
+    /*
+     * example filter:
+     * [
+     * 		'numPerPage' 	=> 20,
+     * 		'pageNum'		=> 1,
+     * 		'orderBy'	=> ['_id' => SORT_DESC, 'sku' => SORT_ASC ],
+     * 		'where'			=> [
+                ['>','price',1],
+                ['<=','price',10]
+     * 			['sku' => 'uk10001'],
+     * 		],
+     * 	'asArray' => true,
+     * ]
+     */
+    public function coll($filter = '')
+    {
+        $query = $this->_attrGroupModel->find();
+        $query = Yii::$service->helper->ar->getCollByFilter($query, $filter);
+        
+        $coll = $query->all();
+        //$arr = [];
+        //foreach ($coll as $one) {
+        //    $arr[] = $this->unserializeData($one) ;
+        //}
+        return [
+            'coll' => $coll,
+            'count'=> $query->limit(null)->offset(null)->count(),
+        ];
+    }
+    /**
+     * @param $one|array
+     * save $data to cms model,then,add url rewrite info to system service urlrewrite.
+     */
+    public function save($one)
+    {
+        $primaryVal = isset($one[$this->getPrimaryKey()]) ? $one[$this->getPrimaryKey()] : '';
+        if ($primaryVal) {
+            $model = $this->_attrGroupModel->findOne($primaryVal);
+            if (!$model) {
+                Yii::$service->helper->errors->add('Product attr group {primaryKey} is not exist', ['primaryKey' => $this->getPrimaryKey()]);
+
+                return;
+            }
+        } else {
+            $model = new $this->_attrGroupModelName();
+            $model->created_at = time();
+        }
+        $model->updated_at = time();
+        $primaryKey = $this->getPrimaryKey();
+        $model      = Yii::$service->helper->ar->save($model, $one);
+        $primaryVal = $model[$primaryKey];
+
+        return true;
+    }
+    
+    public function remove($ids)
+    {
+        if (!$ids) {
+            Yii::$service->helper->errors->add('remove id is empty');
+
+            return false;
+        }
+        if (is_array($ids) && !empty($ids)) {
+            foreach ($ids as $id) {
+                $model = $this->_attrGroupModel->findOne($id);
+                $model->delete();
+            }
+        } else {
+            $id = $ids;
+            $model = $this->_attrGroupModel->findOne($id);
+            $model->delete();
+        }
+
+        return true;
+    }
+    
+    public function getActiveAllColl()
+    {
+        // attribute Group
+        $filter = [
+            'where' => [
+                ['status' => $this->getEnableStatus()]
+            ],
+            'fetchAll' => true,
+            'asArray' => true,
+        ];
+        $query = $this->_attrGroupModel->find();
+        $query = Yii::$service->helper->ar->getCollByFilter($query, $filter);
+        
+        $coll = $query->all();
+        if (is_array($coll)) {
+            foreach ($coll as $k => $groupOne) {
+                if ($groupOne['attr_ids']) {
+                    $attr_ids = unserialize($groupOne['attr_ids']);
+                    $coll[$k]['attr_ids'] = $attr_ids;
+                }
+            }
+            return $coll;
+        }
+        
+        return null;
+    }
+    
+    
+    
+}