|
- <?php
- /**
- * 鏁版嵁搴撹〃绫? cms_category_prod
- * ============================================================================
- * * 鐗堟潈鎵?鏈? 铚樿洓鍑鸿 * *
- * 缃戠珯鍦板潃: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 杩欎笉鏄竴涓嚜鐢辫蒋浠讹紒鎮ㄥ彧鑳藉湪涓嶇敤浜庡晢涓氱洰鐨勭殑鍓嶆彁涓嬪绋嬪簭浠g爜杩涜淇敼鍜?
- * 浣跨敤锛涗笉鍏佽瀵圭▼搴忎唬鐮佷互浠讳綍褰㈠紡浠讳綍鐩殑鐨勫啀鍙戝竷銆?
- * ============================================================================
- * Author By: 鍊畻閿?
- * PhpStorm LoginController.php
- * Create By 2017/06/13 14:27 $
- */
-
- namespace common\models;
-
- use common\util\Util;
- use yii\db\ActiveRecord;
- use yii\db\Expression;
-
- /**
- * 鏁版嵁搴撹〃绫? cms_category_prod.
- * @property integer $id
- * @property integer $prod_cate_id
- * @property integer $cms_cate_id
- * @property integer $show_sort
- * @property integer $delete_flag
- * @property string $create_time
- * @property string $update_time
- * @property string $update_user
- */
- class CmsCategoryProd extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'cms_category_prod';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['prod_cate_id', 'cms_cate_id', 'show_sort', 'delete_flag', 'system'], 'integer'],
- [['cms_cate_id'], 'required'],
- [['create_time', 'update_time'], 'safe'],
- [['update_user'], 'string', 'max' => 50],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'prod_cate_id' => 'Prod Cate ID',
- 'cms_cate_id' => 'Cms Cate ID',
- 'show_sort' => 'Show Sort',
- 'delete_flag' => 'Delete Flag',
- 'create_time' => 'Create Time',
- 'update_time' => 'Update Time',
- 'update_user' => 'Update User',
- 'system' => 'System',
- ];
- }
-
- /*
- * 获取子产品列表
- */
- public function getChildProdList($param)
- {
- $page_size = $param['page_size'];
- $current_page = $param['current_page'];
- $system_id = $param['system_id'];
- $cms_category_id = $param['cms_category_id'];
- $where = [
- 'and',
- ['=', 'a.delete_flag', 0],
- ['=', 'a.system', $system_id],
- ['=', 'a.cms_cate_id', $cms_category_id],
- ['=', 'b.delete_flag', 0],
- ['!=', 'b.show_img', '']
- ];
- $offset = ($current_page - 1) * $page_size;
- $select = [
- 'a.prod_cate_id',
- 'a.show_sort',
- 'b.pro_cate_name'
- ];
- $result = self::find()->select($select)
- ->from(self::tableName() . ' a')
- ->innerJoin(ProdCategory::tableName() . ' b', 'b.pro_cate_id = a.prod_cate_id')
- ->where($where)
- ->groupBy('a.prod_cate_id')
- ->orderBy('a.show_sort DESC')
- ->offset($offset)
- ->limit((int)$page_size)
- ->asArray()
- ->all();
- $result1 = self::find()->select('count(1) as count')
- ->from(self::tableName() . ' a')
- ->leftJoin(ProdCategory::tableName() . ' b', 'b.pro_cate_id = a.prod_cate_id')
- ->asArray()
- ->where($where)
- ->one();
- $result1 = $result1['count'];
- return ['list' => $result, 'count' => $result1];
- }
-
-
- /*
- * 选择产品
- */
- public function selectProd($param)
- {
- $pro_cate_id = $param['pro_cate_id'];
- $system_id = $param['system_id'];
- $cms_cate_id = $param['cms_cate_id'];
-
- $values = [
- 'cms_cate_id' => $cms_cate_id,
- 'system' => $system_id,
- 'create_time' => date('Y-m-d H:i:s'),
- 'show_sort' => 1000,
- 'delete_flag' => 0,
- 'prod_cate_id' => $pro_cate_id
- ];
-
-
- $this->attributes = $values;
- $flag = $this->insert();
- return $flag;
-
- }
-
-
- /*
- * 取消或删除产品
- */
- public function cancelSelectProd($param)
- {
- $pro_cate_id = $param['pro_cate_id'];
- $system_id = $param['system_id'];
- $cms_cate_id = $param['cms_cate_id'];
-
- $tab = clone $this;
- $flag = $tab::deleteAll(['and', ['=', 'system', $system_id], ['=', 'cms_cate_id', $cms_cate_id], ['=', 'prod_cate_id', $pro_cate_id]]);
- return $flag;
- }
-
- /*
- * 修改子产品排序
- */
- public function changeProdSort($param)
- {
- $system_id = $param['system_id'];
- $cms_cate_id = $param['cms_cate_id'];
- $show_sort = $param['show_sort'];
- $prod_cate_id = $param['prod_cate_id'];
-
- $flag = self::updateAll(['show_sort' => $show_sort, 'update_time' => date('Y-m-d H:i:s')], ['and', ['=', 'system', $system_id], ['=', 'cms_cate_id', $cms_cate_id], ['=', 'prod_cate_id', $prod_cate_id], ['=', 'delete_flag', 0]]);
- return $flag;
- }
-
-
- /*
- * ************************C端接口
- *
- * */
- /**
- * Des:获取首页产品数据
- * Name: getHomePro
- * @param $cmsArr
- * @return array|ActiveRecord[]
- * @author 倪宗锋
- */
- public function getHomePro($cmsArr)
- {
- $where = [
- 'and',
- ['=', 'a.delete_flag', 0],
- ['=', 'a.system', 2],
- ['=', 'a.cms_cate_id', $cmsArr['cms_id']],
- ['!=', 'b.show_img', ''],
- ['=', 'b.delete_flag', 0]
- ];
- $select = [
- 'b.pro_cate_id',
- 'b.pro_cate_name',
- 'b.show_price',
- 'b.star',
- 'b.show_img',
- 'b.sales_count',
- 'b.original_price',
- 'b.category_id',
- '(select category_name from base_category as c where c.category_id = b.category_id) as category_name'
- ];
- $result = self::find()->select($select)
- ->from(self::tableName() . ' a')
- ->innerJoin(ProdCategory::tableName() . ' b', 'b.pro_cate_id = a.prod_cate_id')
- ->where($where)
- ->groupBy('a.prod_cate_id')
- ->orderBy('a.show_sort DESC')
- ->limit($cmsArr['cnt'])
- ->asArray()
- ->all();
- return $result;
-
- }
-
- //猜你喜欢
- public function getLikeList()
- {
- $where = ['and', ['=', 'a.delete_flag', 0], ['=', 'a.system', 2], ['=', 'a.cms_cate_id', 106]];
- $select = [
- 'b.pro_cate_id',
- 'b.pro_cate_name',
- 'b.show_price',
- 'b.star',
- 'b.show_img',
- 'b.sales_count',
- 'b.original_price',
- 'b.category_id',
- '(select category_name from base_category as c where c.category_id = b.category_id) as category_name'
- ];
- $result = self::find()->select($select)
- ->from(self::tableName() . ' a')
- ->innerJoin(ProdCategory::tableName() . ' b', 'b.pro_cate_id = a.prod_cate_id')
- ->where($where)
- ->groupBy('a.prod_cate_id')
- ->orderBy('a.show_sort DESC')
- ->limit(3)
- ->asArray()
- ->all();
- foreach ($result as &$v) {
- $v['show_price'] = $this->dealFloat($v['show_price']);
- }
- return $result;
- }
-
- //精品推荐
- public function getRecommendList($config)
- {
- $where = ['and', ['=', 'a.delete_flag', 0], ['=', 'b.delete_flag', 0], ['=', 'c.delete_flag', 0], ['=', 'a.system', 2], ['=', 'a.cms_cate_id', $config['cms_id']], ['!=', 'b.category_id', 1]];
- $select = [
- 'b.pro_cate_id',
- 'b.pro_cate_name',
- 'b.show_price',
- 'show_img' => new Expression("CONCAT(b.show_img,'.min',RIGHT(b.show_img,LOCATE('.', REVERSE(b.show_img))))"),
- 'b.original_price',
- 'b.category_id',
- 'c.category_name',
- 'comment_count' => new Expression('(select count(id) from prod_comment where prod_id=b.pro_cate_id)'),
- 'b.sales_count',
- 'b.star'
- ];
- $result = self::find()->select($select)
- ->from(self::tableName() . ' a')
- ->innerJoin(ProdCategory::tableName() . ' b', 'b.pro_cate_id = a.prod_cate_id')
- ->leftJoin(BaseCategory::tableName() . ' c', 'c.category_id = b.category_id')
- ->where($where)
- ->groupBy('a.prod_cate_id')
- ->orderBy('a.show_sort DESC,a.prod_cate_id')
- ->limit($config['cnt'])
- ->asArray()
- ->all();
- foreach ($result as &$v) {
- $v['show_price'] = $this->dealFloat($v['show_price']);
- }
- return $result;
- }
-
-
- public function getShowProdList($prodIds)
- {
- $where = [
- 'and',
- ['=', 'b.delete_flag', 0],
- ['=', 'c.delete_flag', 0],
- ['!=', 'b.category_id', 1],
- ['in', 'b.pro_cate_id', explode(",", $prodIds)]
- ];
- $select = [
- 'b.pro_cate_id',
- 'b.pro_cate_name',
- 'b.show_price',
- 'show_img' => new Expression("CONCAT(b.show_img,'.min',RIGHT(b.show_img,LOCATE('.', REVERSE(b.show_img))))"),
- 'b.original_price',
- 'b.category_id',
- 'c.category_name',
- 'comment_count' => new Expression('(select count(id) from prod_comment where prod_id=b.pro_cate_id)'),
- 'b.sales_count',
- 'b.star'
- ];
- $result = self::find()->select($select)
- ->from(ProdCategory::tableName() . ' b')
- ->leftJoin(BaseCategory::tableName() . ' c', 'c.category_id = b.category_id')
- ->where($where)
- ->groupBy('b.pro_cate_id')
- ->orderBy('b.pro_cate_id DESC')
- ->asArray()
- ->all();
- foreach ($result as &$v) {
- $v['show_price'] = $this->dealFloat($v['show_price']);
- }
- return $result;
- }
-
- /**
- * Des:获取门票数据列表
- * Name: getCatCold
- * @param $param
- * @return array
- * @author 孙彤
- */
- public function getProdForDestination($param)
- {
- $select = [
- 'b.prod_cate_id',
- 'd.category_name',
- 'c.pro_cate_name',
- 'c.star',
- 'c.prod_des',
- 'c.category_id',
- 'c.show_price',
- 'c.original_price',
- 'c.show_img',
- 'c.sales_count',
- ];
- $where = [
- 'and',
- ['=', 'b.cms_cate_id', $param['cms_category_id']],
- ['=', 'c.delete_flag', 0]
- ];
- if (empty($param['prod_name']) == false) {
- $where[] = ['like', 'c.pro_cate_name', $param['prod_name']];
- }
- $list = self::find()->select($select)
- ->from(self::tableName() . ' b')
- ->innerJoin(CmsCategory::tableName() . ' a', 'b.cms_cate_id=a.cms_category_id')
- ->innerJoin(ProdCategory::tableName() . ' c', 'c.pro_cate_id = b.prod_cate_id')
- ->innerJoin(BaseCategory::tableName() . ' d', 'c.category_id=d.category_id')
- ->where($where)
- ->orderBy('b.show_sort DESC')
- ->asArray()
- ->all();
- if (empty($list['0'])) {
- return [];
- } else {
- foreach ($list as &$v) {
- $v['show_price'] = $this->dealFloat($v['show_price']);
- $v['original_price'] = $this->dealFloat($v['original_price']);
- }
- }
- return $list;
- }
-
-
- /**
- * Function Description:根据cms_category_id获取当地玩乐一日游信息
- * Function Name: getOneDayTrip
- * @param $categoryId
- * @return array|ActiveRecord[]
- * @author 田玲菲
- */
- public function getOneDayTrip($categoryId)
- {
- $select = [
- 'b.prod_cate_id',
- 'd.category_name',
- 'c.pro_cate_name',
- 'c.star',
- 'c.prod_des',
- 'c.category_id',
- 'c.show_price',
- 'c.original_price',
- 'show_img' => new Expression('concat(c.show_img,".min.jpg")'),
- 'c.sales_count',
- 'comment_count' => new Expression('(select count(id) from prod_comment where prod_id=c.pro_cate_id)'),
- ];
- $where = [
- 'and',
- ['=', 'b.cms_cate_id', $categoryId],
- ['=', 'c.delete_flag', 0],
- ['=', 'd.category_id', 4]
- ];
- $list = self::find()->select($select)
- ->from(self::tableName() . ' b')
- ->innerJoin(CmsCategory::tableName() . ' a', 'b.cms_cate_id=a.cms_category_id and a.system = 2')
- ->innerJoin(ProdCategory::tableName() . ' c', 'c.pro_cate_id = b.prod_cate_id')
- ->innerJoin(BaseCategory::tableName() . ' d', 'c.category_id=d.category_id')
- ->where($where)
- ->orderBy('b.show_sort DESC')
- ->asArray()
- ->all();
- if (empty($list['0'])) {
- return [];
- } else {
- foreach ($list as &$v) {
- $v['show_price'] = $this->dealFloat($v['show_price']);
- $v['original_price'] = $this->dealFloat($v['original_price']);
- }
- }
- return $list;
- }
-
-
- /**
- * Function Description:根据cms_category_id获取当地玩乐门票信息
- * Function Name: getTicket
- * @param $categoryId
- * @return array|ActiveRecord[]
- * @author 田玲菲
- */
- public function getTicket($categoryId)
- {
- $food_list = self::find()->select('prod_cate_id')->from(self::tableName())
- ->where(['and', ['=', 'delete_flag', 0], ['=', 'system', 2], ['=', 'cms_cate_id', 127]])->indexBy('prod_cate_id')->asArray()->all();
- $food_list = array_keys($food_list);
- $select = [
- 'b.prod_cate_id',
- 'd.category_name',
- 'c.pro_cate_name',
- 'c.star',
- 'c.prod_des',
- 'c.category_id',
- 'c.show_price',
- 'c.original_price',
- 'show_img' => new Expression('concat(c.show_img,".min.jpg")'),
- 'c.sales_count',
- 'comment_count' => new Expression('(select count(id) from prod_comment where prod_id=c.pro_cate_id)'),
- ];
- $where = [
- 'and',
- ['=', 'b.cms_cate_id', $categoryId],
- ['=', 'c.delete_flag', 0],
- ['=', 'd.category_id', 2],
- ['!=', 'a.cms_category_id', 127],
- ['not in', 'b.prod_cate_id', $food_list]
- ];
- $list = self::find()->select($select)
- ->from(self::tableName() . ' b')
- ->innerJoin(CmsCategory::tableName() . ' a', 'b.cms_cate_id=a.cms_category_id and a.system = 2')
- ->innerJoin(ProdCategory::tableName() . ' c', 'c.pro_cate_id = b.prod_cate_id')
- ->innerJoin(BaseCategory::tableName() . ' d', 'c.category_id=d.category_id')
- ->where($where)
- ->orderBy('b.show_sort DESC')
- ->asArray()
- ->all();
- if (empty($list['0'])) {
- return [];
- } else {
- foreach ($list as &$v) {
- $v['show_price'] = $this->dealFloat($v['show_price']);
- $v['original_price'] = $this->dealFloat($v['original_price']);
- }
- }
- return $list;
- }
-
-
- /**
- * Function Description:根据cms_category_id获取当地玩乐美食娱乐的列表
- * Function Name: getFoodList
- * @param $categoryId
- * @return array|ActiveRecord[]
- * @author 田玲菲
- */
- public function getFoodList($categoryId)
- {
- $cmcCategory = new CmsCategory();
- $foodId = $cmcCategory->getFoodId();
- if (!isset($foodId['cms_category_id'])) {
- $foodId['cms_category_id'] = 0;
- }
- $select = [
- 'b.prod_cate_id',
- 'd.category_name',
- 'c.pro_cate_name',
- 'c.star',
- 'c.prod_des',
- 'c.category_id',
- 'c.show_price',
- 'c.original_price',
- 'show_img' => new Expression('concat(c.show_img,".min.jpg")'),
- 'c.sales_count',
- 'comment_count' => new Expression('(select count(id) from prod_comment where prod_id=c.pro_cate_id)'),
- ];
- $where = [
- 'and',
- ['=', 'b.cms_cate_id', $categoryId],
- ['=', 'c.delete_flag', 0],
- ];
- $list = self::find()->select($select)
- ->from(self::tableName() . ' b')
- ->innerJoin(self::tableName() . ' e', 'e.prod_cate_id = b.prod_cate_id and e.cms_cate_id = ' . $foodId['cms_category_id'])
- // ->innerJoin(self::tableName() . ' e')
- ->innerJoin(CmsCategory::tableName() . ' a', 'b.cms_cate_id=a.cms_category_id and a.system = 2')
- ->innerJoin(ProdCategory::tableName() . ' c', 'c.pro_cate_id = b.prod_cate_id')
- ->innerJoin(BaseCategory::tableName() . ' d', 'c.category_id=d.category_id')
- ->where($where)
- ->orderBy('b.show_sort DESC')
- ->asArray()
- ->all();
- if (empty($list['0'])) {
- return [];
- } else {
- foreach ($list as &$v) {
- $v['show_price'] = $this->dealFloat($v['show_price']);
- $v['original_price'] = $this->dealFloat($v['original_price']);
- }
- }
- return $list;
- }
-
- /**
- * 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;
- }
- }
|