|
@@ -4,7 +4,10 @@ namespace app\admin\logic;
|
|
|
|
|
|
use app\model\CommonModel;
|
|
|
use app\model\GoodModel;
|
|
|
+use app\model\MasterOrder;
|
|
|
+use app\model\MasterOrderModel;
|
|
|
use app\model\OrderModel;
|
|
|
+use app\model\ServiceModel;
|
|
|
use think\Exception;
|
|
|
use think\facade\Db;
|
|
|
use think\facade\Validate;
|
|
@@ -21,9 +24,9 @@ class OrderLogic extends BaseLogic
|
|
|
->leftJoin('card c', 'c.id=a.card_id AND c.is_del=' . CommonModel::$del_normal)
|
|
|
->leftJoin('account d', 'd.id=a.uid AND d.is_del=' . CommonModel::$del_normal)
|
|
|
->leftJoin('addr e', 'e.id=a.addr_id AND e.is_del=' . CommonModel::$del_normal)
|
|
|
- ->leftJoin('good f', 'f.id=a.good_id AND f.is_del=' . CommonModel::$del_normal)
|
|
|
->where('a.is_del', CommonModel::$del_normal);
|
|
|
|
|
|
+ if ($data['masterOrderCode'] != '') $db->whereLike('a.masterOrderCode', '%' . $data['masterOrderCode'] . '%');
|
|
|
if ($data['orderCode'] != '') $db->whereLike('a.orderCode', '%' . $data['orderCode'] . '%');
|
|
|
if ($data['status'] != '') $db->where('a.status', $data['status']);
|
|
|
if ($data['name'] !== '') $db->whereLike('d.name', '%' . $data['name'] . '%');
|
|
@@ -34,7 +37,7 @@ class OrderLogic extends BaseLogic
|
|
|
$count = $db->count('a.id');
|
|
|
|
|
|
$list = $db
|
|
|
- ->field('a.id,a.orderCode,a.type,b.title company_title,c.title card_title,d.name,d.username,a.num,e.contactor,e.mobile,a.status,a.post_name,a.post_code,a.addtime,e.addr_code,"" addr_name,e.addr,f.good_code,f.good_name,f.good_cover_img')
|
|
|
+ ->field('a.id,a.masterOrderCode,a.orderCode,a.type,b.title company_title,c.title card_title,d.name,d.username,a.num,e.contactor,e.mobile,a.status,a.post_name,a.post_code,a.addtime,e.addr_code,"" addr_name,e.addr,"" good_code,"" good_name,""good_cover_img,a.child_id')
|
|
|
->page($data['page'], $data['size'])
|
|
|
->withAttr('addr_code', function ($val) {
|
|
|
return explode(',', $val);
|
|
@@ -46,6 +49,20 @@ class OrderLogic extends BaseLogic
|
|
|
->select()
|
|
|
->toArray();
|
|
|
|
|
|
+ //所有服务
|
|
|
+ $service = ServiceModel::where('is_del', CommonModel::$del_normal)
|
|
|
+ ->whereIn('id', array_column($list, 'child_id'))
|
|
|
+ ->column('title', 'id');
|
|
|
+
|
|
|
+ $good = GoodModel::where('is_del', CommonModel::$del_normal)
|
|
|
+ ->whereIn('id', array_column($list, 'child_id'))
|
|
|
+ ->column('good_cover_img,good_code,good_name', 'id');
|
|
|
+
|
|
|
+ foreach ($list as &$order) {
|
|
|
+ if ($order['type'] == MasterOrderModel::$type_service) $order['good_name'] = $service[$order['child_id']] ?? '';
|
|
|
+ else $order = array_merge($order, $good[$order['child_id']]);
|
|
|
+ }
|
|
|
+
|
|
|
return json_show(CommonModel::$success, '获取订单列表成功', ['count' => $count, 'list' => $list]);
|
|
|
}
|
|
|
|
|
@@ -53,12 +70,11 @@ class OrderLogic extends BaseLogic
|
|
|
public static function read(int $id = 0): Json
|
|
|
{
|
|
|
$rs = $db = OrderModel::alias('a')
|
|
|
- ->field('a.id,a.orderCode,a.type,b.title company_title,c.title card_title,d.name,d.username,a.num,e.contactor,e.mobile,e.addr_code,a.status,a.post_name,a.post_code,a.addtime,"" addr_name,f.good_code,f.good_name,f.good_cover_img')
|
|
|
+ ->field('a.id,a.orderCode,a.type,b.title company_title,c.title card_title,d.name,d.username,a.num,e.contactor,e.mobile,e.addr_code,e.addr,a.status,a.post_name,a.post_code,a.addtime,"" addr_name,"" good_code,"" good_name,"" good_cover_img,a.child_id')
|
|
|
->leftJoin('company b', 'b.id=a.company_id AND b.is_del=' . CommonModel::$del_normal)
|
|
|
->leftJoin('card c', 'c.id=a.card_id AND c.is_del=' . CommonModel::$del_normal)
|
|
|
->leftJoin('account d', 'd.id=a.uid AND d.is_del=' . CommonModel::$del_normal)
|
|
|
->leftJoin('addr e', 'e.id=a.addr_id AND e.is_del=' . CommonModel::$del_normal)
|
|
|
- ->leftJoin('good f', 'f.id=a.good_id AND f.is_del=' . CommonModel::$del_normal)
|
|
|
->where(['a.is_del' => CommonModel::$del_normal, 'a.id' => $id])
|
|
|
->withAttr('addr_code', function ($val) {
|
|
|
return explode(',', $val);
|
|
@@ -68,6 +84,11 @@ class OrderLogic extends BaseLogic
|
|
|
})
|
|
|
->findOrEmpty()
|
|
|
->toArray();
|
|
|
+
|
|
|
+ if ($rs['type'] == MasterOrderModel::$type_service) $rs['good_name'] = ServiceModel::where(['is_del' => CommonModel::$del_normal, 'id' => $rs['child_id']])->value('title');
|
|
|
+ else $rs = array_merge($rs, GoodModel::where(['is_del' => CommonModel::$del_normal, 'id' => $rs['child_id']])->field('good_code,good_name,good_cover_img')->findOrEmpty()->toArray());
|
|
|
+
|
|
|
+
|
|
|
return json_show(CommonModel::$success, '获取商品详情成功', $rs);
|
|
|
}
|
|
|
|
|
@@ -80,15 +101,20 @@ class OrderLogic extends BaseLogic
|
|
|
->leftJoin('card c', 'c.id=a.card_id AND c.is_del=' . CommonModel::$del_normal)
|
|
|
->leftJoin('account d', 'd.id=a.uid AND d.is_del=' . CommonModel::$del_normal)
|
|
|
->leftJoin('addr e', 'e.id=a.addr_id AND e.is_del=' . CommonModel::$del_normal)
|
|
|
- ->leftJoin('good f', 'f.id=a.good_id AND f.is_del=' . CommonModel::$del_normal)->where('a.is_del', CommonModel::$del_normal)
|
|
|
->where('a.is_del', CommonModel::$del_normal);
|
|
|
|
|
|
+ if ($data['masterOrderCode'] != '') $db->whereLike('a.masterOrderCode', '%' . $data['masterOrderCode'] . '%');
|
|
|
if ($data['orderCode'] != '') $db->whereLike('a.orderCode', '%' . $data['orderCode'] . '%');
|
|
|
if ($data['status'] != '') $db->where('a.status', $data['status']);
|
|
|
if ($data['name'] !== '') $db->whereLike('d.name', '%' . $data['name'] . '%');
|
|
|
if ($data['username']) $db->whereLike('d.username', '%' . $data['username'] . '%');
|
|
|
if (($data['start_date'] != '') && ($data['end_date'] != '')) $db->whereBetween('a.addtime', [$data['start_date'], $data['end_date']]);
|
|
|
- if ($data['type'] != '') $db->where('a.type', $data['type']);
|
|
|
+ if ($data['type'] !== '') $db->where('a.type', $data['type']);
|
|
|
+
|
|
|
+ $list = $db
|
|
|
+ ->field('a.id `订单ID`,a.masterOrderCode `主订单编号`,a.orderCode `订单编号`,a.type `订单类型`,b.title `业务公司`,c.title `卡类型`,d.name `购买用户名`,d.username `购买账号`,a.num `购买数量`,e.contactor `收货联系人`,e.mobile `收货联系电话`,a.status `状态`,a.post_name `物流公司`,a.post_code `物流单号`,a.addtime `创建时间`,e.addr_code,"" `收货地址`,e.addr,"" `商品编码`,"" `商品(服务)名称`,a.child_id')
|
|
|
+ ->order('a.addtime desc')
|
|
|
+ ->cursor();
|
|
|
|
|
|
$status = [
|
|
|
CommonModel::$order_status_wait_pay => '待支付',
|
|
@@ -97,26 +123,34 @@ class OrderLogic extends BaseLogic
|
|
|
CommonModel::$order_status_deliver => '已发货',
|
|
|
CommonModel::$order_status_receipt => '已收货',
|
|
|
];
|
|
|
- $type = [GoodModel::$type_shopping => '商城', GoodModel::$type_exchange => '兑换'];
|
|
|
- $list = $db
|
|
|
- ->field('a.id 订单ID,a.orderCode 订单编号,a.type,b.title 业务公司,c.title 卡类型,d.name 购买用户名,d.username 购买账号,a.num 购买数量,e.contactor 收货联系人,e.mobile 收货联系电话,e.addr_code,a.status 状态,a.post_name 物流公司,a.post_code 物流单号,a.addtime 创建时间,e.addr,f.good_code 商品编码,f.good_name 商品名称')
|
|
|
- ->order('a.addtime desc')
|
|
|
- ->cursor();
|
|
|
+ $type = [MasterOrderModel::$type_exchange_good => '兑换商品订单', MasterOrderModel::$type_shopping_good => '商城商品订单', MasterOrderModel::$type_service => '服务订单'];
|
|
|
|
|
|
$da = [];
|
|
|
foreach ($list as $v) {
|
|
|
$v = $v->toArray();
|
|
|
+
|
|
|
+ if ($v['订单类型'] == MasterOrderModel::$type_service) $v['商品(服务)名称'] = ServiceModel::where(['is_del' => CommonModel::$del_normal, 'id' => $v['child_id']])->value('title', '');
|
|
|
+ else {
|
|
|
+ $good = GoodModel::where(['is_del' => CommonModel::$del_normal, 'id' => $v['child_id']])
|
|
|
+ ->field('good_code,good_name')
|
|
|
+ ->findOrEmpty()
|
|
|
+ ->toArray();
|
|
|
+ $v['商品编码'] = $good['good_code'] ?? '';
|
|
|
+ $v['商品(服务)名称'] = $good['good_name'] ?? '';
|
|
|
+ };
|
|
|
+
|
|
|
$v['收货地址'] = $v['addr_code'] ? get_addr_name($v['addr_code']) . $v['addr'] : $v['addr'];
|
|
|
$v['状态'] = $status[$v['状态']] ?? '';
|
|
|
- $v['订单类型'] = $type[$v['type']] ?? '';
|
|
|
+ $v['订单类型'] = $type[$v['订单类型']] ?? '';
|
|
|
|
|
|
unset($v['addr_code']);
|
|
|
unset($v['addr']);
|
|
|
- unset($v['type']);
|
|
|
+ unset($v['child_id']);
|
|
|
|
|
|
$da[] = $v;
|
|
|
}
|
|
|
|
|
|
+ halt($da);
|
|
|
if (empty($da)) $da[] = '没有可供导出的数据';
|
|
|
|
|
|
$headerArr = array_keys($da[0]);
|