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.

108 lines
3.0 KiB

<?php
namespace app\mall\model;
use app\base\model\user\UserInfo;
use think\model\concern\SoftDelete;
class MallOrderRefund extends Base
{
use SoftDelete;
/**
* 类型转换
*/
protected $type = [
'cause_img' => 'serialize',
'arrival_time' => 'timestamp'
];
/**
* 退款状态文案
*/
public function getStatusTextAttr($value, $data)
{
$status_text = [
1 => '待审核',
2 => '已退款',
3 => '已拒绝',
4 => '已撤销'
];
return $status_text[$data['status']];
}
/**
* API-获取产品退还列表
* @date 2021-06-01
*/
public function getAllRefund($where, $field = '*', $order = '', $limit = 0)
{
$primary_key_name = $this->getPk();
if (empty($order)) {
$order = (empty($data[$primary_key_name]) ? 'id' : $data[$primary_key_name]) . ' desc';
}
return $this->field($field)->where($where)->order($order)->limit($limit)->select()->each(function ($item, $key) {
$item['status_text'] = $item->status_text;
$item['create_time_show'] = date("Y.m.d H:i", strtotime($item->create_time)); //申请时间
return $item;
});
}
/**
* API-获取产品退款
* @date 2021-06-01
*/
public function getOneRefund($where = [], $field = '*', $order = '')
{
$primary_key_name = $this->getPk();
if (empty($order)) {
$order = (empty($data[$primary_key_name]) ? 'id' : $data[$primary_key_name]) . ' desc';
}
$array = explode(',', $field);
if ($field != '*') {
if (count($array) <= 1) {
$data = $this->where($where)->order($order)->value($field);
} else {
$data = $this->field($field)->where($where)->order($order)->find();
}
} else {
$data = $this->where($where)->order($order)->find();
}
$data['status_text'] = $data->status_text;
$data['create_time_show'] = date("Y.m.d H:i", strtotime($data->create_time)); //申请时间
$data['arrival_time_show'] = date("Y.m.d H:i", strtotime($data->arrival_time)); //退款时间
return $data;
}
public function userInfo()
{
return $this->hasOne(UserInfo::class, 'user_id', 'user_id')->bind(["nick_name"]);
}
public function mallOrder()
{
return $this->hasOne('MallOrder', 'id', 'order_id')->bind([
'product_order_number' => 'order_number',
'total_price',
'pay_money',
'coupon_money',
'freight',
'linkman',
'mobile_phone',
'province',
'city',
'area',
'address',
]);
}
public function mallProduct()
{
return $this->hasOne('MallOrderProduct', 'id', 'order_product_id')->bind(['product_name', 'is_product_spec_open', 'product_sku_name']);
}
}