<?php
/*
 * @Author: taowj 965042433@qq.com
 * @Date: 2023-07-14 14:58:11
 * @LastEditors: taowj 965042433@qq.com
 * @LastEditTime: 2023-07-28 11:13:36
 * @FilePath: \zhupu\application\api\model\OrderModel.php
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2021/11/24
 * Time: 13:44
 */

namespace app\api\model;

use think\Model;
use think\exception\HttpResponseException;
use think\Request;
use think\Response;

class OrderModel extends Model
{



    // 表名
    protected $name = 'order';

    public static function orderlist($where, $page, $pageSize)
    {
        return self::alias('o')
            ->join('user u', 'u.id = o.user_id', 'left')
            ->join('payment_logs pl', 'pl.order_id = o.id', 'left')
            ->join('worship_goods wg','wg.id=o.goods_id','left')
            ->where($where)
            ->page($page)
            ->limit($pageSize)
            ->order('o.createtime desc')
            ->field("o.*,wg.*,FROM_UNIXTIME(o.createtime,'%Y-%m-%d %T') as createtime,FROM_UNIXTIME(o.paytime,'%Y-%m-%d %T') as paytime,u.username,u.username,u.nickname,u.avatar,pl.order_sn,
            CASE WHEN pl.status='1' THEN '待支付'
            WHEN pl.status='2' THEN '已支付'
            WHEN pl.status='3' THEN '已退款' END AS pl_status,
            CASE WHEN pl.pay_way='money' THEN '余额支付'
            WHEN pl.pay_way='weixin' THEN '微信支付'
            WHEN pl.pay_way='alipay' THEN '支付宝支付' END AS pay_way")
            ->select();
    }

    public static function orderdetail($where)
    {
        return self::alias('o')
            ->join('user u', 'u.id = o.user_id', 'left')
            ->join('payment_logs pl', 'pl.order_id = o.id', 'left')
            ->join('worship_goods wg','wg.id=o.goods_id','left')
            ->where($where)
            ->field("o.*,wg.*,FROM_UNIXTIME(o.createtime,'%Y-%m-%d %T') as createtime,FROM_UNIXTIME(o.paytime,'%Y-%m-%d %T') as paytime,u.username,u.username,u.nickname,u.avatar,pl.order_sn,
            CASE WHEN pl.status='1' THEN '待支付'
            WHEN pl.status='2' THEN '已支付'
            WHEN pl.status='3' THEN '已退款' END AS pl_status,
            CASE WHEN pl.pay_way='money' THEN '余额支付'
            WHEN pl.pay_way='weixin' THEN '微信支付'
            WHEN pl.pay_way='alipay' THEN '支付宝支付' END AS pay_way")
            ->find();
    }
}
