|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902 |
- <?php
-
- namespace common\models;
-
- use common\util\OrderUtil;
- use common\util\Util;
- use Yii;
- use yii\base\Exception;
- use yii\db\ActiveRecord;
- use yii\db\Expression;
-
- /**
- * This is the model class for table "prod_category".
- *
- * @property integer $pro_cate_id
- * @property string $pro_cate_name
- * @property integer $category_id
- * @property string $show_price
- * @property string $show_img
- * @property integer $sales_count
- * @property string $memo
- * @property string $commission
- * @property integer $create_user_id
- * @property integer $is_recom
- * @property string $create_time
- * @property string $update_time
- * @property integer $delete_flag
- * @property string $update_user
- * @property string $address
- * @property integer $bus_ticket_id
- * @property integer $bus_line_type
- */
- class ProdCategory extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'prod_category';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['pro_cate_name'], 'required'],
- [['prod_des', 'memo', 'trip_desc', 'feature'], 'string'],
- [['category_id', 'show_price', 'original_price', 'sales_count', 'commission', 'create_user_id', 'is_recom', 'delete_flag', 'bus_ticket_id', 'bus_line_type'], 'integer'],
- [['show_price', 'original_price'], 'number'],
- [['create_time', 'update_time'], 'safe'],
- [['sign', 'show_img', 'start_area', 'address'], 'string', 'max' => 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;
- }
- }
|