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.
143 lines
3.6 KiB
143 lines
3.6 KiB
<?php
|
|
|
|
namespace app\integral\model;
|
|
|
|
use app\base\model\user\UserInfo;
|
|
use app\integral\model\IntegralConfig;
|
|
use think\model\concern\SoftDelete;
|
|
|
|
class IntegralOrder extends Base
|
|
{
|
|
use SoftDelete;
|
|
|
|
protected $type = [
|
|
'pay_time' => 'timestamp',
|
|
'remind_time' => 'timestamp',
|
|
'express_time' => 'timestamp',
|
|
'confirm_time' => 'timestamp',
|
|
'cancel_time' => 'timestamp',
|
|
'user_delete_time' => 'timestamp',
|
|
];
|
|
|
|
/**
|
|
* 获取状态名称
|
|
* @date 2021-03-01
|
|
*/
|
|
public function getStatusTextAttr($value, $data)
|
|
{
|
|
return INTEGRAL_STATUS[$data['status']]['name'];
|
|
}
|
|
|
|
/**
|
|
* 获取付款方式名称
|
|
* @date 2021-03-01
|
|
*/
|
|
public function getPayTypeTextAttr($value, $data)
|
|
{
|
|
$pay_type_text = [
|
|
0 => '0元单',
|
|
1 => '微信支付',
|
|
2 => '支付宝支付',
|
|
3 => '余额支付',
|
|
4 => '付呗微信',
|
|
5 => '付呗支付宝',
|
|
];
|
|
return $pay_type_text[$data['pay_type']];
|
|
}
|
|
|
|
/**
|
|
* 获取配送方式名称
|
|
* @date 2021-03-01
|
|
*/
|
|
public function getDeliveryTypeTextAttr($value, $data)
|
|
{
|
|
$delivery_type_text = [
|
|
0 => '无需配送',
|
|
1 => '邮寄',
|
|
2 => '自提'
|
|
];
|
|
return $delivery_type_text[$data['delivery_type']];
|
|
}
|
|
|
|
/**
|
|
* 通过last_id获取我的订单列表
|
|
* @param array $where 查询条件
|
|
* @param string $field 查询字段
|
|
* @date 2022-11-21
|
|
*/
|
|
public function listMyOrderByLastId($where = [], $field = '*')
|
|
{
|
|
// 排序条件
|
|
$order = 'id desc';
|
|
// 每页加载条数
|
|
$per_page_number = 10;
|
|
|
|
$data_list = $this->with(['integralOrderProduct'])
|
|
->where($where)->order($order)->field($field)
|
|
->limit($per_page_number)->select()->each(function ($item) {
|
|
$item['status_text'] = $item->status_text;
|
|
|
|
// 释放无用数据
|
|
foreach ($item['integralOrderProduct'] as $k => &$v) {
|
|
// unset($v['refund_total_number']);
|
|
// unset($v['refund_cur_number']);
|
|
// unset($v['total_price']);
|
|
}
|
|
});
|
|
|
|
return $data_list;
|
|
}
|
|
|
|
/**
|
|
* API-获取商品详情
|
|
* @date 2022-11-21
|
|
*/
|
|
public function getMyOrder($where = [], $field = '*')
|
|
{
|
|
// 排序条件
|
|
$order = 'id desc';
|
|
|
|
$data = $this->with(['integralOrderProduct'])
|
|
->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;
|
|
}
|
|
|
|
if(isset($data['delivery_type'])){
|
|
// 到货方式显示文案
|
|
$data['delivery_type_text'] = $data->delivery_type_text;
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 下单人信息
|
|
* @date 2021-03-01
|
|
*/
|
|
public function userInfo()
|
|
{
|
|
return $this->hasOne(UserInfo::class, 'user_id', 'user_id')->bind(['nick_name']);
|
|
}
|
|
|
|
|
|
/**
|
|
* 一对多关联订单产品
|
|
* @date 2022-11-21
|
|
*/
|
|
public function integralOrderProduct()
|
|
{
|
|
return $this->hasMany('IntegralOrderProduct', 'order_id', 'id')
|
|
->field('id,order_id,product_id,product_name,product_cover_img,product_type,is_product_spec_open,product_sku_name,product_integral,product_price,number');
|
|
}
|
|
|
|
|
|
} |