|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php
- /**
- * 数据库表类 prod_comment
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm LoginController.php
- * Create By 2017/06/28 10:12 $
- */
-
- namespace common\models;
-
- use yii\db\ActiveRecord;
- use yii\db\Exception;
- use yii\db\Expression;
-
- /**
- * 数据库表类 prod_comment.
- * @property integer $id
- * @property integer $travel_id
- * @property integer $prod_id
- * @property integer $star
- * @property string $title
- * @property string $content
- * @property string $u_name
- * @property integer $u_id
- * @property string $create_time
- * @property integer $look_over
- * @property integer $type
- * @property integer $comment_id
- * @property integer $parent_id
- * @property integer $cancel_flag
- */
- class ProdComment extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'prod_comment';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['travel_id', 'star', 'u_id', 'look_over', 'type', 'comment_id', 'parent_id', 'cancel_flag'], 'integer'],
- [['title', 'content'], 'required'],
- [['content'], 'string'],
- [['create_time'], 'safe'],
- [['prod_id'], 'string', 'max' => 255],
- [['title'], 'string', 'max' => 30],
- [['u_name'], 'string', 'max' => 100],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'travel_id' => 'Travel ID',
- 'prod_id' => 'Prod ID',
- 'star' => 'Star',
- 'title' => 'Title',
- 'content' => 'Content',
- 'u_name' => 'U Name',
- 'u_id' => 'U ID',
- 'create_time' => 'Create Time',
- 'look_over' => 'Look Over',
- 'type' => 'Type',
- 'comment_id' => 'Comment ID',
- 'parent_id' => 'Parent ID',
- 'cancel_flag' => 'Cancel Flag',
- ];
- }
-
- /**
- * Des:获取产品的评论列表
- * Name: getListByProdId
- * @param $param
- * @return array
- * @author 倪宗锋
- */
- public function getListByProdId($param)
- {
- $offset = (intval($param['page']) - 1) * $param['page_size'];//从第几条开始读取
- //要查询的字段
- $select = [
- 'a.id',
- 'a.star',
- 'a.content',
- 'a.create_time',
- 'u_name' => new Expression("CONCAT(LEFT(a.u_name,3),'*****',RIGHT(a.u_name,3))"),
- 'head_img' => new Expression("ifnull(b.head_img,'')")
- ];
- $list = self::find()->select($select)
- ->from(self::tableName() . ' a')
- ->innerJoin(ShUser::tableName() . ' b', 'a.u_id=b.uid')
- ->where(new Expression('FIND_IN_SET(:prod_id, a.prod_id)'))
- ->addParams([':prod_id' => $param['pro_cate_id']])
- ->limit($param['page_size'])
- ->offset($offset)
- ->orderBy('a.create_time desc')
- ->asArray()
- ->all();
- if (empty($list['0'])) {
- return [];
- }
- return $list;
- }
-
- /**
- * Des:获取行程的评论数
- * Name: getTravelByTravelId
- * @param $param
- * @return int
- * @author 孙彤
- */
- public function getTravelByTravelId($param)
- {
- $result = self::find()->select('count(1)')->from(self::tableName())->where(['=', 'travel_id', $param['travel_id']])
- ->asArray()
- ->one();
- return $result['count(1)'];
- }
-
- /**
- * Des:添加评价
- * Name: addComment
- * @param $param
- * @return bool
- * @author 倪宗锋
- */
- public function addComment($param)
- {
- $attr = [
- 'travel_id' => $param['travel_id'],
- 'prod_id' => $param['prod_id'],
- 'star' => intval($param['star']),
- 'content' => $param['content'],
- 'title'=> '行程评价',
- 'u_name' => $param['u_name'],
- 'u_id' => $param['u_id']
- ];
- $self = clone $this;
- $self->setAttributes($attr);
- $flag = $self->save();
- return $flag;
- }
-
-
-
-
-
- public function addCommentone($param)
- {
- $attr = [
- // 'travel_id' => $param['travel_id'],
- 'prod_id' => $param['prod_id'],
- 'star' => $param['star'],
- 'content' => $param['content'],
- 'title'=> '行程评价',
- 'u_name' => $param['u_name'],
- 'u_id' => $param['u_id']
- ];
- $self = clone $this;
- $self->setAttributes($attr);
- $flag = $self->save();
- return $flag;
- }
-
- //查询数据
- public function selectComment($page='' ,$size='')
- {
- $select=[
- // 'travel_id' => 'Travel ID',
- 'prod_id' ,
- 'star' ,
- 'title' ,
- 'content' ,
- // 'u_name' => 'U Name',
- 'u_id',
- 'create_time'
- //
- ];
- if($page!=''&&$size!=''){
- $offset=($page - 1) * $size;
- $list = self::find()->select($select)
- ->limit($size)
- ->offset($offset)
- ->asArray()
- ->all();
- }else {
- $list = self::find()->select($select)
- ->asArray()
- ->all();
- }
- // var_dump($list);
- if (empty($list)) {
- return [];
- }
- return $list;
- }
-
-
-
- public function getCommentList($param){
- $offset = ($param['current_page'] - 1) * $param['page_size'];
-
- $select = [
- 'id' => 'ID',
- 'travel_id',
- 'prod_id',
- 'star',
- 'title',
- 'content',
- 'u_name',
- 'u_id',
- 'create_time',
- 'look_over',
- 'type',
- 'comment_id',
- 'parent_id',
- 'cancel_flag',
- 'prod_name'=>new Expression("(select group_concat(a.pro_cate_name SEPARATOR '<br/>') from prod_category a where find_in_set(a.pro_cate_id,prod_id))")
- ];
- $list=self::find()->select($select)
- ->offset($offset)
- ->limit((int)$param['page_size'])
- ->asArray()
- ->all();
-
- $result = self::find()->select('count(1) as count')
- ->from(self::tableName())
- ->asArray()
- ->one();
- $result = $result['count'];
- return ['list' => $list, 'count' => $result];
- }
-
- }
|