function action_remove() { session_start(); $model = $_SESSION['basket']; $productId = $_POST['productId']; $model->Remove(ProductHelper::PopulateProductViewModel(ProductService::GetById($productId))); $_SESSION['basket'] = $model; }
public static function GetProductsByOrderId($order_id) { $orders = OrderListService::GetByOrderId($order_id); for ($i = 0; $i < count($orders); $i++) { $products[$i] = ProductHelper::PopulateProductViewModel(ProductService::GetById($orders[$i]->product_id)); } return $products; }
public static function PopulateReviewViewModel($review) { $model = new ReviewViewModel(); $model->id = $review->review_id; $model->product = ProductHelper::PopulateProductViewModel(ProductService::GetById($review->product_id)); $model->account = AccountHelper::PopulateAccountViewModel(AccountService::GetById($review->account_id)); $model->value = $review->value; return $model; }
public static function PopulateCatalogueViewModel($catalogue) { $model = new CatalogViewModel(); $model->id = $catalogue->catalogue_id; $model->name = $catalogue->name; $model->section = $catalogue->section->section_name; $model->products = ProductService::GetByCatalogue($model->name); return $model; }
public static function getSearchableField($productId) { $searchAbleArr = self::getBasicSearchFieldConfig($productId); if (!empty($productId)) { $customSearchAbleFieldArr = ProductService::getSearchableCostomField('case', $productId); $searchAbleArr = array_merge($searchAbleArr, $customSearchAbleFieldArr); } return $searchAbleArr; }
public static function getSearchableField($productId) { $searchAbleArr = self::getBasicSearchFieldConfig($productId); if (!empty($productId)) { $searchAbleArr['solution'] = array('label' => BugInfo::model()->getAttributeLabel('solution'), 'type' => Info::$InputType['option'], 'isBasic' => true, 'value' => InfoService::getBugSolutionOptions($productId)); $customSearchAbleFieldArr = ProductService::getSearchableCostomField('bug', $productId); $searchAbleArr = array_merge($searchAbleArr, $customSearchAbleFieldArr); } return $searchAbleArr; }
private function checkEditable() { if (empty($_GET['product_id'])) { throw new CHttpException(400, Yii::t('Common', 'Required URL not found or permission denied.')); } else { if (!ProductService::isProductEditable($_GET['product_id'])) { throw new CHttpException(400, Yii::t('Common', 'Required URL not found or permission denied.')); } } }
/** * 通过商品SKU创建货品SKU * * @param string $product_sku * @return string */ public static function create_good_sku($product_sku) { $good_service = ProductService::get_instance(); do { $good_sku = strtoupper($product_sku . '-' . substr(uniqid(), -4)); if (strlen($good_sku) > 32) { $good_sku = substr($good_sku, -32); } } while ($good_service->query_count(array('where' => array('sku' => $good_sku))) > 0); return $good_sku; }
public function get_product_page_by_site_id($site_id, $on_sale = 0) { $products = array(); $product_service = ProductService::get_instance(); $request_struct = array('where' => array('site_id' => $site_id, 'status' => 1)); if ($on_sale == 1) { $request_struct['where']['on_sale'] = 1; } $products = $product_service->query_assoc($request_struct); return $products; }
/** * 设置商品的关联商品 * * @param array $product * @param array $relation_ids * @return boolean */ public static function set(&$product) { ORM::factory('product_relation')->where('product_id', $product['id'])->delete_all(); if (isset($product['pdt_relation_ids']) && count($product['pdt_relation_ids']) > 0) { $relations = ProductService::get_instance()->index(array('where' => array('id' => $product['pdt_relation_ids']))); foreach ($relations as $relation) { if ($relation['id'] != $product['id']) { Product_relationService::get_instance()->add(array('product_id' => $product['id'], 'relation_product_id' => $relation['id'])); } } } return TRUE; }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $availableProductServices = ProductService::getAvailableService($model->rate_company_service_id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['ServiceDetail'])) { $model->attributes = $_POST['ServiceDetail']; if ($model->save()) { $this->redirect(array('index', 'company_service_id' => $model->rate_company_service_id)); } } $this->render('update', array('model' => $model, 'availableProductServices' => $availableProductServices)); }
/** * 使用商品模板创建一个新的商品 * * @return array */ public static function get($site_id, $type = 0) { if (Product_templateService::get_instance()->is_template_exist($site_id)) { $template = Product_templateService::get_instance()->get_template_by_site($site_id); unset($template['id']); unset($template['create_timestamp']); unset($template['update_timestamp']); unset($template['descriptions']); $product = $template; $product['type'] = $type; $product['sku'] = strtoupper(uniqid()); } else { $product = array('site_id' => $site_id, 'status' => 0, 'sku' => strtoupper(uniqid()), 'category_id' => 0, 'on_sale' => 1, 'type' => $type); } $product_id = ProductService::get_instance()->add($product); return BLL_Product::get($product_id); }
/** * 提交商品修改 */ public function post() { // 初始化返回结构体 $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); $url_redirect = url::base() . 'product/gift_card'; $id = isset($request_data['id']) ? (int) $request_data['id'] : 0; $on_sale = isset($request_data['on_sale']) ? (int) $request_data['on_sale'] : 0; $price = (int) $request_data['price']; if ($price <= 0) { throw new MyRuntimeException("价格必须为整数", 500); } $data = array('front_visible' => 0, 'type' => ProductService::PRODUCT_TYPE_GIFT_CARD, 'price' => $price, 'title' => $request_data['title'], 'sku' => $request_data['sku'], 'on_sale' => $on_sale); if ($id > 0) { $data['id'] = $id; $data['update_time'] = time(); ProductService::get_instance()->update($data); } else { $data['create_time'] = time(); $id = ProductService::get_instance()->add($data); } if ($id <= 0) { throw new MyRuntimeException(Kohana::lang('o_product.no_save'), 500); } remind::set(Kohana::lang('o_product.edit_product_success'), $url_redirect, 'success'); } catch (MyRuntimeException $ex) { $this->_ex($ex, $return_struct, $request_data); } }
/** * 检查货品SKU是否重复 * * @param integer $site_id * @param string $sku * @param integer $good_id * @return boolean */ public static function good_sku_exists($sku, $good_id = 0) { $query_struct = array('where' => array('sku' => trim($sku))); if ($good_id > 0) { $query_struct['where']['id !='] = $good_id; } return ProductService::get_instance()->count($query_struct) > 0 ? TRUE : FALSE; }
/** * 设置商品特性关联 * * @param array $product * @return boolean */ public static function set_fetuoptrs(&$product) { $fetuoptrs = isset($product['pdt_fetuoptrs']) ? $product['pdt_fetuoptrs'] : array(); if ($product['classify_id'] > 0 && $fetuoptrs) { $product['product_featureoption_relation_struct'] = array(); $features = self::get_clsfeturs($product['classify_id']); if ($features) { $rs = array(); foreach ($fetuoptrs as $fetu_id => $opti_name) { if (isset($features[$fetu_id])) { $opti_name = trim($opti_name); if (!empty($opti_name)) { //输入项目 if ($features[$fetu_id]['type'] == 1) { //组合商品属性保存 Product_attributeoption_relationService::get_instance()->add(array('apply' => AttributeService::ATTRIBUTE_FEATURE, 'product_id' => $product['id'], 'attribute_id' => $fetu_id, 'attributeoption_id' => '0', 'attribute_value' => $opti_name)); $rs[$fetu_id] = '0'; } else { //选择项目 foreach ($features[$fetu_id]['options'] as $option) { if (strtolower(trim($option['name'])) === strtolower($opti_name)) { Product_attributeoption_relationService::get_instance()->add(array('apply' => AttributeService::ATTRIBUTE_FEATURE, 'product_id' => $product['id'], 'attribute_id' => $fetu_id, 'attributeoption_id' => $option['id'], 'attribute_value' => $opti_name)); $rs[$fetu_id] = (string) $option['id']; break; } } } } } } if (!empty($rs)) { $product_feature_relation_struct = json_encode(array('items' => array_keys($rs))); $product_featureoption_relation_struct = json_encode(array('items' => $rs)); //更新商品数据 $data = array('id' => $product['id'], 'product_feature_relation_struct' => $product_feature_relation_struct, 'product_featureoption_relation_struct' => $product_featureoption_relation_struct, 'update_time' => time()); ProductService::get_instance()->update($data); //更新货品数据 if (!empty($product['pdt_goods'])) { foreach ($product['pdt_goods'] as $index => $good) { $data = array('id' => $good['id'], 'product_feature_relation_struct' => $product_feature_relation_struct, 'product_featureoption_relation_struct' => $product_featureoption_relation_struct, 'update_time' => time()); ProductService::get_instance()->update($data); } } } } } return TRUE; }
/** * 通过商品ID设置货品的上下架状态 * * @param integer $product_id * @param integer $on_sale * @return boolean */ public static function set_on_sale($product_id, $on_sale) { $goods = ProductService::get_instance()->index(array('where' => array('product_id' => $product_id))); if (!empty($goods)) { foreach ($goods as $good) { $good['on_sale'] = $on_sale; ProductService::get_instance()->set($good['id'], $good); } } return TRUE; }
public function put_products() { role::check('product_auction'); $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); $this->template = new View('layout/commonfix_html'); try { //$profiler = new Profiler; //* 初始化返回数据 */ $return_data = array(); //* 收集请求数据 ==根据业务逻辑定制== */ $request_data = $this->input->post(); $experiences = $this->input->post('experiences', array()); if (empty($request_data['relation_ids'])) { throw new MyRuntimeException('Input Error', 500); } if (isset($request_data['relation_ids']) && !empty($request_data['relation_ids'])) { $query_struct = array('where' => array('id' => $request_data['relation_ids'])); $pdata = ProductService::get_instance()->query_assoc($query_struct); $product_data = array(); foreach ($pdata as $p) { $product_data[$p['id']] = $p; } $auction_service = Product_auctionService::get_instance(); foreach ($request_data['relation_ids'] as $pid => $val) { $relation_query_struct = array('where' => array('product_id' => $val)); $pdata = $data = array(); $pdata = array_shift($auction_service->query_assoc($relation_query_struct)); $data['experience'] = isset($experiences[$pid]) ? 1 : 0; if (empty($pdata)) { $data['qty'] = 1; $data['status'] = 0; $data['product_id'] = $val; $data['price_start'] = '0.00'; $data['price_increase'] = '0.01'; $data['time_end'] = 3600 * 24; $data['time_reset'] = 10; if (isset($product_data[$val])) { $data['price'] = $product_data[$val]['price']; $data['name'] = $product_data[$val]['title']; if (!empty($product_data[$val]['default_image_id'])) { $data['default_image'] = '/att/product/' . $product_data[$val]['default_image_id']; } elseif (!empty($product_data[$val]['goods_productpic_relation_struct'])) { $img = json_decode($product_data[$val]['goods_productpic_relation_struct'], 1); if (isset($img['items'][0])) { $img = ProductpicService::get_instance()->get($img['items'][0]); $data['default_image'] = '/att/product/' . $img['image_id']; } } else { $data['default_image'] = '/att/product/'; } $data['category_ids'] = ',' . $product_data[$val]['category_id'] . ',' . $product_data[$val]['category_ids'] . ','; } $result = $auction_service->add($data); if (!$result) { throw new MyRuntimeException('Internal Error', 500); } } elseif ($pdata['id'] > 0) { $data['id'] = $pdata['id']; $data['status'] = $pdata['status'] == 2 ? 0 : $pdata['status']; if (isset($product_data[$val])) { $data['price'] = $product_data[$val]['price']; $data['name'] = $product_data[$val]['title']; if (!empty($product_data[$val]['default_image_id'])) { $data['default_image'] = '/att/product/' . $product_data[$val]['default_image_id']; } elseif (!empty($product_data[$val]['goods_productpic_relation_struct'])) { $img = json_decode($product_data[$val]['goods_productpic_relation_struct'], 1); if (isset($img['items'][0])) { $img = ProductpicService::get_instance()->get($img['items'][0]); $data['default_image'] = '/att/product/' . $img['image_id']; } } else { $data['default_image'] = '/att/product/'; } $data['category_ids'] = ',' . $product_data[$val]['category_id'] . ',' . $product_data[$val]['category_ids'] . ','; } $auction_service->update($data); } } } //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = '添加成功!'; $return_struct['content'] = $return_data; //* 请求类型 */ if ($this->is_ajax_request()) { // ajax 请求 // json 输出 $this->template->content = $return_struct; } else { // html 输出 $this->template = new View('layout/empty_html'); //* 变量绑定 */ $this->template->content = new View('product/auction/put_products'); //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } } catch (MyRuntimeException $ex) { $this->_ex($ex, $return_struct, $request_data); } }
/** * 根据 类型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; } }
public function actionPermission() { $this->layout = '//layouts/permission'; $permissionTable = ProductService::getPermissionTable(); $this->render('permission', array('permissionTable' => $permissionTable)); }
protected function update_product($product_id) { try { $grade_count = 0; $grade_score = 0; $comments = ProductcommentService::get_instance()->query_assoc(array('where' => array('product_id' => $product_id, 'status' => ProductcommentService::COMMENT_EXAMINE_TRUE))); foreach ($comments as $comment) { if ($comment['grade'] > 0) { $grade_count++; $grade_score += $comment['grade']; } } ProductService::get_instance()->set($product_id, array('comments_count' => count($comments), 'graded_count' => $grade_count, 'star_average' => $grade_count > 0 ? round($grade_score / $grade_count, 1) : 0, 'update_time' => time())); } catch (MyRuntimeException $ex) { throw $ex; } }
public static function getSingleHistoryStr($fieldLabelArr, $type, $productId, $historyInfo) { $singleHistoryStr = ''; if (isset($fieldLabelArr[$historyInfo['action_field']])) { $fieldName = $fieldLabelArr[$historyInfo['action_field']]; } else { //search label in Common.php if BugInfo.php not contain related label //ex. created_by field $fieldName = Yii::t('Common', Yii::t(ucfirst($type) . 'Info', $historyInfo['action_field'])); } if ('repeat_step' == $historyInfo['action_field'] || 'case_step' == $historyInfo['action_field'] || 'result_step' == $historyInfo['action_field']) { $historyInfo['old_value'] = htmlspecialchars($historyInfo['old_value']); $historyInfo['old_value'] = str_replace("\r\n", '', $historyInfo['old_value']); $historyInfo['old_value'] = str_replace("\n", '', $historyInfo['old_value']); $historyInfo['new_value'] = htmlspecialchars($historyInfo['new_value']); $historyInfo['new_value'] = str_replace("\r\n", '', $historyInfo['new_value']); $historyInfo['new_value'] = str_replace("\n", '', $historyInfo['new_value']); $singleHistoryStr = 'Changed <strong>' . $fieldName . '</strong> from <strong onmouseover="return overlib(\'' . str_replace("'", "\\'", str_replace("\"", "\\\"", $historyInfo['old_value'])) . '\',ABOVE,WIDTH,300,BGCOLOR,\'#75736E\',FGCOLOR,\'#F6F6F6\');" onmouseout="return nd();">' . '"<a href="javascript:void(0);">...</a>"</strong> to <strong onmouseover="return overlib(\'' . str_replace("'", "\\'", str_replace("\"", "\\\"", $historyInfo['new_value'])) . '\',ABOVE,WIDTH,300,BGCOLOR,\'#75736E\',FGCOLOR,\'#F6F6F6\');" onmouseout="return nd();">' . '"<a href="javascript:void(0);" >...</a>"</strong>'; } else { if ('delete_flag' == $historyInfo['action_field']) { $historyInfo['old_value'] = CommonService::getTrueFalseName($historyInfo['old_value']); $historyInfo['new_value'] = CommonService::getTrueFalseName($historyInfo['new_value']); } else { if ('severity' == $historyInfo['action_field'] || 'priority' == $historyInfo['action_field']) { $nameArr = array(); if ('priority' == $historyInfo['action_field']) { if (Info::TYPE_BUG == $type) { $nameArr = ProductService::getBugPriorityOption($productId); } else { $nameArr = ProductService::getCasePriorityOption($productId); } } else { $nameArr = ProductService::getBugSeverityOption($productId); } $historyInfo['old_value'] = CommonService::getNameByValue($nameArr, $historyInfo['old_value']); $historyInfo['new_value'] = CommonService::getNameByValue($nameArr, $historyInfo['new_value']); } } $singleHistoryStr = 'Changed <strong>' . $fieldName . '</strong> from <strong>"' . CHtml::encode($historyInfo['old_value']) . '"</strong> to <strong>"' . CHtml::encode($historyInfo['new_value']) . '"</strong>'; } return $singleHistoryStr; }
public function put() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); try { /* 初始化返回数据 */ $return_data = array(); /* 收集请求数据 ==根据业务逻辑定制== */ $request_data = $this->input->get(); if (!isset($request_data['relation_ids'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } //* 权限验证 ==根据业务逻辑定制== */ $good_service = ProductService::get_instance(); $query_relation_ids = explode('-', $request_data['relation_ids']); $relation_ids = array(); $goods = array(); $query_struct = array('where' => array('id' => $query_relation_ids)); foreach ($good_service->query_assoc($query_struct) as $relation) { $relation_ids[$relation['id']] = true; $goods[] = $relation; } $list = new View($this->package_name . '/' . $this->class_name . '/list'); $list->goods = $goods; $return_data['relation_ids'] = $relation_ids; $return_data['list'] = (string) $list; /* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = '添加成功!'; $return_struct['content'] = $return_data; /* 请求类型 */ if ($this->is_ajax_request()) { // ajax 请求 // json 输出 $this->template->content = $return_struct; } } catch (MyRuntimeException $ex) { $return_struct['status'] = 0; $return_struct['code'] = $ex->getCode(); $return_struct['msg'] = $ex->getMessage(); if ($this->is_ajax_request()) { $this->template->content = $return_struct; } else { //$return_struct['action']['type']= 'close'; // 当前应用为弹出窗口所以定义失败后续动作为关闭窗口 $this->template = new View('layout/default_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; } } }
/** * 设置商品批发 * * @param array $product * @param array $wholesales * @return boolean */ public static function set(&$product) { self::delete($product['id']); $wholesales = isset($product['wholesales']) ? $product['wholesales'] : array(); if ($product['is_wholesale'] > 0 and isset($wholesales['items'])) { foreach ($wholesales['items'] as $index => $wholesale) { $wholesale['product_id'] = $product['id']; $wholesale['type'] = $wholesales['type']; $wholesales['items'][$index] = $wholesale; } while (TRUE) { $order = FALSE; foreach ($wholesales['items'] as $index => $wholesale) { $next = $index + 1; if (isset($wholesales['items'][$next])) { if ($wholesale['num_begin'] > $wholesales['items'][$next]['num_begin']) { $wholesales['items'][$index] = $wholesales['items'][$next]; $wholesales['items'][$next] = $wholesale; $order = TRUE; } elseif ($wholesale['num_begin'] == $wholesales['items'][$next]['num_begin']) { unset($wholesales['items'][$index]); } } } if ($order == FALSE) { break; } } foreach ($wholesales['items'] as $index => $wholesale) { $prev = $index - 1; if (isset($wholesales['items'][$prev])) { $wholesales['items'][$prev]['num_end'] = $wholesale['num_begin'] - 1; } } isset($wholesales['items'][0]['num_begin']) and $product['lowest_wholesale_num'] = $wholesales['items'][0]['num_begin']; foreach ($wholesales['items'] as $wholesale) { Product_wholesaleService::get_instance()->add($wholesale); } } else { $product['is_wholesale'] = 0; $product['lowest_wholesale_num'] = 0; } //更新商品数据 $data = array('id' => $product['id'], 'is_wholesale' => $product['is_wholesale'], 'lowest_wholesale_num' => $product['lowest_wholesale_num'], 'update_time' => time()); ProductService::get_instance()->update($data); //更新货品数据 if (isset($product['pdt_goods']) && is_array($product['pdt_goods'])) { foreach ($product['pdt_goods'] as $good) { if (isset($good['id'])) { $data['id'] = $good['id']; ProductService::get_instance()->update($data); } } } return TRUE; }
/** * Lists all models. */ public function actionIndex() { $name = ''; $pageSize = CommonService::getPageSize(); $productIdNameArr = ProductService::getActiveProductIdNameArr(); $criteria = new CDbCriteria(); if (CommonService::$TrueFalseStatus['FALSE'] == Yii::app()->user->getState('system_admin')) { $managedProducts = TestUserService::getManagedProduct(Yii::app()->user->id); $criteria->addInCondition('id', $managedProducts); $criteria->addCondition('is_dropped="0"'); } if (isset($_GET['name'])) { $name = $_GET['name']; $criteria->addSearchCondition('name', $name); } $dataProvider = new CActiveDataProvider('Product', array('criteria' => $criteria, 'sort' => array('defaultOrder' => array('is_dropped' => false, 'display_order' => true)), 'pagination' => array('pageSize' => $pageSize))); $this->render('index', array('dataProvider' => $dataProvider, 'name' => $name, 'productIdNameArr' => $productIdNameArr)); }
public function delete_all() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented.', 'content' => array()); try { //$profiler = new Profiler; //* 初始化返回数据 */ $return_data = array(); //* 收集请求数据 ==根据业务逻辑定制== */ $request_data = $this->input->get(); //* 实现功能后屏蔽此异常抛出 */ //throw new MyRuntimeException('Not Implemented',501); //* 权限验证,数据验证,逻辑验证 ==根据业务逻辑定制== */ $site_ids = role::get_site_ids(); if (empty($site_ids)) { throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403); } if (empty($request_data['product_id']) or empty($request_data['relation_ids'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } //* 权限验证 ==根据业务逻辑定制== */ $product_service = ProductService::get_instance(); $product_relation_service = Product_relationService::get_instance(); $product = $product_service->get($request_data['product_id']); if (!in_array($product['site_id'], $site_ids)) { throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403); } $relation_ids = array(); $query_struct = array('where' => array('product_id' => $product, 'relation_product_id' => explode('-', $request_data['relation_ids']))); foreach (Product_relationService::get_instance()->query_assoc($query_struct) as $relation) { $relation_ids[$relation['relation_product_id']] = TRUE; } ORM::factory('product_relation')->where('product_id', $request_data['product_id'])->in('relation_product_id', array_keys($relation_ids))->delete_all(); ProductService::get_instance()->set($product['id'], array('update_timestamp' => time())); //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = ''; $return_struct['content'] = $relation_ids; //* 请求类型 */ if ($this->is_ajax_request()) { // ajax 请求 // json 输出 $this->template->content = $return_struct; } else { throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 404); // html 输出 $this->template = new View('layout/empty_html'); //$this->template->manager_data = $this->manager; //* 模板输出 */ //$this->template->return_struct = $return_struct; $content = new View($this->package_name . '/' . $this->class_name . '/' . __FUNCTION__); //* 变量绑定 */ //$this->template->title = Kohana::config('site.name'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; //:: 当前应用专用数据 $this->template->content->title = Kohana::config('site.name'); } // end of request type determine } catch (MyRuntimeException $ex) { $return_struct['status'] = 0; $return_struct['code'] = $ex->getCode(); $return_struct['msg'] = $ex->getMessage(); //TODO 异常处理 //throw $ex; if ($this->is_ajax_request()) { $this->template->content = $return_struct; } else { //$return_struct['action']['type']= 'close'; // 当前应用为弹出窗口所以定义失败后续动作为关闭窗口 $this->template = new View('layout/default_html'); $this->template->return_struct = $return_struct; $content = new View('info2'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } } }
public function do_edit() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); try { //* 初始化返回数据 */ $return_data = array(); $request_data = $this->input->post(); /* 数据验证 ==根据业务逻辑定制== */ if (empty($request_data['id'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403); } $validResult = Validation::factory($request_data)->pre_filter('trim')->add_rules('id', 'required', 'digit')->add_rules('is_receive', 'digit')->add_rules('is_show', 'digit')->add_rules('reply_content', 'length[0,1024]'); if (!$validResult->validate()) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403); } //* 逻辑验证 ==根据业务逻辑定制== */ // 调用底层服务 $productinquiry_service = ProductinquiryService::get_instance(); //* 调用后端服务获取数据 */ try { $productinquiry = $productinquiry_service->get($request_data['id']); if (!isset($productinquiry) || empty($productinquiry)) { throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403); } $set_data = array('reply_content' => $request_data['reply_content'], 'is_show' => $request_data['is_show'], 'update_timestamp' => date('Y-m-d H:i:s'), 'status' => 1); if (!empty($request_data['is_receive']) && $productinquiry['is_receive'] != 1) { $product = ProductService::get_instance()->get($productinquiry['product_id']); if (!empty($productinquiry['user_id'])) { $email = Myuser::instance($productinquiry['user_id'])->get('email'); } else { $email = $productinquiry['email']; } $email_flag = 'reply_inquiry'; $title_param = array(); $title_param['{title}'] = strip_tags($product['title']); $content_param = array(); $content_param['{user_name}'] = strip_tags($productinquiry['user_name']); $content_param['{reply_content}'] = strip_tags($request_data['reply_content']); $content_param['{product_title}'] = strip_tags($product['title']); if (!mail::send_mail($email_flag, $email, '', $title_param, $content_param)) { throw new MyRuntimeException(Kohana::lang('o_global.mail_send_error'), 500); } else { $set_data['is_receive'] = 1; } //不套用邮件模板的方式 /* $subject = 'Reply to Inquiry About '.$product['title']; $content = ''; $content .= 'Dear '.$productinquiry['user_name'].' :<br>'; $content .= 'Having received your letter regarding the inquiry about '.$product['title'].'.<br>'; $content .= $productinquiry['reply_content'].'<br>'; $content .= 'If we may be of further service, please feel free to contact us.<br>'; $content .= 'Sincerely yours,<br>'; $content .= $site['name']; if(!mail::send($email,$subject,$content)) { throw new MyRuntimeException(Kohana::lang('o_global.mail_send_error'), 500); } else { $set_data['is_receive'] = 1; } */ } $productinquiry_service->set($productinquiry['id'], $set_data); } catch (MyRuntimeException $ex) { throw $ex; } //* 补充&修改返回结构体 */ $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()) { $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) { $return_struct['status'] = 0; $return_struct['code'] = $ex->getCode(); $return_struct['msg'] = $ex->getMessage(); //TODO 异常处理 //throw $ex; if ($this->is_ajax_request()) { $this->template->content = $return_struct; } else { $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; } } }
public function search_good() { // 收集请求数据 $request_data = $this->input->get(); $request_struct_current = array('where' => array('type' => ProductService::PRODUCT_TYPE_GOODS, 'on_sale' => 1), 'limit' => array('per_page' => 6, 'page' => 1), 'like' => array(), 'orderby' => array('id' => 'DESC')); if (isset($request_data['page']) && !empty($request_data['page'])) { $request_struct_current['limit']['page'] = $request_data['page']; $returnData['page'] = $request_struct_current['limit']['page']; } // 当前支持的查询业务逻辑 if (isset($request_data['type']) && isset($request_data['keyword']) && !empty($request_data['keyword'])) { switch ($request_data['type']) { case 'id': $request_struct_current['where'][$request_data['type']] = intval(trim($request_data['keyword'])); break; case 'title': $request_struct_current['like'][$request_data['type']] = trim($request_data['keyword']); break; case 'sku': $request_struct_current['where'][$request_data['type']] = trim($request_data['keyword']); break; } } $goods = ProductService::get_instance()->index($request_struct_current); $returnData['content'] = $goods; $returnData['count'] = ceil(ProductService::get_instance()->count($request_struct_current) / $request_struct_current['limit']['per_page']); $returnData['page'] = isset($returnData['page']) ? $returnData['page'] : 1; //header('Content-Type: text/javascript; charset=UTF-8'); echo json_encode($returnData); exit; }
/** * get bug's solution options * * @author youzhao.zxw<*****@*****.**> * @param int $productId product id * @return array bug's solution array */ public static function getBugSolutionOptions($productId) { $productInfo = ProductService::loadModel($productId); $solutionValueStr = $productInfo->solution_value; $solutionArr = CommonService::splitStringToArray(',', $solutionValueStr); $optionArr = array(); $optionArr[''] = ''; foreach ($solutionArr as $solution) { $optionArr[$solution] = $solution; } return $optionArr; }
public function post() { $request_data = $this->input->post(); $total_products = 0; $total = 0; if ($_POST) { if (!$request_data['id']) { remind::set(Kohana::lang('o_global.access_denied'), request::referrer()); } if (!is_numeric($request_data['discount_price']) || $request_data['discount_price'] < 0 || !is_numeric($request_data['amount']) || $request_data['amount'] < 0) { remind::set(Kohana::lang('o_global.illegal_data'), request::referrer()); } $data = Myorder_product::instance($request_data['id'])->get(); if (!$data['id']) { remind::set(Kohana::lang('o_global.access_denied'), request::referrer()); } $good = ProductService::get_instance()->get($data['good_id']); $order = Myorder::instance($data['order_id'])->get(); if ($good['store'] == '0') { remind::set(Kohana::lang('o_global.bad_request'), request::referrer()); } //得到合理的价格数值 if ($good['store'] == -1 && $request_data['amount'] > 999) { $request_data['amount'] = 999; } if ($good['store'] != -1 && $request_data['amount'] > $good['store']) { $request_data['amount'] = $good['store']; } $final_price = $request_data['discount_price'] * $order['conversion_rate']; $set_data = array('discount_price' => $final_price, 'quantity' => $request_data['amount']); if (Myorder_product::instance($data['id'])->edit($set_data)) { //重新查询数据库,计算价格 if (Myorder::instance($order['id'])->update_total()) { remind::set(Kohana::lang('o_global.update_success'), 'order/order/edit/id/' . $data['order_id'], 'success'); } else { remind::set(Kohana::lang('o_global.update_error'), 'order/order/edit/id/' . $data['order_id'], 'error'); } } else { remind::set(Kohana::lang('o_global.update_error'), 'order/order/edit/id/' . $data['order_id']); } } else { remind::set(Kohana::lang('o_global.update_error'), request::referrer()); } }
/** * 批量更新商品的name_url */ public function update_product_name_url() { $site = Mysite::instance($this->site_id)->get(); if ($_POST) { $domain = $this->input->post('domain'); if (empty($domain) || $domain != $site['domain']) { remind::set(Kohana::lang('o_global.input_error'), 'site/update/update_product_name_url'); } $query_struct = array('where' => array('site_id' => $this->site_id), 'like' => array(), 'orderby' => array(), 'limit' => array('per_page' => 20, 'page' => 1)); $product_count = ProductService::get_instance()->count($query_struct); //1000个商品以下直接读取所有的商品 if ($product_count < 1000) { $query_struct['limit']['per_page'] = $product_count; $products = ProductService::get_instance()->index($query_struct); foreach ($products as $key => $value) { $product_name = $value['title']; if (!empty($product_name)) { //判断是否为中文的商品 if (preg_match('/[\\x7f-\\xff]/', $product_name)) { continue; } //过滤重复的NAME URL $product_name_url = product::create_uri_name($product_name, $value['site_id'], $value['id']); echo $product_name_url . "<br/>"; $data = array(); $data['uri_name'] = $product_name_url; $return_sturct = ProductService::get_instance()->set($value['id'], $data); } } } else { remind::set(Kohana::lang('o_site.product_request_check'), 'site/update/update_product_name_url'); } remind::set(Kohana::lang('o_site.sku_update_success'), 'site/update/update_product_name_url', 'success'); } $this->template->content = new View("site/update_product_name_url"); $this->template->content->site = $site; }