wufeng 2 سال پیش
والد
کامیت
343d710c77
3فایلهای تغییر یافته به همراه40 افزوده شده و 24 حذف شده
  1. 9 6
      app/mobile/controller/Order.php
  2. 29 15
      app/mobile/logic/OrderLogic.php
  3. 2 3
      app/model/MasterOrderModel.php

+ 9 - 6
app/mobile/controller/Order.php

@@ -11,15 +11,16 @@ use think\facade\Validate;
 //【订单】
 class Order extends BaseController
 {
-    //下单
+    //下单
     public function add()
     {
-        $param = $this->request->only(['type', 'list', 'addr_id'], 'post');
+        $param = $this->request->only(['type', 'list', 'addr_id', 'remark' => ''], 'post');
 
         $val = Validate::rule([
             'type|购买类型' => 'require|number|in:' . MasterOrderModel::$type_exchange_good . ',' . MasterOrderModel::$type_shopping_good . ',' . MasterOrderModel::$type_service,
             'list|购买列表' => 'require|array|max:100',
-            'addr_id|收货地址' => 'require|number|gt:0'
+            'addr_id|收货地址' => 'require|number|gt:0',
+            'remark|备注' => 'max:255'
         ]);
         if (!$val->check($param)) throw new ValidateException($val->getError());
 
@@ -36,13 +37,15 @@ class Order extends BaseController
     }
 
     //订单列表
-    public function list(){
-        $param = $this->request->only(['page' => 1, 'size' => 10,'status'=>''], 'post');
+    public function list()
+    {
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'status' => ''], 'post');
         return OrderLogic::list($param);
     }
 
     //订单详情
-    public function info(){
+    public function info()
+    {
         $id = $this->request->post('id/d', 0);
         return OrderLogic::info($id);
     }

+ 29 - 15
app/mobile/logic/OrderLogic.php

@@ -47,6 +47,7 @@ class OrderLogic extends BaseLogic
                 'updaterid' => self::$aid,
                 'updater' => self::$aname,
                 'updatetime' => $date,
+                'remark' => $data['remark']
             ];
 
             //子订单数据
@@ -55,7 +56,6 @@ class OrderLogic extends BaseLogic
             //库存变动记录数据
             $insert_inventory_exchange_log = [];
 
-
             //兑换商品
             if ($data['type'] == MasterOrderModel::$type_exchange_good) {
 
@@ -82,6 +82,7 @@ class OrderLogic extends BaseLogic
                         'card_id' => self::$card_id,
                         'uid' => self::$aid,
                         'child_id' => $item['id'],
+                        'child_title' => $item['good_name'],
                         'num' => $num[$item['id']],
                         'price' => 0,
                         'total_price' => 0,
@@ -171,6 +172,7 @@ class OrderLogic extends BaseLogic
                                 'card_id' => self::$card_id,
                                 'uid' => self::$aid,
                                 'child_id' => $item['id'],
+                                'child_title' => $item['title'],
                                 'num' => $num[$item['id']] ?? 0,
                                 'price' => $price,
                                 'total_price' => $total_price,
@@ -212,13 +214,14 @@ class OrderLogic extends BaseLogic
                             $total_price = bcmul($rs['price'], $num[$item['id']] ?? 0, 2);//总价
                             $amount = bcadd($amount, $total_price, 2);//总金额
 
-                            $order_insert[] = [
+                            $insert_order[] = [
                                 'masterOrderCode' => $masterOrderCode,
                                 'orderCode' => $orderCode,
                                 'company_id' => self::$company_id,
                                 'card_id' => self::$card_id,
                                 'uid' => self::$aid,
                                 'child_id' => $item['id'],
+                                'child_title' => $item['good_name'],
                                 'num' => $num[$item['id']],
                                 'price' => $rs['price'],
                                 'total_price' => $total_price,
@@ -299,22 +302,27 @@ class OrderLogic extends BaseLogic
 
     }
 
-
     //订单列表
     public static function list(array $data = []): Json
     {
-        $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, 'a.uid' => self::$aid]);
+        $db = MasterOrderModel::where(['uid' => self::$aid]);
 
-        if ($data['status'] != '') $db->where('a.status', $data['status']);
+        if ($data['status'] != '') $db->where('status', $data['status']);
 
-        $count = $db->count('a.id');
+        $count = $db->count('id');
 
         $list = $db
-            ->field('a.id,a.orderCode,b.good_name,a.num,a.status,a.addtime,a.type,a.price,a.total_price')
+            ->field('id,masterOrderCode,amount,status,addtime')
+            ->append(['order_list'])
+            ->withAttr('order_list', function ($val, $da) {
+                return OrderModel::field('id,orderCode,child_title,price,num,total_price')
+                    ->where(['is_del' => CommonModel::$del_normal, 'masterOrderCode' => $da['masterOrderCode'], 'uid' => self::$aid])
+                    ->order('id')
+                    ->select()
+                    ->toArray();
+            })
             ->page($data['page'], $data['size'])
-            ->order('a.id', 'desc')
+            ->order('id', 'desc')
             ->select()
             ->toArray();
 
@@ -325,15 +333,21 @@ class OrderLogic extends BaseLogic
     //订单详情
     public static function info(int $id = 0): Json
     {
-        $rs = OrderModel::alias('a')
-            ->field('a.id,a.orderCode,a.status,a.addtime,a.type,b.good_name,a.num,c.contactor,c.mobile,c.addr,c.addr_code,a.price,a.total_price,a.post_name,a.post_code,a.remark,"支付流水号" p')
-            ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
+        $rs = MasterOrderModel::alias('a')
+            ->field('a.id,a.masterOrderCode,a.amount,a.status,a.addtime,c.contactor,c.mobile,c.addr,c.addr_code,a.transaction_id,a.remark')
             ->leftJoin('addr c', 'c.id=a.addr_id AND c.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('pay_info d', 'd.id=a.pay_info_id')
-            ->where(['a.is_del' => CommonModel::$del_normal, 'a.id' => $id, 'a.uid' => self::$aid])
+            ->append(['order_list'])
+            ->withAttr('order_list', function ($val, $da) {
+                return OrderModel::field('id,orderCode,child_title,child_cover,price,num,total_price')
+                    ->where(['is_del' => CommonModel::$del_normal, 'masterOrderCode' => $da['masterOrderCode'], 'uid' => self::$aid])
+                    ->order('id')
+                    ->select()
+                    ->toArray();
+            })
             ->withAttr('addr', function ($val, $da) {
                 return $da['addr_code'] ? get_addr_name($da['addr_code']) . $val : $val;
             })
+            ->where('a.id', $id)
             ->findOrEmpty()
             ->toArray();
 

+ 2 - 3
app/model/MasterOrderModel.php

@@ -8,8 +8,8 @@ use think\Model;
 class MasterOrderModel extends Model
 {
 
-    protected $table='fc_master_order';
-    protected $pk='id';
+    protected $table = 'fc_master_order';
+    protected $pk = 'id';
 
     //订单类型,1兑换商品,2商城商品,3服务
     public static $type_exchange_good = 1;
@@ -24,5 +24,4 @@ class MasterOrderModel extends Model
     public static $order_status_receipt = 4;
 
 
-
 }