WIN-2308041133\Administrator 5 months ago
parent
commit
814066c836

+ 190 - 39
app/common/repositories/store/order/StoreOrderRepository.php

@@ -11,6 +11,8 @@
 // +----------------------------------------------------------------------
 namespace app\common\repositories\store\order;
 
+use app\common\model\store\order\StoreCart;
+use app\controller\api\server\StoreProduct;
 use think\facade\Cache;
 use app\common\dao\store\order\StoreOrderDao;
 use app\common\model\store\order\StoreGroupOrder;
@@ -134,8 +136,8 @@ class StoreOrderRepository extends BaseRepository
 
         // 生成支付配置
         $config = $service->pay($user);
-        if($authCode) {
-            if($config['paid'] == 1) {
+        if ($authCode) {
+            if ($config['paid'] == 1) {
                 $orders['transaction_id'] = $config['transaction_id'];
                 $this->paySuccess($groupOrder, 0, $orders);
             } else {
@@ -481,7 +483,7 @@ class StoreOrderRepository extends BaseRepository
                 }
                 $userMerchantRepository->updatePayTime($uid, $order->mer_id, $order->pay_price);
                 // 如果不是定时任务通知,则推送消息通知商家有新订单
-                if(!$isListen) {
+                if (!$isListen) {
                     SwooleTaskService::merchant('notice', [
                         'type' => 'new_order',
                         'data' => [
@@ -529,7 +531,7 @@ class StoreOrderRepository extends BaseRepository
         Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_PAY_SUCCESS', 'id' => $groupOrder->group_order_id]);
         Queue::push(SendSmsJob::class, ['tempId' => 'ADMIN_PAY_SUCCESS_CODE', 'id' => $groupOrder->group_order_id]);
 
-        if($groupOrder->uid) {
+        if ($groupOrder->uid) {
             Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->uid, 'type' => 'pay_money', 'inc' => $groupOrder->pay_price]);
             Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->uid, 'type' => 'pay_num', 'inc' => 1]);
             app()->make(UserBrokerageRepository::class)->incMemberValue($groupOrder->uid, 'member_pay_num', $groupOrder->group_order_id, $groupOrder->pay_price);
@@ -591,7 +593,7 @@ class StoreOrderRepository extends BaseRepository
     public function autoPrinter(int $orderId, int $merId, $print_type = 1)
     {
         // 检查商家是否启用了自动打印功能
-        $config = merchantConfig($merId, ['printing_auto_status','printing_status']);
+        $config = merchantConfig($merId, ['printing_auto_status', 'printing_status']);
         if ($config['printing_auto_status'] && $config['printing_status']) {
             try {
                 // 如果自动打印功能已启用,则尝试批量打印订单小票
@@ -823,7 +825,7 @@ class StoreOrderRepository extends BaseRepository
             return null;
         }
 
-        $config = merchantConfig($order['mer_id'],['mer_take_address','mer_take_day','mer_take_time','mer_take_phone']);
+        $config = merchantConfig($order['mer_id'], ['mer_take_address', 'mer_take_day', 'mer_take_time', 'mer_take_phone']);
         $order['merchant']['mer_take_address'] = $config['mer_take_address'];
         $order['merchant']['mer_take_day'] = $config['mer_take_day'];
         $order['merchant']['mer_take_time'] = $config['mer_take_time'];
@@ -842,8 +844,8 @@ class StoreOrderRepository extends BaseRepository
         if ($order->is_virtual == 4 && $order->is_cancel) {
             $reservation = $order['orderProduct'][0]['cart_info']['reservation'] ?? '';
             if ($reservation && $reservation['is_cancel_reservation'] == 1) {
-                $star = explode('-',$order['orderProduct'][0]['reservation_time_part']);
-                $cancelTime = strtotime($order['orderProduct'][0]['reservation_date'] . ' ' .$star[0]);
+                $star = explode('-', $order['orderProduct'][0]['reservation_time_part']);
+                $cancelTime = strtotime($order['orderProduct'][0]['reservation_date'] . ' ' . $star[0]);
                 $cancelTime = $cancelTime - time() >= $reservation['cancel_reservation_time'] * 3600;
                 $order['cancel_status'] = $cancelTime;
             }
@@ -887,12 +889,12 @@ class StoreOrderRepository extends BaseRepository
             throw new ValidateException('数据不存在');
 
         // 如果订单状态为已核销,则抛出异常提示订单已全部核销
-        if($data['product_type'] == 0 && $data['is_virtual'] == 4) {
-            if(!in_array($data['status'], [0,1,20])) {
+        if ($data['product_type'] == 0 && $data['is_virtual'] == 4) {
+            if (!in_array($data['status'], [0, 1, 20])) {
                 throw new ValidateException('该订单已全部核销');
             }
         } else {
-            if($data['status']) {
+            if ($data['status']) {
                 throw new ValidateException('该订单已全部核销');
             }
         }
@@ -1073,9 +1075,149 @@ class StoreOrderRepository extends BaseRepository
         });
         // 触发订单领取后的事件。
         event('order.take', compact('order'));
+//        订单赠送的分红额度和积分处理还是礼包购买数处理
+        $this->getOrderAward($order);
+    }
+
+//    订单收货赠送分红额度
+    public function getOrderAward($order)
+    {
+        $cartIdArray = explode(',', $order['cart_id']); // 使用逗号分割字符串
+        $product_id = StoreCart::where('id', $cartIdArray[0])->value('product_id');
+        $product_type = StoreProduct::where('id', $product_id)->value('type');
+        // 创建用户账单仓库实例
+        $make = app()->make(UserBillRepository::class);
+        $user = User::where('uid', $order['uid'])->find();
+        $award_range = $user['award_range'];
+        if ($product_type == 5) {  //节能油商品
+            $number = systemConfig('award_energy_saving_oil', 1);
+            if ($order['pay_price'] >= $number) {
+                $order_award_range = bcmul($order['pay_price'], 3, 2);
+                $after = bcadd($award_range, $order_award_range, 2);
+                $make->incBill($order['uid'], 'award_range', 'energy_saving_oil', [
+                    'number' => $order['pay_price'],
+                    'title' => '下单节能油获得分红额度',
+                    'balance' => $after,
+                    'status' => 1,
+                    'link_id' => $order['id'],
+                    'mark' => $user['nickname'] . '成功消费节能油商品' . floatval($order['pay_price']) . '元,奖励分红额度' . $order_award_range,
+                ]);
+            }
+        } elseif ($product_id == 6) {  //礼包商品
+            $number = systemConfig('award_energy_saving_oil', 1);
+            if ($order['pay_price'] >= $number) {
+                $order_award_range = bcmul($order['pay_price'], 3, 2);
+                $after = bcadd($award_range, $order_award_range, 2);
+                $make->incBill($order['uid'], 'award_range', 'award_gift_pack', [
+                    'number' => $order['pay_price'],
+                    'title' => '下单礼包获得分红额度',
+                    'balance' => $after,
+                    'status' => 1,
+                    'link_id' => $order['id'],
+                    'mark' => $user['nickname'] . '成功消费礼包商品' . floatval($order['pay_price']) . '元,奖励分红额度' . $order_award_range,
+                ]);
+            }
+//            礼包购买数
+            $this->pack_count($order['uid']);
+        } else {
+//            普通商品获取分红额度
+            $number = systemConfig('award_ordinary', 1);
+            if ($order['pay_price'] >= $number) {
+                $order_award_range = bcmul($order['pay_price'], 1, 2);
+                $after = bcadd($award_range, $order_award_range, 2);
+                $make->incBill($order['uid'], 'award_range', 'ordinary', [
+                    'number' => $order['pay_price'],
+                    'title' => '下单普通商品获得分红额度',
+                    'balance' => $after,
+                    'status' => 1,
+                    'link_id' => $order['id'],
+                    'mark' => $user['nickname'] . '成功消费普通商品' . floatval($order['pay_price']) . '元,奖励分红额度' . $order_award_range,
+                ]);
+                User::where('uid', $order['uid'])->update(['award_range' => $after]);
+            }
+//            普通商品获得分红积分
+            $number2 = systemConfig('award_integral_ordinary', 1);
+            $award_integral = $user['award_integral'];
+            if ($order['pay_price'] >= $number2) {
+                $order_award_range = bcmul($order['pay_price'], 0.2, 2);
+                $after2 = bcadd($award_integral, $order_award_range, 2);
+                $make->incBill($order['uid'], 'award_integral', 'ordinary_integral', [
+                    'number' => $order['pay_price'],
+                    'title' => '下单普通商品获得分红积分',
+                    'balance' => $after2,
+                    'status' => 1,
+                    'link_id' => $order['id'],
+                    'mark' => $user['nickname'] . '成功消费普通商品' . floatval($order['pay_price']) . '元,奖励分红积分' . $order_award_range,
+                ]);
+                User::where('uid', $order['uid'])->update(['ordinary_integral' => $after]);
+            }
+        }
+        //份额和积分变动时触发
+        $UserRepository = app()->make(UserRepository::class);
+        $UserRepository->checkAward($order['uid']);
+//        上级推荐奖励的分红积分
+        $this->getSpreadIntegral($order, $product_type,$user);
+    }
+
+//礼包购买数
+    public function pack_count($uid)
+    {
+//            增加礼包购买数
+        $pack_count = User::where('uid', $uid)->value('pack_count');
+        User::where('uid', $uid)->update(['pack_count' => bcadd($pack_count,1,0)]);
+    }
+//  上级推荐奖励的分红积分
+    public function getSpreadIntegral($order, $type,$user)
+    {
+//        $spread_uid = User::where('uid', $order['uid'])->value('spread_uid');
+        if ($user['spread_uid']!=0){
+            $make = app()->make(UserBillRepository::class);
+            switch ($type) {
+                case 0:  //普通商品
+                    break;
+                case 5:  //节能油商品
+                    $award_integral = User::where('uid',$user['spread_uid'])->value('award_integral');
+                    $order_award_range = bcmul($order['pay_price'], 0.06, 2);
+                    $after = bcadd($award_integral, $order_award_range, 2);
+                    $make->incBill($user['spread_uid'], 'award_integral', 'spread_oil_integral', [
+                        'number' => $order['pay_price'],
+                        'title' => '下级节能油订单获得分红积分',
+                        'balance' => $after,
+                        'status' => 1,
+                        'link_id' => $order['id'],
+                        'mark' => $user['nickname'] . '成功消费节能油商品' . floatval($order['pay_price']) . '元,奖励上级分红积分' . $order_award_range,
+                    ]);
+                    break;
+                case 6:  //礼包商品
+                    $remainder = bcmod($user['pack_count'], 3);  //取余
+                    $award_integral = User::where('uid',$user['spread_uid'])->value('award_integral');
+                    switch ($remainder){
+                        case 1:
+                            $order_award_range = bcmul($order['pay_price'], 0.2, 2);
+                            break;
+                            case 2:
+                                $order_award_range = bcmul($order['pay_price'], 0.3, 2);
+                            break;
+                            case 0:
+                                $order_award_range = bcmul($order['pay_price'], 0.5, 2);
+                            break;
+                    }
+                    $after = bcadd($award_integral, $order_award_range, 2);
+                    $make->incBill($user['spread_uid'], 'award_integral', 'spread_oil_integral', [
+                        'number' => $order['pay_price'],
+                        'title' => '下级礼包订单获得分红积分',
+                        'balance' => $after,
+                        'status' => 1,
+                        'link_id' => $order['id'],
+                        'mark' => $user['nickname'] . '成功消费礼包商品' . floatval($order['pay_price']) . '元,奖励上级分红积分' . $order_award_range,
+                    ]);
+                    break;
+                    continue;
+            }
+            User::where('uid', $user['spread_uid'])->update(['award_integral'=>$after]);
+        }
     }
 
-
     /**
      *  获取订单列表头部统计数据
      * @Author:Qinii
@@ -1537,12 +1679,12 @@ class StoreOrderRepository extends BaseRepository
         $config = merchantConfig($merId, ['mer_is_cargo', 'mer_dump_type', 'mer_config_siid']);
         // 遍历订单中的每个商品,组装商品详情,并计算商品总数和总重量。
         foreach ($orderInfo->orderProduct as $item) {
-            $cargo .= $item['cart_info']['product']['store_name']. ' ' . $item['cart_info']['productAttr']['sku'] . ' * ' . $item['product_num'] . $item['cart_info']['product']['unit_name'] . PHP_EOL;
+            $cargo .= $item['cart_info']['product']['store_name'] . ' ' . $item['cart_info']['productAttr']['sku'] . ' * ' . $item['product_num'] . $item['cart_info']['product']['unit_name'] . PHP_EOL;
             $count += $item['product_num'];
             $weight += $item['cart_info']['productAttr']['weight'];
         }
         if ($config['mer_is_cargo'] !== 0) {
-            $expData['cargo'] = mb_substr($cargo, 0, 19) .'等';
+            $expData['cargo'] = mb_substr($cargo, 0, 19) . '等';
         }
         // 组装发货数据,包括运输公司、收货人和发货人信息、模板ID等。
         $expData['com'] = $data['com'];
@@ -1660,7 +1802,7 @@ class StoreOrderRepository extends BaseRepository
         $num = $make->checkCrmebNum($merId, 'dump');
         $service = app()->make(CrmebServeServices::class, [$num ? 0 : $merId]);
         $result = $service->express()->dump($merId, $data);
-        Log::info('电子面单返回数据:'.var_export($result, true));
+        Log::info('电子面单返回数据:' . var_export($result, true));
         if (!merchantConfig($merId, 'mer_dump_type') && !isset($result['kuaidinum']))
             throw new ValidateException('打印失败');
         $delivery = [
@@ -1975,6 +2117,7 @@ class StoreOrderRepository extends BaseRepository
         // 返回生成的表单HTML代码
         return $form;
     }
+
     /**
      * 修改收货信息表单
      *
@@ -2154,7 +2297,7 @@ class StoreOrderRepository extends BaseRepository
 
         // 构造查询,根据商家状态添加相应的订单状态查询条件,并加载关联数据
         $query = $this->dao->search($where)
-          //  ->where('is_virtual','<>',4)
+            //  ->where('is_virtual','<>',4)
             ->where($this->getOrderType($status))
             ->with([
                 'orderProduct',
@@ -2396,7 +2539,7 @@ class StoreOrderRepository extends BaseRepository
             }
 
             if ($order->is_virtual == 4) {
-                $order->merchant['checkin'] = merchantConfig($order->mer_id,['enable_assigned', 'enable_checkin', 'checkin_radius', 'enable_trace', 'trace_form_id','enable_tostore_assigned','checkin_take_photo']);
+                $order->merchant['checkin'] = merchantConfig($order->mer_id, ['enable_assigned', 'enable_checkin', 'checkin_radius', 'enable_trace', 'trace_form_id', 'enable_tostore_assigned', 'checkin_take_photo']);
             }
             // 计算领取数量
             $order->takeOrderCount = count($order['takeOrderList']);
@@ -2599,7 +2742,7 @@ class StoreOrderRepository extends BaseRepository
      */
     public function batchPrinter(int $id, int $merId, $print_type = 1)
     {
-        $config = merchantConfig($merId, ['printing_auto_status','printing_status']);
+        $config = merchantConfig($merId, ['printing_auto_status', 'printing_status']);
         if (!$config['printing_status']) throw new ValidateException('打印功能未开启');
         // 根据订单ID获取订单及其产品和商家信息
         $order = $this->dao->getWhere(['order_id' => $id], '*', ['orderProduct', 'merchant' => function ($query) {
@@ -3436,7 +3579,7 @@ class StoreOrderRepository extends BaseRepository
 
     public function payConfig($id, $uid)
     {
-        $groupOrder =null;
+        $groupOrder = null;
         $user = app()->make(UserRepository::class)->get($uid);
         $config = systemConfig(['recharge_switch', 'yue_pay_status', 'pay_weixin_open', 'alipay_open', 'offline_switch', 'auto_close_order_timer', 'balance_func_status']);
         $timer = (int)($config['auto_close_order_timer'] ?: 15);
@@ -3481,7 +3624,9 @@ class StoreOrderRepository extends BaseRepository
     public function note($where, $limit = 20)
     {
         $key = 'note_' . json_encode($where);
-        if ($list = Cache::get($key)) { return $list; }
+        if ($list = Cache::get($key)) {
+            return $list;
+        }
         // 获取查询条件中的商家状态,后续用于构造查询条件
         $status = $where['status'];
         // 移除查询条件中的状态字段,避免直接在where中使用可能导致的混淆
@@ -3496,7 +3641,7 @@ class StoreOrderRepository extends BaseRepository
                 },
                 'finalOrder',
             ])->select();
-        foreach($list as &$v){
+        foreach ($list as &$v) {
             $v['coupon_price'] = bcsub($v['coupon_price'], $v['platform_coupon_price'], 2);
         }
         Cache::set($key, $list, 60);
@@ -3526,12 +3671,13 @@ class StoreOrderRepository extends BaseRepository
         if (!$order) {
             throw new ValidateException('订单不存在或未支付,请检查');
         }
-        if($order['staffs_id'] != 0){
+        if ($order['staffs_id'] != 0) {
             throw new ValidateException('订单已派单');
         }
 
         return $this->merDispatch($merId, $serviceId, $order, $data, self::ENABLE_ASSIGNED['DISPATCH']);
     }
+
     /**
      * 预约订单改派
      *
@@ -3548,6 +3694,7 @@ class StoreOrderRepository extends BaseRepository
 
         return $this->merDispatch($merId, $serviceId, $order, $data, self::ENABLE_ASSIGNED['DISPATCH']);
     }
+
     /**
      * 预约订单排单
      *
@@ -3562,7 +3709,7 @@ class StoreOrderRepository extends BaseRepository
         if (!$staffs) {
             throw new ValidateException('员工状态异常,请检查');
         }
-        foreach($order['refundOrder'] as $refundInfo){
+        foreach ($order['refundOrder'] as $refundInfo) {
             if ($refundInfo['status'] == 0) {
                 throw new ValidateException('该订单存在待处理的退款单,请先处理~');
             }
@@ -3572,7 +3719,7 @@ class StoreOrderRepository extends BaseRepository
         $order->enable_assigned = $enableAssigned;
         // 如果是上门订单并且打卡配置未开启,则将订单状态设置为服务中
         if ($order->order_type == 0) {
-            $config = merchantConfig($merId,['enable_checkin']);
+            $config = merchantConfig($merId, ['enable_checkin']);
             if (!$config['enable_checkin']) {
                 $order->status = OrderStatus::RESERVATION_ORDER_STATUS_INSERVICE;
             }
@@ -3602,6 +3749,7 @@ class StoreOrderRepository extends BaseRepository
             throw new ValidateException('失败:' . $e->getMessage());
         }
     }
+
     /**
      * 预约订单改期
      *
@@ -3618,13 +3766,13 @@ class StoreOrderRepository extends BaseRepository
         if (!$order) {
             throw new ValidateException('订单不存在或未支付,请检查');
         }
-        foreach($order['refundOrder'] as $refundInfo){
+        foreach ($order['refundOrder'] as $refundInfo) {
             if ($refundInfo['status'] == 0) {
                 throw new ValidateException('该订单存在待处理的退款单,请先处理~');
             }
         }
         // 判断订单状态是否为待派单或待服务
-        if(!in_array($order->status,[OrderStatus::ORDER_STATUS_PENDING_SHIPMENT, OrderStatus::ORDER_STATUS_PENDING_RECEIPT])){
+        if (!in_array($order->status, [OrderStatus::ORDER_STATUS_PENDING_SHIPMENT, OrderStatus::ORDER_STATUS_PENDING_RECEIPT])) {
             throw new ValidateException('订单状态异常,请检查');
         }
         // 订单
@@ -3641,7 +3789,7 @@ class StoreOrderRepository extends BaseRepository
         // 订单商品
         $orderProduct = $order->orderProduct[0];
         $orderProduct->reservation_date = $data['reservation_date'];
-        $orderProduct->reservation_time_part = $data['part_start'] .' - ' .$data['part_end'];
+        $orderProduct->reservation_time_part = $data['part_start'] . ' - ' . $data['part_end'];
 
         try {
             Db::transaction(function () use ($order, $groupOrder, $orderProduct, $serviceId) {
@@ -3669,6 +3817,7 @@ class StoreOrderRepository extends BaseRepository
             throw new ValidateException('失败:' . $e->getMessage());
         }
     }
+
     /**
      * 单独修改预约时间
      *
@@ -3684,19 +3833,19 @@ class StoreOrderRepository extends BaseRepository
         if (!$order) {
             throw new ValidateException('订单不存在或未支付,请检查');
         }
-        foreach($order['refundOrder'] as $refundInfo){
+        foreach ($order['refundOrder'] as $refundInfo) {
             if ($refundInfo['status'] == 0) {
                 throw new ValidateException('该订单存在待处理的退款单,请先处理~');
             }
         }
         // 判断订单状态是否为待派单或待服务
-        if(!in_array($order->status,[OrderStatus::ORDER_STATUS_PENDING_SHIPMENT, OrderStatus::ORDER_STATUS_PENDING_RECEIPT])){
+        if (!in_array($order->status, [OrderStatus::ORDER_STATUS_PENDING_SHIPMENT, OrderStatus::ORDER_STATUS_PENDING_RECEIPT])) {
             throw new ValidateException('订单状态异常,请检查');
         }
-        
+
         $orderProduct = $order->orderProduct[0];
         $orderProduct->reservation_date = $data['reservation_date'];
-        $orderProduct->reservation_time_part = $data['part_start'] .' - ' .$data['part_end'];
+        $orderProduct->reservation_time_part = $data['part_start'] . ' - ' . $data['part_end'];
 
 
         try {
@@ -3726,6 +3875,7 @@ class StoreOrderRepository extends BaseRepository
 
         return true;
     }
+
     /**
      * 预约订单核销
      *
@@ -3739,7 +3889,7 @@ class StoreOrderRepository extends BaseRepository
         if (!$order) {
             throw new ValidateException('订单不存在或未支付,请检查');
         }
-        foreach($order['refundOrder'] as $refundInfo){
+        foreach ($order['refundOrder'] as $refundInfo) {
             if ($refundInfo['status'] == 0) {
                 throw new ValidateException('该订单存在待处理的退款单,请先处理~');
             }
@@ -3798,8 +3948,8 @@ class StoreOrderRepository extends BaseRepository
         $cancel_status = false;
         $reservation = $order['orderProduct'][0]['cart_info']['reservation'] ?? '';
         if ($order->is_cancel && $reservation && $reservation['is_cancel_reservation'] == 1) {
-            $star = explode('-',$order['orderProduct'][0]['reservation_time_part']);
-            $cancelTime = strtotime($order['orderProduct'][0]['reservation_date'] . ' ' .$star[0]);
+            $star = explode('-', $order['orderProduct'][0]['reservation_time_part']);
+            $cancelTime = strtotime($order['orderProduct'][0]['reservation_date'] . ' ' . $star[0]);
             $cancelTime = $cancelTime - time() >= $reservation['cancel_reservation_time'] * 3600;
             $cancel_status = $cancelTime;
         }
@@ -3808,18 +3958,18 @@ class StoreOrderRepository extends BaseRepository
         $order->is_cancel = 0;
         if ($order->paid) {
             $repository = app()->make(StoreRefundOrderRepository::class);
-            $refund = $repository->createRefund($order,1,'用户取消预约订单');
+            $refund = $repository->createRefund($order, 1, '用户取消预约订单');
             $repository->agree($refund[$repository->getPk()], []);
         }
         $order->save();
     }
 
     public function getStaffOrders(int $merId, array $params)
-    {   
+    {
         $list = app()->make(StaffsRepository::class)->fetchMerAll($merId, $params['staff_id'])->toArray(); // 获取员工
         [$noStaffsOrder, $staffsOrder, $count] = $this->searchOrders($merId, $params); // 获取订单
         foreach ($list as &$staff) {
-            $staff['orders'] = array_values(array_filter($staffsOrder, function($order) use ($staff) { // 筛选属于当前员工的订单
+            $staff['orders'] = array_values(array_filter($staffsOrder, function ($order) use ($staff) { // 筛选属于当前员工的订单
                 return $order['staffs_id'] == $staff['staffs_id'];
             }));
         }
@@ -3827,6 +3977,7 @@ class StoreOrderRepository extends BaseRepository
 
         return compact('count', 'list');
     }
+
     /**
      * 未指派数据
      *
@@ -3834,7 +3985,7 @@ class StoreOrderRepository extends BaseRepository
      * @param array $noStaffsOrder
      * @return array
      */
-    protected function noAssigned(int $merId, array $noStaffsOrder) : array
+    protected function noAssigned(int $merId, array $noStaffsOrder): array
     {
         return ['staffs_id' => 0, 'mer_id' => $merId, 'phone' => '', 'name' => '未指派', 'orders' => $noStaffsOrder];
     }
@@ -3858,7 +4009,7 @@ class StoreOrderRepository extends BaseRepository
 
         $staffsOrder = []; // 已指派订单
         $noStaffsOrder = []; // 未指派订单
-        array_map(function($order) use (&$staffsOrder, &$noStaffsOrder) {
+        array_map(function ($order) use (&$staffsOrder, &$noStaffsOrder) {
             // 处理订单商品信息
             $orderProduct = array_shift($order['orderProduct']);
             $cartInfo = array_pop($orderProduct);

+ 12 - 0
app/common/repositories/user/UserBillRepository.php

@@ -87,6 +87,16 @@ class UserBillRepository extends BaseRepository
             'sys_members/member_reply_num' => '评价获得成长值',
             'sys_members/member_share_num' => '邀请获得成长值',
             'sys_members/member_community_num'  => '社区种草内容获得成长值',
+        ],
+        'award_range' =>[
+            'award/energy_saving_oil' =>'下单节能油获得分红额度',
+            'award/award_gift_pack' =>'下单礼包获得分红额度',
+            'award/ordinary' =>'下单普通商品获得分红额度',
+        ],
+        'award_integral' =>[
+            'award/spread_oil_integral' =>'下级节能油订单获得分红积分',
+            'award/spread_pack_integral' =>'下级礼包订单获得分红积分',
+            'award/ordinary_integral' =>'下单普通商品获得分红积分'
         ]
     ];
 
@@ -98,6 +108,8 @@ class UserBillRepository extends BaseRepository
     const CATEGORY_MER_INTEGRAL = 'mer_integral';
     const CATEGORY_MER_LOCK_MONEY = 'mer_lock_money';
     const CATEGORY_SYS_MEMBERS = 'sys_members';
+    const CATEGORY_AWARD_RANGE = 'award_range';
+    const CATEGORY_AWARD_INTEGRAL = 'award_integral';
 
     // 需要去重复的类型
     const TO_REPEAT_TYPE = ['member_community_num'];

+ 14 - 0
app/controller/admin/user/UserBill.php

@@ -95,4 +95,18 @@ class UserBill extends BaseController
         $where['category'] = [$this->repository::CATEGORY_BROKERAGE];
         return app('json')->success($this->repository->getList($where, $page, $limit));
     }
+//    分红积分记录
+    public function award_integral_list(){
+        [$page, $limit] = $this->getPage();
+        $where = $this->request->params(['keyword', 'date', 'type','uid','phone','real_name','nickname']);
+        $where['category'] = [$this->repository::CATEGORY_AWARD_INTEGRAL];
+        return app('json')->success($this->repository->getList($where, $page, $limit));
+    }
+    //    分红份额记录
+    public function award_range_list(){
+        [$page, $limit] = $this->getPage();
+        $where = $this->request->params(['keyword', 'date', 'type','uid','phone','real_name','nickname']);
+        $where['category'] = [$this->repository::CATEGORY_AWARD_RANGE];
+        return app('json')->success($this->repository->getList($where, $page, $limit));
+    }
 }

+ 30 - 1
app/controller/api/user/User.php

@@ -206,7 +206,36 @@ class User extends BaseController
         $where['category'] = 'brokerage';
         return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit));
     }
-
+    /**
+     * 分红份额明细
+     * @param UserBillRepository $billRepository
+     * @return mixed
+     * @author xaboy
+     * @day 2020/6/22
+     */
+    public function award_range_list(UserBillRepository $billRepository)
+    {
+        [$page, $limit] = $this->getPage();
+        return app('json')->success($billRepository->userList([
+            'award_range' => $this->request->param('type', 0),
+            'status' => 1,
+        ], $this->request->uid(), $page, $limit));
+    }
+    /**
+     * 分红积分明细
+     * @param UserBillRepository $billRepository
+     * @return mixed
+     * @author xaboy
+     * @day 2020/6/22
+     */
+    public function award_integral_list(UserBillRepository $billRepository)
+    {
+        [$page, $limit] = $this->getPage();
+        return app('json')->success($billRepository->userList([
+            'award_integral' => $this->request->param('type', 0),
+            'status' => 1,
+        ], $this->request->uid(), $page, $limit));
+    }
     /**
      * @return mixed
      * @throws DataNotFoundException

+ 3 - 0
route/admin/accounts.php

@@ -137,6 +137,9 @@ Route::group(function () {
             '_alias' => '导出',
         ]);
         Route::get('brokerage', '/brokerage_list');
+        Route::get('award_integral', '/award_integral_list');
+        Route::get('award_range', '/award_range_list');
+
     })->prefix('admin.user.UserBill')->option([
         '_path' => '/accounts/capital',
         '_auth' => true,

+ 4 - 1
route/api.php

@@ -203,7 +203,10 @@ Route::group('api/', function () {
             Route::get('fields/info', 'UserFields/info');
             Route::post('fields/save', 'UserFields/save');
             Route::delete('fields/delete', 'UserFields/delete');
-
+            //分红积分明细
+            Route::get('award/integral_list', 'User/award_integral_list');
+            //分红份额明细
+            Route::get('award/range_list', 'User/award_range_list');
         })->prefix('api.user.');
 
         //购物车