1557492053 il y a 3 ans
Parent
commit
19764c747f

+ 69 - 2
app/api/controller/Order.php

@@ -96,6 +96,7 @@ class Order extends \app\BaseController
     /**
      * @return \think\response\Json
      * @throws BaseException
+     * @throws \think\db\exception\DbException
      */
     public function fetchByCustomerId() {
         $params = $this->request->param();
@@ -105,6 +106,12 @@ class Order extends \app\BaseController
         return $this->ok($res);
     }
 
+    public function fetchOrderProducts() {
+        $params = $this->request->param();
+        predicate(isset($params['order_id']) && $params['order_id'] > 0, '订单ID不能为空');
+        return $this->ok($this->service->fetchOrderProducts($params['order_id'], $params['page'] ?? 1, $params['size'] ?? 10));
+    }
+
     /**
      * @return \think\response\Json
      * @throws BaseException
@@ -118,6 +125,9 @@ class Order extends \app\BaseController
         return $this->ok($res->data);
     }
 
+    /**
+     * @return \think\response\Json
+     */
     public function fetchWaitGatherAnnualFee() {
         $params = $this->request->param();
         return $this->ok($this->service->fetchWaitGatherAnnualFee(
@@ -130,6 +140,10 @@ class Order extends \app\BaseController
         ));
     }
 
+    /**
+     * @return \think\response\Json
+     * @throws BaseException
+     */
     public function paymentAnnualFee() {
         $params = $this->request->param();
         predicate(isset($params['annual_fee_id']) && $params['annual_fee_id'] > 0, '待收取年费的ID错误!');
@@ -138,11 +152,64 @@ class Order extends \app\BaseController
         return $this->ok($r->data);
     }
 
+    /**
+     * @return \think\response\Json
+     * @throws BaseException
+     */
+    public function fetchOrderByReturn() {
+        $params = $this->request->param();
+        predicate(isset($params['store_id']) && $params['store_id'] > 0, '门店ID错误!');
+        return $this->ok($this->service->fetchOrderByReturn(
+            $params['admin_id'],
+            $params['store_id'],
+            format_string($params['order_no'] ?? null),
+            format_string($params['customer_name'] ?? null),
+            $params['page'] ?? 1,
+            $params['size'] ?? 10
+        ));
+    }
 
+    /**
+     * @return \think\response\Json
+     * @throws BaseException
+     */
+    public function returnOrderProduct() {
+        $params = $this->request->param();
+        predicate(isset($params['order_id']) && $params['order_id'] > 0, '订单ID不存在!');
+        predicate(isset($params['order_product_ids']), lang("Please select the item to return"));
+        $order_product_ids = explode(',', $params['order_product_ids']);
+        $r = $this->service->returnOrderProduct($params['admin_id'],$params['order_id'], array_unique($order_product_ids));
+        predicate($r->bool, $r->message);
+        return $this->ok($r->data);
+    }
 
+    /**
+     * @return \think\response\Json
+     * @throws BaseException
+     */
+    public function findByOrderNo() {
+        $params = $this->request->param();
+        predicate(isset($params['order_no']) && strlen($params['order_no']) > 0, '请输入订单编号!');
+        $r = $this->service->findByOrderNo($params['admin_id'], $params['order_no']);
+        predicate($r->bool, $r->message);
+        return $this->ok($r->data);
+    }
 
-
-
+    /**
+     * @return \think\response\Json
+     * @throws BaseException
+     */
+    public function exchange() {
+        $params = $this->request->param();
+        predicate(isset($params['order_id']) && $params['order_id'] > 0, '订单ID不存在!');
+        predicate(isset($params['origin_order_product_ids']) && $params['origin_order_product_ids'] > 0, '原来的订单商品IDs不存在!');
+        predicate(isset($params['append_product_ids']) && $params['append_product_ids'] > 0, '新添加的商品IDs不存在!');
+        $origin_order_product_ids = explode(',', $params['origin_order_product_ids']);
+        $append_product_ids = explode(',', $params['append_product_ids']);
+        $r = $this->service->exchange($params['admin_id'], $params['order_id'], $origin_order_product_ids, $append_product_ids);
+        predicate($r->bool, $r->message);
+        return $this->ok($r->data);
+    }
 
 
 }

+ 3 - 0
app/api/lang/zh-cn.php

@@ -47,6 +47,9 @@ return [
     "inventory shortage"            =>  "库存不足",
     "No customer found"             =>  "未找到客户",
     'Account password error'        =>  "账号密码错误!",
+    "Please select the item to return"  =>  "请选择需要退掉的商品!",
+    "Order does not exist"  =>  "订单不存在",
+    "The order item was incorrectly selected"   =>  "订单商品选择有误!",
 ];
 
 

+ 5 - 1
app/api/route/app.php

@@ -22,7 +22,6 @@ Route::group('api/user', function () {
     Route::rule('fetchMenus', 'api/admin/fetchMenus');
 })->middleware(\app\common\middleware\VerifySessionToken::class);
 
-
 Route::group('api/order', function () {
     Route::rule('create', 'api/order/create');
     Route::rule('payment', 'api/order/payment');
@@ -31,6 +30,11 @@ Route::group('api/order', function () {
     Route::rule('upload_numerology', 'api/order/upload_numerology');
     Route::rule('fetchWaitGatherAnnualFee', 'api/order/fetchWaitGatherAnnualFee');
     Route::rule('paymentAnnualFee', 'api/order/paymentAnnualFee');
+    Route::rule('fetchOrderProducts', 'api/order/fetchOrderProducts');
+    Route::rule('fetchOrderByReturn', 'api/order/fetchOrderByReturn');
+    Route::rule('returnOrderProduct', 'api/order/returnOrderProduct');
+    Route::rule('findByOrderNo', 'api/order/findByOrderNo');
+    Route::rule('exchange', 'api/order/exchange');
 })->middleware(\app\common\middleware\VerifySessionToken::class);
 
 Route::group('api/payment', function () {

+ 4 - 3
app/api/service/AuthService.php

@@ -16,14 +16,15 @@ class AuthService extends \app\BaseService
 //        $this->adminModel = new AdminModel();
 //    }
 
-    public static function is_look_all($admin_id, $data_rule_id) {
-
+    public static function verify($admin_id, $data_rule_id) {
         // 定金订单查看全部
         if (in_array($data_rule_id, [10004]))
             return true;
         $admin = (new AdminModel())->findById($admin_id);
         if(!$admin || !$admin->access || !$admin->access->group) return false;
-        return in_array($data_rule_id,$admin->access->group->data_rules ? explode(',', $admin->access->group->data_rules) : []);
+        $data_rules = $admin->access->group->data_rules ? explode(',', $admin->access->group->data_rules) : [];
+        $reception_rules = $admin->access->group->reception_rules ? explode(',', $admin->access->group->reception_rules) : [];
+        return in_array($data_rule_id, $data_rules) && in_array($data_rule_id, $reception_rules);
     }
 
 

+ 230 - 47
app/api/service/OrderService.php

@@ -177,7 +177,7 @@ class OrderService extends \app\BaseService
                     'reduce_type'    => $store_product['activity'] ? $store_product['activity']['type'] : 0,
                     'sales_tax_rate' => $store_product['product']['sales_tax_rate'],
                     'sales_tax' => $store_product['product']['sales_tax'],
-                    'transaction_price' =>  0,
+                    'transaction_price' =>  fixed2Float($store_product['product']['real_price'] + $store_product['product']['sales_tax'] + $store_product['product']['annuity']),
                     'zue_coin'  =>  0,
                     'create_time' => time(),
                     'update_time' => time(),
@@ -207,7 +207,7 @@ class OrderService extends \app\BaseService
             'total_annual_fee' => $total_annual_fee,
             'type'  =>  2,
             'store_id'  =>  $store->id,
-            'advisor_ids' => join(',', $advisor_ids),
+            'advisor_ids' => join(',', array_unique($advisor_ids)),
             'create_time' => time(),
             'update_time' => time()
         ]);
@@ -236,7 +236,7 @@ class OrderService extends \app\BaseService
     public function payment($params, $channels) {
         $order = $this->orderModel->findById($params);
         if(!$order)
-            return $this->fail('订单不存在!');
+            return $this->fail(lang("Order does not exist"));
         if($order->type == 1)
             return $this->fail('订单状态为历史订单!不支持付款');
         // 客户
@@ -271,6 +271,7 @@ class OrderService extends \app\BaseService
             $item = [
                 'order_id' => $order->id,
                 'channel_id' => $channel->channel_id,
+                'channel_name' => $fmt_pay_channel['name'],
                 'create_time' => time(),
                 'update_time' => time(),
             ];
@@ -301,6 +302,7 @@ class OrderService extends \app\BaseService
                     $el = [
                         'order_id' => $order->id,
                         'channel_id' => $channel->channel_id,
+                        'channel_name' => $fmt_pay_channel['name'],
                         'fee'   => $credit_card->fee,
                         'credit_card_id' => $credit_card->credit_card_id,
                         'credit_card_name' => $fmt_credit_card_config['bank'],
@@ -345,35 +347,41 @@ class OrderService extends \app\BaseService
         $order_use_zue_coin_amount = $order->zue_coin_amount;
 
         $change_zue_coin_record = null;
+        $zue_coin_model = $this->zueCoinModel->findByCustomerId($customer->id);
+        if(!$zue_coin_model)
+            return $this->fail("当前客户御龙币账户余额: 0");
+        if ($zue_coin > $zue_coin_model->zue_coin)
+            return $this->fail("当前客户御龙币账户余额:{$zue_coin_model->zue_coin}");
+        $zue_coin_config = $fmt_pay_channels['11'];
+        if(!$zue_coin_config)
+            return $this->fail("御龙币设置不存在!");
+        $zue_coin_exchange_rate = $zue_coin_config['zue_coin_exchange_rate'] ?? 0; // 兑换比例
+        $zue_coin_consume_rate = $zue_coin_config['zue_coin_consume_rate'] ?? 0; // 报销比例
         if($zue_coin > 0) {
-            $zue_coin_model = $this->zueCoinModel->findByCustomerId($customer->id);
-            if(!$zue_coin_model)
-                return $this->fail("当前客户御龙币账户余额: 0");
-            if ($zue_coin > $zue_coin_model->zue_coin)
-                return $this->fail("当前客户御龙币账户余额:{$zue_coin_model->zue_coin}");
-            $zue_coin_config = $fmt_pay_channels['11'];
-            if(!$zue_coin_config)
-                return $this->fail("御龙币设置不存在!");
-            $zue_coin_exchange_rate = $zue_coin_config['zue_coin_exchange_rate'] ?? 0; // 兑换比例
-            $zue_coin_consume_rate = $zue_coin_config['zue_coin_consume_rate'] ?? 0; // 报销比例
             if($zue_coin_exchange_rate == 0 || $zue_coin_consume_rate == 0) {
                 return $this->fail("该笔订单不支持御龙币支付");
             }
-
             // 1.计算出该订单能使用多少御龙币
             // 2.结合之前已使用的御龙币 算出还能使用多少御龙币
             // 3.判断当前御龙币是否符合兑换数额
             // 4.进行扣除并记录
 
-            // 总共能报销这么多钱
-            $total_consume_amount = fixed2Float($imposed_amount * ($zue_coin_consume_rate / 100));
-            // 总共能消耗这么多御龙币
-            $total_can_zue_coin = fixed2Float($total_consume_amount / $zue_coin_exchange_rate);
-            // 还能使用多少御龙币
-            $now_can_consume_zue_coin = $total_can_zue_coin - $order_use_zue_coin;
+            // 根据御龙币的设置 总共能报销这么多钱
+            $max_consume_amount = fixed2Float($imposed_amount * ($zue_coin_consume_rate / 100));
+            // 根据御龙币的设置 最大的报销的御龙币
+            $max_consume_zue_coin = fixed2Float($max_consume_amount / $zue_coin_exchange_rate);
+            if ($max_consume_zue_coin - ($order->zue_coin + $zue_coin) < 0) {
+                return $this->fail("最多能使用御龙币: {$max_consume_zue_coin}, 当前已使用{$order->zue_coin}");
+            }
+
+            // 根据当前订单支付情况 得出现在最大的报销金额;
+            $now_max_consume_amount = $order->imposed_amount < $max_consume_amount ? $order->imposed_amount : $max_consume_amount;
+            // 当前最多还能使用多少御龙币
+            $now_can_consume_zue_coin = fixed2Float($now_max_consume_amount / $zue_coin_exchange_rate);
             // 判断当前还能使用
             if ($now_can_consume_zue_coin - $zue_coin < 0)
-                return $this->fail("当前已使用御龙币数额: {$order_use_zue_coin}/{$total_can_zue_coin},当前已兑换金额: {$order_use_zue_coin_amount}/{$total_consume_amount},御龙币兑换比例: {$zue_coin_exchange_rate},御龙币报销比例:{$zue_coin_consume_rate}");
+                return $this->fail("当前剩余可使用的: {$now_can_consume_zue_coin}");
+
             // 总共使用了这么多御龙币
             $order_use_zue_coin += $zue_coin;
             // 总共兑换了这么多钱
@@ -393,10 +401,11 @@ class OrderService extends \app\BaseService
 
         // 总计实收金额
         $receive_amount = fixed2Float($order->receive_amount + $total_fee);
-        if (round($receive_amount) > round($imposed_amount)) return $this->fail("实收金额大于待收金额! 应该支付 {$imposed_amount} (商品总价:{$order->product_amount} + 商品总消费税:{$order->total_sales_tax} + 第一年年费:{$order->total_annual_fee} + 信用卡总手续费:{$total_service_charge_amount})");
+        if (round($receive_amount) > round($imposed_amount)) return $this->fail("实收金额大于待收金额! 当前已付款: {$order->receive_amount} / {$order->receivable_amount} (商品总价:{$order->product_amount} + 商品总消费税:{$order->total_sales_tax} + 第一年年费:{$order->total_annual_fee} + 信用卡总手续费:{$order->service_charge_amount})");
         $order_annual_fees = [];
         $update_store_products = [];
         $update_order_products = [];
+
         if (round($receive_amount) == round($imposed_amount)) { // 减库存
             $order_products = $this->orderProductModel->findByOrderId($order->id)->toArray();
             $store_products = $this->storeProductModel->findByIds(array_map(function ($r) {return $r['store_product_id'];}, $order_products))->toArray();
@@ -404,13 +413,12 @@ class OrderService extends \app\BaseService
                 $result[$item['id']] = $item;
                 return $result;
             },[]);
-            // 商品本身的价格 | 年费 | 消费税 |  信用卡支付的服务费 | 御龙币使用的御龙币退还
-            $total_ = $imposed_amount - ($order->service_charge_amount + $service_charge);
-
-            // 每一块钱所占的比例
-            $item_service_charge = ($order->service_charge_amount + $service_charge) / $total_;
+            // 商品本身的价格 | 年费 | 消费税
+            $total_ = $order->product_amount + $order->total_annual_fee + $order->total_sales_tax;
+            // 信用卡手续费 每一块钱所占的比例
+            $item_service_charge_rate = ($order->service_charge_amount + $service_charge) / $total_;
             // 每一个御龙币所占的比例
-            $item_zue_coin = $order_use_zue_coin / $total_;
+            $item_zue_coin_rate = $order_use_zue_coin / $total_;
             foreach ($order_products as $order_product) {
                 predicate($fmt_store_products[$order_product['store_product_id']]['now_stock'] > 0, lang('inventory shortage'));
                 $fmt_store_products[$order_product['store_product_id']]['now_stock'] -= 1;
@@ -441,11 +449,14 @@ class OrderService extends \app\BaseService
                     ]);
                 }
                 $now = $order_product['real_price'] + $order_product['annuity'] + $order_product['sales_tax'];
+                $item_service_charge = fixed2Float($now * $item_service_charge_rate);
+                $item_zue_coin = fixed2Float($now * $item_zue_coin_rate);
+                $transaction_price = fixed2Float($now + $item_service_charge - ($item_zue_coin * $zue_coin_exchange_rate));
                 array_push($update_order_products, [
                     'id'    =>  $order_product['id'],
-                    'service_charge'    =>  $now * $item_service_charge,
-                    'zue_coin'          =>  $now * $item_zue_coin,
-                    'transaction_price' =>  $now + ($now * $item_service_charge),
+                    'service_charge'    => $item_service_charge,
+                    'zue_coin'          => $item_zue_coin,
+                    'transaction_price' => $transaction_price,
                     'is_pay' => 1
                 ]);
             }
@@ -467,7 +478,7 @@ class OrderService extends \app\BaseService
                 $update_order['type'] = 1;
                 if(count($update_order_products) > 0) {
                     foreach ($update_order_products as $item) {
-                        Db::table('erp_order_product')->where('order_id', $item['id'])->update($item);
+                        Db::table('erp_order_product')->where('id', $item['id'])->update($item);
                     }
                 }
                 if(count($order_annual_fees) > 0) {
@@ -498,6 +509,7 @@ class OrderService extends \app\BaseService
                     return  [
                         "order_id" => isset($data['order_id']) ? $data['order_id'] : null,
                         "channel_id" => isset($data['channel_id']) ? $data['channel_id'] : null,
+                        "channel_name" => isset($data['channel_name']) ? $data['channel_name']: null,
                         "fee" => isset($data['fee']) ? $data['fee'] : null,
                         "credit_card_id" => isset($data['credit_card_id']) ? $data['credit_card_id'] : null,
                         "credit_card_name" => isset($data['credit_card_name']) ? $data['credit_card_name'] : null,
@@ -508,7 +520,7 @@ class OrderService extends \app\BaseService
                         "service_charge_rate" => isset($data['service_charge_rate']) ? $data['service_charge_rate'] : null,
                         "service_charge" => isset($data['service_charge']) ? $data['service_charge'] : null
                     ];
-                },$order_payments));
+                }, $order_payments));
             }
             Db::table('erp_order')->where('id', $order->id)->update($update_order);
             Db::commit();
@@ -519,18 +531,68 @@ class OrderService extends \app\BaseService
         return $this->ok(true);
     }
 
+    /**
+     * @param $params
+     * @return array
+     * @throws \think\db\exception\DbException
+     */
     public function fetch($params) {
-        $is_look_all = AuthService::is_look_all($params['admin_id'],$params['type'] == 1 ? 10003 : 10004);
-        $res = $this->orderModel->search($params, $is_look_all);
+        $verify = AuthService::verify($params['admin_id'],$params['type'] == 1 ? 10003 : 10004);
+        $res = $this->orderModel->search($params, $verify);
         $items = $res['data'];
-        foreach ($items as &$item) {
-            $item['is_need_upload'] = $item['type'] == 1 && in_array(true, array_map(function ($product) {
-                return $product['is_upload_numerology'] == 1 && $product['is_upload'] == 0;
-            }, $item['products']));
-        }
-        return [$items, $res['total']];
+        return [array_map(function ($item) {
+            return [
+                "id" => $item['id'],
+                "no" => $item['no'],
+                "customer_id" => $item['customer_id'],
+                "customer_name" => $item['customer_name'],
+                "obj_names" => $item['obj_names'],
+                "rental_amount" => $item['rental_amount'],
+                "receivable_amount" => $item['receivable_amount'],
+                "receive_amount" => $item['receive_amount'],
+                "imposed_amount" => $item['imposed_amount'],
+                "product_amount" => $item['product_amount'],
+                "total_sales_tax" => $item['total_sales_tax'],
+                "service_charge_amount" => $item['service_charge_amount'],
+                "total_annual_fee" => $item['total_annual_fee'],
+                "zue_coin" => $item['zue_coin'],
+                "zue_coin_amount" => $item['zue_coin_amount'],
+                "type" => $item['type'],
+                "store_id" => $item['store_id'],
+                "advisor_ids" => $item['advisor_ids'],
+                "remarks" => $item['remarks'],
+                "create_time" => $item['create_time'],
+                "advisers"  => join('/',array_unique(array_reduce($item['products'], function ($result, $item) {
+                    array_push($result, $item['adviser_1_name']);
+                    if($item['adviser_2_id'] > 0)
+                        array_push($result, $item['adviser_2_name']);
+                    return $result;
+                }, []))),
+                "teachers"  =>  join('/', array_unique(array_reduce($item['products'], function ($result, $item) {
+                    if($item['teacher_1_id'] > 0)
+                        array_push($result, $item['teacher_1_name']);
+                    if($item['teacher_2_id'] > 0)
+                        array_push($result, $item['teacher_2_name']);
+                    return $result;
+                }, []))),
+                "payments" => join(' ', array_unique(array_reduce($item['payments'], function ($result, $item) {
+                    array_push($result, '['.$item['channel_name'].']');
+                    return $result;
+                }, []))),
+                "stage_num" => array_reduce($item['payments'], function ($result, $item) {
+                    if($item['stage_num'] && $item['stage_num'] > $result) {
+                        $result = $item['stage_num'];
+                    }
+                    return $result;
+                }, 0),
+                'is_need_upload'    =>  $item['type'] == 1 && in_array(true, array_map(function ($product) {
+                        return $product['is_upload_numerology'] == 1 && $product['is_upload'] == 0;
+                    }, $item['products'])),
+            ];
+        }, $items), $res['total']];
     }
 
+
     /**
      * @param $params
      * @return array
@@ -539,14 +601,60 @@ class OrderService extends \app\BaseService
     public function fetchByCustomerId($params) {
         $res = $this->orderModel->fetchByCustomerId($params['customer_id'], $params['page'] ?? 1, $params['size'] ?? 20);
         $items = $res['data'];
-        foreach ($items as &$item) {
-            $item['is_need_upload'] = $item['type'] == 1 && in_array(true, array_map(function ($product) {
-                    return $product['is_upload_numerology'] == 1 && $product['is_upload'] == 0;
-                }, $item['products']));
-        }
-        return [$items, $res['total']];
+        return [array_map(function ($item) {
+            return [
+                "id" => $item['id'],
+                "no" => $item['no'],
+                "customer_id" => $item['customer_id'],
+                "customer_name" => $item['customer_name'],
+                "obj_names" => $item['obj_names'],
+                "rental_amount" => $item['rental_amount'],
+                "receivable_amount" => $item['receivable_amount'],
+                "receive_amount" => $item['receive_amount'],
+                "imposed_amount" => $item['imposed_amount'],
+                "product_amount" => $item['product_amount'],
+                "total_sales_tax" => $item['total_sales_tax'],
+                "service_charge_amount" => $item['service_charge_amount'],
+                "total_annual_fee" => $item['total_annual_fee'],
+                "zue_coin" => $item['zue_coin'],
+                "zue_coin_amount" => $item['zue_coin_amount'],
+                "type" => $item['type'],
+                "store_id" => $item['store_id'],
+                "advisor_ids" => $item['advisor_ids'],
+                "remarks" => $item['remarks'],
+                "create_time" => $item['create_time'],
+                "advisers"  => join('/',array_unique(array_reduce($item['products'], function ($result, $item) {
+                    array_push($result, $item['adviser_1_name']);
+                    if($item['adviser_2_id'] > 0)
+                        array_push($result, $item['adviser_2_name']);
+                    return $result;
+                }, []))),
+                "teachers"  =>  join('/', array_unique(array_reduce($item['products'], function ($result, $item) {
+                    if($item['teacher_1_id'] > 0)
+                        array_push($result, $item['teacher_1_name']);
+                    if($item['teacher_2_id'] > 0)
+                        array_push($result, $item['teacher_2_name']);
+                    return $result;
+                }, []))),
+                "stage_num" => array_reduce($item['payments'], function ($result, $item) {
+                    if($item['stage_num'] && $item['stage_num'] > $result) {
+                        $result = $item['stage_num'];
+                    }
+                    return $result;
+                }, 0),
+                'is_need_upload'    =>  $item['type'] == 1 && in_array(true, array_map(function ($product) {
+                        return $product['is_upload_numerology'] == 1 && $product['is_upload'] == 0;
+                    }, $item['products'])),
+            ];
+        }, $items), $res['total']];
     }
 
+    public function fetchOrderProducts($order_id, $page = 1, $size = 10) {
+        $res = $this->orderProductModel->fetchByOrderId($order_id, $page, $size);
+        return [$res->items(),$res->total()];
+    }
+
+
     public function upload_numerology($order_product_id, $report) {
         $order_product = $this->orderProductModel->findById($order_product_id);
         if (!$order_product) return $this->fail('订单商品不存在,无法上传命理报告!');
@@ -575,6 +683,81 @@ class OrderService extends \app\BaseService
         return $this->ok($annual_fee);
     }
 
+    public function fetchOrderByReturn($admin_id, $store_id, $no = null, $customer_name = null, $page = 1, $size = 10) {
+        $verify = AuthService::verify($admin_id, 10005);
+        $res = $this->orderModel->fetchOrderByReturn($admin_id, $store_id, $no, $customer_name, $page, $size, $verify);
+        return [$res->items(),$res->total()];
+    }
+
+    /**
+     * @param $admin_id
+     * @param $order_id
+     * @param array $order_product_ids
+     * @return \SResult
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function returnOrderProduct($admin_id, $order_id, array $order_product_ids) {
+//        $verify = AuthService::verify($admin_id, 10005);
+        $order = $this->orderModel->findById($order_id);
+        if (!$order) return $this->fail(lang("Order does not exist"));
+        $return_order_products = $this->orderProductModel->findByIds($order_product_ids)->toArray();
+        if (count($order_product_ids) != count($return_order_products)) return $this->fail(lang("The order item was incorrectly selected"));
+        $all_order_products = $this->orderProductModel->findByOrderId($order->id)->toArray();
+
+        array_reduce($return_order_products, function ($result, $item) {
+            $item[''];
+            return $result;
+        }, [
+            'total_real_price' => 0,
+            'total_annuity' => 0,
+            'service_charge'    => 0,
+            'total_sales_tax' => 0,
+            'total_zue_coin'  => 0,
+        ]);
+
+        Db::startTrans();
+        try {
+            if(count($return_order_products) == count($all_order_products)) {
+                Db::table('erp_order')->where('id', $order->id)->update(['is_delete' => 1]);
+                Db::table('erp_order_product')->where('order_id', $order->id)->update(['is_delete' => 1]);
+                Db::table('erp_order')->where('id', $order->id)->update(['is_delete' => 1]);
+            }
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->fail(lang($e->getMessage()));
+        }
+        return $this->ok(true);
+    }
+
+    public function findByOrderNo($admin_id, $order_no) {
+        $order = $this->orderModel->findByOrderNo($admin_id, $order_no);
+        if(!$order)
+            return $this->fail(lang("Order does not exist"));
+        return $this->ok($order);
+    }
+
+    public function exchange($admin_id, $order_id, $origin_order_product_ids, $append_product_ids) {
+        return $this->ok(true);
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 }
 
 

+ 40 - 5
app/common/model/OrderModel.php

@@ -83,11 +83,11 @@ class OrderModel extends BaseModel
 
     /**
      * @param $params
-     * @param bool $is_look_all
+     * @param bool $verify
      * @return array
      * @throws \think\db\exception\DbException
      */
-    public function search($params, $is_look_all = false) {
+    public function search($params, $verify = false) {
         $where = [
             ['is_delete', '=', 0],
             ['type', '=', $params['type']],
@@ -102,10 +102,10 @@ class OrderModel extends BaseModel
         if (isset($params['obj_name']) && strlen($params['obj_name']) > 0)
             array_push($where, ['obj_names', 'like', '%'.$params['obj_name'].'%']);
         $query = $this->where($where)
-            ->with(['products']);
+            ->with(['products', 'payments']);
         if (isset($params['advisor_id']))
             $query->where("FIND_IN_SET('{$params['advisor_id']}', advisor_ids)");
-        if (!$is_look_all) {
+        if (!$verify) {
             $query->where("FIND_IN_SET('{$params['admin_id']}', advisor_ids)");
         }
         return $query->order('update_time', 'desc')
@@ -136,7 +136,7 @@ class OrderModel extends BaseModel
             ['is_delete', '=', 0],
             ['customer_id', '=', $customer_id]
         ])
-            ->with(['products'])
+            ->with(['products', 'payments'])
             ->order('update_time', 'desc')
             ->page($page)
             ->paginate($size)
@@ -144,7 +144,42 @@ class OrderModel extends BaseModel
     }
 
 
+    public function fetchOrderByReturn($admin_id, $store_id, $no = null, $customer_name = null, $page = 1, $size = 10, $verify = false) {
+        $where = [
+            ['is_delete', '=', 0],
+            ['type', '=', 1],
+            ['store_id', '=', $store_id],
+        ];
+        if (isset($no) && strlen($no) > 0)
+            array_push($where, ['no', 'like', '%'.$no.'%']);
+        if ($customer_name)
+            array_push($where, ['customer_name', 'like', '%'.$customer_name.'%']);
+        $query = $this->where($where)
+            ->with(['products']);
+        if (!$verify) {
+            $query->where("FIND_IN_SET('{$admin_id}', advisor_ids)");
+        }
+        return $query->order('update_time', 'desc')
+            ->page($page)
+            ->paginate($size);
+    }
 
+    public function findByOrderNo($admin_id, $order_no, $verify = false) {
+        $where = [
+            ['is_delete', '=', 0],
+            ['type', '=', 1],
+        ];
+        if (isset($order_no) && strlen($order_no) > 0)
+            array_push($where, ['no', '=', $order_no]);
+//            array_push($where, ['no', 'like', '%'.$order_no.'%']);
+        $query = $this->where($where)
+            ->with(['products']);
+        if (!$verify) {
+            $query->where("FIND_IN_SET('{$admin_id}', advisor_ids)");
+        }
+        return $query->order('update_time', 'desc')
+            ->find();
+    }
 
 
 

+ 14 - 0
app/common/model/OrderProductModel.php

@@ -27,6 +27,20 @@ class OrderProductModel extends BaseModel
     }
 
     /**
+     * @param $o_id
+     * @param int $page
+     * @param int $size
+     * @return \think\Paginator
+     * @throws \think\db\exception\DbException
+     */
+    public function fetchByOrderId($o_id, $page = 1, $size = 10) {
+        return $this->where('is_delete', 0)
+            ->where('order_id',$o_id)
+            ->page($page)
+            ->paginate($size);
+    }
+
+    /**
      * @param $c_id
      * @param int $is_upload_numerology
      * @param int $is_upload