123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace app\api\controller;
- use app\common\model\GoodsOrder;
- use app\common\model\PlatformMessage;
- use app\common\model\PlatformReadLog;
- use app\common\model\SeckillActivity;
- use app\common\model\SeckillGoods;
- use app\common\model\StoreGoodsItem;
- use app\common\model\UserMessage;
- use library\tools\Data;
- /**
- * @title 消息管理
- * @controller Message
- * @group base
- */
- class Message extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::checkLogin();
- }
- /**
- * @title 获取视频平台消息
- * @desc 获取视频平台消息
- * @author qc
- * @url /api/Message/getVideoPlatformNews
- * @method GET
- * @return name:content type:string default:-- desc:标题
- * @return name:is_read type:string default:-- desc:是否已读(0否)
- */
- public function getVideoPlatformNews()
- {
- $video = PlatformMessage::where(['type'=>1])->order('id desc')->find();
- if(!$video)$this->success('ok',['detail'=>['content'=>'','is_read'=>0]]);
- $detail = $video->toArray();
- $detail['is_read'] = PlatformReadLog::where(['user_id'=>$this->user_id,'type'=>1,'relation_id'=>$detail['id']])->count();
- $this->success('ok',['detail'=>$detail]);
- }
- /**
- * @title 获取交易物流消息(菜单)
- * @desc 获取交易物流消息
- * @author qc
- * @url /api/Message/getExpressMessageMenu
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:create_at type:string default:-- desc:时间
- * @return name:content type:string default:-- desc:内容
- * @return name:is_read type:int default:-- desc:是否已读(0否)
- */
- public function getExpressMessageMenu()
- {
- $where[] = ['user_id','=',$this->user_id];
- $where[] = ['type_id','in','2,3'];
- $detail = UserMessage::where($where)->order('id desc')->find();
- $this->success('ok',['detail'=>$detail ? $detail->toArray():['content'=>'','is_read'=>0]]);
- }
- /**
- * @title 获取交易物流消息(内页列表)
- * @desc 获取交易物流消息(内页列表)
- * @author qc
- * @url /api/Message/getExpressMessageList
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @return name:create_at type:string default:-- desc:时间
- * @return name:content type:string default:-- desc:内容
- * @return name:type_id type:int default:-- desc:类型[2发货通知,3收货通知]
- * @return name:order_info type:array default:-- desc:订单信息
- * @return name:order_info.id type:int default:-- desc:订单id
- * @return name:order_info.express_send_no type:string default:-- desc:发货单号
- * @return name:order_info.order_no type:string default:-- desc:订单号
- * @return name:goods_list type:array default:-- desc:商品列表
- * @return name:goods_list.goods_name type:string default:-- desc:商品名
- * @return name:goods_list.cover type:string default:-- desc:商品图
- * @return name:goods_list.goods_spec type:string default:-- desc:商品规格
- */
- public function getExpressMessageList()
- {
- $where[] = ['user_id','=',$this->user_id];
- $where[] = ['type_id','in','2,3'];
- $list = UserMessage::where($where)
- ->limit($this->off_set,$this->page_num)
- ->order('id desc')
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['goods_list'] = StoreGoodsItem::field('goods_name,cover,goods_spec')->where(['order_id'=>$v['relation_id']])->select()->toArray();
- $v['order_info'] = GoodsOrder::field('id,order_no,express_send_no')->where('id',$v['relation_id'])->find()->toArray();
- }
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取活动平台消息(菜单)
- * @desc 获取活动平台消息(菜单)
- * @author qc
- * @url /api/Message/getActivityNews
- * @method GET
- * @return name:content type:string default:-- desc:标题
- * @return name:is_read type:string default:-- desc:是否已读(0否)
- */
- public function getActivityNews()
- {
- $detail = PlatformMessage::where(['type'=>2])->order('id desc')->find();
- if(!$detail)$this->success('ok',['detail'=>['content'=>'','is_read'=>0]]);
- $detail = $detail->toArray();
- $detail['is_read'] = PlatformReadLog::where(['user_id'=>$this->user_id,'type'=>2,'relation_id'=>$detail['id']])->count();
- $this->success('ok',['detail'=>$detail]);
- }
- /**
- * @title 获取活动平台消息(内页)
- * @desc 获取活动平台消息(内页)
- * @author qc
- * @url /api/Message/getActivityNewsList
- * @method GET
- * @return name:title type:string default:-- desc:标题
- * @return name:cover type:string default:-- desc:封面
- * @return name:start_time type:string default:-- desc:活动开始时间
- * @return name:end_time type:string default:-- desc:活动结束时间
- * @return name:goods_list type:array default:-- desc:商品列表(最多查3个)
- * @return name:goods_list.name type:string default:-- desc:商品名
- * @return name:goods_list.cover type:string default:-- desc:商品图
- */
- public function getActivityNewsList()
- {
- $sel_where = [];
- $sel_where[] = ['is_deleted','=',0];
- $sel_where[] = ['status','=',1];
- $list = SeckillActivity::where($sel_where)
- ->field('id,title,cover,start_time,end_time')
- ->order('id desc')->limit(0,5)->select()->toArray();
- if(!empty($list)){
- $relation_id = PlatformMessage::where(['type'=>2])->max('id');// 最新的一条视频推荐
- Data::save('PlatformReadLog',['user_id'=>$this->user_id,'type'=>2,'relation_id'=>$relation_id,'create_at'=>date('Y-m-d H:i:s')],'user_id',['user_id'=>$this->user_id,'type'=>2,'relation_id'=>$relation_id]);
- }
- foreach ($list as &$v){
- $v['goods_list'] = SeckillGoods::field('g.id,g.name,g.cover')
- ->alias('s')
- ->leftJoin('StoreGoods g','g.id = s.goods_id')
- ->order('s.id desc')
- ->limit(0,3)
- ->select()->toArray();
- }
- $this->success('ok',['list'=>$list]);
- }
- }
|