diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index e7242390..731b016b 100755 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -597,7 +597,7 @@ class StoreOrderRepository extends BaseRepository $where['activity_type'] = $product_type; if ($source == 103) { $where['activity_type'] = [0, 2, 98]; - $where['source'] = [0, 2, 103,105]; + $where['source'] = [0, 2, 103,105, 999]; } $noComment = $this->dao->search(['uid' => $uid, 'is_user' => $isUser])->where($this->getOrderType(4))->where($where)->where('StoreOrder.is_del', 0)->count(); $noPay = $this->dao->search(['uid' => $uid, 'is_user' => $isUser])->where($this->getOrderType(1))->whereRaw("(StoreOrder.paid=0 and StoreOrder.pay_type!=8) or (StoreOrder.paid=1 and StoreOrder.pay_type=8 and StoreOrder.status=2)")->where($where)->where('StoreOrder.is_del', 0)->count(); @@ -792,7 +792,7 @@ class StoreOrderRepository extends BaseRepository } $order->save(); - if ($order->uid != $order->merchant->uid) { + if ($order->uid != $order->merchant->uid && !$order->orderProduct[0]->product->isPlatformCard()) { $refundPrice = StoreRefundOrder::where('order_id', $order['order_id'])->where('status', '<>', -1)->sum('refund_price'); $money = bcsub($order->total_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2); $money = bcsub($money, $refundPrice, 2); diff --git a/app/controller/api/server/Store.php b/app/controller/api/server/Store.php index f64a2ba5..c5e81eac 100644 --- a/app/controller/api/server/Store.php +++ b/app/controller/api/server/Store.php @@ -97,6 +97,7 @@ class Store extends BaseController $saleTarget = $userConsumption['coupon_price']; $purchaseTarget = $userConsumption['coupon_price']; $merchant['purchase_amount'] = bcsub($userConsumption['coupon_price'], $userConsumption['balance'], 2); + $merchant['balance'] = $userConsumption['balance']; } } else { //增收销售补贴 @@ -108,17 +109,18 @@ class Store extends BaseController ->field('coupon_price,balance,status') ->find(); $subsidyAmount = $userConsumption['coupon_price'] ?? '0.00'; + $merchant['balance'] = $userConsumption['balance'] ?? '0.00'; foreach ($consumption['config'] as $k => $item) { if (empty($userConsumption) && in_array($merchant['type_id'], $item['type_id'])) { $saleTarget = $item['amount']; - $subsidyAmount = $saleTarget; + $subsidyAmount = $item['subsidy']; $purchaseTarget = bcmul($saleTarget, 0.5, 2); break; } if (!empty($userConsumption) && in_array($merchant['type_id'], $item['type_id'])) { $nextItem = $consumption['config'][$k + 1] ?? $item; $saleTarget = $nextItem['amount']; - $subsidyAmount = $saleTarget; + $subsidyAmount = $nextItem['subsidy']; $purchaseTarget = bcmul($saleTarget, 0.5, 2); break; } @@ -143,6 +145,7 @@ class Store extends BaseController 'spring_subsidy' => $saleTarget, 'spring_subsidy_amount' => $merchant['purchase_amount'], 'spring_subsidy_rate' => $springSubsidyRate, + 'balance' => $merchant['balance'] ?? '0.00', ]); } diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 946d49db..2becc0ca 100755 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -565,25 +565,31 @@ class User extends BaseController { [$page, $limit] = $this->getPage(); $userIds = UserModel::where('spread_uid', $this->user->uid)->column('uid'); - $query = Merchant::whereIn('uid', $userIds) - ->where('status', 1) - ->where('is_del', 0) - ->where('mer_state', 1); + $query = Merchant::whereIn('uid', $userIds)->where('is_del', 0); $count = $query->count(); - $result = $query->page($page, $limit) + $merchants = $query->page($page, $limit) ->field('mer_id,mer_name,uid,real_name') ->select()->toArray(); $dao = new StoreOrderDao(); /** @var PresellOrderRepository $preSellDao */ $preSellRepo = app()->make(PresellOrderRepository::class); - foreach ($result as &$item) { - $saleOrderQuery = $dao->search(['mer_id' => $item['mer_id']])->whereIn('StoreOrder.status', [0, 1, 2, 3, 9, 10])->where('paid', 1); - $saleOrderIds = $saleOrderQuery->column('order_id'); - $saleAmount1 = $saleOrderQuery->sum('StoreOrder.pay_price'); - $saleAmount2 = $preSellRepo->search(['paid' => 1, 'order_ids' => $saleOrderIds])->sum('pay_price'); - $item['sale_amount'] = bcadd($saleAmount1, $saleAmount2, 2); - $item['buy_amount'] = StoreOrderOther::where('uid', $item['uid'])->whereIn('status', [0, 1, 2, 3, 9, 10])->where('paid', 1)->sum('pay_price'); - $item['buy_amount'] = bcadd($item['buy_amount'], 0, 2); + $merchants = reset_index($merchants, 'uid'); + $result = []; + foreach ($userIds as $userId) { + if (isset($merchants[$userId])) { + $merchant = $merchants[$userId]; + $saleOrderQuery = $dao->search(['mer_id' => $merchant['mer_id']])->whereIn('StoreOrder.status', [0, 1, 2, 3, 9, 10])->where('paid', 1); + $saleOrderIds = $saleOrderQuery->column('order_id'); + $saleAmount1 = $saleOrderQuery->sum('StoreOrder.pay_price'); + $saleAmount2 = $preSellRepo->search(['paid' => 1, 'order_ids' => $saleOrderIds])->sum('pay_price'); + $merchant['sale_amount'] = bcadd($saleAmount1, $saleAmount2, 2); + $merchant['buy_amount'] = StoreOrderOther::where('uid', $merchant['uid'])->whereIn('status', [0, 1, 2, 3, 9, 10])->where('paid', 1)->sum('pay_price'); + $merchant['buy_amount'] = bcadd($merchant['buy_amount'], 0, 2); + $merchant['status'] = 1; + $result[] = $merchant; + } else { + $result[] = ['mer_id' => '', 'mer_name' => '', 'uid' => $userId, 'real_name' => '', 'sale_amount' => '0.00', 'buy_amount' => '0.00', 'status' => 0]; + } } return app('json')->success(['count' => $count, 'list' => $result]); }