255], [['pro_cate_name'], 'string', 'max' => 100], [['close_sale_time', 'update_user'], 'string', 'max' => 50], [['star'], 'string', 'max' => 4], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'pro_cate_id' => 'Pro Cate ID', 'sign' => 'Sign', 'pro_cate_name' => 'Pro Cate Name', 'prod_des' => 'Prod Des', 'category_id' => 'Category ID', 'show_price' => 'Show Price', 'original_price' => 'Original Price', 'show_img' => 'Show Img', 'sales_count' => 'Sales Count', 'memo' => 'Memo', 'trip_desc' => 'Trip Desc', 'feature' => 'Feature', 'commission' => 'Commission', 'create_user_id' => 'Create User ID', 'is_recom' => 'Is Recom', 'start_area' => 'Start Area', 'address' => 'Address', 'close_sale_time' => 'Close Sale Time', 'star' => 'Star', 'create_time' => 'Create Time', 'update_time' => 'Update Time', 'delete_flag' => 'Delete Flag', 'update_user' => 'Update User', 'bus_ticket_id' => 'Bus Ticket ID', 'bus_line_type' => 'Bus Line Type', ]; } /* * 后台产品列表 */ public function AdminGetList($param) { $where = ['and', ['=', 'a.delete_flag', 0]]; if ($param['category_id'] != '') { $where[] = ['=', 'a.category_id', $param['category_id']]; } $keywords = $param['pro_cate_name_keywords']; if ($param['pro_cate_name_keywords'] != '') { $where[] = ['or', ['like', 'pro_cate_name', "$keywords"], ['like', 'pro_cate_id', $keywords]]; } if ($param['bs_type'] == 1) { $where[] = ['=', 'a.category_id', '1']; $where[] = ['is', 'a.sign', null]; } else if ($param['bs_type'] == 2) { $where[] = ['=', 'a.category_id', '1']; $where[] = ['is not', 'a.sign', null]; } $offset = ($param['current_page'] - 1) * $param['page_size']; $select = [ 'pro_cate_id', 'a.category_id', "if(a.category_id=1,if(a.sign is not null,concat(c.category_name,'(主线路)'),concat(c.category_name,'(子线路)')),c.category_name) as base_category", 'pro_cate_name', 'close_sale_time', 'memo', "IFNULL(prod_des, '') prod_des", 'original_price', 'show_price', 'commission', 'show_img', 'IFNULL(trip_desc, \'\') trip_desc' ]; $result = self::find()->select($select) ->from(self::tableName() . ' a') ->innerJoin(BaseCategory::tableName() . ' c', 'c.category_id = a.category_id') ->where($where) ->groupBy('a.pro_cate_id') ->orderBy('a.pro_cate_id DESC') ->offset($offset) ->limit((int)$param['page_size']) ->asArray() ->all(); $result1 = self::find()->select('count(1) as count') ->from(self::tableName() . ' a') ->leftJoin('base_category as b', 'b.category_id=a.category_id') ->asArray() ->where($where) ->one(); $result1 = $result1['count']; return ['list' => $result, 'count' => $result1]; } //修改原价 public function updateOriginalPrice($param) { $where = ['and', ['=', 'delete_flag', 0]]; $pro_cate_id = $param['pro_cate_id']; $original_price = $param['original_price']; $where[] = ['=', 'pro_cate_id', $pro_cate_id]; // self::updateAll(['commission' => $commission], ['and', ['=', 'pro_cate_id', $pro_cate_id]]); $count = self::updateAll(['original_price' => $original_price], $where); return $count; } //修改展示价 public function updateShowPrice($param) { $where = ['and', ['=', 'delete_flag', 0]]; $pro_cate_id = $param['pro_cate_id']; $show_price = $param['show_price']; $where[] = ['=', 'pro_cate_id', $pro_cate_id]; // self::updateAll(['commission' => $commission], ['and', ['=', 'pro_cate_id', $pro_cate_id]]); $count = self::updateAll(['show_price' => $show_price], $where); return $count; } /* * 給銷售終端產品管理的產品庫列表 * */ public function toClientProdList($param) { $where = ['and', ['=', 'a.delete_flag', 0]]; if ($param['category_id'] != '') { $where[] = ['=', 'a.category_id', $param['category_id']]; } $keywords = $param['pro_cate_name']; if ($param['pro_cate_name'] != '') { $where[] = ['or', ['like', 'pro_cate_name', "$keywords"], ['like', 'pro_cate_id', $keywords]]; } $offset = ($param['current_page'] - 1) * $param['page_size']; $select = [ 'pro_cate_id', 'a.category_id', "if(a.category_id=1,if(a.sign is not null,concat(c.category_name,'(主线路)'),concat(c.category_name,'(子线路)')),c.category_name) as base_category", 'pro_cate_name' ]; $result = self::find()->select($select) ->from(self::tableName() . ' a') ->innerJoin(BaseCategory::tableName() . ' c', 'c.category_id = a.category_id') ->where($where) ->groupBy('a.pro_cate_id') ->orderBy('a.pro_cate_id DESC') ->offset($offset) ->limit((int)$param['page_size']) ->asArray() ->all(); $result1 = self::find()->select('count(1) as count') ->from(self::tableName() . ' a') ->leftJoin('base_category as b', 'b.category_id=a.category_id') ->asArray() ->where($where) ->one(); $result1 = $result1['count']; return ['list' => $result, 'count' => $result1]; } /* * 自定义佣金 */ public function DefineCommission($pro_cate_id, $commission) { $count = self::updateAll(['commission' => $commission], ['and', ['=', 'pro_cate_id', $pro_cate_id]]); return $count; } /* * Des:设置产品佣金 (根据prod_cate_id) * Name: setProdCommissionByCateId * @param $param * @return int * @author 付泓程 */ public function setProdCommissionByCateId($param) { $commission = $param['commission']; $prod_cate_id = $param['prod_cate_id']; $count = $this->updateAll(['commission' => $commission], ['and', ['=', 'prod_cate_id', $prod_cate_id], ['=', 'delete_flag', '0']]); return $count; } /* * Des:设置产品佣金 (根据prod_id) * Name: setProdCommissionByProdId * @param $param * @return int * @author 付泓程 */ public function setProdCommissionByProdId($param) { $commission = $param['commission']; $prod_id = $param['prod_id']; $count = $this->updateAll(['commission' => $commission], ['and', ['=', 'prod_id', $prod_id], ['=', 'delete_flag', '0']]); return $count; } /* * 添加产品 */ public function addProd($param) { $values = [ 'category_id' => $param['category_id'], 'pro_cate_name' => $param['pro_cate_name'], 'memo' => $param['memo'], 'sales_count' => rand(1, 10), 'show_img' => $param['show_img'], 'create_time' => date('Y-m-d H:i:s'), 'prod_des' => $param['prod_des'], 'trip_desc' => $param['trip_desc'], 'close_sale_time' => $param['close_sale_time'], //截止售卖时间 2017-05-18 fuhc 'star' => '3.5' ]; $transaction = Yii::$app->db->beginTransaction(); try { $this->attributes = $values; $res = $this->insert(false); if (!$res) { return false; } $transaction->commit(); return true; } catch (Exception $e) { $transaction->rollBack(); return false; } } /* * 后台修改产品信息 */ public function uptAdminProd($param) { $values = [ 'category_id' => $param['category_id'], 'pro_cate_name' => $param['pro_cate_name'], 'memo' => $param['memo'], 'show_img' => $param['show_img'], 'prod_des' => $param['prod_des'], 'trip_desc' => $param['trip_desc'], 'update_time' => date('Y-m-d H:i:s'), 'close_sale_time' => $param['close_sale_time'] //截止售卖时间 2017-05-18 fuhc ]; $transaction = Yii::$app->db->beginTransaction(); try { $count = self::updateAll($values, ['=', 'pro_cate_id', $param['pro_cate_id']]); if (!$count) { return false; } $transaction->commit(); return true; } catch (Exception $e) { $transaction->rollBack(); return false; } } /* * 修改show price */ public function changeShowPrice($pro_cate_id) { //查当前产品的子产品最低价 $show_price = ProdMain::find()->select(['min(prod_price) as price'])->from('prod_main')->where(['and', ['=', 'delete_flag', '0'], ['=', 'prod_cate_id', $pro_cate_id]])->asArray()->one(); $show_price = $show_price['price']; $count = self::updateAll(['show_price' => $show_price], ['and', ['=', 'pro_cate_id', $pro_cate_id]]); return $count; } /* * 获取主产品列表 */ public function getMainProdList($param) { $page_size = $param['page_size']; $current_page = $param['current_page']; $system_id = $param['system_id']; $prod_name = $param['prod_name']; $where = [ 'and', ['=', 'a.delete_flag', 0], ['like', 'a.pro_cate_name', $prod_name], ['!=', 'a.show_img', ''] ]; if (empty($param['base_category_id']) == false) { $where[] = ['=', 'a.category_id', $param['base_category_id']]; } $offset = ($current_page - 1) * $page_size; $select = [ 'a.pro_cate_id', 'pro_cate_name' => new Expression("concat('[',c.category_name,']',' ',if(a.category_id=1,concat('[',if(a.sign is not null,'主线路','子线路'),']'),''),' ',a.pro_cate_name)"), 'if(b.system=' . $system_id . ',0,1) as if_have', ]; $result = self::find()->select($select) ->distinct() ->from(self::tableName() . ' a') ->innerJoin(BaseCategory::tableName() . ' c', 'a.category_id=c.category_id') ->leftJoin(CmsCategoryProd::tableName() . ' b', 'b.prod_cate_id = a.pro_cate_id and b.cms_cate_id=' . $param['cms_category_id'] . ' and b.system = ' . $system_id . ' and b.delete_flag = 0') ->where($where) ->orderBy('a.sign desc,a.category_id') ->offset($offset) ->limit((int)$page_size) ->asArray() ->all(); $result1 = self::find()->select('count(1) as count') ->from(self::tableName() . ' a') ->where($where) ->asArray() ->one(); $result1 = $result1['count']; return ['list' => $result, 'count' => $result1]; } /** * Function Description:巴士产品获取详情 * Function Name: getBusProdDetail * @param $pro_cate_id * * @return array|null|\yii\db\ActiveRecord * * @author 娄梦宁 */ public function getBusProdDetail($pro_cate_id) { $select = [ 'a.pro_cate_id', 'a.pro_cate_name', "IFNULL(a.prod_des, '') prod_des", 'a.category_id', 'sign' => new Expression("ifnull(a.sign,'')"), 'a.show_img', 'IFNULL(a.close_sale_time,24) as close_sale_time', 'category_name' => new Expression("''"), "IFNULL(a.memo, '') booking_notice", "IFNULL(a.trip_desc, '') trip_desc", 'a.star', 'a.original_price', 'comment_cnt' => new Expression("ifnull(c.comment_cnt,0)"), 'a.delete_flag', 'b.start_area_name', 'b.start_area_id', 'b.start_res_name', 'b.end_res_name', 'b.end_area_name', 'b.end_area_id', ]; $result = self::find()->select($select) ->from(self::tableName() . ' as a') ->leftJoin('bus_ticket b', 'a.bus_ticket_id=b.ticket_id') ->leftJoin(ProdCategoryInfo::tableName() . ' c', 'a.pro_cate_id = c.pro_cate_id') ->where(['and', ['=', 'a.pro_cate_id', $pro_cate_id]]) ->asArray() ->one(); return $result; } /** * Des:获取查询列表 * Name: getSearchList * @param $param * @param $type * @return array * @author 倪宗锋 */ public function getSearchList($param, $type) { $siteConfig = Util::getSiteConfig(); $where = [ 'and', ['=', 'a.delete_flag', '0'], ['!=', 'a.show_img', ''], ['=', 'b.system', $siteConfig['system']], ['=', 'a.category_id', $type], ['=', 'd.delete_flag', 0] ]; if (empty($param['prod_name']) == false) {//查询条件 $where[] = ['like', 'a.pro_cate_name', $param['prod_name']]; } if (empty($param['cms_id']) == false) { $where[] = ['=', 'b.cms_cate_id', $param['cms_id']]; } $select = [ 'a.category_id', 'a.pro_cate_id', 'a.pro_cate_name', 'a.show_img', 'b.system', 'c.category_name', 'a.star', 'a.original_price', 'a.show_price', 'a.sales_count', 'a.prod_des' ]; $result = self::find()->select($select) ->from(self::tableName() . ' a') ->innerJoin(CmsCategoryProd::tableName() . ' b', 'b.prod_cate_id = a.pro_cate_id') ->innerJoin(BaseCategory::tableName() . ' c', 'a.category_id = c.category_id') ->innerJoin(CmsCategory::tableName() . ' d', 'b.cms_cate_id = d.cms_category_id') ->where($where) ->orderBy('b.show_sort desc') ->asArray() ->all(); return $result; } /** * Des:获取bus产品记录 根据开始POI * Name: getBusProdByPoi_s * @param $params * @return array * @author 倪宗锋 */ public function getBusProdByPoi_s($params) { //where条件 $where = ['and']; $where[] = ['=', 'a.start_area_id', $params['poi']]; if (empty($params['category_id']) == false) { $where[] = ['=', 'c.cms_cate_id', $params['category_id']]; } //查询字段 $select = [ 'b.pro_cate_name',//主线路名称 'b.pro_cate_id',//主线路ID 'a.start_area_name',//上车POI名称 'a.end_area_name',//下车POI名称 'a.start_area_id',//上册 'a.end_area_id', 'show_price' => new Expression("min(d.show_price)"), 'original_price' => new Expression("min(d.original_price)"), 'sale_count' => new Expression("SUM(d.sales_count)"), 'is_hot' => new Expression('1'), 'b.show_img', 'a.line_id' ]; $start_list = self::find()->select($select) ->from(BusTicket::tableName() . ' a') ->innerJoin(ProdCategory::tableName() . ' b', 'a.line_id = b.sign and b.delete_flag =0') ->innerJoin(CmsCategoryProd::tableName() . ' c', 'c.prod_cate_id = b.pro_cate_id') ->innerJoin(ProdCategory::tableName() . ' d', 'a.ticket_id = d.bus_ticket_id and d.sign is NULL and d.delete_flag=0') ->orderBy('b.pro_cate_id desc') ->where($where) ->groupBy('a.line_id') //->createCommand()->getRawSql(); ->asArray() ->all(); if (empty($start_list[0])) { $return = []; } else { $return = []; foreach ($start_list as $val) { $val['show_price'] = OrderUtil::getBusDiscountPrice($val['pro_cate_id'], $val['show_price']); $return[$val['end_area_name']][$val['line_id']] = $val; } } return $return; } /** * Function Description:获取bus产品记录 根据结束POI * Function Name: getBusProdByPoi_e * @param $params * * @return array * * @author 冒炎 */ public function getBusProdByPoi_e($params) { //where条件 $where = ['and']; $where[] = ['=', 'a.end_area_id', $params['poi']]; if (empty($params['category_id']) == false) { $where[] = ['=', 'c.cms_cate_id', $params['category_id']]; } //查询字段 $select = [ 'b.pro_cate_name',//主线路名称 'b.pro_cate_id',//主线路ID 'a.start_area_name',//上车POI名称 'a.end_area_name',//下车POI名称 'a.start_area_id',//上册 'a.end_area_id', 'show_price' => new Expression("min(d.show_price)"), 'original_price' => new Expression("min(d.original_price)"), 'sale_count' => new Expression("SUM(d.sales_count)"), 'is_hot' => new Expression('1'), 'b.show_img', 'a.line_id' ]; $start_list = self::find()->select($select) ->from(BusTicket::tableName() . ' a') ->innerJoin(ProdCategory::tableName() . ' b', 'a.line_id = b.sign and b.delete_flag =0') ->innerJoin(CmsCategoryProd::tableName() . ' c', 'c.prod_cate_id = b.pro_cate_id') ->innerJoin(ProdCategory::tableName() . ' d', 'a.ticket_id = d.bus_ticket_id and d.sign is NULL and d.delete_flag=0') ->orderBy('b.pro_cate_id desc') ->where($where) ->groupBy('a.line_id') //->createCommand()->getRawSql(); ->asArray() ->all(); if (empty($start_list[0])) { $return = []; } else { $return = []; foreach ($start_list as $val) { $val['show_price'] = OrderUtil::getBusDiscountPrice($val['pro_cate_id'], $val['show_price']); $return[$val['start_area_name']][$val['line_id']] = $val; } } return $return; } /** * Function Description:根据票种id获取对应的子线路产品 * Function Name: getBusProdByTicket * @param $ticket_id * * @return array|null|ActiveRecord * * @author 冒炎 */ public function getBusProdByTicket($ticket_id) { $where = ['=', 'a.ticket_id', $ticket_id]; $select = [ 'a.start_area_name',//上车POI名称 'a.end_area_name',//下车POI名称 'a.start_area_id', 'a.end_area_id', 'a.start_res_name',//上车站点名称 'a.end_res_name',//下车站点名称 'a.start_res_id', 'a.end_res_id', 'show_price' => new Expression('(select min(prod_price) from prod_main where delete_flag=0 and prod_cate_id=b.pro_cate_id)'), 'b.original_price', 'b.pro_cate_id', ]; $result = self::find()->select($select) ->from(BusTicket::tableName() . ' a') ->innerJoin(ProdCategory::tableName() . ' b', 'a.ticket_id = b.bus_ticket_id and b.sign is NULL and b.delete_flag=0') ->where($where) ->asArray() ->one(); if (empty($result) == false) { $result['show_price'] = OrderUtil::getBusDiscountPrice($result['pro_cate_id'], $result['show_price']); } return $result; } /** * Des:根据POI获取巴士自由行产品 * Name: getRecommendByPoi * @param $params * @return array * @author 倪宗锋 */ public function getRecommendByPoi($params) { //查询字段 $select = [ 'a.pro_cate_name', 'a.pro_cate_id', 'a.show_price', 'a.prod_des', 'a.sales_count', 'is_hot' => new Expression('1'), 'a.show_img', 'a.category_id', 'a.original_price' ]; //where条件 $where = ['and']; $where[] = ['=', 'a.delete_flag', '0']; $where[] = ['=', 'a.category_id', '4'];//巴士自由行产品 $where[] = ['in', 'b.ID', [$params['start_poi'], $params['end_poi']]];//巴士自由行产品 $list = self::find()->select($select) ->from(self::tableName() . ' a') ->innerJoin(BaseArea::tableName() . ' b', 'locate(b.AREA_NAME,a.pro_cate_name)') ->where($where) ->limit(6) ->asArray() ->all(); if (empty($list['0'])) { $list = []; } return $list; } /** * Function Description:非巴士产品获取详情 * Function Name: getProdDetail * @param $pro_cate_id * * @return array * * @author 娄梦宁 */ public function getProdDetail($pro_cate_id) { $select = [ 'a.pro_cate_id', 'a.pro_cate_name', 'prod_des' => new Expression("IFNULL(a.prod_des, '')"), 'feature' => new Expression("IFNULL(a.feature, '')"), 'a.category_id', 'a.show_img', 'booking_notice' => new Expression("IFNULL(a.memo, '')"), 'sign' => new Expression("ifnull(a.sign,'')"), 'a.show_price', 'a.close_sale_time', 'category_name' => new Expression("''"), 'trip_desc' => new Expression("IFNULL(a.trip_desc, '')"), 'a.star', 'a.original_price', 'comment_cnt' => new Expression("(select count(id) from prod_comment where prod_id=a.pro_cate_id)"), 'a.delete_flag', 'a.sales_count' ]; $result = self::find()->select($select) ->from(self::tableName() . ' a') ->leftJoin(ProdCategoryInfo::tableName() . ' c', 'a.pro_cate_id = c.pro_cate_id') ->where(['and', ['=', 'a.pro_cate_id', $pro_cate_id], ['=', 'a.delete_flag', 0]]) ->asArray() ->one(); $result['show_price'] = $this->dealFloat($result['show_price']); return $result; } /** * Des:获取产品详细信息 * Name: getProdInfo * @param $pro_cate_id * @return array * @author 倪宗锋 */ public function getProdCateInfo($pro_cate_id) { $select = [ new Expression('a.*'), 'start_area' => new Expression("if(b.start_area_name=b.start_res_name,b.start_res_name,CONCAT(b.start_area_name,b.start_res_name))"), 'end_area' => new Expression("if(b.end_area_name=b.end_res_name,b.end_res_name,CONCAT(b.end_area_name,b.end_res_name))") ]; $result = self::find()->select($select) ->from(self::tableName() . ' a') ->leftJoin(BusTicket::tableName() . ' b', 'a.bus_ticket_id=b.ticket_id') ->where(['=', 'a.pro_cate_id', $pro_cate_id]) ->asArray() ->one(); return $result; } /** * Des:产品增加销售量 * Name: addCount * @param $pro_cate_id * @param $cnt * @return bool * @author 倪宗锋 */ public function addCount($pro_cate_id, $cnt) { $sql = "UPDATE prod_category set sales_count=sales_count+$cnt where pro_cate_id = $pro_cate_id "; $res = $this->getDb()->createCommand($sql)->execute(); if (!$res) { return false; } return true; } /** * Des:获取主线路产品的子线路产品ID * Name: getBusSubProdIds * @param $pro_cate_id * @return string * @author 倪宗锋 */ public function getBusSubProdIds($pro_cate_id) { $select = [ 'ids' => new Expression("GROUP_CONCAT(c.pro_cate_id)") ]; $getProdCateIds = self::find()->select($select) ->from(self::tableName() . 'a') ->innerJoin(BusTicket::tableName() . ' b', 'a.sign=b.line_id') ->innerJoin(self::tableName() . ' c', 'b.ticket_id = c.bus_ticket_id and c.sign is null') ->where(['=', 'pro_cate_id', $pro_cate_id]) ->asArray() ->one(); if (empty($getProdCateIds['ids'])) { return ''; } return $getProdCateIds['ids']; } /** * Des:获取把自由行产品的产品ID组合 * Name: getFreeWalkSigns * @return array * @author 倪宗锋 */ public function getFreeWalkSigns() { $select = ['sign', 'pro_cate_id']; $where = [ 'and', ['=', 'category_id', '4'], ['=', 'delete_flag', 0] ]; $getSigns = self::find()->select($select) ->where($where) ->indexBy('sign') ->asArray() ->all(); if (empty($getSigns)) { return []; } return $getSigns; } /** * Des:根据ID获取产品列表 * Name: getProdListByIds * @param $ids * @return array|ActiveRecord[] * @author 倪宗锋 */ public function getProdListByIds($ids) { //查询字段 $select = [ 'a.pro_cate_name', 'a.pro_cate_id', 'a.show_price', 'a.prod_des', 'a.sales_count', 'is_hot' => new Expression('1'), 'a.show_img', 'a.category_id', 'a.original_price' ]; //where条件 $where = ['and']; $where[] = ['=', 'a.delete_flag', '0']; $where[] = ['!=', 'a.show_img', '']; $where[] = ['in', 'a.pro_cate_id', $ids];//巴士自由行产品 $list = self::find()->select($select) ->from(self::tableName() . ' a') ->where($where) ->limit(6) ->asArray() ->all(); if (empty($list['0'])) { $list = []; } return $list; } /** * Function Description:根据prod_id查询cms_category_id * Function Name: getCategoryId * @param $prod_id * * @return array|mixed|null|ActiveRecord * * @author 李健 */ public function getCategoryId($prod_id) { //查询字段 $select = [ 'c.category_id' ]; //where条件 $where = ['and']; $where[] = ['=', 'a.pro_cate_id', $prod_id]; $list = self::find()->select($select) ->from(self::tableName() . ' a') ->leftJoin(BusTicket::tableName() . ' b', 'b.ticket_id=a.bus_ticket_id') ->leftJoin(CmsCategoryExtra::tableName() . ' c', 'c.area_id=b.end_area_id') ->where($where) ->asArray() ->one(); if (!empty($list['category_id'])) { $list = $list['category_id']; } else { $list = null; } return $list; } /** * Function Description:获取自由行产品的sign * Function Name: getFreeWalkSign * @param $pro_cate_id * @return array|null|ActiveRecord * @author 田玲菲 */ public function getFreeWalkSign($pro_cate_id) { $select = ['sign' => new Expression('ifnull(sign,0)')]; $where = [ 'and', ['=', 'category_id', '4'], ['=', 'delete_flag', 0], ['=', 'pro_cate_id', $pro_cate_id] ]; $result = self::find()->select($select) ->where($where) ->asArray() ->one(); return $result; } /** * Function Description:处理价格 * Function Name: dealFloat * @param $float * * @return float * * @author LUOCJ */ public function dealFloat($float) { $int = floor($float); if ($float - $int == 0) { $float = $int; } return $float; } }