// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\timer\model\groupon; use app\common\model\groupon\Robot as RobotModel; use app\common\library\helper; /** * 拼团机器人模型 * Class Robot * @package app\timer\model\groupon */ class Robot extends RobotModel { /** * 获取指定数量的随机机器人 * @param int $num * @param int $storeId * @return array */ public static function getRandomRobot(int $num, int $storeId): array { $allRobotIds = static::getRobotIds($storeId); if (empty($allRobotIds) || count($allRobotIds) < $num) { return []; } return helper::getArrayRand($allRobotIds, $num); } /** * 获取全部机器人ID集 * @param int $storeId * @return array */ private static function getRobotIds(int $storeId): array { return (new static)->cache('robotIds', 60 * 60, 'cache') ->where('store_id', '=', $storeId) ->where('is_delete', '=', 0) ->limit(500) ->column('robot_id'); } }