HaniBlindBox/server/php/app/common/model/FFOrders.php
2026-01-01 20:46:07 +08:00

150 lines
3.8 KiB
PHP

<?php
namespace app\common\model;
use app\common\model\Base;
use app\common\model\User;
use think\Model;
class FFOrders extends Base
{
// 设置当前模型对应的完整数据表名称
protected $table = 'ff_orders';
// 设置主键
protected $pk = 'order_id';
/**
* 获取列表
*/
public static function getList($where = [], $field = '*', $order = 'order_id desc', $pageSize = "15")
{
$list = self::where($where)
->field($field)
->order($order)
->paginate(['list_rows' => $pageSize, 'query' => request()->param()]);
$page = $list->render();
$data['list'] = $list->toArray()['data'];
$data['count'] = $list->total();
$data['last_page'] = $list->toArray()['last_page'];
$data['page'] = $page;
return $data;
}
/**
* 获取列表 不分页
*/
public static function getAllList($where = [], $field = '*', $order = 'order_id desc', $limit = '0')
{
$data = self::where($where)
->field($field)
->order($order)
->limit($limit)
->select();
return $data;
}
/**
* 获取单条数据
*/
public static function getInfo($where = [], $field = '*')
{
$data = self::where($where)
->field($field)
->find();
return $data;
}
/**
* 获取关联用户信息
*/
public function getUserInfoAttr($value, $data)
{
$user_info = User::field('nickname,headimg,mobile')->where(['id' => $data['user_id']])->find();
return $user_info;
}
/**
* 订单状态获取器
*/
public function getOrderStatusTextAttr($value, $data)
{
$status = [
0 => '待支付',
1 => '已支付待发货',
2 => '已发货',
3 => '已完成',
4 => '已关闭',
5 => '已取消'
];
return isset($status[$data['order_status']]) ? $status[$data['order_status']] : '未知状态';
}
/**
* 支付状态获取器
*/
public function getPayStatusTextAttr($value, $data)
{
$status = [
0 => '未支付',
1 => '支付中',
2 => '已支付'
];
return isset($status[$data['pay_status']]) ? $status[$data['pay_status']] : '未知状态';
}
/**
* 配送状态获取器
*/
public function getShippingStatusTextAttr($value, $data)
{
$status = [
0 => '未发货',
1 => '已发货',
2 => '已收货'
];
return isset($status[$data['shipping_status']]) ? $status[$data['shipping_status']] : '未知状态';
}
/**
* 支付方式获取器
*/
public function getPaymentTypeTextAttr($value, $data)
{
$types = [
1 => '支付宝',
2 => '微信',
3 => '银联'
];
return isset($types[$data['payment_type']]) ? $types[$data['payment_type']] : '未知方式';
}
/**
* 订单来源获取器
*/
public function getSourceTextAttr($value, $data)
{
$sources = [
1 => 'PC',
2 => 'APP',
3 => '小程序',
4 => 'H5'
];
return isset($sources[$data['source']]) ? $sources[$data['source']] : '未知来源';
}
/**
* 发票类型获取器
*/
public function getInvoiceTypeTextAttr($value, $data)
{
if (empty($data['invoice_type'])) {
return '';
}
$types = [
1 => '个人',
2 => '企业'
];
return isset($types[$data['invoice_type']]) ? $types[$data['invoice_type']] : '未知类型';
}
}