| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- /**
- * 邀请佣金变动流水 xhMainInviteFlow
- * 职责:佣金变动明细分页、格式化;配合 xhMainInvite.ableCommission 落 ableAfter 快照
- */
- namespace bizHd\shop\classes;
- use biz\shop\classes\ShopClass;
- use bizHd\base\classes\BaseClass;
- use common\components\dateUtil;
- use Yii;
- class MainInviteFlowClass extends BaseClass
- {
- public static $baseFile = '\bizHd\shop\models\MainInviteFlow';
- /** 邀请开通获佣 */
- const FLOW_TYPE_EARN = 1;
- /** 佣金存入中央钱包 */
- const FLOW_TYPE_DEPOSIT = 2;
- /** 退款扣回佣金 */
- const FLOW_TYPE_REFUND = 3;
- /** 关联 xhMainInviteCommission.id */
- const REF_TYPE_COMMISSION = 1;
- /** 关联 xhMainWalletChange.id */
- const REF_TYPE_WALLET_CHANGE = 2;
- /**
- * 佣金变动明细分页(默认近30天)
- */
- public static function getFlowList($mainId)
- {
- $where = self::buildFlowListWhere($mainId);
- $result = self::getList('*', $where, 'flowTime DESC,id DESC');
- $rows = $result['list'] ?? [];
- $list = [];
- foreach ($rows as $row) {
- $list[] = self::formatFlowListItem($row);
- }
- $result['list'] = $list;
- return $result;
- }
- /**
- * 列表查询条件:mainId + 时间筛选
- */
- protected static function buildFlowListWhere($mainId)
- {
- $where = ['mainId' => (int) $mainId];
- $get = Yii::$app->request->get();
- $searchTime = isset($get['searchTime']) ? trim((string) $get['searchTime']) : 'last30Days';
- $startTime = isset($get['startTime']) ? trim((string) $get['startTime']) : '';
- $endTime = isset($get['endTime']) ? trim((string) $get['endTime']) : '';
- if ($searchTime !== '' && $searchTime !== 'all') {
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
- if (!empty($period['startTime']) && !empty($period['endTime'])) {
- $where['flowTime'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- }
- return $where;
- }
- /**
- * 格式化单行,字段与 hdApp shopInviteCommissionList 一致
- */
- public static function formatFlowListItem($row)
- {
- $flowType = (int) ($row['flowType'] ?? 0);
- $lsShopId = (int) ($row['lsShopId'] ?? 0);
- $shop = [];
- if ($lsShopId > 0) {
- $shop = ShopClass::getById($lsShopId, false) ?: [];
- }
- $shopName = trim((string) ($row['inviteeShopName'] ?? ''));
- $mobile = trim((string) ($row['inviteeMobile'] ?? ''));
- $mobileMask = $mobile !== '' ? MainInviteCommissionClass::maskMobile($mobile) : '-';
- if ($flowType === self::FLOW_TYPE_DEPOSIT) {
- $orderSnLabel = '存入编号';
- $baseAmountLabel = '存余额金额';
- $recordType = 'deposit';
- $shopName = '存入钱包余额';
- $mobile = '';
- $mobileMask = '-';
- $shop = [];
- } else {
- $orderSnLabel = '会员订单号';
- $baseAmountLabel = '会员实付金额';
- $recordType = 'member';
- }
- $orderSn = trim((string) ($row['refSn'] ?? ''));
- $baseAmount = round((float) ($row['baseAmount'] ?? 0), 2);
- $rawAmount = round((float) ($row['amount'] ?? 0), 2);
- $commissionAmount = round(abs($rawAmount), 2);
- $commissionSign = $rawAmount < 0 ? -1 : 1;
- if ($flowType === self::FLOW_TYPE_REFUND) {
- $commissionSign = -1;
- }
- $createTime = trim((string) ($row['flowTime'] ?? ($row['addTime'] ?? '')));
- if ($createTime !== '' && strlen($createTime) === 10) {
- $createTime .= ' 00:00:00';
- }
- return [
- 'id' => $row['id'] ?? 0,
- 'shopName' => $shopName !== '' ? $shopName : '-',
- 'shopImg' => self::resolveShopImg($shop),
- 'mobile' => $mobile !== '' ? $mobile : '-',
- 'mobileMask' => $mobileMask,
- 'orderSnLabel' => $orderSnLabel,
- 'orderSn' => $orderSn !== '' ? $orderSn : '-',
- 'baseAmountLabel' => $baseAmountLabel,
- 'baseAmount' => $baseAmount,
- 'createTime' => $createTime !== '' ? $createTime : '-',
- 'commissionAmount' => $commissionAmount,
- 'commissionSign' => $commissionSign,
- 'recordType' => $recordType,
- 'flowType' => $flowType,
- 'ableAfter' => round((float) ($row['ableAfter'] ?? 0), 2),
- ];
- }
- protected static function resolveShopImg($shop)
- {
- $avatar = is_array($shop) ? ($shop['avatar'] ?? '') : '';
- if (empty($avatar)) {
- return '';
- }
- if (strpos($avatar, 'http') === 0) {
- return $avatar;
- }
- $host = Yii::$app->params['hdImgHost'] ?? '';
- return $host . $avatar;
- }
- }
|