| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- namespace app\backend\modules\goods\models;
- use app\common\models\Order;
- use Illuminate\Support\Facades\DB;
- /**
- * Created by PhpStorm.
- * Author: 芸众商城 www.yunzshop.com
- * Date: 2017/2/27
- * Time: 下午5:10
- */
- class Comment extends \app\common\models\Comment
- {
- static protected $needLog = true;
- /**
- * @param $search
- * @param $comment_type
- * @return mixed
- */
- public static function getComments($search,$comment_type='')
- {
- $commentModdel = self::uniacid();
- if ($search['keyword']) {
- $commentModdel->whereHas('goods', function ($query) use ($search) {
- return $query->searchLike($search['keyword']);
- });
- }
- if ($search['order_sn']){
- $commentModdel->whereHas('hasOneOrder', function ($query) use ($search) {
- return $query->where('order_sn',$search['order_sn']);
- });
- }
- $commentModdel->with([
- 'goods' => function ($query) {
- return $query->select(['id', 'title', 'thumb','plugin_id']);
- },
- 'hasOneOrder' => function ($query) use ($search) {
- return $query->select('id','order_sn');
- }
- ]);
- if (!$comment_type) {
- $commentModdel->where('comment_id', '0');
- }
- if ($search['fade'] == 1) {
- $commentModdel->where('uid', '>', '0');
- } elseif ($search['fade'] == 2) {
- $commentModdel->where('uid', '=', '0');
- }
- if ($search['searchtime']) {
- if ($search['starttime'] != '请选择' && $search['endtime'] != '请选择') {
- $range = [$search['starttime'], $search['endtime']];
- $commentModdel->whereBetween('created_at', $range);
- }
- }
- $commentModdel->orderBy('created_at', 'desc');
- return $commentModdel;
- }
- /**
- * @param $id
- * @return mixed
- */
- public static function getComment($id)
- {
- return self::with(['hasManyReply'=>function ($query) {
- return $query->where('type', 2)
- ->orderBy('created_at', 'asc');
- }])
- ->with(['hasManyAppend' => function ($query) {
- return $query->where('type', 3)
- ->orderBy('created_at', 'asc');
- }])
- ->where('id', $id);
- }
- /**
- * @param $comment
- * @return bool
- */
- public static function saveComment($comment)
- {
- return self::insert($comment);
- }
- /**
- * @param $comment_id
- * @return mixed
- */
- public static function getReplysByCommentId($comment_id)
- {
- return self::where('comment_id', $comment_id)
- ->orderBy('created_at', 'asc')
- ->get();
- }
- /**
- * @param $id
- * @return mixed
- */
- public static function daletedComment($id)
- {
- return self::where('id', $id)
- ->delete();
- }
- /**
- *
- * @return mixed
- */
- public function goods()
- {
- return $this->belongsTo(\app\common\models\Goods::class);
- }
- /**
- * 定义字段名
- * 可使
- * @return array
- */
- public function atributeNames()
- {
- return [
- 'goods_id' => '评论商品',
- 'content' => '评论内容',
- ];
- }
- /**
- * 字段规则
- * @return array
- */
- public function rules()
- {
- return [
- 'goods_id' => 'required',
- 'content' => 'required'
- ];
- }
- public function hasOneOrder()
- {
- return $this->hasOne(\app\common\models\Order::class,'id','order_id');
- }
- }
|