Browse Source

订单重新划分

wufeng 2 years ago
parent
commit
393b04a9fb

+ 3 - 2
app/admin/controller/Order.php

@@ -14,7 +14,7 @@ class Order extends BaseController
     //列表
     public function list()
     {
-        $param = $this->request->only(['page' => 1, 'size' => 10, 'orderCode' => '', 'status' => '', 'name' => '', 'username' => '', 'start_date' => '', 'end_date' => '', 'type' => ''], 'post');
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'masterOrderCode' => '', 'orderCode' => '', 'status' => '', 'name' => '', 'username' => '', 'start_date' => '', 'end_date' => '', 'type' => ''], 'post');
 
         return OrderLogic::list($param);
     }
@@ -29,7 +29,8 @@ class Order extends BaseController
     //导出
     public function export()
     {
-        $param = $this->request->only(['orderCode' => '', 'status' => '', 'name' => '', 'username' => '', 'start_date' => '', 'end_date' => '', 'type' => ''], 'post');
+        $param = $this->request->only(['masterOrderCode' => '', 'orderCode' => '', 'status' => '', 'name' => '', 'username' => '', 'start_date' => '', 'end_date' => '', 'type' => ''], 'post');
+
 
         return OrderLogic::export($param);
     }

+ 0 - 51
app/admin/controller/OrderService.php

@@ -1,51 +0,0 @@
-<?php
-
-namespace app\admin\controller;
-
-use app\admin\logic\OrderServiceLogic;
-use app\BaseController;
-use think\exception\ValidateException;
-use think\facade\Validate;
-
-//服务订单
-class OrderService extends BaseController
-{
-
-    //列表
-    public function list()
-    {
-        $param = $this->request->only(['page' => 1, 'size' => 10, 'orderCode' => '', 'status' => '', 'name' => '', 'username' => '', 'start_date' => '', 'end_date' => ''], 'post');
-
-        return OrderServiceLogic::list($param);
-    }
-
-    //详情
-    public function read()
-    {
-        $id = $this->request->post('id/d', 0);
-        return OrderServiceLogic::read($id);
-    }
-
-    //导出
-    public function export()
-    {
-        $param = $this->request->only(['orderCode' => '', 'status' => '', 'name' => '', 'username' => '', 'start_date' => '', 'end_date' => ''], 'post');
-
-        return OrderServiceLogic::export($param);
-    }
-
-    //发货
-    public function deliver()
-    {
-
-        $list = $this->request->post('list/a', 'post');
-
-        $val = Validate::rule(['list|发货列表' => 'require|array|length:1,100']);
-
-        if (!$val->check(['list' => $list])) throw new ValidateException($val->getError());
-
-        return OrderServiceLogic::deliver($list);
-
-    }
-
-}

+ 47 - 13
app/admin/logic/OrderLogic.php

@@ -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]);

+ 0 - 181
app/admin/logic/OrderServiceLogic.php

@@ -1,181 +0,0 @@
-<?php
-
-namespace app\admin\logic;
-
-use app\model\CommonModel;
-use app\model\OrderServiceModel;
-use think\Exception;
-use think\facade\Db;
-use think\facade\Validate;
-use think\response\Json;
-
-class OrderServiceLogic extends BaseLogic
-{
-    //列表
-    public static function list(array $data = []): Json
-    {
-
-        $db = OrderServiceModel::alias('a')
-            ->leftJoin('service s', 's.id=a.service_id AND s.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('company b', 'b.id=s.company_id AND b.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('card c', 'c.id=s.card_id AND c.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('account d', 'd.id=a.uid AND d.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('company bb', 'bb.id=d.company_id AND bb.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('card cc', 'cc.id=d.card_id AND cc.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('addr e', 'e.id=a.addr_id AND e.is_del=' . CommonModel::$del_normal)
-            ->where('a.is_del', CommonModel::$del_normal);
-
-        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']]);
-
-        $count = $db->count('a.id');
-
-        $list = $db
-            ->field('a.id,a.orderCode,bb.title account_company_title,c.title account_card_title,d.name,d.username,a.num,e.contactor,e.mobile,e.addr_code,s.title,a.amount,a.status,a.addtime,a.post_name,a.post_code,"" addr_name,e.addr')
-            ->page($data['page'], $data['size'])
-            ->withAttr('addr_code', function ($val) {
-                return explode(',', $val);
-            })
-            ->withAttr('addr_name', function ($val, $da) {
-                return $da['addr_code']?get_addr_name($da['addr_code']):'';
-            })
-            ->order('a.addtime desc')
-            ->select()
-            ->toArray();
-
-        return json_show(CommonModel::$success, '获取服务订单列表成功', ['count' => $count, 'list' => $list]);
-    }
-
-    //详情
-    public static function read(int $id = 0): Json
-    {
-        $rs = OrderServiceModel::alias('a')
-            ->field('a.id,a.orderCode,bb.title account_company_title,c.title account_card_title,d.name,d.username,a.num,e.contactor,e.mobile,e.addr_code,s.title,a.amount,a.status,a.addtime,a.post_name,a.post_code,"" addr_name,e.addr')
-            ->leftJoin('service s', 's.id=a.service_id AND s.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('company b', 'b.id=s.company_id AND b.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('card c', 'c.id=s.card_id AND c.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('account d', 'd.id=a.uid AND d.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('company bb', 'bb.id=d.company_id AND bb.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('card cc', 'cc.id=d.card_id AND cc.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('addr e', 'e.id=a.addr_id AND e.is_del=' . CommonModel::$del_normal)
-            ->where(['a.is_del' => CommonModel::$del_normal, 'a.id' => $id])
-            ->withAttr('addr_code', function ($val) {
-                return explode(',', $val);
-            })
-            ->withAttr('addr_name', function ($val, $da) {
-                return $da['addr_code']?get_addr_name($da['addr_code']):'';
-            })
-            ->findOrEmpty()
-            ->toArray();
-        return json_show(CommonModel::$success, '获取商品详情成功', $rs);
-    }
-
-    //导出
-    public static function export(array $data = []): Json
-    {
-
-        $db = OrderServiceModel::alias('a')
-            ->leftJoin('service s', 's.id=a.service_id AND s.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('company b', 'b.id=s.company_id AND b.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('card c', 'c.id=s.card_id AND c.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('account d', 'd.id=a.uid AND d.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('company bb', 'bb.id=d.company_id AND bb.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('card cc', 'cc.id=d.card_id AND cc.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('addr e', 'e.id=a.addr_id AND e.is_del=' . CommonModel::$del_normal)
-            ->where('a.is_del', CommonModel::$del_normal);
-
-        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']]);
-
-        $list = $db
-            ->field('a.id 订单ID,a.orderCode 订单编号,bb.title 购买账号业务公司,c.title 购买账号卡类型,d.name 购买用户名,d.username 购买账号,a.num 购买数量,e.contactor 收货联系人,e.mobile 收货联系电话,e.addr_code,s.title 服务名称,a.amount 支付金额,a.status 状态,a.addtime 创建时间,a.post_name 物流公司,a.post_code 物流单号,e.addr')
-            ->order('a.addtime desc')
-            ->cursor();
-
-        $status =  $status = [
-            CommonModel::$order_status_wait_pay => '待支付',
-            CommonModel::$order_status_pay_fail => '支付失败',
-            CommonModel::$order_status_not_deliver => '待发货',
-            CommonModel::$order_status_deliver => '已发货',
-            CommonModel::$order_status_receipt => '已收货',
-        ];
-
-        $da = [];
-        foreach ($list as $v) {
-            $v = $v->toArray();
-
-            $v['收货地址'] = $v['addr_code']?get_addr_name($v['addr_code']).$v['addr']:$v['addr'];
-            $v['状态'] = $status[$v['状态']] ?? '';
-
-            unset($v['addr_code']);
-            unset($v['addr']);
-
-            $da[] = $v;
-        }
-
-        if (empty($da)) $da[] = '没有可供导出的数据';
-
-        $headerArr = array_keys($da[0]);
-        excel_save('服务订单导出' . date('YmdHis'), $headerArr, $da);
-
-    }
-
-    //发货
-    public static function deliver(array $list = [])
-    {
-
-        $db = new OrderServiceModel();
-        $temp = $db
-            ->field('id,orderCode')
-            ->where(['is_del' => CommonModel::$del_normal])
-            ->where('status', '<>', CommonModel::$order_status_not_deliver)
-            ->whereIn('orderCode', array_column($list, 'orderCode'))
-            ->findOrEmpty();
-
-        if (!$temp->isEmpty()) return json_show(CommonModel::$error_param, $temp->orderCode . '订单并不是未发货状态');
-
-        $val = Validate::rule([
-            'orderCode|订单编号' => 'require|length:18',
-            'post_name|物流公司' => 'require|max:255',
-            'post_code|物流单号' => 'require|max:255',
-        ]);
-
-        Db::startTrans();
-        try {
-
-            $date = date('Y-m-d H:i:s');
-
-            foreach ($list as $order) {
-
-                if (!$val->check($order)) throw new Exception($val->getError());
-
-                $db->where([
-                    'is_del' => CommonModel::$del_normal,
-                    'orderCode' => $order['orderCode'],
-                    'status' => CommonModel::$order_status_not_deliver,
-                ])->save([
-                    'status' => CommonModel::$order_status_deliver,
-                    'post_name' => $order['post_name'],
-                    'post_code' => $order['post_code'],
-                    'updater' => self::$uname,
-                    'updaterid' => self::$uid,
-                    'updatetime' => $date,
-                ]);
-            }
-
-            Db::commit();
-            return json_show(CommonModel::$success, '发货成功');
-        } catch (Exception $exception) {
-            Db::rollback();
-            return json_show(CommonModel::$error_param, '发货失败,' . $exception->getMessage());
-        }
-
-    }
-
-}

+ 4 - 4
app/admin/route/app.php

@@ -140,10 +140,10 @@ Route::rule('orderRead', 'admin/Order/read');//详情
 Route::rule('orderDeliver', 'admin/Order/deliver');//发货
 Route::rule('orderExport', 'admin/Order/export');//导出
 //【服务订单】
-Route::rule('orderServiceList', 'admin/OrderService/list');//列表
-Route::rule('orderServiceRead', 'admin/OrderService/read');//详情
-Route::rule('orderServiceDeliver', 'admin/OrderService/deliver');//发货
-Route::rule('orderServiceExport', 'admin/OrderService/export');//导出
+//Route::rule('orderServiceList', 'admin/OrderService/list');//列表
+//Route::rule('orderServiceRead', 'admin/OrderService/read');//详情
+//Route::rule('orderServiceDeliver', 'admin/OrderService/deliver');//发货
+//Route::rule('orderServiceExport', 'admin/OrderService/export');//导出
 
 //【手机主题】
 Route::rule('themeList', 'admin/Theme/list');//列表

+ 1 - 0
app/mobile/logic/PayLogic.php

@@ -42,6 +42,7 @@ class PayLogic extends BaseLogic
             $pay_info_id = Db::name('pay_info')->insertGetId([
                 'pay_code' => $pay_code,
                 'wx_openId' => $openId,
+                'uid' => self::$aid,
                 'type' => $data['type'],
                 'ids' => json_encode($data['list']),
                 'status' => CommonModel::$order_status_wait_pay,

+ 1 - 3
app/model/CommonModel.php

@@ -41,8 +41,6 @@ class CommonModel
     public static $order_status_receipt = 4;
 
 
-    //购买的类型,1购买服务,2购买商城商品
-    public static $pay_type_service = 1;
-    public static $pay_type_shopping_good = 2;
+
 
 }

+ 20 - 0
app/model/MasterOrderModel.php

@@ -0,0 +1,20 @@
+<?php
+
+
+namespace app\model;
+
+use think\Model;
+
+class MasterOrderModel extends Model
+{
+
+    protected $table='master_order';
+    protected $pk='id';
+
+    //订单类型,1兑换商品,2商城商品,3服务
+    public static $type_exchange_good = 1;
+    public static $type_shopping_good = 2;
+    public static $type_service = 3;
+
+
+}