Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

253 rader
6.8 KiB

  1. <?php
  2. /**
  3. * 数据库表类 prod_comment
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm LoginController.php
  13. * Create By 2017/06/28 10:12 $
  14. */
  15. namespace common\models;
  16. use yii\db\ActiveRecord;
  17. use yii\db\Exception;
  18. use yii\db\Expression;
  19. /**
  20. * 数据库表类 prod_comment.
  21. * @property integer $id
  22. * @property integer $travel_id
  23. * @property integer $prod_id
  24. * @property integer $star
  25. * @property string $title
  26. * @property string $content
  27. * @property string $u_name
  28. * @property integer $u_id
  29. * @property string $create_time
  30. * @property integer $look_over
  31. * @property integer $type
  32. * @property integer $comment_id
  33. * @property integer $parent_id
  34. * @property integer $cancel_flag
  35. */
  36. class ProdComment extends ActiveRecord
  37. {
  38. /**
  39. * @inheritdoc
  40. */
  41. public static function tableName()
  42. {
  43. return 'prod_comment';
  44. }
  45. /**
  46. * @inheritdoc
  47. */
  48. public function rules()
  49. {
  50. return [
  51. [['travel_id', 'star', 'u_id', 'look_over', 'type', 'comment_id', 'parent_id', 'cancel_flag'], 'integer'],
  52. [['title', 'content'], 'required'],
  53. [['content'], 'string'],
  54. [['create_time'], 'safe'],
  55. [['prod_id'], 'string', 'max' => 255],
  56. [['title'], 'string', 'max' => 30],
  57. [['u_name'], 'string', 'max' => 100],
  58. ];
  59. }
  60. /**
  61. * @inheritdoc
  62. */
  63. public function attributeLabels()
  64. {
  65. return [
  66. 'id' => 'ID',
  67. 'travel_id' => 'Travel ID',
  68. 'prod_id' => 'Prod ID',
  69. 'star' => 'Star',
  70. 'title' => 'Title',
  71. 'content' => 'Content',
  72. 'u_name' => 'U Name',
  73. 'u_id' => 'U ID',
  74. 'create_time' => 'Create Time',
  75. 'look_over' => 'Look Over',
  76. 'type' => 'Type',
  77. 'comment_id' => 'Comment ID',
  78. 'parent_id' => 'Parent ID',
  79. 'cancel_flag' => 'Cancel Flag',
  80. ];
  81. }
  82. /**
  83. * Des:获取产品的评论列表
  84. * Name: getListByProdId
  85. * @param $param
  86. * @return array
  87. * @author 倪宗锋
  88. */
  89. public function getListByProdId($param)
  90. {
  91. $offset = (intval($param['page']) - 1) * $param['page_size'];//从第几条开始读取
  92. //要查询的字段
  93. $select = [
  94. 'a.id',
  95. 'a.star',
  96. 'a.content',
  97. 'a.create_time',
  98. 'u_name' => new Expression("CONCAT(LEFT(a.u_name,3),'*****',RIGHT(a.u_name,3))"),
  99. 'head_img' => new Expression("ifnull(b.head_img,'')")
  100. ];
  101. $list = self::find()->select($select)
  102. ->from(self::tableName() . ' a')
  103. ->innerJoin(ShUser::tableName() . ' b', 'a.u_id=b.uid')
  104. ->where(new Expression('FIND_IN_SET(:prod_id, a.prod_id)'))
  105. ->addParams([':prod_id' => $param['pro_cate_id']])
  106. ->limit($param['page_size'])
  107. ->offset($offset)
  108. ->orderBy('a.create_time desc')
  109. ->asArray()
  110. ->all();
  111. if (empty($list['0'])) {
  112. return [];
  113. }
  114. return $list;
  115. }
  116. /**
  117. * Des:获取行程的评论数
  118. * Name: getTravelByTravelId
  119. * @param $param
  120. * @return int
  121. * @author 孙彤
  122. */
  123. public function getTravelByTravelId($param)
  124. {
  125. $result = self::find()->select('count(1)')->from(self::tableName())->where(['=', 'travel_id', $param['travel_id']])
  126. ->asArray()
  127. ->one();
  128. return $result['count(1)'];
  129. }
  130. /**
  131. * Des:添加评价
  132. * Name: addComment
  133. * @param $param
  134. * @return bool
  135. * @author 倪宗锋
  136. */
  137. public function addComment($param)
  138. {
  139. $attr = [
  140. 'travel_id' => $param['travel_id'],
  141. 'prod_id' => $param['prod_id'],
  142. 'star' => intval($param['star']),
  143. 'content' => $param['content'],
  144. 'title'=> '行程评价',
  145. 'u_name' => $param['u_name'],
  146. 'u_id' => $param['u_id']
  147. ];
  148. $self = clone $this;
  149. $self->setAttributes($attr);
  150. $flag = $self->save();
  151. return $flag;
  152. }
  153. public function addCommentone($param)
  154. {
  155. $attr = [
  156. // 'travel_id' => $param['travel_id'],
  157. 'prod_id' => $param['prod_id'],
  158. 'star' => $param['star'],
  159. 'content' => $param['content'],
  160. 'title'=> '行程评价',
  161. 'u_name' => $param['u_name'],
  162. 'u_id' => $param['u_id']
  163. ];
  164. $self = clone $this;
  165. $self->setAttributes($attr);
  166. $flag = $self->save();
  167. return $flag;
  168. }
  169. //查询数据
  170. public function selectComment($page='' ,$size='')
  171. {
  172. $select=[
  173. // 'travel_id' => 'Travel ID',
  174. 'prod_id' ,
  175. 'star' ,
  176. 'title' ,
  177. 'content' ,
  178. // 'u_name' => 'U Name',
  179. 'u_id',
  180. 'create_time'
  181. //
  182. ];
  183. if($page!=''&&$size!=''){
  184. $offset=($page - 1) * $size;
  185. $list = self::find()->select($select)
  186. ->limit($size)
  187. ->offset($offset)
  188. ->asArray()
  189. ->all();
  190. }else {
  191. $list = self::find()->select($select)
  192. ->asArray()
  193. ->all();
  194. }
  195. // var_dump($list);
  196. if (empty($list)) {
  197. return [];
  198. }
  199. return $list;
  200. }
  201. public function getCommentList($param){
  202. $offset = ($param['current_page'] - 1) * $param['page_size'];
  203. $select = [
  204. 'id' => 'ID',
  205. 'travel_id',
  206. 'prod_id',
  207. 'star',
  208. 'title',
  209. 'content',
  210. 'u_name',
  211. 'u_id',
  212. 'create_time',
  213. 'look_over',
  214. 'type',
  215. 'comment_id',
  216. 'parent_id',
  217. 'cancel_flag',
  218. '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))")
  219. ];
  220. $list=self::find()->select($select)
  221. ->offset($offset)
  222. ->limit((int)$param['page_size'])
  223. ->asArray()
  224. ->all();
  225. $result = self::find()->select('count(1) as count')
  226. ->from(self::tableName())
  227. ->asArray()
  228. ->one();
  229. $result = $result['count'];
  230. return ['list' => $list, 'count' => $result];
  231. }
  232. }