@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\order;
|
||||
|
||||
use think\Model;
|
||||
use traits\model\SoftDelete;
|
||||
use addons\shopro\library\traits\model\order\OrderAftersaleScope;
|
||||
use app\admin\model\shopro\activity\Activity;
|
||||
|
||||
class Aftersale extends Model
|
||||
{
|
||||
|
||||
use SoftDelete, OrderAftersaleScope;
|
||||
|
||||
|
||||
|
||||
// 表名
|
||||
protected $name = 'shopro_order_aftersale';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
protected $deleteTime = 'deletetime';
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'type_text',
|
||||
'dispatch_status_text',
|
||||
'aftersale_status_text',
|
||||
'aftersale_status_desc',
|
||||
'refund_status_text',
|
||||
'activity_type_arr',
|
||||
'activity_type_text_arr',
|
||||
];
|
||||
|
||||
|
||||
// 发货状态
|
||||
const DISPATCH_STATUS_NOSEND = 0; // 未发货
|
||||
const DISPATCH_STATUS_SENDED = 1; // 已发货
|
||||
const DISPATCH_STATUS_GETED = 2; // 已收货
|
||||
|
||||
// 售后状态
|
||||
const AFTERSALE_STATUS_CANCEL = -2; // 售后取消
|
||||
const AFTERSALE_STATUS_REFUSE = -1; // 拒绝
|
||||
const AFTERSALE_STATUS_NOOPER = 0; // 未处理
|
||||
const AFTERSALE_STATUS_AFTERING = 1; // 处理中
|
||||
const AFTERSALE_STATUS_OK = 2; // 售后完成
|
||||
|
||||
|
||||
// 退款状态
|
||||
const REFUND_STATUS_REFUSE = -1; // 拒绝退款(不用了)
|
||||
const REFUND_STATUS_NOREFUND = 0; // 未退款
|
||||
const REFUND_STATUS_FINISH = 1; // 同意
|
||||
|
||||
|
||||
public function getTypeList()
|
||||
{
|
||||
return ['refund' => __('Type refund'), 'return' => __('Type return'), 'other' => __('Type other')];
|
||||
}
|
||||
|
||||
public function getDispatchStatusList()
|
||||
{
|
||||
return ['0' => __('Dispatch_status 0'), '1' => __('Dispatch_status 1'), '2' => __('Dispatch_status 2')];
|
||||
}
|
||||
|
||||
public function getAftersaleStatusList()
|
||||
{
|
||||
return ['-2' => __('Aftersale_status -2'), '-1' => __('Aftersale_status -1'), '0' => __('Aftersale_status 0'), '1' => __('Aftersale_status 1'), '2' => __('Aftersale_status 2')];
|
||||
}
|
||||
|
||||
public function getAftersaleStatusDescList()
|
||||
{
|
||||
return ['-2' => __('Aftersale_status_desc -2'), '-1' => __('Aftersale_status_desc -1'), '0' => __('Aftersale_status_desc 0'), '1' => __('Aftersale_status_desc 1'), '2' => __('Aftersale_status_desc 2')];
|
||||
}
|
||||
|
||||
public function getRefundStatusList()
|
||||
{
|
||||
return ['-1' => __('Refund_status -1'), '0' => __('Refund_status 0'), '1' => __('Refund_status 1')];
|
||||
}
|
||||
|
||||
|
||||
public function getTypeTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
|
||||
$list = $this->getTypeList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
public function getActivityTypeArrAttr($value, $data) {
|
||||
$activity_types = $value ? $value : (isset($data['activity_type']) ? $data['activity_type'] : '');
|
||||
$activityTypes = array_values(array_filter(explode(',', $activity_types)));
|
||||
|
||||
return $activityTypes;
|
||||
}
|
||||
|
||||
public function getActivityTypeTextArrAttr($value, $data)
|
||||
{
|
||||
$activityTypes = $this->activity_type_arr;
|
||||
$list = \app\admin\model\shopro\activity\Activity::getTypeList();
|
||||
|
||||
$activityTypeTextArr = [];
|
||||
foreach ($activityTypes as $key => $activity_type) {
|
||||
if (isset($list[$activity_type])) {
|
||||
|
||||
$activityTypeTextArr[$activity_type] = $list[$activity_type];
|
||||
}
|
||||
}
|
||||
|
||||
return $activityTypeTextArr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function getDispatchStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['dispatch_status']) ? $data['dispatch_status'] : '');
|
||||
$list = $this->getDispatchStatusList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
public function getAftersaleStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['aftersale_status']) ? $data['aftersale_status'] : '');
|
||||
$list = $this->getAftersaleStatusList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
public function getAftersaleStatusDescAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['aftersale_status']) ? $data['aftersale_status'] : '');
|
||||
$list = $this->getAftersaleStatusDescList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
public function getRefundStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['refund_status']) ? $data['refund_status'] : '');
|
||||
$list = $this->getRefundStatusList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\User::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\shopro\order\Order::class, 'order_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->hasMany(AftersaleLog::class, 'order_aftersale_id', 'id')->order('id', 'desc');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\order;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class AftersaleLog extends Model
|
||||
{
|
||||
|
||||
// 表名
|
||||
protected $name = 'shopro_order_aftersale_log';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'images_arr'
|
||||
];
|
||||
|
||||
|
||||
|
||||
public function getImagesArrAttr($value, $data)
|
||||
{
|
||||
$imagesArray = [];
|
||||
if (!empty($data['images'])) {
|
||||
$imagesArray = explode(',', $data['images']);
|
||||
return $imagesArray;
|
||||
}
|
||||
return $imagesArray;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\order;
|
||||
|
||||
use addons\shopro\library\traits\model\order\OrderOper;
|
||||
use addons\shopro\library\traits\model\order\OrderScope;
|
||||
use addons\shopro\library\traits\model\order\OrderStatus;
|
||||
use app\admin\model\shopro\activity\Activity;
|
||||
use think\Model;
|
||||
use traits\model\SoftDelete;
|
||||
use think\Log;
|
||||
|
||||
class Order extends Model
|
||||
{
|
||||
|
||||
use OrderOper, OrderScope, OrderStatus, SoftDelete;
|
||||
|
||||
|
||||
// 表名
|
||||
protected $name = 'shopro_order';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
protected $deleteTime = 'deletetime';
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'type_text',
|
||||
'status_text',
|
||||
'pay_type_text',
|
||||
'paytime_text',
|
||||
'platform_text',
|
||||
'ext_arr',
|
||||
'status_code',
|
||||
'status_name',
|
||||
'status_desc',
|
||||
'btns',
|
||||
];
|
||||
|
||||
// 订单状态
|
||||
const STATUS_INVALID = -2; // 已失效|交易关闭
|
||||
const STATUS_CANCEL = -1; // 已取消
|
||||
const STATUS_NOPAY = 0; // 未付款
|
||||
const STATUS_PAYED = 1; // 买家已付款
|
||||
const STATUS_FINISH = 2; // 已完成
|
||||
|
||||
public function getTypeList()
|
||||
{
|
||||
return ['goods' => __('Type goods'), 'score' => __('Type score')];
|
||||
}
|
||||
|
||||
public function getStatusList()
|
||||
{
|
||||
return ['-2' => __('Status -2'), '-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
|
||||
}
|
||||
|
||||
public function getPayTypeList()
|
||||
{
|
||||
return ['group' => '组合支付', 'wechat' => __('Pay_type wechat'), 'alipay' => __('Pay_type alipay'), 'wallet' => __('Pay_type wallet'), 'score' => __('Pay_type score')];
|
||||
}
|
||||
|
||||
public function getPlatformList()
|
||||
{
|
||||
return ['H5' => __('Platform h5'), 'wxOfficialAccount' => __('Platform wxofficialaccount'), 'wxMiniProgram' => __('Platform wxminiprogram'), 'App' => __('Platform app')];
|
||||
}
|
||||
|
||||
public function getTypeTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
|
||||
$list = $this->getTypeList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
public function getStatusTextAttr($value, $data)
|
||||
{
|
||||
return $this->getStatus($data, 'status_name');
|
||||
}
|
||||
|
||||
|
||||
public function getPayTypeTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
|
||||
$list = $this->getPayTypeList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
public function getPaytimeTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
|
||||
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
|
||||
}
|
||||
|
||||
|
||||
public function getPlatformTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['platform']) ? $data['platform'] : '');
|
||||
$list = $this->getPlatformList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
protected function setPaytimeAttr($value)
|
||||
{
|
||||
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
|
||||
}
|
||||
|
||||
public function getExtArrAttr($value, $data)
|
||||
{
|
||||
$ext = (isset($data['ext']) && $data['ext']) ? json_decode($data['ext'], true) : [];
|
||||
|
||||
if ($ext && isset($ext['activity_discount_infos']) && $ext['activity_discount_infos']) {
|
||||
|
||||
foreach ($ext['activity_discount_infos'] as $key => $info) {
|
||||
$ext['activity_discount_infos'][$key]['activity_type_text'] = Activity::getTypeList()[$info['activity_type']];
|
||||
$ext['activity_discount_infos'][$key]['format_text'] = \addons\shopro\model\Activity::formatDiscountTags($info['activity_type'], array_merge([
|
||||
'type' => $info['rule_type'],
|
||||
], $info['discount_rule']));
|
||||
}
|
||||
}
|
||||
return $ext;
|
||||
}
|
||||
|
||||
|
||||
protected function getStatus($data, $type)
|
||||
{
|
||||
$btns = [];
|
||||
$status_name = '';
|
||||
$status_desc = '';
|
||||
|
||||
switch ($this->status_code) {
|
||||
case 'cancel':
|
||||
$status_name = '已取消';
|
||||
$status_desc = '买家已取消';
|
||||
break;
|
||||
case 'invalid':
|
||||
$status_name = '交易关闭';
|
||||
$status_desc = '买家未在规定时间内付款,订单将按照预定时间逾期自动关闭';
|
||||
break;
|
||||
case 'nopay':
|
||||
$status_name = '待付款';
|
||||
$status_desc = '买家已下单,等待付款';
|
||||
break;
|
||||
|
||||
// 已支付的
|
||||
case 'commented':
|
||||
$status_name = '已评价';
|
||||
$status_desc = '买家已评价';
|
||||
$btns[] = 'refund'; // 全部退款 直接不申请退款
|
||||
break;
|
||||
case 'nocomment':
|
||||
$status_name = '未评价';
|
||||
$status_desc = '等待买家评价';
|
||||
$btns[] = 'refund'; // 全部退款 直接不申请退款
|
||||
break;
|
||||
case 'noget':
|
||||
$status_name = '商家已发货';
|
||||
$status_desc = '买家若在设置天数内未确认收货,系统将自动确认收货完成订单';
|
||||
$btns[] = 'refund'; // 全部退款 直接不申请退款
|
||||
break;
|
||||
case 'nosend':
|
||||
$is_send_btn = false;
|
||||
$is_send_store_btn = false;
|
||||
foreach ($this->item as $key => $item) {
|
||||
// 获取 item status
|
||||
$dispatchType[] = $item['dispatch_type'];
|
||||
|
||||
// 如果有一个快递的未发货,显示发货按钮
|
||||
if ($item['dispatch_type'] == 'express' && $item['dispatch_status'] == OrderItem::DISPATCH_STATUS_NOSEND) {
|
||||
$is_send_btn = true;
|
||||
}
|
||||
|
||||
// 如果有一个到店,或者商家配送未发货,显示备货按钮
|
||||
if (in_array($item['dispatch_type'], ['store', 'selfetch']) && $item['dispatch_status'] == OrderItem::DISPATCH_STATUS_NOSEND) {
|
||||
$is_send_store_btn = true;
|
||||
}
|
||||
}
|
||||
$dispatchType = array_unique(array_filter($dispatchType));
|
||||
if (in_array('express', $dispatchType)) {
|
||||
$status_name = '买家已付款';
|
||||
$status_desc = '买家已付款,请尽快发货';
|
||||
} else {
|
||||
$status_name = '买家已付款';
|
||||
$status_desc = '买家已付款,请通知相关门店发货';
|
||||
}
|
||||
|
||||
if ($is_send_btn) {
|
||||
$btns[] = 'send'; // 快递发货
|
||||
}
|
||||
|
||||
if ($is_send_store_btn) {
|
||||
$btns[] = 'send_store'; // 总后台也可直接帮门店发货
|
||||
}
|
||||
|
||||
$btns[] = 'refund'; // 全部退款 直接不申请退款
|
||||
break;
|
||||
case 'refund_finish':
|
||||
$status_name = '退款完成';
|
||||
$status_desc = '订单退款完成';
|
||||
break;
|
||||
case 'refund_ing':
|
||||
$status_name = '退款处理中';
|
||||
$status_desc = '请尽快处理退款';
|
||||
$btns[] = 'refund'; // 全部退款 直接不申请退款
|
||||
break;
|
||||
case 'groupon_ing':
|
||||
$status_name = '等待成团';
|
||||
$status_desc = '请等待拼团完成之后再发货';
|
||||
$btns[] = 'refund'; // 全部退款 直接不申请退款
|
||||
break;
|
||||
case 'groupon_invalid':
|
||||
$status_name = '拼团失败';
|
||||
$status_desc = '未在规定时间完成拼团,团已解散';
|
||||
|
||||
break;
|
||||
// 已支付的结束
|
||||
|
||||
case 'finish':
|
||||
$status_name = '交易完成';
|
||||
$status_desc = '交易已完成';
|
||||
break;
|
||||
}
|
||||
|
||||
if ($data['activity_type']) {
|
||||
// 有活动
|
||||
if (strpos($data['activity_type'], 'groupon') !== false) {
|
||||
// 是拼团订单
|
||||
$ext_arr = json_decode($data['ext'], true);
|
||||
if (isset($ext_arr['groupon_id']) && $ext_arr['groupon_id']) {
|
||||
$btns[] = 'groupon'; // 拼团详情
|
||||
} else {
|
||||
if ($data['status'] > 0) {
|
||||
$btns[] = 'groupon_alone'; // 拼团单独购买,支付了,也没有 groupon_id 的情况
|
||||
} else {
|
||||
$btns[] = 'groupon'; // 拼团详情 未支付显示拼团
|
||||
}
|
||||
}
|
||||
} else if (strpos($data['activity_type'], 'seckill') !== false) {
|
||||
// 秒杀订单
|
||||
$btns[] = 'seckill'; // 秒杀
|
||||
}
|
||||
}
|
||||
|
||||
return $type == 'status_name' ? $status_name : ($type == 'btns' ? $btns : $status_desc);
|
||||
}
|
||||
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->hasMany(\app\admin\model\shopro\order\OrderItem::class, 'order_id');
|
||||
}
|
||||
|
||||
public function express()
|
||||
{
|
||||
return $this->hasMany(\app\admin\model\shopro\order\OrderExpress::class, 'order_id');
|
||||
}
|
||||
|
||||
|
||||
public function aftersale()
|
||||
{
|
||||
return $this->hasMany(\app\admin\model\shopro\order\Aftersale::class, 'order_id')->order('id', 'desc');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\order;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class OrderAction extends Model
|
||||
{
|
||||
// 表名
|
||||
protected $name = 'shopro_order_action';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
];
|
||||
|
||||
|
||||
public function oper() {
|
||||
// 用户和system 都不需要关联,这里直接只关联 admin,列表循环处理
|
||||
return $this->belongsTo(\app\admin\model\Admin::class, 'oper_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\order;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class OrderExpress extends Model
|
||||
{
|
||||
// 表名
|
||||
protected $name = 'shopro_order_express';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 记得用的时候一定要额外加上 order_id 等于当前订单号
|
||||
*/
|
||||
public function item()
|
||||
{
|
||||
return $this->hasMany(\app\admin\model\shopro\order\OrderItem::class, 'express_no', 'express_no');
|
||||
}
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(\addons\shopro\model\Order::class, 'order_id');
|
||||
}
|
||||
|
||||
|
||||
public function log()
|
||||
{
|
||||
return $this->hasMany(\app\admin\model\shopro\order\OrderExpressLog::class, 'order_express_id')->order('id', 'desc');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\order;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class OrderExpressLog extends Model
|
||||
{
|
||||
// 表名
|
||||
protected $name = 'shopro_order_express_log';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'status_name'
|
||||
];
|
||||
|
||||
|
||||
public function getStatusNameAttr($value, $data)
|
||||
{
|
||||
$status = substr($data['status'], 0, 1);
|
||||
|
||||
$list = \addons\shopro\model\OrderExpressLog::getStatusList();
|
||||
return isset($list[$status]) ? $list[$status] : '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\order;
|
||||
|
||||
use think\Model;
|
||||
|
||||
|
||||
class OrderInvoice extends Model
|
||||
{
|
||||
|
||||
// 表名
|
||||
protected $name = 'shopro_order_invoice';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = false;
|
||||
protected $deleteTime = false;
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'type_text',
|
||||
'status_text',
|
||||
'confirmtime_text'
|
||||
];
|
||||
|
||||
|
||||
|
||||
public function getTypeList()
|
||||
{
|
||||
return ['person' => __('Person'), 'company' => __('Company')];
|
||||
}
|
||||
|
||||
public function getStatusList()
|
||||
{
|
||||
return ['0' => __('Status 0'), '1' => __('Status 1')];
|
||||
}
|
||||
|
||||
|
||||
public function getTypeTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
|
||||
$list = $this->getTypeList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
public function getStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
|
||||
$list = $this->getStatusList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
public function getConfirmtimeTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['confirmtime']) ? $data['confirmtime'] : '');
|
||||
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
|
||||
}
|
||||
|
||||
protected function setConfirmtimeAttr($value)
|
||||
{
|
||||
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
|
||||
}
|
||||
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('\app\admin\model\shopro\user\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
||||
}
|
||||
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo('\app\admin\model\shopro\order\Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\order;
|
||||
|
||||
use think\Model;
|
||||
use traits\model\SoftDelete;
|
||||
use addons\shopro\library\traits\model\order\OrderItemStatus;
|
||||
|
||||
class OrderItem extends Model
|
||||
{
|
||||
|
||||
use OrderItemStatus, SoftDelete;
|
||||
|
||||
|
||||
|
||||
// 表名
|
||||
protected $name = 'shopro_order_item';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
protected $deleteTime = 'deletetime';
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'dispatch_type_text',
|
||||
'dispatch_status_text',
|
||||
'aftersale_status_text',
|
||||
'comment_status_text',
|
||||
'activity_type_arr',
|
||||
'activity_type_text_arr',
|
||||
'activity_type_text',
|
||||
'refund_status_text',
|
||||
'status_code',
|
||||
'status_name',
|
||||
'status_desc',
|
||||
'btns',
|
||||
'ext_arr'
|
||||
];
|
||||
|
||||
// 发货状态
|
||||
const DISPATCH_STATUS_NOSEND = 0; // 未发货
|
||||
const DISPATCH_STATUS_SENDED = 1; // 已发货
|
||||
const DISPATCH_STATUS_GETED = 2; // 已收货
|
||||
|
||||
|
||||
// 售后状态
|
||||
const AFTERSALE_STATUS_REFUSE = -1; // 驳回
|
||||
const AFTERSALE_STATUS_NOAFTER = 0; // 未申请
|
||||
const AFTERSALE_STATUS_AFTERING = 1; // 申请退款
|
||||
const AFTERSALE_STATUS_OK = 2; // 售后完成
|
||||
|
||||
|
||||
// 退款状态
|
||||
const REFUND_STATUS_REFUSE = -1; // 拒绝退款 // 驳回aftersale_status(状态不会出现)
|
||||
const REFUND_STATUS_NOREFUND = 0; // 退款状态 未申请
|
||||
const REFUND_STATUS_ING = 1; // 申请中 // 不需要申请(状态不会出现)
|
||||
const REFUND_STATUS_OK = 2; // 已同意
|
||||
const REFUND_STATUS_FINISH = 3; // 退款完成
|
||||
|
||||
// 评价状态
|
||||
const COMMENT_STATUS_NO = 0; // 待评价
|
||||
const COMMENT_STATUS_OK = 1; // 已评价
|
||||
|
||||
public function getExtArrAttr($value, $data)
|
||||
{
|
||||
return (isset($data['ext']) && $data['ext']) ? json_decode($data['ext'], true) : [];
|
||||
}
|
||||
|
||||
public function getDispatchStatusList()
|
||||
{
|
||||
return ['0' => __('Dispatch_status 0'), '1' => __('Dispatch_status 1'), '2' => __('Dispatch_status 2')];
|
||||
}
|
||||
|
||||
public function getAftersaleStatusList()
|
||||
{
|
||||
return ['-1' => __('Aftersale_status -1'), '0' => __('Aftersale_status 0'), '1' => __('Aftersale_status 1'), '2' => __('Aftersale_status 2')];
|
||||
}
|
||||
|
||||
public function getCommentStatusList()
|
||||
{
|
||||
return ['0' => __('Comment_status 0'), '1' => __('Comment_status 1')];
|
||||
}
|
||||
|
||||
public function getRefundStatusList()
|
||||
{
|
||||
return ['-1' => __('Refund_status -1'), '0' => __('Refund_status 0'), '1' => __('Refund_status 1'), '2' => __('Refund_status 2'), '3' => __('Refund_status 3')];
|
||||
}
|
||||
|
||||
|
||||
public function getDispatchTypeTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['dispatch_type']) ? $data['dispatch_type'] : '');
|
||||
$list = (new \app\admin\model\shopro\dispatch\Dispatch)->getTypeList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
public function getDispatchStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['dispatch_status']) ? $data['dispatch_status'] : '');
|
||||
$list = $this->getDispatchStatusList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
public function getAftersaleStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['aftersale_status']) ? $data['aftersale_status'] : '');
|
||||
$list = $this->getAftersaleStatusList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
public function getActivityTypeArrAttr($value, $data) {
|
||||
$activity_types = $value ? $value : (isset($data['activity_type']) ? $data['activity_type'] : '');
|
||||
$activityTypes = array_values(array_filter(explode(',', $activity_types)));
|
||||
|
||||
return $activityTypes;
|
||||
}
|
||||
|
||||
public function getActivityTypeTextArrAttr($value, $data)
|
||||
{
|
||||
$activityTypes = $this->activity_type_arr;
|
||||
$list = \app\admin\model\shopro\activity\Activity::getTypeList();
|
||||
|
||||
$activityTypeTextArr = [];
|
||||
foreach ($activityTypes as $key => $activity_type) {
|
||||
if (isset($list[$activity_type])) {
|
||||
|
||||
$activityTypeTextArr[$activity_type] = $list[$activity_type];
|
||||
}
|
||||
}
|
||||
|
||||
return $activityTypeTextArr;
|
||||
}
|
||||
|
||||
|
||||
public function getActivityTypeTextAttr($value, $data) {
|
||||
$activityTypeTextArr = $this->activityTypeTextArr;
|
||||
return join(',', $activityTypeTextArr);
|
||||
}
|
||||
|
||||
|
||||
public function getCommentStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['comment_status']) ? $data['comment_status'] : '');
|
||||
$list = $this->getCommentStatusList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
public function getRefundStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['refund_status']) ? $data['refund_status'] : '');
|
||||
$list = $this->getRefundStatusList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
public function getStatus($data, $type)
|
||||
{
|
||||
$btns = [];
|
||||
$status_name = '';
|
||||
$status_desc = '';
|
||||
|
||||
$status_code = $this->status_code;
|
||||
|
||||
$item_code = 'null'; // 有售后的时候,第二状态
|
||||
if (strpos($status_code, '|') !== false) {
|
||||
$codes = explode('|', $status_code);
|
||||
$status_code = $codes[0] ?? 'null';
|
||||
$item_code = $codes[1] ?? 'null';
|
||||
}
|
||||
|
||||
switch ($status_code) {
|
||||
case 'null':
|
||||
case 'cancel':
|
||||
case 'invalid':
|
||||
case 'nopay':
|
||||
// 未支付的返回空
|
||||
break;
|
||||
case 'nosend':
|
||||
$status_name = '待发货';
|
||||
$status_desc = '等待卖家发货';
|
||||
|
||||
// 细分订单发货
|
||||
switch ($data['dispatch_type']) {
|
||||
case 'store':
|
||||
$status_name = '待配送';
|
||||
$status_desc = '等待卖家上门配送';
|
||||
$btns[] = 'send_store'; // 总后台也可直接帮门店发货
|
||||
break;
|
||||
case 'selfetch':
|
||||
$status_name = '待备货';
|
||||
$status_desc = '等待卖家备货';
|
||||
$btns[] = 'send_store'; // 总后台也可直接帮门店发货
|
||||
break;
|
||||
case 'express':
|
||||
$btns[] = 'send'; // 发货
|
||||
break;
|
||||
}
|
||||
|
||||
$btns[] = 'refund'; // 退款
|
||||
break;
|
||||
case 'noget':
|
||||
switch ($data['dispatch_type']) {
|
||||
case 'express':
|
||||
$status_name = '待收货';
|
||||
$status_desc = '等待买家收货';
|
||||
$btns[] = 'get'; // 确认收货
|
||||
break;
|
||||
case 'selfetch':
|
||||
$status_name = '待自提/到店';
|
||||
$status_desc = '等待买家提货/到店';
|
||||
break;
|
||||
case 'store':
|
||||
$status_name = '待取货';
|
||||
$status_desc = '卖家上门配送中';
|
||||
break;
|
||||
case 'autosend': // 正常不需要确认收货
|
||||
$status_name = '待收货';
|
||||
$status_desc = '等待买家收货';
|
||||
$btns[] = 'get'; // 确认收货
|
||||
break;
|
||||
}
|
||||
$btns[] = 'refund'; // 售后
|
||||
break;
|
||||
case 'nocomment':
|
||||
$status_name = '待评价';
|
||||
$status_desc = '等待买家评价';
|
||||
$btns[] = 'refund'; // 退款
|
||||
break;
|
||||
case 'commented':
|
||||
$status_name = '已评价';
|
||||
$status_desc = '订单已评价';
|
||||
$btns[] = 'refund'; // 退款
|
||||
break;
|
||||
case 'refund_finish':
|
||||
$status_name = '退款完成';
|
||||
$status_desc = '订单退款完成';
|
||||
break;
|
||||
case 'refund_ing': // 不需要申请退款(状态不会出现)
|
||||
$status_name = '退款处理中';
|
||||
$status_desc = '退款处理中';
|
||||
$btns[] = 'refund'; // 退款
|
||||
break;
|
||||
case 'refund_refuse': // 驳回aftersale_status(状态不会出现)
|
||||
$status_name = '拒绝退款';
|
||||
$status_desc = '卖家拒绝退款';
|
||||
break;
|
||||
case 'after_ing':
|
||||
$status_name = '售后中';
|
||||
$status_desc = '售后处理中';
|
||||
break;
|
||||
case 'after_refuse':
|
||||
case 'after_finish':
|
||||
switch ($status_code) {
|
||||
case 'after_refuse':
|
||||
$status_name = '售后拒绝';
|
||||
$status_desc = '售后申请拒绝';
|
||||
break;
|
||||
case 'after_finish':
|
||||
$status_name = '售后完成';
|
||||
$status_desc = '售后完成';
|
||||
break;
|
||||
}
|
||||
|
||||
// 售后拒绝,或者完成的时候,还可以继续操作订单
|
||||
switch ($item_code) {
|
||||
case 'nosend':
|
||||
if ($data['dispatch_type'] == 'express') {
|
||||
$btns[] = 'send'; // 发货
|
||||
} else if (in_array($data['dispatch_type'], ['store', 'selfetch'])) {
|
||||
$btns[] = 'send_store'; // 备货
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// 只要有售后单号,就显示售后详情按钮
|
||||
$ext_arr = json_decode($data['ext'], true);
|
||||
if (isset($ext_arr['aftersale_id']) && !empty($ext_arr['aftersale_id'])) {
|
||||
$btns[] = 'aftersale_info'; // 查看详情
|
||||
}
|
||||
|
||||
return $type == 'status_name' ? $status_name : ($type == 'btns' ? $btns : $status_desc);
|
||||
}
|
||||
|
||||
|
||||
// 商家配送, 到店自提的门店
|
||||
public function store()
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\shopro\store\Store::class, 'store_id');
|
||||
}
|
||||
|
||||
|
||||
public function reward()
|
||||
{
|
||||
return $this->hasMany(\app\admin\model\shopro\commission\Reward::class, 'order_item_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
public function commissionOrder()
|
||||
{
|
||||
return $this->hasOne(\app\admin\model\shopro\commission\Order::class, 'order_item_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\order;
|
||||
|
||||
use think\Model;
|
||||
use think\Log;
|
||||
|
||||
class RefundLog extends Model
|
||||
{
|
||||
// 表名
|
||||
protected $name = 'shopro_refund_log';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
protected $deleteTime = 'deletetime';
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'status_text',
|
||||
];
|
||||
|
||||
// 订单状态
|
||||
const STATUS_INVALID = -2;
|
||||
const STATUS_CANCEL = -1;
|
||||
const STATUS_NOPAY = 0;
|
||||
const STATUS_PAYED = 1;
|
||||
const STATUS_FINISH = 2;
|
||||
|
||||
public function getStatusList()
|
||||
{
|
||||
return ['-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1')];
|
||||
}
|
||||
|
||||
|
||||
public function getStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
|
||||
$list = $this->getStatusList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
// 获取退款单号
|
||||
public static function getSn($user_id)
|
||||
{
|
||||
$rand = $user_id < 9999 ? mt_rand(100000, 99999999) : mt_rand(100, 99999);
|
||||
$order_sn = date('Yhis') . $rand;
|
||||
|
||||
$id = str_pad($user_id, (24 - strlen($order_sn)), '0', STR_PAD_BOTH);
|
||||
|
||||
return 'R' . $order_sn . $id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\order;
|
||||
|
||||
use addons\shopro\library\traits\model\order\TradeOrderStatus;
|
||||
use think\Model;
|
||||
use traits\model\SoftDelete;
|
||||
|
||||
class TradeOrder extends Model
|
||||
{
|
||||
|
||||
use TradeOrderStatus, SoftDelete;
|
||||
|
||||
|
||||
|
||||
// 表名
|
||||
protected $name = 'shopro_trade_order';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
protected $deleteTime = 'deletetime';
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'status_code',
|
||||
'status_name',
|
||||
'status_desc',
|
||||
'pay_type_text',
|
||||
'pay_time_text',
|
||||
'platform_text',
|
||||
'ext_arr'
|
||||
];
|
||||
|
||||
// 订单状态
|
||||
const STATUS_INVALID = -2; // 已失效|交易关闭
|
||||
const STATUS_CANCEL = -1; // 已取消
|
||||
const STATUS_NOPAY = 0; // 未付款
|
||||
const STATUS_PAYED = 1; // 买家已付款
|
||||
const STATUS_FINISH = 2; // 已完成
|
||||
|
||||
|
||||
|
||||
|
||||
public function user ()
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\User::class, 'user_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\order;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Verify extends Model
|
||||
{
|
||||
|
||||
|
||||
// 表名
|
||||
protected $name = 'shopro_verify';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'type_text',
|
||||
'status_code',
|
||||
'status_name'
|
||||
];
|
||||
|
||||
|
||||
public function getTypeList()
|
||||
{
|
||||
return [
|
||||
'verify' => '核销券'
|
||||
];
|
||||
}
|
||||
|
||||
public function scopeCanUse($query)
|
||||
{
|
||||
return $query->where('usetime', null)->where(function ($query) {
|
||||
$query->where('expiretime', null)->whereOr('expiretime', '>', time());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getTypeTextAttr($value, $data)
|
||||
{
|
||||
$value = isset($data['type']) ? $data['type'] : '';
|
||||
$list = $this->getTypeList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getStatusNameAttr($value, $data)
|
||||
{
|
||||
$status_name = '';
|
||||
switch ($this->status_code) {
|
||||
case 'used':
|
||||
$status_name = '已使用';
|
||||
break;
|
||||
case 'nouse':
|
||||
$status_name = '未使用';
|
||||
break;
|
||||
case 'expire':
|
||||
$status_name = '已过期';
|
||||
break;
|
||||
}
|
||||
|
||||
return $status_name;
|
||||
}
|
||||
|
||||
|
||||
public function getStatusCodeAttr($value, $data)
|
||||
{
|
||||
$status_code = '';
|
||||
|
||||
if ($data['usetime']) {
|
||||
// 已使用
|
||||
$status_code = 'used';
|
||||
} else {
|
||||
// 未使用
|
||||
if (is_null($data['expiretime']) || $data['expiretime'] > time()) {
|
||||
// 不过期,或者过期时间大于当前时间
|
||||
$status_code = 'nouse';
|
||||
} else {
|
||||
// 已过期
|
||||
$status_code = 'expire';
|
||||
}
|
||||
}
|
||||
|
||||
return $status_code;
|
||||
}
|
||||
|
||||
|
||||
public function orderItem()
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\shopro\order\OrderItem::class, 'order_item_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\shopro\order\Order::class, 'order_id', 'id');
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户