You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
5.0 KiB
177 lines
5.0 KiB
<?php
|
|
|
|
namespace app\mall\model;
|
|
|
|
use app\base\model\user\UserInfo;
|
|
use think\model\concern\SoftDelete;
|
|
|
|
class MallOrder extends Base
|
|
{
|
|
use SoftDelete;
|
|
|
|
protected $type = [
|
|
'pay_time' => 'timestamp',
|
|
'remind_time' => 'timestamp',
|
|
'express_time' => 'timestamp',
|
|
'confirm_time' => 'timestamp',
|
|
'review_time' => 'timestamp',
|
|
'cancel_time' => 'timestamp',
|
|
'user_delete_time' => 'timestamp',
|
|
];
|
|
|
|
/**
|
|
* 获取状态名称
|
|
* @date 2021-03-01
|
|
*/
|
|
public function getStatusTextAttr($value, $data)
|
|
{
|
|
$status_text = [
|
|
1 => '待支付',
|
|
2 => '待发货',
|
|
3 => '待收货',
|
|
4 => '待评价',
|
|
5 => '已完成',
|
|
6 => '退款中',
|
|
7 => '已退款',
|
|
8 => '已取消',
|
|
];
|
|
return $status_text[$data['status']];
|
|
}
|
|
|
|
/**
|
|
* 获取付款方式名称
|
|
* @date 2021-03-01
|
|
*/
|
|
public function getPayTypeTextAttr($value, $data)
|
|
{
|
|
$pay_type_text = [
|
|
0 => '',
|
|
1 => '微信支付',
|
|
2 => '支付宝支付',
|
|
3 => '余额支付'
|
|
];
|
|
return $pay_type_text[$data['pay_type']];
|
|
}
|
|
|
|
/**
|
|
* 通过last_id获取我的订单列表
|
|
* @param array $where 查询条件
|
|
* @param array $where_order_product 关联订单产品表查询条件
|
|
* @param string $field 查询字段
|
|
* @date 2022-09-28
|
|
*/
|
|
public function listMyOrderByLastId($where = [], $where_order_product = [], $field = '*')
|
|
{
|
|
// 排序条件
|
|
$order = 'id desc';
|
|
// 每页加载条数
|
|
$per_page_number = 10;
|
|
|
|
$data_list = $this->with(['mallOrderProduct'])
|
|
->hasWhere('mallOrderProduct', $where_order_product, $field)
|
|
->where($where)->order($order)
|
|
->limit($per_page_number)->select()->each(function ($item) {
|
|
$item['status_text'] = $item->status_text;
|
|
|
|
// 释放无用数据
|
|
foreach($item['mallOrderProduct'] as $k=>&$v){
|
|
unset($v['refund_total_number']);
|
|
unset($v['refund_cur_number']);
|
|
unset($v['total_price']);
|
|
}
|
|
return $item;
|
|
});
|
|
|
|
return $data_list;
|
|
}
|
|
|
|
/**
|
|
* 获取单条商品
|
|
* @param array $where 查询条件
|
|
* @param string $field 查询字段
|
|
* @date 2022-09-28
|
|
*/
|
|
public function getMyOrder($where = [], $field = '*')
|
|
{
|
|
// 排序条件
|
|
$order = 'id desc';
|
|
|
|
$data = $this->with(['mallOrderProduct'])
|
|
->field($field)->where($where)->order($order)
|
|
->find();
|
|
|
|
if(isset($data['status'])){
|
|
// 状态显示文案
|
|
$data['status_text'] = $data->status_text;
|
|
}
|
|
|
|
if(isset($data['pay_type'])){
|
|
// 支付方式显示文案
|
|
$data['pay_type_text'] = $data->pay_type_text;
|
|
}
|
|
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
/**
|
|
* 后台列表
|
|
* @param $where
|
|
* @param $search
|
|
* @param string $field
|
|
* @param string $order
|
|
* @param int $per_page_number
|
|
* @return \think\Paginator
|
|
*/
|
|
public function getMemberList($where, $search, $field = "*", $order = '', $per_page_number = 10)
|
|
{
|
|
if (empty($order)) {
|
|
if ($this->getPk() != null) {
|
|
$order = $this->getPk() . ' desc';
|
|
} else {
|
|
$order = 'id desc';
|
|
}
|
|
}
|
|
if (isset($where['product_name'])) {
|
|
$product_name = $where['product_name'];
|
|
unset($where['product_name']);
|
|
$where = $this->whereChange($where);
|
|
return $this::hasWhere('MallOrderProduct', [['product_name', 'like', '%' . $product_name . '%']])->where($where)->field($field)->order($order)->paginate([
|
|
'list_rows' => $per_page_number,
|
|
'page' => array_key_exists("page", $search) ? (string)$search['page'] : "1",
|
|
'query' => $search
|
|
], false);
|
|
} else {
|
|
return $this->where($where)->field($field)->order($order)->paginate([
|
|
'list_rows' => $per_page_number,
|
|
'page' => array_key_exists("page", $search) ? (string)$search['page'] : "1",
|
|
'query' => $search
|
|
], false);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 下单人信息
|
|
*/
|
|
public function userInfo()
|
|
{
|
|
return $this->hasOne(UserInfo::class, 'user_id', 'user_id')->bind([
|
|
'nick_name'
|
|
]);
|
|
}
|
|
|
|
|
|
/**
|
|
* 【关联模型】一对多关联订单产品
|
|
* @date 2021-09-28
|
|
*/
|
|
public function mallOrderProduct()
|
|
{
|
|
return $this->hasMany('MallOrderProduct', 'order_id', 'id')
|
|
->field('id,order_id,product_id,product_id,product_name,product_cover_img,is_product_spec_open,
|
|
product_sku,product_sku_name,product_price,number,refund_total_number,refund_cur_number,total_price');
|
|
}
|
|
|
|
|
|
} |