Browse Source

订单(合并兑换订单和商城订单)

wufeng 2 years ago
parent
commit
7bd9195a88

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

@@ -0,0 +1,51 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\admin\logic\OrderLogic;
+use app\BaseController;
+use think\exception\ValidateException;
+use think\facade\Config;
+use think\facade\Validate;
+
+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');
+
+        return OrderLogic::list($param);
+    }
+
+    //详情
+    public function read()
+    {
+        $id = $this->request->post('id/d', 0);
+        return OrderLogic::read($id);
+    }
+
+    //导出
+    public function export()
+    {
+        $param = $this->request->only(['orderCode' => '', 'status' => '', 'name' => '', 'username' => '', 'start_date' => '', 'end_date' => '', 'type' => ''], 'post');
+
+        return OrderLogic::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 OrderLogic::deliver($list);
+
+    }
+
+}

+ 0 - 47
app/admin/controller/OrderExchange.php

@@ -1,47 +0,0 @@
-<?php
-
-namespace app\admin\controller;
-
-use app\admin\logic\OrderExchangeLogic;
-use app\BaseController;
-use think\exception\ValidateException;
-use think\facade\Config;
-use think\facade\Validate;
-
-class OrderExchange extends BaseController
-{
-
-    //列表
-    public function list(){
-        $param = $this->request->only(['page' => 1, 'size' => 10, 'orderCode'=>'','status' => '', 'name' => '', 'username' => '','start_date'=>'','end_date'=>''], 'post');
-
-        return OrderExchangeLogic::list($param);
-    }
-
-    //详情
-    public function read(){
-        $id = $this->request->post('id/d',0);
-        return OrderExchangeLogic::read($id);
-    }
-
-    //导出
-    public function export(){
-        $param = $this->request->only(['orderCode'=>'','status' => '', 'name' => '', 'username' => '','start_date'=>'','end_date'=>''], 'post');
-
-        return OrderExchangeLogic::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 OrderExchangeLogic::deliver($list);
-
-    }
-
-}

+ 1 - 1
app/admin/logic/CompanyGoodLogic.php

@@ -30,7 +30,7 @@ class CompanyGoodLogic extends BaseLogic
         if ($data['good_name'] != '') $db->whereLike('b.good_name', '%' . $data['good_name'] . '%');
         if ($data['good_code'] != '') $db->whereLike('b.good_code', '%' . $data['good_code'] . '%');
         if ($data['status'] != '') $db->where('a.status', $data['status']);
-        if ($data['type'] != '') $db->where('a.type', $data['type']);
+        if ($data['type'] != '') $db->where('b.type', $data['type']);
 
         $count = $db->count('a.id');
 

+ 20 - 14
app/admin/logic/OrderExchangeLogic.php → app/admin/logic/OrderLogic.php

@@ -3,19 +3,20 @@
 namespace app\admin\logic;
 
 use app\model\CommonModel;
-use app\model\OrderExchangeModel;
+use app\model\GoodModel;
+use app\model\OrderModel;
 use think\Exception;
 use think\facade\Db;
 use think\facade\Validate;
 use think\response\Json;
 
-class OrderExchangeLogic extends BaseLogic
+class OrderLogic extends BaseLogic
 {
     //列表
     public static function list(array $data = []): Json
     {
 
-        $db = OrderExchangeModel::alias('a')
+        $db = OrderModel::alias('a')
             ->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)
@@ -28,30 +29,31 @@ class OrderExchangeLogic extends BaseLogic
         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']);
 
         $count = $db->count('a.id');
 
         $list = $db
-            ->field('a.id,a.orderCode,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.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')
             ->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']):'';
+                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]);
+        return json_show(CommonModel::$success, '获取订单列表成功', ['count' => $count, 'list' => $list]);
     }
 
     //详情
     public static function read(int $id = 0): Json
     {
-        $rs = $db = OrderExchangeModel::alias('a')
-            ->field('a.id,a.orderCode,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')
+        $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')
             ->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)
@@ -62,7 +64,7 @@ class OrderExchangeLogic extends BaseLogic
                 return explode(',', $val);
             })
             ->withAttr('addr_name', function ($val, $da) {
-                return $da['addr_code']?get_addr_name($da['addr_code']):'';
+                return $da['addr_code'] ? get_addr_name($da['addr_code']) : '';
             })
             ->findOrEmpty()
             ->toArray();
@@ -73,7 +75,7 @@ class OrderExchangeLogic extends BaseLogic
     public static function export(array $data = []): Json
     {
 
-        $db = OrderExchangeModel::alias('a')
+        $db = OrderModel::alias('a')
             ->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)
@@ -86,21 +88,25 @@ class OrderExchangeLogic extends BaseLogic
         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']);
 
         $status = [CommonModel::$status_not_deliver => '待发货', CommonModel::$status_deliver => '已发货', CommonModel::$status_receipt => '已收货'];
+        $type = [GoodModel::$type_shopping => '商城', GoodModel::$type_exchange => '兑换'];
         $list = $db
-            ->field('a.id 订单ID,a.orderCode 订单编号,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 商品名称')
+            ->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();
 
         $da = [];
         foreach ($list as $v) {
             $v = $v->toArray();
-            $v['收货地址'] = $v['addr_code']?get_addr_name($v['addr_code']).$v['addr']:$v['addr'];
+            $v['收货地址'] = $v['addr_code'] ? get_addr_name($v['addr_code']) . $v['addr'] : $v['addr'];
             $v['状态'] = $status[$v['状态']] ?? '';
+            $v['订单类型'] = $type[$v['type']] ?? '';
 
             unset($v['addr_code']);
             unset($v['addr']);
+            unset($v['type']);
 
             $da[] = $v;
         }
@@ -108,7 +114,7 @@ class OrderExchangeLogic extends BaseLogic
         if (empty($da)) $da[] = '没有可供导出的数据';
 
         $headerArr = array_keys($da[0]);
-        excel_save('兑换订单导出' . date('YmdHis'), $headerArr, $da);
+        excel_save('订单导出' . date('YmdHis'), $headerArr, $da);
 
     }
 
@@ -116,7 +122,7 @@ class OrderExchangeLogic extends BaseLogic
     public static function deliver(array $list = [])
     {
 
-        $db = new OrderExchangeModel();
+        $db = new OrderModel();
         $temp = $db
             ->field('id,orderCode')
             ->where(['is_del' => CommonModel::$del_normal])

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

@@ -134,11 +134,11 @@ Route::rule('serviceEdit', 'admin/Service/edit');//修改
 Route::rule('serviceDelete', 'admin/Service/delete');//删除
 Route::rule('serviceStatus', 'admin/Service/status');//上下架
 
-//【兑换订单】
-Route::rule('orderExchangeList', 'admin/OrderExchange/list');//列表
-Route::rule('orderExchangeRead', 'admin/OrderExchange/read');//详情
-Route::rule('orderExchangeDeliver', 'admin/OrderExchange/deliver');//发货
-Route::rule('orderExchangeExport', 'admin/OrderExchange/export');//导出
+//【订单】
+Route::rule('orderList', 'admin/Order/list');//列表
+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');//详情

+ 4 - 4
app/mobile/logic/ExchangeLogic.php

@@ -8,7 +8,7 @@ use app\model\CompanyGoodModel;
 use app\model\GoodModel;
 use app\model\GroupModel;
 use app\model\InventoryExchangeModel;
-use app\model\OrderExchangeModel;
+use app\model\OrderModel;
 use think\Exception;
 use think\facade\Db;
 use think\response\Json;
@@ -114,7 +114,7 @@ class ExchangeLogic extends BaseLogic
                 ->save(['inventory' => $after_inventory, 'updaterid' => self::$aid, 'updater' => self::$aname, 'updatetime' => $date]);
 
             //生成兑换订单
-            OrderExchangeModel::create([
+            OrderModel::create([
                 'orderCode' => make_no('DH'),
                 'company_id' => self::$company_id,
                 'card_id' => self::$card_id,
@@ -146,7 +146,7 @@ class ExchangeLogic extends BaseLogic
     //兑换订单列表
     public static function orderList(array $data = []): Json
     {
-        $db = OrderExchangeModel::alias('a')
+        $db = OrderModel::alias('a')
             ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
             ->where('a.is_del', CommonModel::$del_normal);
 
@@ -168,7 +168,7 @@ class ExchangeLogic extends BaseLogic
     //兑换订单详情
     public static function orderInfo(int $id = 0): Json
     {
-        $rs = OrderExchangeModel::alias('a')
+        $rs = OrderModel::alias('a')
             ->field('a.id,a.orderCode,a.status,a.addtime,b.good_name,a.num,c.contactor,c.mobile,c.addr,c.addr_code')
             ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
             ->leftJoin('addr c', 'c.id=a.addr_id AND c.is_del=' . CommonModel::$del_normal)

+ 1 - 1
app/mobile/logic/ShoppingLogic.php

@@ -8,7 +8,7 @@ use app\model\CompanyGoodModel;
 use app\model\GoodModel;
 use app\model\GroupModel;
 use app\model\InventoryExchangeModel;
-use app\model\OrderExchangeModel;
+use app\model\OrderModel;
 use think\Exception;
 use think\facade\Db;
 use think\response\Json;

+ 3 - 3
app/model/OrderExchangeModel.php → app/model/OrderModel.php

@@ -4,15 +4,15 @@ namespace app\model;
 
 use think\Model;
 
-class OrderExchangeModel extends Model
+class OrderModel extends Model
 {
-    protected $table = 'fc_order_exchange';
+    protected $table = 'fc_order';
     protected $pk = 'id';
 
-
     //状态:0未发货,1已发货,2已收货
     public static $status_not_deliver = 0;
     public static $status_deliver = 1;
     public static $status_receipt = 2;
 
+
 }