diff --git a/app/common/dao/store/coupon/StoreCouponUserDao.php b/app/common/dao/store/coupon/StoreCouponUserDao.php index 974f1807..0df3a5e7 100644 --- a/app/common/dao/store/coupon/StoreCouponUserDao.php +++ b/app/common/dao/store/coupon/StoreCouponUserDao.php @@ -306,11 +306,11 @@ class StoreCouponUserDao extends BaseDao $totalAmount = reset_index($totalAmount, 'coupon_type'); $result = [ [ - 'coupon_type' => 1, + 'coupon_type' => StoreCouponRepository::TYPE_STORE_COUPON, 'total_amount' => 0.00 ], [ - 'coupon_type' => 2, + 'coupon_type' => StoreCouponRepository::TYPE_PLATFORM_CARD, 'total_amount' => 0.00 ] ]; @@ -325,12 +325,36 @@ class StoreCouponUserDao extends BaseDao public function record($userId, $type, $page, $limit) { - + $totalAmount = StoreCouponUser::where('uid', $userId) + ->where('type', $type) + ->where('status', StoreCouponUserRepository::STATUS_UNUSED) + ->sum('coupon_price'); + $query = StoreCouponDetail::field('order_id,create_time,amount coupon_price,pay_price') + ->where('uid', $userId) + ->where('type', StoreCouponDetail::TYPE_INCOME); + $count = $query->count(); + $record = $query->page($page)->limit($limit)->select()->toArray(); + foreach ($record as &$item) { + $item['order_amount'] = bcadd($item['coupon_price'], $item['pay_price'], 2); + } + return ['total_amount' => $totalAmount, 'count' => $count, 'record' => $record]; } public function useRecord($userId, $type, $page, $limit) { - + $totalAmount = StoreCouponUser::where('uid', $userId) + ->where('type', $type) + ->where('status', StoreCouponUserRepository::STATUS_UNUSED) + ->sum('coupon_price'); + $query = StoreCouponDetail::field('order_id,create_time,amount coupon_price,pay_price') + ->where('uid', $userId) + ->where('type', StoreCouponDetail::TYPE_EXPEND); + $count = $query->count(); + $record = $query->page($page)->limit($limit)->select()->toArray(); + foreach ($record as &$item) { + $item['order_amount'] = bcadd($item['coupon_price'], $item['pay_price'], 2); + } + return ['total_amount' => $totalAmount, 'count' => $count, 'record' => $record]; } }