Пример #1
0
 public static function get_clsattrrs($classify_id, $type = AttributeService::ATTRIBUTE_SPEC)
 {
     if ($classify_id > 0) {
         $attroptrids = array();
         $records = Classify_attribute_relationService::get_instance()->index(array('where' => array('classify_id' => $classify_id, 'apply' => $type)));
         //d($records);
         if (!empty($records)) {
             foreach ($records as $record) {
                 $attroptrids[] = $record['attribute_id'];
             }
         }
         if (!empty($attroptrids)) {
             return self::index(array('id' => $attroptrids));
         }
     }
     return array();
 }
Пример #2
0
 /** 
  * 根据 类型ID数组批量删除类型 
  * @param $categorys  array 
  * @return void 
  * @throws MyRuntimeException 
  */
 public function delete_classifies($classifies)
 {
     try {
         $del_all = TRUE;
         if (!empty($classifies)) {
             foreach ($classifies as $val) {
                 $query_struct = array('where' => array('classify_id' => $val));
                 if (CategoryService::get_instance()->count($query_struct)) {
                     $del_all = FALSE;
                 }
                 if ($del_all === TRUE and ProductService::get_instance()->count($query_struct) > 0) {
                     $del_all = FALSE;
                 }
                 if ($del_all === TRUE) {
                     $where = array('classify_id' => $val);
                     Classify_brand_relationService::get_instance()->delete_relations($where);
                     Classify_attribute_relationService::get_instance()->delete_relations($where);
                     //Classify_feature_relationService::get_instance()->delete_relations($where);
                     $this->remove($val);
                 }
             }
             if (!$del_all) {
                 throw new MyRuntimeException('无法删除部分被关联的类型', 500);
             }
         }
     } catch (MyRuntimeException $ex) {
         throw $ex;
     }
 }
Пример #3
0
 /**
  * 通过 attribute.id 判断该 attribute当前是否正在被关联
  * @param  int $attribute_id  规格ID
  * @return bool
  * @throws MyRuntimeException
  */
 public function is_relation_by_attribute_id($attribute_id)
 {
     // 获取 attribute 下所有的 attributeoption
     $attributeoptions = $this->get_attributeoptions_by_attribute_id($attribute_id);
     if (!empty($attributeoptions)) {
         // 获取所有 attributeoption 的 ID
         $attributeoption_ids = array_keys($attributeoptions);
         if (!empty($attributeoption_ids)) {
             // 初始化默认查询条件
             $request_struct = array('where' => array('attributeoption_id' => $attributeoption_ids));
             // 判断与  product_attributeoption_relations 表的关联
             if (Product_attributeoption_relationService::get_instance()->count($request_struct)) {
                 return TRUE;
             }
             // 判断与  product_attributeoption_productpic_relations 表的关联
             //if(Product_attributeoption_productpic_relationService::get_instance()->count($request_struct)){
             //    return TRUE;
             //}
         }
     }
     //判断与classify_attribute_relation 表的关联
     $request_struct = array('where' => array('attribute_id' => $attribute_id));
     if (Classify_attribute_relationService::get_instance()->count($request_struct)) {
         return TRUE;
     }
     return FALSE;
 }
Пример #4
0
 public function put()
 {
     role::check('product_classify_add');
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         //* 初始化返回数据 */
         $return_data = array();
         //* 收集请求数据 ==根据业务逻辑定制== */
         $request_data = $this->input->post();
         $request_data = trims::run($request_data);
         //标签过滤
         tool::filter_strip_tags($request_data);
         //数据验证
         $validResult = Validation::factory($request_data)->pre_filter('trim')->add_rules('name', 'required', 'length[1,100]');
         if ($validResult->validate() == FALSE) {
             //* 输出错误的具体信息 ==根据业务逻辑定制== */
             $return_struct['content']['errors'] = $validResult->errors();
             throw new MyRuntimeException(Kohana::lang('o_global.input_error'), 400);
         }
         //执行添加
         $set_data = array();
         $set_data['name'] = $request_data['name'];
         $set_data['alias'] = $request_data['alias'];
         $set_data['create_timestamp'] = time();
         $set_data['update_timestamp'] = time();
         // 调用底层服务
         $classify_service = ClassifyService::get_instance();
         //判断name是否存在
         if ($classify_service->check_exist_name($set_data['name'])) {
             throw new MyRuntimeException(Kohana::lang('o_product.product_classify_exist'), 409);
         }
         //类型的参数处理
         $this->get_arguments($request_data, $set_data);
         $return_data['classify_id'] = $classify_service->add($set_data);
         if (!$return_data['classify_id']) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 500);
         }
         //相关品牌添加
         if (isset($request_data['brand_id']) && is_array($request_data['brand_id'])) {
             foreach ($request_data['brand_id'] as $key => $val) {
                 $set_data = array();
                 $set_data['classify_id'] = $return_data['classify_id'];
                 $set_data['brand_id'] = $val;
                 if (isset($request_data['brand_show'][$val])) {
                     $set_data['is_show'] = $request_data['brand_show'][$val];
                 }
                 $result = Classify_brand_relationService::get_instance()->add($set_data);
                 if (!$result) {
                     throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 500);
                 }
             }
         }
         //相关规格添加
         if (isset($request_data['attribute_id']) && is_array($request_data['attribute_id'])) {
             foreach ($request_data['attribute_id'] as $val) {
                 $set_data = array();
                 $set_data['type'] = AttributeService::ATTRIBUTE_SPEC;
                 $set_data['classify_id'] = $return_data['classify_id'];
                 $set_data['attribute_id'] = $val;
                 if (isset($request_data['attribute_show'][$val])) {
                     $set_data['is_show'] = $request_data['attribute_show'][$val];
                 }
                 $result = Classify_attribute_relationService::get_instance()->add($set_data);
                 if (!$result) {
                     throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 500);
                 }
             }
         }
         //相关特性添加
         if (isset($request_data['feature_id']) && is_array($request_data['feature_id'])) {
             foreach ($request_data['feature_id'] as $val) {
                 $set_data = array();
                 $set_data['type'] = AttributeService::ATTRIBUTE_FEATURE;
                 $set_data['classify_id'] = $return_data['classify_id'];
                 $set_data['attribute_id'] = $val;
                 if (isset($request_data['feature_show'][$val])) {
                     $set_data['is_show'] = $request_data['feature_show'][$val];
                 }
                 $result = Classify_attribute_relationService::get_instance()->add($set_data);
                 if (!$result) {
                     throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 500);
                 }
             }
         }
         //* 补充&修改返回结构体 */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = '添加成功';
         $return_struct['content'] = $return_data;
         $return_struct['action'] = array('type' => 'location', 'url' => url::base() . 'product/' . $this->class_name . '/' . 'index');
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             // html 输出
             $this->template->return_struct = $return_struct;
             $content = new View('info');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             //* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $this->_ex($ex, $return_struct, $request_data);
     }
 }