修改邀请记录 采购金额和销售金额的错误

This commit is contained in:
luofei 2024-03-09 16:33:35 +08:00
parent dfa7e6e2c9
commit 60221e78e4

View File

@ -566,23 +566,13 @@ class User extends BaseController
$userIds = UserModel::where('spread_uid', $this->user->uid)->page($page, $limit)->column('uid');
$query = Merchant::whereIn('uid', $userIds)->where('is_del', 0);
$merchants = $query->page($page, $limit)
->field('mer_id,mer_name,uid,real_name')
->field('mer_id,mer_name,uid,real_name,sale_amount,purchase_amount as buy_amount')
->select()->toArray();
$dao = new StoreOrderDao();
/** @var PresellOrderRepository $preSellDao */
$preSellRepo = app()->make(PresellOrderRepository::class);
$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 {