Example #1
0
 /**
  * @brief 商品属性添加/修改
  * @param array $attribute 表字段 数组格式,如Array ([name] 		=> Array ( [0] => '' )
  *													[show_type] => Array ( [0] => '' )
  *													[value] 	=> Array ( [0] => '' )
  *													[is_seach] 	=> Array ( [0] => 1 ))
  * @param int $model_id 模型编号
  */
 public function _attribute_update($attribute, $model_id)
 {
     //初始化attribute商品模型属性表类对象
     $attributeObj = new IModel('attribute');
     $len = count($attribute['name']);
     $ids = "";
     for ($i = 0; $i < $len; $i++) {
         if (IValidate::required($attribute['name'][$i]) && IValidate::required($attribute['value'][$i])) {
             $options = str_replace(',', ',', $attribute['value'][$i]);
             $type = isset($attribute['is_search'][$i]) ? $attribute['is_search'][$i] : 0;
             //设置商品模型扩展属性 字段赋值
             $filedData = array("model_id" => intval($model_id), "type" => IFilter::act($attribute['show_type'][$i]), "name" => IFilter::act($attribute['name'][$i]), "value" => rtrim(IFilter::act($options), ','), "search" => IFilter::act($type));
             $attributeObj->setData($filedData);
             $id = intval($attribute['id'][$i]);
             if ($id) {
                 //更新商品模型扩展属性
                 $attributeObj->update("id = " . $id);
             } else {
                 //新增商品模型扩展属性
                 $id = $attributeObj->add();
             }
             $ids .= $id . ',';
         }
     }
     if ($ids) {
         $ids = trim($ids, ',');
         //删除商品模型扩展属性
         $where = "model_id = {$model_id}  and id not in (" . $ids . ") ";
         $attributeObj->del($where);
     }
 }
Example #2
0
 /**
  * @brief 商品模型添加/修改
  */
 public function model_update()
 {
     // 获取POST数据
     $attribute = IReq::get("attr");
     $spec = IReq::get("spec");
     $model_name = IReq::get("model_name");
     $model_id = IReq::get("model_id");
     //初始化Model类对象
     $modelObj = new Model();
     //校验数据
     if (!IValidate::required($model_name)) {
         //处理post数据,渲染到前台
         $result = $modelObj->postArrayChange($attribute, $spec);
         $this->data = array('id' => $model_id, 'name' => $model_name, 'model_attr' => $result['model_attr'], 'model_spec' => $result['model_spec']);
         $this->setRenderData($this->data);
         $this->redirect('model_edit', false);
         Util::showMessage('模型名称不能为空!');
         exit;
     }
     //更新模型数据
     $result = $modelObj->model_update($model_id, $model_name, $attribute, $spec);
     if ($result) {
         $this->redirect('model_list');
     } else {
         //处理post数据,渲染到前台
         $result = $modelObj->postArrayChange($attribute, $spec);
         $this->data = array('id' => $model_id, 'name' => $model_name, 'model_attr' => $result['model_attr'], 'model_spec' => $result['model_spec']);
         $this->setRenderData($this->data);
         $this->redirect('model_edit', false);
     }
 }