'待返佣', 2 => '已结算', 3 => '已失效']; return $desc[$value] ?? ''; } /** * @notes 结算时间获取器 * @param $value * @return string|null * @author Tab * @date 2021/7/28 9:21 */ public function getSettlementTimeAttr($value) { return $value ? date('Y-m-d H:i:s', $value) : ''; } /** * @notes 分销层级描述获取器 * @param $value * @return string * @author Tab * @date 2021/8/5 14:12 */ public function getLevelDescAttr($value) { $desc = ['自购佣金', '一级分佣', '二级分佣']; return $desc[$value] ?? ''; } /** * @notes 累计已入账佣金 * @param $userId * @return float * @author Tab * @date 2021/7/27 17:18 */ public static function getEarnings($userId) { return self::where([ 'user_id' => $userId, 'status' => DistributionOrderGoodsEnum::RETURNED ])->sum('earnings'); } /** * @notes 累计未返还佣金 * @param $userId * @return float * @author Tab * @date 2021/8/5 15:03 */ public static function getUnReturnedCommission($userId) { return self::where([ 'user_id' => $userId, 'status' => DistributionOrderGoodsEnum::UN_RETURNED ])->sum('earnings'); } /** * @notes 买家信息 * @param $userId * @return User|array|\think\Model * @author Tab * @date 2021/8/5 13:57 */ public static function getBueyer($userId) { return User::field('id,sn,nickname,avatar')->findOrEmpty($userId); } /** * @notes 订单用户信息搜索器 * @param $query * @param $value * @param $data * @author Tab * @date 2021/9/22 16:49 */ public function searchUserIdAttr($query, $value, $data) { if (!isset($data['user_info']) || empty($data['user_info'])) { return $query; } $ids = User::where('sn|nickname', 'like', '%' . $data['user_info'] . '%')->column('id'); return $query->where('o.user_id', 'in', $ids); } }