/** * 初始化属性 */ public function initAttr($productid, $layerid) { $data = ['name' => '样式' . $layerid, 'style_name' => $this->prefix_attr . $productid . '_' . rand(0, 10000), 'productid' => $productid, 'layerid' => $layerid, 'padding' => '', 'size' => '720,405', 'pos' => '0,,', 'float' => 0, 'opacity' => '0,0', 'border' => '0,,1,1', 'created_at' => time()]; $data1 = $data; $data2 = $data; $data3 = $data; $data1['genre'] = 1; $data2['genre'] = 2; $data3['genre'] = 3; ProductAttrModel::create($data1); ProductAttrModel::create($data2); ProductAttrModel::create($data3); }
/** * 查看有没样式记录,有则获取样式名称 */ public function getAttrs($productid, $layerid) { return ProductAttrModel::where('productid', $productid)->where('layerid', $layerid)->orderBy('genre', 'asc')->get(); }
/** * 获得属性样式名称 */ public function getAttrName() { // $layer = ProductLayerModel::where('layerid',$this->layerid)->first(); $attrModel = ProductAttrModel::where('layerid', $this->layerid)->first(); return $attrModel ? $attrModel->style_name : ''; }
/** * 获取该产品的属性 */ public function getAttrs() { $attrModels = ProductAttrModel::where('productid', $this->id)->get(); return count($attrModels) ? $attrModels : []; }
/** * 获取子级属性 */ public function getSub($genre) { return ProductAttrModel::where('parent', $this->id)->where('genre', $genre)->first(); }
/** * 获得动画的属性名 */ public function getAttrStyleName() { return ProductAttrModel::where('layerid', $this->id)->first()->style_name; }
/** * 收集属性数据 */ public function getAttrData($pid, $layerid, $genre, $newpid, $layerNewId, $styleName) { $attrModel = ProductAttrModel::where('productid', $pid)->where('layerid', $layerid)->where('genre', $genre)->first(); $record = ['padding' => 0, 'size' => 0, 'pos' => 0, 'float' => 0, 'opacity' => 0, 'border' => 0]; $data = ['name' => $attrModel->name, 'style_name' => $styleName, 'productid' => $newpid, 'layerid' => $layerNewId, 'genre' => $genre, 'padding' => $attrModel->padding, 'size' => $attrModel->size, 'pos' => $attrModel->pos, 'float' => $attrModel->float, 'opacity' => $attrModel->opacity, 'border' => $attrModel->border, 'created_at' => time(), 'record' => serialize($record)]; ProductAttrModel::create($data); }