Omessages.php 2.7 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use think\Validate;
/**
 * 订单消息接口**
 */
class Omessages extends Api
{
    protected  $noNeedLogin = [];
    protected $noNeedRight = '*';
    protected $user_id = '';//token存贮user_id
    protected $normal = '';//商品正常状态,1:下架
    public function _initialize()
    {
        parent::_initialize();
        $this->normal = config('site.goods_status');
        $this->user_id = $this->auth->getUserId();
    }

    /**
     * @ApiTitle    (我的订单消息列表)
     * @ApiSummary  (我的订单消息列表)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/omessages/orderMessageList)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="page", type="integer", required=true, description="分页页码")
     * @ApiReturn ({
            "code": 1,
            "msg": "成功",
            "time": "1553777266",
            "data":[
                {
                    "id": 1,
                    "order_sn": "gc_155358608729209200",//订单号
                    "status": 3,//订单状态 0:待付款 1:待收货 2:待评价 3:已完成
                    "title": "我的垃圾商品1",//商品名称
                    "username": "风起时呀"//收货人
                    "is_read":0,//0:未读 1:已读
                },
                {
                    "id": 3,
                    "order_sn": "gc_155358608729212300",
                    "status": 0,
                    "title": "废品商品2",
                    "username": "风起时呀",
                    "is_read":0,//0:未读 1:已读
                }
            ]
            })
     */
    public function orderMessageList(){
        if($this->request->isGet()){
            $page = $this->request->get('page');//分页页码
            $limit = config('site.page_limit');//分页限制数量
            $rule = config('site.gift_pages');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check(['page'=>$page])) {
                $this->error($validate->getError());
            }
            $data = Db::table('gc_porder')
                ->alias('o')
                ->join('gc_product p','o.p_id = p.id','LEFT')
                ->join('gc_user u','o.s_uid = u.id','LEFT')
                ->where(['o.s_uid'=>$this->user_id,'p.status'=>$this->normal,'u.status'=>'normal'])
                ->page($page,$limit)
                ->field('o.id,o.order_sn,o.status,p.title,u.username,o.is_read')
                ->select();
            $this->success('成功',$data);
        }else{
            $this->error('请求方式错误');
        }
    }

}